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  struct XRootDChannelInfo;
39  struct PluginUnloadHandler;
40 
41  //----------------------------------------------------------------------------
43  //----------------------------------------------------------------------------
44  struct XRootDQuery
45  {
46  static const uint16_t SIDManager = 1001;
47  static const uint16_t ServerFlags = 1002;
48  static const uint16_t ProtocolVersion = 1003;
49  };
50 
51  //----------------------------------------------------------------------------
53  //----------------------------------------------------------------------------
55  {
56  public:
57  //------------------------------------------------------------------------
59  //------------------------------------------------------------------------
61 
62  //------------------------------------------------------------------------
64  //------------------------------------------------------------------------
66 
67  //------------------------------------------------------------------------
78  //------------------------------------------------------------------------
79  virtual Status GetHeader( Message *message, int socket );
80 
81  //------------------------------------------------------------------------
90  //------------------------------------------------------------------------
91  virtual Status GetBody( Message *message, int socket );
92 
93  //------------------------------------------------------------------------
95  //------------------------------------------------------------------------
96  virtual void InitializeChannel( AnyObject &channelData );
97 
98  //------------------------------------------------------------------------
100  //------------------------------------------------------------------------
101  virtual void FinalizeChannel( AnyObject &channelData );
102 
103  //------------------------------------------------------------------------
105  //------------------------------------------------------------------------
106  virtual Status HandShake( HandShakeData *handShakeData,
107  AnyObject &channelData );
108 
109  //------------------------------------------------------------------------
111  //------------------------------------------------------------------------
112  virtual bool IsStreamTTLElapsed( time_t time,
113  uint16_t streamId,
114  AnyObject &channelData );
115 
116  //------------------------------------------------------------------------
119  //------------------------------------------------------------------------
120  virtual Status IsStreamBroken( time_t inactiveTime,
121  uint16_t streamId,
122  AnyObject &channelData );
123 
124  //------------------------------------------------------------------------
130  //------------------------------------------------------------------------
131  virtual PathID Multiplex( Message *msg,
132  AnyObject &channelData,
133  PathID *hint = 0 );
134 
135  //------------------------------------------------------------------------
141  //------------------------------------------------------------------------
142  virtual PathID MultiplexSubStream( Message *msg,
143  uint16_t streamId,
144  AnyObject &channelData,
145  PathID *hint = 0 );
146 
147  //------------------------------------------------------------------------
149  //------------------------------------------------------------------------
150  virtual uint16_t StreamNumber( AnyObject &channelData );
151 
152  //------------------------------------------------------------------------
154  //------------------------------------------------------------------------
155  virtual uint16_t SubStreamNumber( AnyObject &channelData );
156 
157  //------------------------------------------------------------------------
160  //------------------------------------------------------------------------
161  virtual bool NeedControlConnection()
162  {
163  return true;
164  }
165 
166  //------------------------------------------------------------------------
168  //------------------------------------------------------------------------
169  static Status MarshallRequest( Message *msg );
170 
171  //------------------------------------------------------------------------
174  //------------------------------------------------------------------------
175  static Status UnMarshallRequest( Message *msg );
176 
177  //------------------------------------------------------------------------
179  //------------------------------------------------------------------------
180  static Status UnMarshallBody( Message *msg, uint16_t reqType );
181 
182  //------------------------------------------------------------------------
184  //------------------------------------------------------------------------
185  static void UnMarshallHeader( Message *msg );
186 
187  //------------------------------------------------------------------------
189  //------------------------------------------------------------------------
190  static void LogErrorResponse( const Message &msg );
191 
192  //------------------------------------------------------------------------
194  //------------------------------------------------------------------------
195  static uint16_t NbConnectedStrm( AnyObject &channelData );
196 
197  //------------------------------------------------------------------------
199  //------------------------------------------------------------------------
200  virtual void Disconnect( AnyObject &channelData,
201  uint16_t streamId,
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 streamId,
221  uint16_t subStream,
222  AnyObject &channelData );
223 
224  //------------------------------------------------------------------------
226  //------------------------------------------------------------------------
227  virtual void MessageSent( Message *msg,
228  uint16_t streamId,
229  uint16_t subStream,
230  uint32_t bytesSent,
231  AnyObject &channelData );
232 
233  //------------------------------------------------------------------------
235  //------------------------------------------------------------------------
236  virtual Status GetSignature( Message *toSign, Message *&sign,
237  AnyObject &channelData );
238 
239  //------------------------------------------------------------------------
241  //------------------------------------------------------------------------
242  Status GetSignature( Message *toSign, Message *&sign, XRootDChannelInfo *info );
243 
244  //------------------------------------------------------------------------
246  //------------------------------------------------------------------------
247  Status ClassifyErrno( int error );
248 
249  private:
250 
251  //------------------------------------------------------------------------
252  // Hand shake the main stream
253  //------------------------------------------------------------------------
254  Status HandShakeMain( HandShakeData *handShakeData,
255  AnyObject &channelData );
256 
257  //------------------------------------------------------------------------
258  // Hand shake a parallel stream
259  //------------------------------------------------------------------------
260  Status HandShakeParallel( HandShakeData *handShakeData,
261  AnyObject &channelData );
262 
263  //------------------------------------------------------------------------
264  // Generate the message to be sent as an initial handshake
265  //------------------------------------------------------------------------
267  XRootDChannelInfo *info );
268 
269  //------------------------------------------------------------------------
270  // Generate the message to be sent as an initial handshake
271  // (handshake + kXR_protocol)
272  //------------------------------------------------------------------------
274  XRootDChannelInfo *info );
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__
virtual void MessageSent(Message *msg, uint16_t streamId, uint16_t subStream, uint32_t bytesSent, AnyObject &channelData)
Notify the transport about a message having been sent.
static std::string FileHandleToStr(const unsigned char handle[4])
Definition: XrdClAnyObject.hh:32
virtual uint16_t StreamNumber(AnyObject &channelData)
Return a number of streams that should be created.
static uint16_t NbConnectedStrm(AnyObject &channelData)
Number of currently connected data streams.
The message representation used throughout the system.
Definition: XrdClMessage.hh:29
virtual uint32_t MessageReceived(Message *msg, uint16_t streamId, uint16_t subStream, AnyObject &channelData)
Check if the message invokes a stream action.
Status ProcessServerHS(HandShakeData *hsData, XRootDChannelInfo *info)
XRootD related protocol queries.
Definition: XrdClXRootDTransport.hh:44
Status ClassifyErrno(int error)
Classify errno while reading/writing.
Status CleanUpProtection(XRootDChannelInfo *info)
XrdSecProtocol *(* XrdSecGetProt_t)(const char *, XrdNetAddrInfo &, XrdSecParameters &, XrdOucErrInfo *)
Typedef to simplify the encoding of methods returning XrdSecProtocol.
Definition: XrdSecInterface.hh:465
Definition: XrdClPostMasterInterfaces.hh:282
~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.
virtual void Disconnect(AnyObject &channelData, uint16_t streamId, uint16_t subStreamId)
The stream has been disconnected, do the cleanups.
static std::string ServerFlagsToStr(uint32_t flags)
Status ProcessProtocolResp(HandShakeData *hsData, XRootDChannelInfo *info)
Status HandShakeParallel(HandShakeData *handShakeData, AnyObject &channelData)
Definition: XrdSecProtect.hh:55
Procedure execution status.
Definition: XrdClStatus.hh:109
Status GetCredentials(XrdSecCredentials *&credentials, HandShakeData *hsData, XRootDChannelInfo *info)
PluginUnloadHandler * pSecUnloadHandler
Definition: XrdClXRootDTransport.hh:363
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.
Definition: XrdSysPlugin.hh:52
friend struct PluginUnloadHandler
Definition: XrdClXRootDTransport.hh:362
static const uint16_t ProtocolVersion
returns the protocol version
Definition: XrdClXRootDTransport.hh:48
Data structure that carries the handshake information.
Definition: XrdClPostMasterInterfaces.hh:256
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:302
static void SetDescription(Message *msg)
Get the description of a message.
Definition: XrdClAnyObject.hh:25
Status HandShakeMain(HandShakeData *handShakeData, AnyObject &channelData)
Handle XRootD stream IDs.
Definition: XrdClSIDManager.hh:33
virtual bool NeedControlConnection()
Definition: XrdClXRootDTransport.hh:161
virtual void FinalizeChannel(AnyObject &channelData)
Finalize channel.
virtual Status GetHeader(Message *message, int socket)
virtual Status GetSignature(Message *toSign, Message *&sign, AnyObject &channelData)
Get signature for given message.
virtual Status IsStreamBroken(time_t inactiveTime, uint16_t streamId, AnyObject &channelData)
Status CleanUpAuthentication(XRootDChannelInfo *info)
static void LogErrorResponse(const Message &msg)
Log server error response.
virtual PathID MultiplexSubStream(Message *msg, uint16_t streamId, AnyObject &channelData, PathID *hint=0)
static Status UnMarshallRequest(Message *msg)
virtual Status HandShake(HandShakeData *handShakeData, AnyObject &channelData)
HandShake.
virtual uint16_t SubStreamNumber(AnyObject &channelData)
Return a number of substreams per stream that should be created.
virtual Status GetBody(Message *message, int socket)
Status ProcessBindResp(HandShakeData *hsData, XRootDChannelInfo *info)
Message * GenerateLogIn(HandShakeData *hsData, XRootDChannelInfo *info)
Status ProcessEndSessionResp(HandShakeData *hsData, XRootDChannelInfo *info)
Message * GenerateInitialHS(HandShakeData *hsData, XRootDChannelInfo *info)
Message * GenerateInitialHSProtocol(HandShakeData *hsData, XRootDChannelInfo *info)
Status ProcessLogInResp(HandShakeData *hsData, XRootDChannelInfo *info)
virtual void InitializeChannel(AnyObject &channelData)
Initialize channel.
Generic structure to pass security information back and forth.
Definition: XrdSecInterface.hh:50
Message * GenerateEndSession(HandShakeData *hsData, XRootDChannelInfo *info)
XRootD transport handler.
Definition: XrdClXRootDTransport.hh:54
virtual bool IsStreamTTLElapsed(time_t time, uint16_t streamId, AnyObject &channelData)
Check if the stream should be disconnected.
static const uint16_t ServerFlags
returns server flags
Definition: XrdClXRootDTransport.hh:47