xrootd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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 "XrdCl/XrdClMessage.hh"
30 #include "XProtocol/XProtocol.hh"
32 #include "XrdOuc/XrdOucEnv.hh"
33 
34 class XrdSysPlugin;
35 class XrdSecProtect;
36 
37 namespace XrdCl
38 {
39  class Tls;
40  class Socket;
41  struct XRootDChannelInfo;
42  struct PluginUnloadHandler;
43 
44  //----------------------------------------------------------------------------
46  //----------------------------------------------------------------------------
47  struct XRootDQuery
48  {
49  static const uint16_t ServerFlags = 1002;
50  static const uint16_t ProtocolVersion = 1003;
51  static const uint16_t IsEncrypted = 1004;
52  };
53 
54  //----------------------------------------------------------------------------
56  //----------------------------------------------------------------------------
58  {
59  public:
60  //------------------------------------------------------------------------
62  //------------------------------------------------------------------------
64 
65  //------------------------------------------------------------------------
67  //------------------------------------------------------------------------
69 
70  //------------------------------------------------------------------------
81  //------------------------------------------------------------------------
82  virtual XRootDStatus GetHeader( Message *message, Socket *socket );
83 
84  //------------------------------------------------------------------------
93  //------------------------------------------------------------------------
94  virtual XRootDStatus GetBody( Message *message, Socket *socket );
95 
96  //------------------------------------------------------------------------
98  //------------------------------------------------------------------------
99  virtual void InitializeChannel( const URL &url,
100  AnyObject &channelData );
101 
102  //------------------------------------------------------------------------
104  //------------------------------------------------------------------------
105  virtual void FinalizeChannel( AnyObject &channelData );
106 
107  //------------------------------------------------------------------------
109  //------------------------------------------------------------------------
110  virtual XRootDStatus HandShake( HandShakeData *handShakeData,
111  AnyObject &channelData );
112 
113  //------------------------------------------------------------------------
114  // @return true if handshake has been done and stream is connected,
115  // false otherwise
116  //------------------------------------------------------------------------
117  virtual bool HandShakeDone( HandShakeData *handShakeData,
118  AnyObject &channelData );
119 
120  //------------------------------------------------------------------------
122  //------------------------------------------------------------------------
123  virtual bool IsStreamTTLElapsed( time_t time,
124  AnyObject &channelData );
125 
126  //------------------------------------------------------------------------
129  //------------------------------------------------------------------------
130  virtual Status IsStreamBroken( time_t inactiveTime,
131  AnyObject &channelData );
132 
133  //------------------------------------------------------------------------
139  //------------------------------------------------------------------------
140  virtual PathID Multiplex( Message *msg,
141  AnyObject &channelData,
142  PathID *hint = 0 );
143 
144  //------------------------------------------------------------------------
150  //------------------------------------------------------------------------
151  virtual PathID MultiplexSubStream( Message *msg,
152  AnyObject &channelData,
153  PathID *hint = 0 );
154 
155  //------------------------------------------------------------------------
157  //------------------------------------------------------------------------
158  virtual uint16_t SubStreamNumber( AnyObject &channelData );
159 
160  //------------------------------------------------------------------------
163  //------------------------------------------------------------------------
164  virtual bool NeedControlConnection()
165  {
166  return true;
167  }
168 
169  //------------------------------------------------------------------------
171  //------------------------------------------------------------------------
172  inline static XRootDStatus MarshallRequest( Message *msg )
173  {
174  MarshallRequest( msg->GetBuffer() );
175  msg->SetIsMarshalled( true );
176  return XRootDStatus();
177  }
178 
179  //------------------------------------------------------------------------
181  //------------------------------------------------------------------------
182  static XRootDStatus MarshallRequest( char *msg );
183 
184  //------------------------------------------------------------------------
187  //------------------------------------------------------------------------
188  static XRootDStatus UnMarshallRequest( Message *msg );
189 
190  //------------------------------------------------------------------------
192  //------------------------------------------------------------------------
193  static XRootDStatus UnMarshallBody( Message *msg, uint16_t reqType );
194 
195  //------------------------------------------------------------------------
197  //------------------------------------------------------------------------
198  static XRootDStatus UnMarshalStatusBody( Message *msg, uint16_t reqType );
199 
200  //------------------------------------------------------------------------
202  //------------------------------------------------------------------------
203  static void UnMarshallHeader( Message *msg );
204 
205  //------------------------------------------------------------------------
207  //------------------------------------------------------------------------
208  static void LogErrorResponse( const Message &msg );
209 
210  //------------------------------------------------------------------------
212  //------------------------------------------------------------------------
213  static uint16_t NbConnectedStrm( AnyObject &channelData );
214 
215  //------------------------------------------------------------------------
217  //------------------------------------------------------------------------
218  virtual void Disconnect( AnyObject &channelData,
219  uint16_t subStreamId );
220 
221  //------------------------------------------------------------------------
223  //------------------------------------------------------------------------
224  virtual Status Query( uint16_t query,
225  AnyObject &result,
226  AnyObject &channelData );
227 
228 
229  //------------------------------------------------------------------------
231  //------------------------------------------------------------------------
232  static void GenerateDescription( char *msg, std::ostringstream &o );
233 
234  //------------------------------------------------------------------------
236  //------------------------------------------------------------------------
237  inline static void SetDescription( Message *msg )
238  {
239  std::ostringstream o;
240  GenerateDescription( msg->GetBuffer(), o );
241  msg->SetDescription( o.str() );
242  }
243 
244  //------------------------------------------------------------------------
246  //------------------------------------------------------------------------
247  virtual uint32_t MessageReceived( Message *msg,
248  uint16_t subStream,
249  AnyObject &channelData );
250 
251  //------------------------------------------------------------------------
253  //------------------------------------------------------------------------
254  virtual void MessageSent( Message *msg,
255  uint16_t subStream,
256  uint32_t bytesSent,
257  AnyObject &channelData );
258 
259  //------------------------------------------------------------------------
261  //------------------------------------------------------------------------
262  virtual Status GetSignature( Message *toSign, Message *&sign,
263  AnyObject &channelData );
264 
265  //------------------------------------------------------------------------
267  //------------------------------------------------------------------------
268  virtual Status GetSignature( Message *toSign, Message *&sign,
269  XRootDChannelInfo *info );
270 
271  //------------------------------------------------------------------------
273  //------------------------------------------------------------------------
274  virtual void DecFileInstCnt( AnyObject &channelData );
275 
276  //------------------------------------------------------------------------
278  //------------------------------------------------------------------------
279  virtual void WaitBeforeExit();
280 
281  //------------------------------------------------------------------------
283  //------------------------------------------------------------------------
284  virtual bool NeedEncryption( HandShakeData *handShakeData,
285  AnyObject &channelData );
286 
287  private:
288 
289  //------------------------------------------------------------------------
290  // Hand shake the main stream
291  //------------------------------------------------------------------------
292  XRootDStatus HandShakeMain( HandShakeData *handShakeData,
293  AnyObject &channelData );
294 
295  //------------------------------------------------------------------------
296  // Hand shake a parallel stream
297  //------------------------------------------------------------------------
299  AnyObject &channelData );
300 
301  //------------------------------------------------------------------------
302  // Generate the message to be sent as an initial handshake
303  // (handshake + kXR_protocol)
304  //------------------------------------------------------------------------
306  XRootDChannelInfo *info,
307  kXR_char expect );
308 
309  //------------------------------------------------------------------------
310  // Generate the protocol message
311  //------------------------------------------------------------------------
313  XRootDChannelInfo *info,
314  kXR_char expect );
315 
316  //------------------------------------------------------------------------
317  // Initialize protocol request
318  //------------------------------------------------------------------------
319  void InitProtocolReq( ClientProtocolRequest *request,
320  XRootDChannelInfo *info,
321  kXR_char expect );
322 
323  //------------------------------------------------------------------------
324  // Process the server initial handshake response
325  //------------------------------------------------------------------------
327  XRootDChannelInfo *info );
328 
329  //-----------------------------------------------------------------------
330  // Process the protocol response
331  //------------------------------------------------------------------------
333  XRootDChannelInfo *info );
334 
335  //------------------------------------------------------------------------
336  // Generate the bind message
337  //------------------------------------------------------------------------
339  XRootDChannelInfo *info );
340 
341  //------------------------------------------------------------------------
342  // Generate the bind message
343  //------------------------------------------------------------------------
345  XRootDChannelInfo *info );
346 
347  //------------------------------------------------------------------------
348  // Generate the login message
349  //------------------------------------------------------------------------
351  XRootDChannelInfo *info );
352 
353  //------------------------------------------------------------------------
354  // Process the login response
355  //------------------------------------------------------------------------
357  XRootDChannelInfo *info );
358 
359  //------------------------------------------------------------------------
360  // Do the authentication
361  //------------------------------------------------------------------------
363  XRootDChannelInfo *info );
364 
365  //------------------------------------------------------------------------
366  // Get the initial credentials using one of the protocols
367  //------------------------------------------------------------------------
369  HandShakeData *hsData,
370  XRootDChannelInfo *info );
371 
372  //------------------------------------------------------------------------
373  // Clean up the data structures created for the authentication process
374  //------------------------------------------------------------------------
375  Status CleanUpAuthentication( XRootDChannelInfo *info );
376 
377  //------------------------------------------------------------------------
378  // Clean up the data structures created for the protection purposes
379  //------------------------------------------------------------------------
380  Status CleanUpProtection( XRootDChannelInfo *info );
381 
382  //------------------------------------------------------------------------
383  // Get the authentication function handle
384  //------------------------------------------------------------------------
386 
387  //------------------------------------------------------------------------
388  // Generate the end session message
389  //------------------------------------------------------------------------
391  XRootDChannelInfo *info );
392 
393  //------------------------------------------------------------------------
394  // Process the end session response
395  //------------------------------------------------------------------------
397  XRootDChannelInfo *info );
398 
399  //------------------------------------------------------------------------
400  // Get a string representation of the server flags
401  //------------------------------------------------------------------------
402  static std::string ServerFlagsToStr( uint32_t flags );
403 
404  //------------------------------------------------------------------------
405  // Get a string representation of file handle
406  //------------------------------------------------------------------------
407  static std::string FileHandleToStr( const unsigned char handle[4] );
408 
409  friend struct PluginUnloadHandler;
411  };
412 }
413 
414 #endif // __XRD_CL_XROOTD_TRANSPORT_HANDLER_HH__
unsigned char kXR_char
Definition: XPtypes.hh:65
XRootDStatus ProcessBindResp(HandShakeData *hsData, XRootDChannelInfo *info)
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
void SetDescription(const std::string &description)
Set the description of the message.
Definition: XrdClMessage.hh:87
static uint16_t NbConnectedStrm(AnyObject &channelData)
Number of currently connected data streams.
Message * GenerateProtocol(HandShakeData *hsData, XRootDChannelInfo *info, kXR_char expect)
void SetIsMarshalled(bool isMarshalled)
Set the marshalling status.
Definition: XrdClMessage.hh:79
virtual XRootDStatus HandShake(HandShakeData *handShakeData, AnyObject &channelData)
HandShake.
The message representation used throughout the system.
Definition: XrdClMessage.hh:29
virtual void DecFileInstCnt(AnyObject &channelData)
Decrement file object instance count bound to this channel.
XRootDStatus GetCredentials(XrdSecCredentials *&credentials, HandShakeData *hsData, XRootDChannelInfo *info)
XRootD related protocol queries.
Definition: XrdClXRootDTransport.hh:47
Status CleanUpProtection(XRootDChannelInfo *info)
Definition: XrdClPostMasterInterfaces.hh:270
~XRootDTransport()
Destructor.
virtual PathID Multiplex(Message *msg, AnyObject &channelData, PathID *hint=0)
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)
XRootDStatus ProcessProtocolResp(HandShakeData *hsData, XRootDChannelInfo *info)
XrdSecProtocol *(* XrdSecGetProt_t)(const char *, XrdNetAddrInfo &, XrdSecParameters &, XrdOucErrInfo *)
Typedef to simplify the encoding of methods returning XrdSecProtocol.
Definition: XrdSecInterface.hh:481
static XRootDStatus UnMarshallRequest(Message *msg)
Definition: XrdSecProtect.hh:55
static XRootDStatus UnMarshallBody(Message *msg, uint16_t reqType)
Unmarshall the body of the incoming message.
const char * GetBuffer(uint32_t offset=0) const
Get the message buffer.
Definition: XrdClBuffer.hh:72
Procedure execution status.
Definition: XrdClStatus.hh:112
PluginUnloadHandler * pSecUnloadHandler
Definition: XrdClXRootDTransport.hh:410
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.
XRootDTransport()
Constructor.
virtual PathID MultiplexSubStream(Message *msg, AnyObject &channelData, PathID *hint=0)
Definition: XrdSysPlugin.hh:52
friend struct PluginUnloadHandler
Definition: XrdClXRootDTransport.hh:409
Message * GenerateInitialHSProtocol(HandShakeData *hsData, XRootDChannelInfo *info, kXR_char expect)
static const uint16_t ProtocolVersion
returns the protocol version
Definition: XrdClXRootDTransport.hh:50
virtual void WaitBeforeExit()
Wait until the program can safely exit.
Data structure that carries the handshake information.
Definition: XrdClPostMasterInterfaces.hh:245
Message * GenerateBind(HandShakeData *hsData, XRootDChannelInfo *info)
XrdSecGetProt_t GetAuthHandler()
Perform the handshake and the authentication for each physical stream.
Definition: XrdClPostMasterInterfaces.hh:290
static XRootDStatus UnMarshalStatusBody(Message *msg, uint16_t reqType)
Unmarshall the body of the status response.
static void SetDescription(Message *msg)
Get the description of a message.
Definition: XrdClXRootDTransport.hh:237
virtual XRootDStatus GetHeader(Message *message, Socket *socket)
Request status.
Definition: XrdClXRootDResponses.hh:218
static XRootDStatus MarshallRequest(Message *msg)
Marshal the outgoing message.
Definition: XrdClXRootDTransport.hh:172
virtual bool NeedControlConnection()
Definition: XrdClXRootDTransport.hh:164
virtual void FinalizeChannel(AnyObject &channelData)
Finalize channel.
static const uint16_t IsEncrypted
returns true if the channel is encrypted
Definition: XrdClXRootDTransport.hh:51
XRootDStatus ProcessServerHS(HandShakeData *hsData, XRootDChannelInfo *info)
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)
XRootDStatus ProcessLogInResp(HandShakeData *hsData, XRootDChannelInfo *info)
URL representation.
Definition: XrdClURL.hh:30
virtual bool NeedEncryption(HandShakeData *handShakeData, AnyObject &channelData)
XRootDStatus HandShakeMain(HandShakeData *handShakeData, AnyObject &channelData)
static void GenerateDescription(char *msg, std::ostringstream &o)
Get the description of a message.
virtual uint16_t SubStreamNumber(AnyObject &channelData)
Return a number of substreams per stream that should be created.
XRootDStatus HandShakeParallel(HandShakeData *handShakeData, AnyObject &channelData)
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)
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.
XRootDStatus DoAuthentication(HandShakeData *hsData, XRootDChannelInfo *info)
XRootD transport handler.
Definition: XrdClXRootDTransport.hh:57
static const uint16_t ServerFlags
returns server flags
Definition: XrdClXRootDTransport.hh:49