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  //------------------------------------------------------------------------
150  virtual PathID MultiplexSubStream( Message *msg,
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  //------------------------------------------------------------------------
171  static Status MarshallRequest( Message *msg );
172 
173  //------------------------------------------------------------------------
176  //------------------------------------------------------------------------
177  static Status UnMarshallRequest( Message *msg );
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  //------------------------------------------------------------------------
265  Status HandShakeMain( HandShakeData *handShakeData,
266  AnyObject &channelData );
267 
268  //------------------------------------------------------------------------
269  // Hand shake a parallel stream
270  //------------------------------------------------------------------------
271  Status HandShakeParallel( HandShakeData *handShakeData,
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  //------------------------------------------------------------------------
292  void InitProtocolReq( ClientProtocolRequest *request,
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  //------------------------------------------------------------------------
341  Status GetCredentials( XrdSecCredentials *&credentials,
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__
unsigned char kXR_char
Definition: XPtypes.hh:65
virtual uint32_t MessageReceived(Message *msg, uint16_t subStream, AnyObject &channelData)
Check if the message invokes a stream action.
static std::string FileHandleToStr(const unsigned char handle[4])
Definition: XrdClAnyObject.hh:32
static uint16_t NbConnectedStrm(AnyObject &channelData)
Number of currently connected data streams.
Message * GenerateProtocol(HandShakeData *hsData, XRootDChannelInfo *info, kXR_char expect)
The message representation used throughout the system.
Definition: XrdClMessage.hh:29
static Status UnMarshalStatusBody(Message *msg, uint16_t reqType)
Unmarshall the body of the status response.
Status ProcessServerHS(HandShakeData *hsData, XRootDChannelInfo *info)
XRootD related protocol queries.
Definition: XrdClXRootDTransport.hh:46
Status CleanUpProtection(XRootDChannelInfo *info)
XrdSecProtocol *(* XrdSecGetProt_t)(const char *, XrdNetAddrInfo &, XrdSecParameters &, XrdOucErrInfo *)
Typedef to simplify the encoding of methods returning XrdSecProtocol.
Definition: XrdSecInterface.hh:481
Definition: XrdClPostMasterInterfaces.hh:296
~XRootDTransport()
Destructor.
virtual PathID Multiplex(Message *msg, AnyObject &channelData, PathID *hint=0)
Status DoAuthentication(HandShakeData *hsData, XRootDChannelInfo *info)
virtual Status Query(uint16_t query, AnyObject &result, AnyObject &channelData)
Query the channel.
Definition: XProtocol.hh:549
static std::string ServerFlagsToStr(uint32_t flags)
virtual XRootDStatus GetBody(Message *message, Socket *socket)
Status ProcessProtocolResp(HandShakeData *hsData, XRootDChannelInfo *info)
Status HandShakeParallel(HandShakeData *handShakeData, AnyObject &channelData)
Definition: XrdSecProtect.hh:55
Procedure execution status.
Definition: XrdClStatus.hh:112
Status GetCredentials(XrdSecCredentials *&credentials, HandShakeData *hsData, XRootDChannelInfo *info)
PluginUnloadHandler * pSecUnloadHandler
Definition: XrdClXRootDTransport.hh:383
virtual void Disconnect(AnyObject &channelData, uint16_t subStreamId)
The stream has been disconnected, do the cleanups.
static void UnMarshallHeader(Message *msg)
Unmarshall the header incoming message.
static Status UnMarshallBody(Message *msg, uint16_t reqType)
Unmarshall the body of the incoming message.
XRootDTransport()
Constructor.
virtual PathID MultiplexSubStream(Message *msg, AnyObject &channelData, PathID *hint=0)
Definition: XrdSysPlugin.hh:52
friend struct PluginUnloadHandler
Definition: XrdClXRootDTransport.hh:382
Message * GenerateInitialHSProtocol(HandShakeData *hsData, XRootDChannelInfo *info, kXR_char expect)
static const uint16_t ProtocolVersion
returns the protocol version
Definition: XrdClXRootDTransport.hh:49
virtual void WaitBeforeExit()
Wait until the program can safely exit.
Data structure that carries the handshake information.
Definition: XrdClPostMasterInterfaces.hh:271
Message * GenerateBind(HandShakeData *hsData, XRootDChannelInfo *info)
XrdSecGetProt_t GetAuthHandler()
static Status MarshallRequest(Message *msg)
Marshal the outgoing message.
Perform the handshake and the authentication for each physical stream.
Definition: XrdClPostMasterInterfaces.hh:316
static void SetDescription(Message *msg)
Get the description of a message.
virtual XRootDStatus GetHeader(Message *message, Socket *socket)
Request status.
Definition: XrdClXRootDResponses.hh:218
Definition: XrdClAnyObject.hh:25
Status HandShakeMain(HandShakeData *handShakeData, AnyObject &channelData)
virtual bool NeedControlConnection()
Definition: XrdClXRootDTransport.hh:163
virtual void FinalizeChannel(AnyObject &channelData)
Finalize channel.
static const uint16_t IsEncrypted
returns true if the channel is encrypted
Definition: XrdClXRootDTransport.hh:50
virtual Status GetSignature(Message *toSign, Message *&sign, AnyObject &channelData)
Get signature for given message.
Status CleanUpAuthentication(XRootDChannelInfo *info)
static void LogErrorResponse(const Message &msg)
Log server error response.
virtual bool HandShakeDone(HandShakeData *handShakeData, AnyObject &channelData)
static Status UnMarshallRequest(Message *msg)
URL representation.
Definition: XrdClURL.hh:30
virtual Status HandShake(HandShakeData *handShakeData, AnyObject &channelData)
HandShake.
virtual bool NeedEncryption(HandShakeData *handShakeData, AnyObject &channelData)
virtual uint16_t SubStreamNumber(AnyObject &channelData)
Return a number of substreams per stream that should be created.
Status ProcessBindResp(HandShakeData *hsData, XRootDChannelInfo *info)
virtual void MessageSent(Message *msg, uint16_t subStream, uint32_t bytesSent, AnyObject &channelData)
Notify the transport about a message having been sent.
Message * GenerateLogIn(HandShakeData *hsData, XRootDChannelInfo *info)
Status ProcessEndSessionResp(HandShakeData *hsData, XRootDChannelInfo *info)
void InitProtocolReq(ClientProtocolRequest *request, XRootDChannelInfo *info, kXR_char expect)
Status ProcessLogInResp(HandShakeData *hsData, XRootDChannelInfo *info)
Generic structure to pass security information back and forth.
Definition: XrdSecInterface.hh:50
virtual Status IsStreamBroken(time_t inactiveTime, AnyObject &channelData)
Message * GenerateEndSession(HandShakeData *hsData, XRootDChannelInfo *info)
A network socket.
Definition: XrdClSocket.hh:41
virtual void InitializeChannel(const URL &url, AnyObject &channelData)
Initialize channel.
virtual bool IsStreamTTLElapsed(time_t time, AnyObject &channelData)
Check if the stream should be disconnected.
XRootD transport handler.
Definition: XrdClXRootDTransport.hh:56
static const uint16_t ServerFlags
returns server flags
Definition: XrdClXRootDTransport.hh:48