xrootd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 XRootDStatus UnMarchalStatusCSE( Message &msg );
204 
205  //------------------------------------------------------------------------
207  //------------------------------------------------------------------------
208  static void UnMarshallHeader( Message &msg );
209 
210  //------------------------------------------------------------------------
212  //------------------------------------------------------------------------
213  static void LogErrorResponse( const Message &msg );
214 
215  //------------------------------------------------------------------------
217  //------------------------------------------------------------------------
218  static uint16_t NbConnectedStrm( AnyObject &channelData );
219 
220  //------------------------------------------------------------------------
222  //------------------------------------------------------------------------
223  virtual void Disconnect( AnyObject &channelData,
224  uint16_t subStreamId );
225 
226  //------------------------------------------------------------------------
228  //------------------------------------------------------------------------
229  virtual Status Query( uint16_t query,
230  AnyObject &result,
231  AnyObject &channelData );
232 
233 
234  //------------------------------------------------------------------------
236  //------------------------------------------------------------------------
237  static void GenerateDescription( char *msg, std::ostringstream &o );
238 
239  //------------------------------------------------------------------------
241  //------------------------------------------------------------------------
242  inline static void SetDescription( Message *msg )
243  {
244  std::ostringstream o;
245  GenerateDescription( msg->GetBuffer(), o );
246  msg->SetDescription( o.str() );
247  }
248 
249  //------------------------------------------------------------------------
251  //------------------------------------------------------------------------
252  virtual uint32_t MessageReceived( Message &msg,
253  uint16_t subStream,
254  AnyObject &channelData );
255 
256  //------------------------------------------------------------------------
258  //------------------------------------------------------------------------
259  virtual void MessageSent( Message *msg,
260  uint16_t subStream,
261  uint32_t bytesSent,
262  AnyObject &channelData );
263 
264  //------------------------------------------------------------------------
266  //------------------------------------------------------------------------
267  virtual Status GetSignature( Message *toSign, Message *&sign,
268  AnyObject &channelData );
269 
270  //------------------------------------------------------------------------
272  //------------------------------------------------------------------------
273  virtual Status GetSignature( Message *toSign, Message *&sign,
274  XRootDChannelInfo *info );
275 
276  //------------------------------------------------------------------------
278  //------------------------------------------------------------------------
279  virtual void DecFileInstCnt( AnyObject &channelData );
280 
281  //------------------------------------------------------------------------
283  //------------------------------------------------------------------------
284  virtual void WaitBeforeExit();
285 
286  //------------------------------------------------------------------------
288  //------------------------------------------------------------------------
289  virtual bool NeedEncryption( HandShakeData *handShakeData,
290  AnyObject &channelData );
291 
292  //------------------------------------------------------------------------
294  //------------------------------------------------------------------------
295  virtual URL GetBindPreference( const URL &url,
296  AnyObject &channelData );
297 
298  private:
299 
300  //------------------------------------------------------------------------
301  // Hand shake the main stream
302  //------------------------------------------------------------------------
303  XRootDStatus HandShakeMain( HandShakeData *handShakeData,
304  AnyObject &channelData );
305 
306  //------------------------------------------------------------------------
307  // Hand shake a parallel stream
308  //------------------------------------------------------------------------
310  AnyObject &channelData );
311 
312  //------------------------------------------------------------------------
313  // Generate the message to be sent as an initial handshake
314  // (handshake + kXR_protocol)
315  //------------------------------------------------------------------------
317  XRootDChannelInfo *info,
318  kXR_char expect );
319 
320  //------------------------------------------------------------------------
321  // Generate the protocol message
322  //------------------------------------------------------------------------
324  XRootDChannelInfo *info,
325  kXR_char expect );
326 
327  //------------------------------------------------------------------------
328  // Initialize protocol request
329  //------------------------------------------------------------------------
330  void InitProtocolReq( ClientProtocolRequest *request,
331  XRootDChannelInfo *info,
332  kXR_char expect );
333 
334  //------------------------------------------------------------------------
335  // Process the server initial handshake response
336  //------------------------------------------------------------------------
338  XRootDChannelInfo *info );
339 
340  //------------------------------------------------------------------------
341  // Process the protocol response
342  //------------------------------------------------------------------------
344  XRootDChannelInfo *info );
345 
346  //------------------------------------------------------------------------
347  // Process the protocol body:
348  // * 'B' : bind preferences
349  // * 'S' : security requirements
350  //------------------------------------------------------------------------
351  XRootDStatus ProcessProtocolBody( char *bodybuff,
352  size_t bodysize,
353  XRootDChannelInfo *info );
354 
355  //------------------------------------------------------------------------
356  // Generate the bind message
357  //------------------------------------------------------------------------
359  XRootDChannelInfo *info );
360 
361  //------------------------------------------------------------------------
362  // Generate the bind message
363  //------------------------------------------------------------------------
365  XRootDChannelInfo *info );
366 
367  //------------------------------------------------------------------------
368  // Generate the login message
369  //------------------------------------------------------------------------
371  XRootDChannelInfo *info );
372 
373  //------------------------------------------------------------------------
374  // Process the login response
375  //------------------------------------------------------------------------
377  XRootDChannelInfo *info );
378 
379  //------------------------------------------------------------------------
380  // Do the authentication
381  //------------------------------------------------------------------------
383  XRootDChannelInfo *info );
384 
385  //------------------------------------------------------------------------
386  // Get the initial credentials using one of the protocols
387  //------------------------------------------------------------------------
389  HandShakeData *hsData,
390  XRootDChannelInfo *info );
391 
392  //------------------------------------------------------------------------
393  // Clean up the data structures created for the authentication process
394  //------------------------------------------------------------------------
395  Status CleanUpAuthentication( XRootDChannelInfo *info );
396 
397  //------------------------------------------------------------------------
398  // Clean up the data structures created for the protection purposes
399  //------------------------------------------------------------------------
400  Status CleanUpProtection( XRootDChannelInfo *info );
401 
402  //------------------------------------------------------------------------
403  // Get the authentication function handle
404  //------------------------------------------------------------------------
406 
407  //------------------------------------------------------------------------
408  // Generate the end session message
409  //------------------------------------------------------------------------
411  XRootDChannelInfo *info );
412 
413  //------------------------------------------------------------------------
414  // Process the end session response
415  //------------------------------------------------------------------------
417  XRootDChannelInfo *info );
418 
419  //------------------------------------------------------------------------
420  // Get a string representation of the server flags
421  //------------------------------------------------------------------------
422  static std::string ServerFlagsToStr( uint32_t flags );
423 
424  //------------------------------------------------------------------------
425  // Get a string representation of file handle
426  //------------------------------------------------------------------------
427  static std::string FileHandleToStr( const unsigned char handle[4] );
428 
429  friend struct PluginUnloadHandler;
431  };
432 }
433 
434 #endif // __XRD_CL_XROOTD_TRANSPORT_HANDLER_HH__
unsigned char kXR_char
Definition: XPtypes.hh:65
XRootDStatus ProcessBindResp(HandShakeData *hsData, XRootDChannelInfo *info)
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)
virtual URL GetBindPreference(const URL &url, AnyObject &channelData)
Get bind preference for the next data stream.
XRootD related protocol queries.
Definition: XrdClXRootDTransport.hh:47
static XRootDStatus UnMarshalStatusBody(Message &msg, uint16_t reqType)
Unmarshall the body of the status response.
Status CleanUpProtection(XRootDChannelInfo *info)
Definition: XrdClPostMasterInterfaces.hh:269
~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:550
static std::string ServerFlagsToStr(uint32_t flags)
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
virtual XRootDStatus GetHeader(Message &message, Socket *socket)
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:113
virtual XRootDStatus GetBody(Message &message, Socket *socket)
PluginUnloadHandler * pSecUnloadHandler
Definition: XrdClXRootDTransport.hh:430
virtual void Disconnect(AnyObject &channelData, uint16_t subStreamId)
The stream has been disconnected, do the cleanups.
XRootDTransport()
Constructor.
virtual PathID MultiplexSubStream(Message *msg, AnyObject &channelData, PathID *hint=0)
Definition: XrdSysPlugin.hh:52
friend struct PluginUnloadHandler
Definition: XrdClXRootDTransport.hh:429
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:244
Message * GenerateBind(HandShakeData *hsData, XRootDChannelInfo *info)
XrdSecGetProt_t GetAuthHandler()
Perform the handshake and the authentication for each physical stream.
Definition: XrdClPostMasterInterfaces.hh:289
static void SetDescription(Message *msg)
Get the description of a message.
Definition: XrdClXRootDTransport.hh:242
Request status.
Definition: XrdClXRootDResponses.hh:218
static XRootDStatus MarshallRequest(Message *msg)
Marshal the outgoing message.
Definition: XrdClXRootDTransport.hh:172
static XRootDStatus UnMarchalStatusCSE(Message &msg)
Unmarshall the correction-segment of the status response for pgwrite.
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)
static void UnMarshallHeader(Message &msg)
Unmarshall the header incoming message.
virtual Status GetSignature(Message *toSign, Message *&sign, AnyObject &channelData)
Get signature for given message.
Status CleanUpAuthentication(XRootDChannelInfo *info)
virtual uint32_t MessageReceived(Message &msg, uint16_t subStream, AnyObject &channelData)
Check if the message invokes a stream action.
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 ProcessProtocolBody(char *bodybuff, size_t bodysize, XRootDChannelInfo *info)
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:42
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