xrootd
XrdClXRootDTransport.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // Copyright (c) 2011-2014 by European Organization for Nuclear Research (CERN)
3 // Author: Lukasz Janyst <ljanyst@cern.ch>
4 //------------------------------------------------------------------------------
5 // This file is part of the XRootD software suite.
6 //
7 // XRootD is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Lesser General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // XRootD is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with XRootD. If not, see <http://www.gnu.org/licenses/>.
19 //
20 // In applying this licence, CERN does not waive the privileges and immunities
21 // granted to it by virtue of its status as an Intergovernmental Organization
22 // or submit itself to any jurisdiction.
23 //------------------------------------------------------------------------------
24 
25 #ifndef __XRD_CL_XROOTD_TRANSPORT_HH__
26 #define __XRD_CL_XROOTD_TRANSPORT_HH__
27 
28 #include "XrdCl/XrdClPostMaster.hh"
29 #include "XProtocol/XProtocol.hh"
31 #include "XrdOuc/XrdOucEnv.hh"
32 
33 class XrdSysPlugin;
34 class XrdSecProtect;
35 
36 namespace XrdCl
37 {
38  class Tls;
39  class Socket;
40  struct XRootDChannelInfo;
41  struct PluginUnloadHandler;
42 
43  //----------------------------------------------------------------------------
45  //----------------------------------------------------------------------------
46  struct XRootDQuery
47  {
48  static const uint16_t ServerFlags = 1002;
49  static const uint16_t ProtocolVersion = 1003;
50  static const uint16_t IsEncrypted = 1004;
51  };
52 
53  //----------------------------------------------------------------------------
55  //----------------------------------------------------------------------------
57  {
58  public:
59  //------------------------------------------------------------------------
61  //------------------------------------------------------------------------
63 
64  //------------------------------------------------------------------------
66  //------------------------------------------------------------------------
68 
69  //------------------------------------------------------------------------
80  //------------------------------------------------------------------------
81  virtual XRootDStatus GetHeader( Message *message, Socket *socket );
82 
83  //------------------------------------------------------------------------
92  //------------------------------------------------------------------------
93  virtual XRootDStatus GetBody( Message *message, Socket *socket );
94 
95  //------------------------------------------------------------------------
97  //------------------------------------------------------------------------
98  virtual void InitializeChannel( const URL &url,
99  AnyObject &channelData );
100 
101  //------------------------------------------------------------------------
103  //------------------------------------------------------------------------
104  virtual void FinalizeChannel( AnyObject &channelData );
105 
106  //------------------------------------------------------------------------
108  //------------------------------------------------------------------------
109  virtual Status HandShake( HandShakeData *handShakeData,
110  AnyObject &channelData );
111 
112  //------------------------------------------------------------------------
113  // @return true if handshake has been done and stream is connected,
114  // false otherwise
115  //------------------------------------------------------------------------
116  virtual bool HandShakeDone( HandShakeData *handShakeData,
117  AnyObject &channelData );
118 
119  //------------------------------------------------------------------------
121  //------------------------------------------------------------------------
122  virtual bool IsStreamTTLElapsed( time_t time,
123  AnyObject &channelData );
124 
125  //------------------------------------------------------------------------
128  //------------------------------------------------------------------------
129  virtual Status IsStreamBroken( time_t inactiveTime,
130  AnyObject &channelData );
131 
132  //------------------------------------------------------------------------
138  //------------------------------------------------------------------------
139  virtual PathID Multiplex( Message *msg,
140  AnyObject &channelData,
141  PathID *hint = 0 );
142 
143  //------------------------------------------------------------------------
149  //------------------------------------------------------------------------
151  AnyObject &channelData,
152  PathID *hint = 0 );
153 
154  //------------------------------------------------------------------------
156  //------------------------------------------------------------------------
157  virtual uint16_t SubStreamNumber( AnyObject &channelData );
158 
159  //------------------------------------------------------------------------
162  //------------------------------------------------------------------------
163  virtual bool NeedControlConnection()
164  {
165  return true;
166  }
167 
168  //------------------------------------------------------------------------
170  //------------------------------------------------------------------------
172 
173  //------------------------------------------------------------------------
176  //------------------------------------------------------------------------
178 
179  //------------------------------------------------------------------------
181  //------------------------------------------------------------------------
182  static Status UnMarshallBody( Message *msg, uint16_t reqType );
183 
184  //------------------------------------------------------------------------
186  //------------------------------------------------------------------------
187  static Status UnMarshalStatusBody( Message *msg, uint16_t reqType );
188 
189  //------------------------------------------------------------------------
191  //------------------------------------------------------------------------
192  static void UnMarshallHeader( Message *msg );
193 
194  //------------------------------------------------------------------------
196  //------------------------------------------------------------------------
197  static void LogErrorResponse( const Message &msg );
198 
199  //------------------------------------------------------------------------
201  //------------------------------------------------------------------------
202  static uint16_t NbConnectedStrm( AnyObject &channelData );
203 
204  //------------------------------------------------------------------------
206  //------------------------------------------------------------------------
207  virtual void Disconnect( AnyObject &channelData,
208  uint16_t subStreamId );
209 
210  //------------------------------------------------------------------------
212  //------------------------------------------------------------------------
213  virtual Status Query( uint16_t query,
214  AnyObject &result,
215  AnyObject &channelData );
216 
217  //------------------------------------------------------------------------
219  //------------------------------------------------------------------------
220  static void SetDescription( Message *msg );
221 
222  //------------------------------------------------------------------------
224  //------------------------------------------------------------------------
225  virtual uint32_t MessageReceived( Message *msg,
226  uint16_t subStream,
227  AnyObject &channelData );
228 
229  //------------------------------------------------------------------------
231  //------------------------------------------------------------------------
232  virtual void MessageSent( Message *msg,
233  uint16_t subStream,
234  uint32_t bytesSent,
235  AnyObject &channelData );
236 
237  //------------------------------------------------------------------------
239  //------------------------------------------------------------------------
240  virtual Status GetSignature( Message *toSign, Message *&sign,
241  AnyObject &channelData );
242 
243  //------------------------------------------------------------------------
245  //------------------------------------------------------------------------
246  virtual Status GetSignature( Message *toSign, Message *&sign,
247  XRootDChannelInfo *info );
248 
249  //------------------------------------------------------------------------
251  //------------------------------------------------------------------------
252  virtual void WaitBeforeExit();
253 
254  //------------------------------------------------------------------------
256  //------------------------------------------------------------------------
257  virtual bool NeedEncryption( HandShakeData *handShakeData,
258  AnyObject &channelData );
259 
260  private:
261 
262  //------------------------------------------------------------------------
263  // Hand shake the main stream
264  //------------------------------------------------------------------------
266  AnyObject &channelData );
267 
268  //------------------------------------------------------------------------
269  // Hand shake a parallel stream
270  //------------------------------------------------------------------------
272  AnyObject &channelData );
273 
274  //------------------------------------------------------------------------
275  // Generate the message to be sent as an initial handshake
276  // (handshake + kXR_protocol)
277  //------------------------------------------------------------------------
279  XRootDChannelInfo *info,
280  kXR_char expect );
281 
282  //------------------------------------------------------------------------
283  // Generate the protocol message
284  //------------------------------------------------------------------------
286  XRootDChannelInfo *info,
287  kXR_char expect );
288 
289  //------------------------------------------------------------------------
290  // Initialize protocol request
291  //------------------------------------------------------------------------
293  XRootDChannelInfo *info,
294  kXR_char expect );
295 
296  //------------------------------------------------------------------------
297  // Process the server initial handshake response
298  //------------------------------------------------------------------------
300  XRootDChannelInfo *info );
301 
302  //-----------------------------------------------------------------------
303  // Process the protocol response
304  //------------------------------------------------------------------------
306  XRootDChannelInfo *info );
307 
308  //------------------------------------------------------------------------
309  // Generate the bind message
310  //------------------------------------------------------------------------
312  XRootDChannelInfo *info );
313 
314  //------------------------------------------------------------------------
315  // Generate the bind message
316  //------------------------------------------------------------------------
318  XRootDChannelInfo *info );
319 
320  //------------------------------------------------------------------------
321  // Generate the login message
322  //------------------------------------------------------------------------
324  XRootDChannelInfo *info );
325 
326  //------------------------------------------------------------------------
327  // Process the login response
328  //------------------------------------------------------------------------
330  XRootDChannelInfo *info );
331 
332  //------------------------------------------------------------------------
333  // Do the authentication
334  //------------------------------------------------------------------------
336  XRootDChannelInfo *info );
337 
338  //------------------------------------------------------------------------
339  // Get the initial credentials using one of the protocols
340  //------------------------------------------------------------------------
342  HandShakeData *hsData,
343  XRootDChannelInfo *info );
344 
345  //------------------------------------------------------------------------
346  // Clean up the data structures created for the authentication process
347  //------------------------------------------------------------------------
348  Status CleanUpAuthentication( XRootDChannelInfo *info );
349 
350  //------------------------------------------------------------------------
351  // Clean up the data structures created for the protection purposes
352  //------------------------------------------------------------------------
353  Status CleanUpProtection( XRootDChannelInfo *info );
354 
355  //------------------------------------------------------------------------
356  // Get the authentication function handle
357  //------------------------------------------------------------------------
359 
360  //------------------------------------------------------------------------
361  // Generate the end session message
362  //------------------------------------------------------------------------
364  XRootDChannelInfo *info );
365 
366  //------------------------------------------------------------------------
367  // Process the end session response
368  //------------------------------------------------------------------------
370  XRootDChannelInfo *info );
371 
372  //------------------------------------------------------------------------
373  // Get a string representation of the server flags
374  //------------------------------------------------------------------------
375  static std::string ServerFlagsToStr( uint32_t flags );
376 
377  //------------------------------------------------------------------------
378  // Get a string representation of file handle
379  //------------------------------------------------------------------------
380  static std::string FileHandleToStr( const unsigned char handle[4] );
381 
382  friend struct PluginUnloadHandler;
384  };
385 }
386 
387 #endif // __XRD_CL_XROOTD_TRANSPORT_HANDLER_HH__
XrdCl::XRootDTransport::UnMarshalStatusBody
static Status UnMarshalStatusBody(Message *msg, uint16_t reqType)
Unmarshall the body of the status response.
XrdSecInterface.hh
XrdCl::Socket
A network socket.
Definition: XrdClSocket.hh:42
XrdCl::XRootDTransport::LogErrorResponse
static void LogErrorResponse(const Message &msg)
Log server error response.
XrdSecGetProt_t
XrdSecProtocol *(* XrdSecGetProt_t)(const char *, XrdNetAddrInfo &, XrdSecParameters &, XrdOucErrInfo *)
Typedef to simplify the encoding of methods returning XrdSecProtocol.
Definition: XrdSecInterface.hh:481
XrdCl::XRootDTransport::ProcessLogInResp
Status ProcessLogInResp(HandShakeData *hsData, XRootDChannelInfo *info)
XrdCl::XRootDTransport::CleanUpAuthentication
Status CleanUpAuthentication(XRootDChannelInfo *info)
XrdCl::XRootDTransport
XRootD transport handler.
Definition: XrdClXRootDTransport.hh:57
XrdCl::PathID
Definition: XrdClPostMasterInterfaces.hh:297
XrdCl::XRootDTransport::SetDescription
static void SetDescription(Message *msg)
Get the description of a message.
XrdCl::XRootDTransport::~XRootDTransport
~XRootDTransport()
Destructor.
XrdCl::XRootDTransport::FinalizeChannel
virtual void FinalizeChannel(AnyObject &channelData)
Finalize channel.
XrdCl::XRootDTransport::MarshallRequest
static Status MarshallRequest(Message *msg)
Marshal the outgoing message.
XrdCl::XRootDTransport::NbConnectedStrm
static uint16_t NbConnectedStrm(AnyObject &channelData)
Number of currently connected data streams.
XrdCl::XRootDTransport::MessageSent
virtual void MessageSent(Message *msg, uint16_t subStream, uint32_t bytesSent, AnyObject &channelData)
Notify the transport about a message having been sent.
XrdCl::XRootDTransport::PluginUnloadHandler
friend struct PluginUnloadHandler
Definition: XrdClXRootDTransport.hh:382
kXR_char
unsigned char kXR_char
Definition: XPtypes.hh:65
XrdCl::XRootDQuery
XRootD related protocol queries.
Definition: XrdClXRootDTransport.hh:47
XrdCl::XRootDTransport::GetBody
virtual XRootDStatus GetBody(Message *message, Socket *socket)
XrdCl::XRootDTransport::CleanUpProtection
Status CleanUpProtection(XRootDChannelInfo *info)
XrdCl::XRootDTransport::DoAuthentication
Status DoAuthentication(HandShakeData *hsData, XRootDChannelInfo *info)
XrdCl::XRootDTransport::NeedControlConnection
virtual bool NeedControlConnection()
Definition: XrdClXRootDTransport.hh:163
XrdCl::XRootDTransport::GetCredentials
Status GetCredentials(XrdSecCredentials *&credentials, HandShakeData *hsData, XRootDChannelInfo *info)
XrdCl::Message
The message representation used throughout the system.
Definition: XrdClMessage.hh:30
XProtocol.hh
XrdCl::XRootDTransport::IsStreamBroken
virtual Status IsStreamBroken(time_t inactiveTime, AnyObject &channelData)
XrdCl::XRootDTransport::pSecUnloadHandler
PluginUnloadHandler * pSecUnloadHandler
Definition: XrdClXRootDTransport.hh:383
XrdCl::XRootDTransport::IsStreamTTLElapsed
virtual bool IsStreamTTLElapsed(time_t time, AnyObject &channelData)
Check if the stream should be disconnected.
XrdCl::XRootDStatus
Request status.
Definition: XrdClXRootDResponses.hh:215
XrdCl::XRootDQuery::ServerFlags
static const uint16_t ServerFlags
returns server flags
Definition: XrdClXRootDTransport.hh:48
XrdCl::XRootDTransport::GenerateInitialHSProtocol
Message * GenerateInitialHSProtocol(HandShakeData *hsData, XRootDChannelInfo *info, kXR_char expect)
XrdCl::XRootDTransport::HandShakeParallel
Status HandShakeParallel(HandShakeData *handShakeData, AnyObject &channelData)
XrdCl::XRootDTransport::Query
virtual Status Query(uint16_t query, AnyObject &result, AnyObject &channelData)
Query the channel.
XrdCl::HandShakeData
Data structure that carries the handshake information.
Definition: XrdClPostMasterInterfaces.hh:272
XrdCl::XRootDTransport::ProcessEndSessionResp
Status ProcessEndSessionResp(HandShakeData *hsData, XRootDChannelInfo *info)
XrdCl::XRootDTransport::InitializeChannel
virtual void InitializeChannel(const URL &url, AnyObject &channelData)
Initialize channel.
XrdCl::XRootDTransport::UnMarshallHeader
static void UnMarshallHeader(Message *msg)
Unmarshall the header incoming message.
XrdCl::XRootDTransport::GenerateBind
Message * GenerateBind(HandShakeData *hsData, XRootDChannelInfo *info)
XrdCl::XRootDQuery::IsEncrypted
static const uint16_t IsEncrypted
returns true if the channel is encrypted
Definition: XrdClXRootDTransport.hh:50
XrdSysPlugin
Definition: XrdSysPlugin.hh:53
XrdCl::XRootDTransport::HandShakeDone
virtual bool HandShakeDone(HandShakeData *handShakeData, AnyObject &channelData)
XrdCl::XRootDTransport::GetSignature
virtual Status GetSignature(Message *toSign, Message *&sign, XRootDChannelInfo *info)
Get signature for given message.
XrdCl::XRootDTransport::SubStreamNumber
virtual uint16_t SubStreamNumber(AnyObject &channelData)
Return a number of substreams per stream that should be created.
XrdCl::XRootDTransport::WaitBeforeExit
virtual void WaitBeforeExit()
Wait until the program can safely exit.
XrdSecBuffer
Generic structure to pass security information back and forth.
Definition: XrdSecInterface.hh:51
XrdCl::XRootDTransport::MultiplexSubStream
virtual PathID MultiplexSubStream(Message *msg, AnyObject &channelData, PathID *hint=0)
XrdCl::XRootDTransport::GetHeader
virtual XRootDStatus GetHeader(Message *message, Socket *socket)
XrdSecProtect
Definition: XrdSecProtect.hh:56
XrdCl::XRootDTransport::ProcessServerHS
Status ProcessServerHS(HandShakeData *hsData, XRootDChannelInfo *info)
XrdCl
Definition: XrdClAnyObject.hh:26
XrdCl::XRootDTransport::XRootDTransport
XRootDTransport()
Constructor.
XrdCl::XRootDTransport::FileHandleToStr
static std::string FileHandleToStr(const unsigned char handle[4])
XrdCl::XRootDTransport::GenerateLogIn
Message * GenerateLogIn(HandShakeData *hsData, XRootDChannelInfo *info)
XrdCl::XRootDTransport::Disconnect
virtual void Disconnect(AnyObject &channelData, uint16_t subStreamId)
The stream has been disconnected, do the cleanups.
XrdCl::XRootDTransport::UnMarshallBody
static Status UnMarshallBody(Message *msg, uint16_t reqType)
Unmarshall the body of the incoming message.
XrdCl::XRootDTransport::ProcessBindResp
Status ProcessBindResp(HandShakeData *hsData, XRootDChannelInfo *info)
XrdCl::XRootDTransport::ServerFlagsToStr
static std::string ServerFlagsToStr(uint32_t flags)
ClientProtocolRequest
Definition: XProtocol.hh:534
XrdCl::XRootDTransport::Multiplex
virtual PathID Multiplex(Message *msg, AnyObject &channelData, PathID *hint=0)
XrdCl::XRootDTransport::HandShakeMain
Status HandShakeMain(HandShakeData *handShakeData, AnyObject &channelData)
XrdCl::XRootDTransport::GenerateProtocol
Message * GenerateProtocol(HandShakeData *hsData, XRootDChannelInfo *info, kXR_char expect)
XrdCl::XRootDQuery::ProtocolVersion
static const uint16_t ProtocolVersion
returns the protocol version
Definition: XrdClXRootDTransport.hh:49
XrdCl::Status
Procedure execution status.
Definition: XrdClStatus.hh:111
XrdCl::URL
URL representation.
Definition: XrdClURL.hh:31
XrdCl::XRootDTransport::ProcessProtocolResp
Status ProcessProtocolResp(HandShakeData *hsData, XRootDChannelInfo *info)
XrdCl::XRootDTransport::MessageReceived
virtual uint32_t MessageReceived(Message *msg, uint16_t subStream, AnyObject &channelData)
Check if the message invokes a stream action.
XrdCl::XRootDTransport::GetAuthHandler
XrdSecGetProt_t GetAuthHandler()
XrdClPostMaster.hh
XrdCl::XRootDTransport::UnMarshallRequest
static Status UnMarshallRequest(Message *msg)
XrdCl::XRootDTransport::HandShake
virtual Status HandShake(HandShakeData *handShakeData, AnyObject &channelData)
HandShake.
XrdCl::XRootDTransport::GenerateEndSession
Message * GenerateEndSession(HandShakeData *hsData, XRootDChannelInfo *info)
XrdCl::TransportHandler
Perform the handshake and the authentication for each physical stream.
Definition: XrdClPostMasterInterfaces.hh:317
XrdCl::XRootDTransport::GetSignature
virtual Status GetSignature(Message *toSign, Message *&sign, AnyObject &channelData)
Get signature for given message.
XrdCl::AnyObject
Definition: XrdClAnyObject.hh:33
XrdCl::XRootDTransport::InitProtocolReq
void InitProtocolReq(ClientProtocolRequest *request, XRootDChannelInfo *info, kXR_char expect)
XrdOucEnv.hh
XrdCl::XRootDTransport::NeedEncryption
virtual bool NeedEncryption(HandShakeData *handShakeData, AnyObject &channelData)