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 "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  };
51 
52  //----------------------------------------------------------------------------
54  //----------------------------------------------------------------------------
56  {
57  public:
58  //------------------------------------------------------------------------
60  //------------------------------------------------------------------------
62 
63  //------------------------------------------------------------------------
65  //------------------------------------------------------------------------
67 
68  //------------------------------------------------------------------------
79  //------------------------------------------------------------------------
80  virtual Status GetHeader( Message *message, Socket *socket );
81 
82  //------------------------------------------------------------------------
91  //------------------------------------------------------------------------
92  virtual Status GetBody( Message *message, Socket *socket );
93 
94  //------------------------------------------------------------------------
96  //------------------------------------------------------------------------
97  virtual void InitializeChannel( const URL &url,
98  AnyObject &channelData );
99 
100  //------------------------------------------------------------------------
102  //------------------------------------------------------------------------
103  virtual void FinalizeChannel( AnyObject &channelData );
104 
105  //------------------------------------------------------------------------
107  //------------------------------------------------------------------------
108  virtual Status HandShake( HandShakeData *handShakeData,
109  AnyObject &channelData );
110 
111  //------------------------------------------------------------------------
112  // @return true if handshake has been done and stream is connected,
113  // false otherwise
114  //------------------------------------------------------------------------
115  virtual bool HandShakeDone( HandShakeData *handShakeData,
116  AnyObject &channelData );
117 
118  //------------------------------------------------------------------------
120  //------------------------------------------------------------------------
121  virtual bool IsStreamTTLElapsed( time_t time,
122  AnyObject &channelData );
123 
124  //------------------------------------------------------------------------
127  //------------------------------------------------------------------------
128  virtual Status IsStreamBroken( time_t inactiveTime,
129  AnyObject &channelData );
130 
131  //------------------------------------------------------------------------
137  //------------------------------------------------------------------------
138  virtual PathID Multiplex( Message *msg,
139  AnyObject &channelData,
140  PathID *hint = 0 );
141 
142  //------------------------------------------------------------------------
148  //------------------------------------------------------------------------
149  virtual PathID MultiplexSubStream( Message *msg,
150  AnyObject &channelData,
151  PathID *hint = 0 );
152 
153  //------------------------------------------------------------------------
155  //------------------------------------------------------------------------
156  virtual uint16_t SubStreamNumber( AnyObject &channelData );
157 
158  //------------------------------------------------------------------------
161  //------------------------------------------------------------------------
162  virtual bool NeedControlConnection()
163  {
164  return true;
165  }
166 
167  //------------------------------------------------------------------------
169  //------------------------------------------------------------------------
170  static Status MarshallRequest( Message *msg );
171 
172  //------------------------------------------------------------------------
175  //------------------------------------------------------------------------
176  static Status UnMarshallRequest( Message *msg );
177 
178  //------------------------------------------------------------------------
180  //------------------------------------------------------------------------
181  static Status UnMarshallBody( Message *msg, uint16_t reqType );
182 
183  //------------------------------------------------------------------------
185  //------------------------------------------------------------------------
186  static void UnMarshallHeader( Message *msg );
187 
188  //------------------------------------------------------------------------
190  //------------------------------------------------------------------------
191  static void LogErrorResponse( const Message &msg );
192 
193  //------------------------------------------------------------------------
195  //------------------------------------------------------------------------
196  static uint16_t NbConnectedStrm( AnyObject &channelData );
197 
198  //------------------------------------------------------------------------
200  //------------------------------------------------------------------------
201  virtual void Disconnect( AnyObject &channelData,
202  uint16_t subStreamId );
203 
204  //------------------------------------------------------------------------
206  //------------------------------------------------------------------------
207  virtual Status Query( uint16_t query,
208  AnyObject &result,
209  AnyObject &channelData );
210 
211  //------------------------------------------------------------------------
213  //------------------------------------------------------------------------
214  static void SetDescription( Message *msg );
215 
216  //------------------------------------------------------------------------
218  //------------------------------------------------------------------------
219  virtual uint32_t MessageReceived( Message *msg,
220  uint16_t subStream,
221  AnyObject &channelData );
222 
223  //------------------------------------------------------------------------
225  //------------------------------------------------------------------------
226  virtual void MessageSent( Message *msg,
227  uint16_t subStream,
228  uint32_t bytesSent,
229  AnyObject &channelData );
230 
231  //------------------------------------------------------------------------
233  //------------------------------------------------------------------------
234  virtual Status GetSignature( Message *toSign, Message *&sign,
235  AnyObject &channelData );
236 
237  //------------------------------------------------------------------------
239  //------------------------------------------------------------------------
240  virtual Status GetSignature( Message *toSign, Message *&sign,
241  XRootDChannelInfo *info );
242 
243  //------------------------------------------------------------------------
245  //------------------------------------------------------------------------
246  virtual void WaitBeforeExit();
247 
248  //------------------------------------------------------------------------
250  //------------------------------------------------------------------------
251  virtual bool NeedEncryption( HandShakeData *handShakeData,
252  AnyObject &channelData );
253 
254  private:
255 
256  //------------------------------------------------------------------------
257  // Hand shake the main stream
258  //------------------------------------------------------------------------
259  Status HandShakeMain( HandShakeData *handShakeData,
260  AnyObject &channelData );
261 
262  //------------------------------------------------------------------------
263  // Hand shake a parallel stream
264  //------------------------------------------------------------------------
265  Status HandShakeParallel( HandShakeData *handShakeData,
266  AnyObject &channelData );
267 
268  //------------------------------------------------------------------------
269  // Generate the message to be sent as an initial handshake
270  // (handshake + kXR_protocol)
271  //------------------------------------------------------------------------
273  XRootDChannelInfo *info,
274  kXR_char expect );
275 
276  //------------------------------------------------------------------------
277  // Process the server initial handshake response
278  //------------------------------------------------------------------------
280  XRootDChannelInfo *info );
281 
282  //-----------------------------------------------------------------------
283  // Process the protocol response
284  //------------------------------------------------------------------------
286  XRootDChannelInfo *info );
287 
288  //------------------------------------------------------------------------
289  // Generate the bind message
290  //------------------------------------------------------------------------
292  XRootDChannelInfo *info );
293 
294  //------------------------------------------------------------------------
295  // Generate the bind message
296  //------------------------------------------------------------------------
298  XRootDChannelInfo *info );
299 
300  //------------------------------------------------------------------------
301  // Generate the login message
302  //------------------------------------------------------------------------
304  XRootDChannelInfo *info );
305 
306  //------------------------------------------------------------------------
307  // Process the login response
308  //------------------------------------------------------------------------
310  XRootDChannelInfo *info );
311 
312  //------------------------------------------------------------------------
313  // Do the authentication
314  //------------------------------------------------------------------------
316  XRootDChannelInfo *info );
317 
318  //------------------------------------------------------------------------
319  // Get the initial credentials using one of the protocols
320  //------------------------------------------------------------------------
321  Status GetCredentials( XrdSecCredentials *&credentials,
322  HandShakeData *hsData,
323  XRootDChannelInfo *info );
324 
325  //------------------------------------------------------------------------
326  // Clean up the data structures created for the authentication process
327  //------------------------------------------------------------------------
328  Status CleanUpAuthentication( XRootDChannelInfo *info );
329 
330  //------------------------------------------------------------------------
331  // Clean up the data structures created for the protection purposes
332  //------------------------------------------------------------------------
333  Status CleanUpProtection( XRootDChannelInfo *info );
334 
335  //------------------------------------------------------------------------
336  // Get the authentication function handle
337  //------------------------------------------------------------------------
339 
340  //------------------------------------------------------------------------
341  // Generate the end session message
342  //------------------------------------------------------------------------
344  XRootDChannelInfo *info );
345 
346  //------------------------------------------------------------------------
347  // Process the end session response
348  //------------------------------------------------------------------------
350  XRootDChannelInfo *info );
351 
352  //------------------------------------------------------------------------
353  // Get a string representation of the server flags
354  //------------------------------------------------------------------------
355  static std::string ServerFlagsToStr( uint32_t flags );
356 
357  //------------------------------------------------------------------------
358  // Get a string representation of file handle
359  //------------------------------------------------------------------------
360  static std::string FileHandleToStr( const unsigned char handle[4] );
361 
362  friend struct PluginUnloadHandler;
364  };
365 }
366 
367 #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])
virtual Status GetBody(Message *message, Socket *socket)
Definition: XrdClAnyObject.hh:32
static uint16_t NbConnectedStrm(AnyObject &channelData)
Number of currently connected data streams.
The message representation used throughout the system.
Definition: XrdClMessage.hh:29
Status ProcessServerHS(HandShakeData *hsData, XRootDChannelInfo *info)
XRootD related protocol queries.
Definition: XrdClXRootDTransport.hh:46
Status CleanUpProtection(XRootDChannelInfo *info)
Definition: XrdClPostMasterInterfaces.hh:280
~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.
static std::string ServerFlagsToStr(uint32_t flags)
XrdSecProtocol *(* XrdSecGetProt_t)(const char *, XrdNetAddrInfo &, XrdSecParameters &, XrdOucErrInfo *)
Typedef to simplify the encoding of methods returning XrdSecProtocol.
Definition: XrdSecInterface.hh:481
Status ProcessProtocolResp(HandShakeData *hsData, XRootDChannelInfo *info)
Status HandShakeParallel(HandShakeData *handShakeData, AnyObject &channelData)
Definition: XrdSecProtect.hh:55
Procedure execution status.
Definition: XrdClStatus.hh:110
Status GetCredentials(XrdSecCredentials *&credentials, HandShakeData *hsData, XRootDChannelInfo *info)
PluginUnloadHandler * pSecUnloadHandler
Definition: XrdClXRootDTransport.hh:363
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:362
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:255
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:300
static void SetDescription(Message *msg)
Get the description of a message.
Status HandShakeMain(HandShakeData *handShakeData, AnyObject &channelData)
virtual bool NeedControlConnection()
Definition: XrdClXRootDTransport.hh:162
virtual void FinalizeChannel(AnyObject &channelData)
Finalize channel.
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)
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:40
virtual void InitializeChannel(const URL &url, AnyObject &channelData)
Initialize channel.
virtual Status GetHeader(Message *message, Socket *socket)
virtual bool IsStreamTTLElapsed(time_t time, AnyObject &channelData)
Check if the stream should be disconnected.
XRootD transport handler.
Definition: XrdClXRootDTransport.hh:55
static const uint16_t ServerFlags
returns server flags
Definition: XrdClXRootDTransport.hh:48