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
29#include "XrdCl/XrdClMessage.hh"
32#include "XrdOuc/XrdOucEnv.hh"
33
34class XrdSysPlugin;
35class XrdSecProtect;
36
37namespace XrdCl
38{
39 class Tls;
40 class Socket;
41 struct XRootDChannelInfo;
42 struct PluginUnloadHandler;
43
44 //----------------------------------------------------------------------------
46 //----------------------------------------------------------------------------
48 {
49 public:
50 //------------------------------------------------------------------------
52 //------------------------------------------------------------------------
54
55 //------------------------------------------------------------------------
57 //------------------------------------------------------------------------
59
60 //------------------------------------------------------------------------
71 //------------------------------------------------------------------------
72 virtual XRootDStatus GetHeader( Message &message, Socket *socket );
73
74 //------------------------------------------------------------------------
83 //------------------------------------------------------------------------
84 virtual XRootDStatus GetBody( Message &message, Socket *socket );
85
86 //------------------------------------------------------------------------
88 //------------------------------------------------------------------------
89 virtual void InitializeChannel( const URL &url,
90 AnyObject &channelData );
91
92 //------------------------------------------------------------------------
94 //------------------------------------------------------------------------
95 virtual void FinalizeChannel( AnyObject &channelData );
96
97 //------------------------------------------------------------------------
99 //------------------------------------------------------------------------
100 virtual XRootDStatus HandShake( HandShakeData *handShakeData,
101 AnyObject &channelData );
102
103 //------------------------------------------------------------------------
104 // @return true if handshake has been done and stream is connected,
105 // false otherwise
106 //------------------------------------------------------------------------
107 virtual bool HandShakeDone( HandShakeData *handShakeData,
108 AnyObject &channelData );
109
110 //------------------------------------------------------------------------
112 //------------------------------------------------------------------------
113 virtual bool IsStreamTTLElapsed( time_t time,
114 AnyObject &channelData );
115
116 //------------------------------------------------------------------------
119 //------------------------------------------------------------------------
120 virtual Status IsStreamBroken( time_t inactiveTime,
121 AnyObject &channelData );
122
123 //------------------------------------------------------------------------
129 //------------------------------------------------------------------------
130 virtual PathID Multiplex( Message *msg,
131 AnyObject &channelData,
132 PathID *hint = 0 );
133
134 //------------------------------------------------------------------------
140 //------------------------------------------------------------------------
142 AnyObject &channelData,
143 PathID *hint = 0 );
144
145 //------------------------------------------------------------------------
147 //------------------------------------------------------------------------
148 virtual uint16_t SubStreamNumber( AnyObject &channelData );
149
150 //------------------------------------------------------------------------
153 //------------------------------------------------------------------------
155 {
156 return true;
157 }
158
159 //------------------------------------------------------------------------
161 //------------------------------------------------------------------------
163 {
164 MarshallRequest( msg->GetBuffer() );
165 msg->SetIsMarshalled( true );
166 return XRootDStatus();
167 }
168
169 //------------------------------------------------------------------------
171 //------------------------------------------------------------------------
172 static XRootDStatus MarshallRequest( char *msg );
173
174 //------------------------------------------------------------------------
177 //------------------------------------------------------------------------
179
180 //------------------------------------------------------------------------
182 //------------------------------------------------------------------------
183 static XRootDStatus UnMarshallBody( Message *msg, uint16_t reqType );
184
185 //------------------------------------------------------------------------
187 //------------------------------------------------------------------------
188 static XRootDStatus UnMarshalStatusBody( Message &msg, uint16_t reqType );
189
190 //------------------------------------------------------------------------
192 //------------------------------------------------------------------------
194
195 //------------------------------------------------------------------------
197 //------------------------------------------------------------------------
198 static void UnMarshallHeader( Message &msg );
199
200 //------------------------------------------------------------------------
202 //------------------------------------------------------------------------
203 static void LogErrorResponse( const Message &msg );
204
205 //------------------------------------------------------------------------
207 //------------------------------------------------------------------------
208 static uint16_t NbConnectedStrm( AnyObject &channelData );
209
210 //------------------------------------------------------------------------
212 //------------------------------------------------------------------------
213 virtual void Disconnect( AnyObject &channelData,
214 uint16_t subStreamId );
215
216 //------------------------------------------------------------------------
218 //------------------------------------------------------------------------
219 virtual Status Query( uint16_t query,
220 AnyObject &result,
221 AnyObject &channelData );
222
223
224 //------------------------------------------------------------------------
226 //------------------------------------------------------------------------
227 static void GenerateDescription( char *msg, std::ostringstream &o );
228
229 //------------------------------------------------------------------------
231 //------------------------------------------------------------------------
232 inline static void SetDescription( Message *msg )
233 {
234 std::ostringstream o;
235 GenerateDescription( msg->GetBuffer(), o );
236 msg->SetDescription( o.str() );
237 }
238
239 //------------------------------------------------------------------------
241 //------------------------------------------------------------------------
242 virtual uint32_t MessageReceived( Message &msg,
243 uint16_t subStream,
244 AnyObject &channelData );
245
246 //------------------------------------------------------------------------
248 //------------------------------------------------------------------------
249 virtual void MessageSent( Message *msg,
250 uint16_t subStream,
251 uint32_t bytesSent,
252 AnyObject &channelData );
253
254 //------------------------------------------------------------------------
256 //------------------------------------------------------------------------
257 virtual Status GetSignature( Message *toSign, Message *&sign,
258 AnyObject &channelData );
259
260 //------------------------------------------------------------------------
262 //------------------------------------------------------------------------
263 virtual Status GetSignature( Message *toSign, Message *&sign,
264 XRootDChannelInfo *info );
265
266 //------------------------------------------------------------------------
268 //------------------------------------------------------------------------
269 virtual void DecFileInstCnt( AnyObject &channelData );
270
271 //------------------------------------------------------------------------
273 //------------------------------------------------------------------------
274 virtual void WaitBeforeExit();
275
276 //------------------------------------------------------------------------
278 //------------------------------------------------------------------------
279 virtual bool NeedEncryption( HandShakeData *handShakeData,
280 AnyObject &channelData );
281
282 //------------------------------------------------------------------------
284 //------------------------------------------------------------------------
285 virtual URL GetBindPreference( const URL &url,
286 AnyObject &channelData );
287
288 private:
289
290 //------------------------------------------------------------------------
291 // Hand shake the main stream
292 //------------------------------------------------------------------------
294 AnyObject &channelData );
295
296 //------------------------------------------------------------------------
297 // Hand shake a parallel stream
298 //------------------------------------------------------------------------
300 AnyObject &channelData );
301
302 //------------------------------------------------------------------------
303 // Generate the message to be sent as an initial handshake
304 // (handshake + kXR_protocol)
305 //------------------------------------------------------------------------
307 XRootDChannelInfo *info,
308 kXR_char expect );
309
310 //------------------------------------------------------------------------
311 // Generate the protocol message
312 //------------------------------------------------------------------------
314 XRootDChannelInfo *info,
315 kXR_char expect );
316
317 //------------------------------------------------------------------------
318 // Initialize protocol request
319 //------------------------------------------------------------------------
321 XRootDChannelInfo *info,
322 kXR_char expect );
323
324 //------------------------------------------------------------------------
325 // Process the server initial handshake response
326 //------------------------------------------------------------------------
328 XRootDChannelInfo *info );
329
330 //------------------------------------------------------------------------
331 // Process the protocol response
332 //------------------------------------------------------------------------
334 XRootDChannelInfo *info );
335
336 //------------------------------------------------------------------------
337 // Process the protocol body:
338 // * 'B' : bind preferences
339 // * 'S' : security requirements
340 //------------------------------------------------------------------------
342 size_t bodysize,
343 XRootDChannelInfo *info );
344
345 //------------------------------------------------------------------------
346 // Generate the bind message
347 //------------------------------------------------------------------------
349 XRootDChannelInfo *info );
350
351 //------------------------------------------------------------------------
352 // Generate the bind message
353 //------------------------------------------------------------------------
355 XRootDChannelInfo *info );
356
357 //------------------------------------------------------------------------
358 // Generate the login message
359 //------------------------------------------------------------------------
361 XRootDChannelInfo *info );
362
363 //------------------------------------------------------------------------
364 // Process the login response
365 //------------------------------------------------------------------------
367 XRootDChannelInfo *info );
368
369 //------------------------------------------------------------------------
370 // Do the authentication
371 //------------------------------------------------------------------------
373 XRootDChannelInfo *info );
374
375 //------------------------------------------------------------------------
376 // Get the initial credentials using one of the protocols
377 //------------------------------------------------------------------------
379 HandShakeData *hsData,
380 XRootDChannelInfo *info );
381
382 //------------------------------------------------------------------------
383 // Clean up the data structures created for the authentication process
384 //------------------------------------------------------------------------
385 Status CleanUpAuthentication( XRootDChannelInfo *info );
386
387 //------------------------------------------------------------------------
388 // Clean up the data structures created for the protection purposes
389 //------------------------------------------------------------------------
390 Status CleanUpProtection( XRootDChannelInfo *info );
391
392 //------------------------------------------------------------------------
393 // Get the authentication function handle
394 //------------------------------------------------------------------------
396
397 //------------------------------------------------------------------------
398 // Generate the end session message
399 //------------------------------------------------------------------------
401 XRootDChannelInfo *info );
402
403 //------------------------------------------------------------------------
404 // Process the end session response
405 //------------------------------------------------------------------------
407 XRootDChannelInfo *info );
408
409 //------------------------------------------------------------------------
410 // Get a string representation of the server flags
411 //------------------------------------------------------------------------
412 static std::string ServerFlagsToStr( uint32_t flags );
413
414 //------------------------------------------------------------------------
415 // Get a string representation of file handle
416 //------------------------------------------------------------------------
417 static std::string FileHandleToStr( const unsigned char handle[4] );
418
419 friend struct PluginUnloadHandler;
421 };
422}
423
424#endif // __XRD_CL_XROOTD_TRANSPORT_HANDLER_HH__
unsigned char kXR_char
Definition: XPtypes.hh:65
XrdSecProtocol *(* XrdSecGetProt_t)(const char *hostname, XrdNetAddrInfo &endPoint, XrdSecParameters &sectoken, XrdOucErrInfo *einfo)
Typedef to simplify the encoding of methods returning XrdSecProtocol.
Definition: XrdSecInterface.hh:483
Definition: XrdClAnyObject.hh:33
const char * GetBuffer(uint32_t offset=0) const
Get the message buffer.
Definition: XrdClBuffer.hh:72
The message representation used throughout the system.
Definition: XrdClMessage.hh:30
void SetDescription(const std::string &description)
Set the description of the message.
Definition: XrdClMessage.hh:87
void SetIsMarshalled(bool isMarshalled)
Set the marshalling status.
Definition: XrdClMessage.hh:79
A network socket.
Definition: XrdClSocket.hh:43
Perform the handshake and the authentication for each physical stream.
Definition: XrdClPostMasterInterfaces.hh:310
URL representation.
Definition: XrdClURL.hh:31
Request status.
Definition: XrdClXRootDResponses.hh:219
XRootD transport handler.
Definition: XrdClXRootDTransport.hh:48
void InitProtocolReq(ClientProtocolRequest *request, XRootDChannelInfo *info, kXR_char expect)
virtual bool NeedControlConnection()
Definition: XrdClXRootDTransport.hh:154
static void SetDescription(Message *msg)
Get the description of a message.
Definition: XrdClXRootDTransport.hh:232
Status CleanUpProtection(XRootDChannelInfo *info)
virtual void InitializeChannel(const URL &url, AnyObject &channelData)
Initialize channel.
static std::string FileHandleToStr(const unsigned char handle[4])
XRootDTransport()
Constructor.
virtual XRootDStatus GetHeader(Message &message, Socket *socket)
virtual Status GetSignature(Message *toSign, Message *&sign, AnyObject &channelData)
Get signature for given message.
static void UnMarshallHeader(Message &msg)
Unmarshall the header incoming message.
virtual bool NeedEncryption(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 * GenerateInitialHSProtocol(HandShakeData *hsData, XRootDChannelInfo *info, kXR_char expect)
XRootDStatus HandShakeParallel(HandShakeData *handShakeData, AnyObject &channelData)
virtual bool HandShakeDone(HandShakeData *handShakeData, AnyObject &channelData)
Status CleanUpAuthentication(XRootDChannelInfo *info)
XRootDStatus ProcessProtocolResp(HandShakeData *hsData, XRootDChannelInfo *info)
Message * GenerateLogIn(HandShakeData *hsData, XRootDChannelInfo *info)
XRootDStatus HandShakeMain(HandShakeData *handShakeData, AnyObject &channelData)
~XRootDTransport()
Destructor.
virtual void WaitBeforeExit()
Wait until the program can safely exit.
Status ProcessEndSessionResp(HandShakeData *hsData, XRootDChannelInfo *info)
XRootDStatus DoAuthentication(HandShakeData *hsData, XRootDChannelInfo *info)
static std::string ServerFlagsToStr(uint32_t flags)
PluginUnloadHandler * pSecUnloadHandler
Definition: XrdClXRootDTransport.hh:420
static XRootDStatus UnMarshalStatusBody(Message &msg, uint16_t reqType)
Unmarshall the body of the status response.
Message * GenerateProtocol(HandShakeData *hsData, XRootDChannelInfo *info, kXR_char expect)
static void LogErrorResponse(const Message &msg)
Log server error response.
XRootDStatus ProcessProtocolBody(char *bodybuff, size_t bodysize, XRootDChannelInfo *info)
virtual Status Query(uint16_t query, AnyObject &result, AnyObject &channelData)
Query the channel.
XRootDStatus ProcessLogInResp(HandShakeData *hsData, XRootDChannelInfo *info)
virtual uint16_t SubStreamNumber(AnyObject &channelData)
Return a number of substreams per stream that should be created.
virtual PathID MultiplexSubStream(Message *msg, AnyObject &channelData, PathID *hint=0)
static uint16_t NbConnectedStrm(AnyObject &channelData)
Number of currently connected data streams.
virtual PathID Multiplex(Message *msg, AnyObject &channelData, PathID *hint=0)
virtual XRootDStatus GetBody(Message &message, Socket *socket)
virtual uint32_t MessageReceived(Message &msg, uint16_t subStream, AnyObject &channelData)
Check if the message invokes a stream action.
XrdSecGetProt_t GetAuthHandler()
Message * GenerateEndSession(HandShakeData *hsData, XRootDChannelInfo *info)
virtual void DecFileInstCnt(AnyObject &channelData)
Decrement file object instance count bound to this channel.
static XRootDStatus UnMarchalStatusCSE(Message &msg)
Unmarshall the correction-segment of the status response for pgwrite.
virtual XRootDStatus HandShake(HandShakeData *handShakeData, AnyObject &channelData)
HandShake.
Message * GenerateBind(HandShakeData *hsData, XRootDChannelInfo *info)
XRootDStatus ProcessBindResp(HandShakeData *hsData, XRootDChannelInfo *info)
static void GenerateDescription(char *msg, std::ostringstream &o)
Get the description of a message.
virtual Status GetSignature(Message *toSign, Message *&sign, XRootDChannelInfo *info)
Get signature for given message.
static XRootDStatus UnMarshallBody(Message *msg, uint16_t reqType)
Unmarshall the body of the incoming message.
XRootDStatus ProcessServerHS(HandShakeData *hsData, XRootDChannelInfo *info)
virtual Status IsStreamBroken(time_t inactiveTime, AnyObject &channelData)
friend struct PluginUnloadHandler
Definition: XrdClXRootDTransport.hh:419
virtual bool IsStreamTTLElapsed(time_t time, AnyObject &channelData)
Check if the stream should be disconnected.
static XRootDStatus MarshallRequest(char *msg)
Marshal the outgoing message.
static XRootDStatus MarshallRequest(Message *msg)
Marshal the outgoing message.
Definition: XrdClXRootDTransport.hh:162
XRootDStatus GetCredentials(XrdSecCredentials *&credentials, HandShakeData *hsData, XRootDChannelInfo *info)
static XRootDStatus UnMarshallRequest(Message *msg)
virtual URL GetBindPreference(const URL &url, AnyObject &channelData)
Get bind preference for the next data stream.
virtual void Disconnect(AnyObject &channelData, uint16_t subStreamId)
The stream has been disconnected, do the cleanups.
virtual void FinalizeChannel(AnyObject &channelData)
Finalize channel.
Definition: XrdSecProtect.hh:56
Definition: XrdSysPlugin.hh:53
Definition: XrdClAction.hh:34
Definition: XProtocol.hh:555
Data structure that carries the handshake information.
Definition: XrdClPostMasterInterfaces.hh:244
Definition: XrdClPostMasterInterfaces.hh:269
Procedure execution status.
Definition: XrdClStatus.hh:115
Generic structure to pass security information back and forth.
Definition: XrdSecInterface.hh:51