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  virtual void Disconnect( AnyObject &channelData,
196  uint16_t streamId,
197  uint16_t subStreamId );
198 
199  //------------------------------------------------------------------------
201  //------------------------------------------------------------------------
202  virtual Status Query( uint16_t query,
203  AnyObject &result,
204  AnyObject &channelData );
205 
206  //------------------------------------------------------------------------
208  //------------------------------------------------------------------------
209  static void SetDescription( Message *msg );
210 
211  //------------------------------------------------------------------------
213  //------------------------------------------------------------------------
214  virtual uint32_t MessageReceived( Message *msg,
215  uint16_t streamId,
216  uint16_t subStream,
217  AnyObject &channelData );
218 
219  //------------------------------------------------------------------------
221  //------------------------------------------------------------------------
222  virtual void MessageSent( Message *msg,
223  uint16_t streamId,
224  uint16_t subStream,
225  uint32_t bytesSent,
226  AnyObject &channelData );
227 
228  //------------------------------------------------------------------------
230  //------------------------------------------------------------------------
231  virtual Status GetSignature( Message *toSign, Message *&sign,
232  AnyObject &channelData );
233 
234  //------------------------------------------------------------------------
236  //------------------------------------------------------------------------
237  Status ClassifyErrno( int error );
238 
239  private:
240 
241  //------------------------------------------------------------------------
242  // Hand shake the main stream
243  //------------------------------------------------------------------------
244  Status HandShakeMain( HandShakeData *handShakeData,
245  AnyObject &channelData );
246 
247  //------------------------------------------------------------------------
248  // Hand shake a parallel stream
249  //------------------------------------------------------------------------
250  Status HandShakeParallel( HandShakeData *handShakeData,
251  AnyObject &channelData );
252 
253  //------------------------------------------------------------------------
254  // Generate the message to be sent as an initial handshake
255  //------------------------------------------------------------------------
257  XRootDChannelInfo *info );
258 
259  //------------------------------------------------------------------------
260  // Generate the message to be sent as an initial handshake
261  // (handshake + kXR_protocol)
262  //------------------------------------------------------------------------
264  XRootDChannelInfo *info );
265 
266  //------------------------------------------------------------------------
267  // Process the server initial handshake response
268  //------------------------------------------------------------------------
270  XRootDChannelInfo *info );
271 
272  //-----------------------------------------------------------------------
273  // Process the protocol response
274  //------------------------------------------------------------------------
276  XRootDChannelInfo *info );
277 
278  //------------------------------------------------------------------------
279  // Generate the bind message
280  //------------------------------------------------------------------------
282  XRootDChannelInfo *info );
283 
284  //------------------------------------------------------------------------
285  // Generate the bind message
286  //------------------------------------------------------------------------
288  XRootDChannelInfo *info );
289 
290  //------------------------------------------------------------------------
291  // Generate the login message
292  //------------------------------------------------------------------------
294  XRootDChannelInfo *info );
295 
296  //------------------------------------------------------------------------
297  // Process the login response
298  //------------------------------------------------------------------------
300  XRootDChannelInfo *info );
301 
302  //------------------------------------------------------------------------
303  // Do the authentication
304  //------------------------------------------------------------------------
306  XRootDChannelInfo *info );
307 
308  //------------------------------------------------------------------------
309  // Get the initial credentials using one of the protocols
310  //------------------------------------------------------------------------
311  Status GetCredentials( XrdSecCredentials *&credentials,
312  HandShakeData *hsData,
313  XRootDChannelInfo *info );
314 
315  //------------------------------------------------------------------------
316  // Clean up the data structures created for the authentication process
317  //------------------------------------------------------------------------
318  Status CleanUpAuthentication( XRootDChannelInfo *info );
319 
320  //------------------------------------------------------------------------
321  // Clean up the data structures created for the protection purposes
322  //------------------------------------------------------------------------
323  Status CleanUpProtection( XRootDChannelInfo *info );
324 
325  //------------------------------------------------------------------------
326  // Get the authentication function handle
327  //------------------------------------------------------------------------
329 
330  //------------------------------------------------------------------------
331  // Generate the end session message
332  //------------------------------------------------------------------------
334  XRootDChannelInfo *info );
335 
336  //------------------------------------------------------------------------
337  // Process the end session response
338  //------------------------------------------------------------------------
340  XRootDChannelInfo *info );
341 
342  //------------------------------------------------------------------------
343  // Get a string representation of the server flags
344  //------------------------------------------------------------------------
345  static std::string ServerFlagsToStr( uint32_t flags );
346 
347  //------------------------------------------------------------------------
348  // Get a string representation of file handle
349  //------------------------------------------------------------------------
350  static std::string FileHandleToStr( const unsigned char handle[4] );
351 
353 
354  friend struct PluginUnloadHandler;
356  };
357 }
358 
359 #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.
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:355
XrdSecGetProt_t pAuthHandler
Definition: XrdClXRootDTransport.hh:352
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:354
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