xrootd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
XrdClPostMasterInterfaces.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_POST_MASTER_INTERFACES_HH__
26 #define __XRD_CL_POST_MASTER_INTERFACES_HH__
27 
29 
30 #include <cstdint>
31 #include <ctime>
32 #include <memory>
33 
34 #include "XrdCl/XrdClStatus.hh"
35 #include "XrdCl/XrdClAnyObject.hh"
36 #include "XrdCl/XrdClURL.hh"
37 
38 class XrdNetAddr;
39 
40 namespace XrdCl
41 {
42  class Channel;
43  class Message;
44  class URL;
45  class Socket;
46 
47  //----------------------------------------------------------------------------
49  //----------------------------------------------------------------------------
50  class MsgHandler
51  {
52  public:
53  //------------------------------------------------------------------------
55  //------------------------------------------------------------------------
56  enum Action
57  {
58  None = 0x0000,
59  Nop = 0x0001,
60  Ignore = 0x0002,
61  RemoveHandler = 0x0004,
62  Raw = 0x0008,
64  NoProcess = 0x0010,
67  Corrupted = 0x0020,
70  More = 0x0040
73  };
74 
75  //------------------------------------------------------------------------
77  //------------------------------------------------------------------------
79  {
80  Ready = 1,
81  Broken = 2,
82  Timeout = 3,
84  };
85 
86  //------------------------------------------------------------------------
88  //------------------------------------------------------------------------
89 
90  virtual ~MsgHandler() {}
91 
92  //------------------------------------------------------------------------
98  //------------------------------------------------------------------------
99  virtual uint16_t Examine( std::shared_ptr<Message> &msg ) = 0;
100 
101  //------------------------------------------------------------------------
110  //------------------------------------------------------------------------
111  virtual uint16_t InspectStatusRsp() = 0;
112 
113  //------------------------------------------------------------------------
117  //------------------------------------------------------------------------
118  virtual uint16_t GetSid() const = 0;
119 
120  //------------------------------------------------------------------------
124  //------------------------------------------------------------------------
125  virtual void Process() {};
126 
127  //------------------------------------------------------------------------
137  //------------------------------------------------------------------------
139  Socket *socket,
140  uint32_t &bytesRead )
141  {
142  (void)msg; (void)socket; (void)bytesRead;
143  return Status( stOK, suDone );
144  };
145 
146  //------------------------------------------------------------------------
152  //------------------------------------------------------------------------
153  virtual uint8_t OnStreamEvent( StreamEvent event,
154  XRootDStatus status )
155  {
156  (void)event; (void)status;
157  return 0;
158  };
159 
160  //------------------------------------------------------------------------
162  //------------------------------------------------------------------------
163  virtual void OnStatusReady( const Message *message,
164  XRootDStatus status ) = 0;
165 
166  //------------------------------------------------------------------------
173  //------------------------------------------------------------------------
174  virtual void OnReadyToSend( Message *msg )
175  {
176  (void)msg;
177  };
178 
179  //------------------------------------------------------------------------
183  //------------------------------------------------------------------------
184  virtual bool IsRaw() const { return false; }
185 
186  //------------------------------------------------------------------------
195  //------------------------------------------------------------------------
197  uint32_t &bytesWritten )
198  {
199  (void)socket; (void)bytesWritten;
200  return Status();
201  }
202 
203  virtual time_t GetExpiration() = 0;
204  };
205 
206  //----------------------------------------------------------------------------
208  //----------------------------------------------------------------------------
210  {
211  public:
212  //------------------------------------------------------------------------
214  //------------------------------------------------------------------------
216  {
220  };
221 
222  //------------------------------------------------------------------------
224  //------------------------------------------------------------------------
225  virtual ~ChannelEventHandler() {};
226 
227  //------------------------------------------------------------------------
235  //------------------------------------------------------------------------
236  virtual bool OnChannelEvent( ChannelEvent event,
237  Status status ) = 0;
238  };
239 
240  //----------------------------------------------------------------------------
242  //----------------------------------------------------------------------------
243 
245  {
246  //--------------------------------------------------------------------------
248  //--------------------------------------------------------------------------
249  HandShakeData( const URL *addr, uint16_t subStream ):
250  step(0), out(0), in(0), url(addr), subStreamId( subStream ),
251  startTime( time(0) ), serverAddr(0)
252  {}
253  uint16_t step;
256  const URL *url;
257  uint16_t subStreamId;
258  time_t startTime;
259  const
261  std::string clientName;
262  std::string streamName;
263  };
264 
265  //----------------------------------------------------------------------------
268  //----------------------------------------------------------------------------
269  struct PathID
270  {
271  PathID( uint16_t u = 0, uint16_t d = 0 ): up(u), down(d) {}
272  uint16_t up;
273  uint16_t down;
274  };
275 
276  //----------------------------------------------------------------------------
279  //----------------------------------------------------------------------------
281  {
282  static const uint16_t Name = 1;
283  static const uint16_t Auth = 2;
284  };
285 
286  //----------------------------------------------------------------------------
288  //----------------------------------------------------------------------------
289  struct XRootDQuery
290  {
291  static const uint16_t ServerFlags = 1002;
292  static const uint16_t ProtocolVersion = 1003;
293  static const uint16_t IsEncrypted = 1004;
294  };
295 
296  //----------------------------------------------------------------------------
299  //----------------------------------------------------------------------------
300  struct StreamQuery
301  {
302  static const uint16_t IpAddr = 2001;
303  static const uint16_t IpStack = 2002;
304  static const uint16_t HostName = 2003;
305  };
306 
307  //----------------------------------------------------------------------------
309  //----------------------------------------------------------------------------
311  {
312  public:
313 
314  //------------------------------------------------------------------------
316  //------------------------------------------------------------------------
318  {
319  NoAction = 0x0000,
320  DigestMsg = 0x0001,
321  AbortStream = 0x0002,
323  CloseStream = 0x0004,
326  ResumeStream = 0x0008,
328  HoldStream = 0x0010,
330  RequestClose = 0x0020
331  };
332 
333 
334  virtual ~TransportHandler() {}
335 
336  //------------------------------------------------------------------------
347  //------------------------------------------------------------------------
348  virtual XRootDStatus GetHeader( Message &message, Socket *socket ) = 0;
349 
350  //------------------------------------------------------------------------
359  //------------------------------------------------------------------------
360  virtual XRootDStatus GetBody( Message &message, Socket *socket ) = 0;
361 
362  //------------------------------------------------------------------------
364  //------------------------------------------------------------------------
365  virtual void InitializeChannel( const URL &url,
366  AnyObject &channelData ) = 0;
367 
368  //------------------------------------------------------------------------
370  //------------------------------------------------------------------------
371  virtual void FinalizeChannel( AnyObject &channelData ) = 0;
372 
373  //------------------------------------------------------------------------
375  //------------------------------------------------------------------------
376  virtual XRootDStatus HandShake( HandShakeData *handShakeData,
377  AnyObject &channelData ) = 0;
378 
379  //------------------------------------------------------------------------
380  // @return true if handshake has been done and stream is connected,
381  // false otherwise
382  //------------------------------------------------------------------------
383  virtual bool HandShakeDone( HandShakeData *handShakeData,
384  AnyObject &channelData ) = 0;
385 
386  //------------------------------------------------------------------------
388  //------------------------------------------------------------------------
389  virtual bool IsStreamTTLElapsed( time_t inactiveTime,
390  AnyObject &channelData ) = 0;
391 
392  //------------------------------------------------------------------------
395  //------------------------------------------------------------------------
396  virtual Status IsStreamBroken( time_t inactiveTime,
397  AnyObject &channelData ) = 0;
398 
399  //------------------------------------------------------------------------
405  //------------------------------------------------------------------------
406  virtual PathID Multiplex( Message *msg,
407  AnyObject &channelData,
408  PathID *hint = 0 ) = 0;
409 
410  //------------------------------------------------------------------------
416  //------------------------------------------------------------------------
417  virtual PathID MultiplexSubStream( Message *msg,
418  AnyObject &channelData,
419  PathID *hint = 0 ) = 0;
420 
421  //------------------------------------------------------------------------
423  //------------------------------------------------------------------------
424  virtual uint16_t SubStreamNumber( AnyObject &channelData ) = 0;
425 
426  //------------------------------------------------------------------------
428  //------------------------------------------------------------------------
429  virtual void Disconnect( AnyObject &channelData,
430  uint16_t subStreamId ) = 0;
431 
432  //------------------------------------------------------------------------
434  //------------------------------------------------------------------------
435  virtual Status Query( uint16_t query,
436  AnyObject &result,
437  AnyObject &channelData ) = 0;
438 
439  //------------------------------------------------------------------------
441  //------------------------------------------------------------------------
442  virtual uint32_t MessageReceived( Message &msg,
443  uint16_t subStream,
444  AnyObject &channelData ) = 0;
445 
446  //------------------------------------------------------------------------
448  //------------------------------------------------------------------------
449  virtual void MessageSent( Message *msg,
450  uint16_t subStream,
451  uint32_t bytesSent,
452  AnyObject &channelData ) = 0;
453 
454  //------------------------------------------------------------------------
456  //------------------------------------------------------------------------
457  virtual void WaitBeforeExit() = 0;
458 
459  //------------------------------------------------------------------------
461  //------------------------------------------------------------------------
462  virtual bool NeedEncryption( HandShakeData *handShakeData,
463  AnyObject &channelData ) = 0;
464 
465  //------------------------------------------------------------------------
467  //------------------------------------------------------------------------
468  virtual Status GetSignature( Message *toSign, Message *&sign,
469  AnyObject &channelData ) = 0;
470 
471  //------------------------------------------------------------------------
473  //------------------------------------------------------------------------
474  virtual void DecFileInstCnt( AnyObject &channelData ) = 0;
475 
476  //------------------------------------------------------------------------
478  //------------------------------------------------------------------------
479  virtual URL GetBindPreference( const URL &url,
480  AnyObject &channelData ) = 0;
481  };
482 }
483 
484 #endif // __XRD_CL_POST_MASTER_INTERFACES_HH__
virtual void MessageSent(Message *msg, uint16_t subStream, uint32_t bytesSent, AnyObject &channelData)=0
Notify the transport about a message having been sent.
Definition: XrdClAnyObject.hh:32
const uint16_t stOK
Everything went OK.
Definition: XrdClStatus.hh:31
Definition: XrdClPostMasterInterfaces.hh:300
virtual uint8_t OnStreamEvent(StreamEvent event, XRootDStatus status)
Definition: XrdClPostMasterInterfaces.hh:153
virtual void FinalizeChannel(AnyObject &channelData)=0
Finalize channel.
virtual void DecFileInstCnt(AnyObject &channelData)=0
Decrement file object instance count bound to this channel.
HandShakeData(const URL *addr, uint16_t subStream)
Constructor.
Definition: XrdClPostMasterInterfaces.hh:249
The message representation used throughout the system.
Definition: XrdClMessage.hh:29
virtual uint16_t GetSid() const =0
const XrdNetAddr * serverAddr
Server address.
Definition: XrdClPostMasterInterfaces.hh:260
time_t startTime
Timestamp of when the handshake started.
Definition: XrdClPostMasterInterfaces.hh:258
virtual ~ChannelEventHandler()
Destructor.
Definition: XrdClPostMasterInterfaces.hh:225
XRootD related protocol queries.
Definition: XrdClPostMasterInterfaces.hh:289
StreamAction
Stream actions that may be triggered by incoming control messages.
Definition: XrdClPostMasterInterfaces.hh:317
const URL * url
Destination URL.
Definition: XrdClPostMasterInterfaces.hh:256
Definition: XrdClOperationTimeout.hh:19
virtual PathID Multiplex(Message *msg, AnyObject &channelData, PathID *hint=0)=0
Definition: XrdClPostMasterInterfaces.hh:269
const uint16_t suDone
Definition: XrdClStatus.hh:38
uint16_t subStreamId
Sub-stream id.
Definition: XrdClPostMasterInterfaces.hh:257
static const uint16_t IpStack
Definition: XrdClPostMasterInterfaces.hh:303
Message handler.
Definition: XrdClPostMasterInterfaces.hh:50
virtual XRootDStatus ReadMessageBody(Message *msg, Socket *socket, uint32_t &bytesRead)
Definition: XrdClPostMasterInterfaces.hh:138
std::string clientName
Client name (an IPv6 representation)
Definition: XrdClPostMasterInterfaces.hh:261
static const uint16_t Name
Transport name, returns const char *.
Definition: XrdClPostMasterInterfaces.hh:282
virtual XRootDStatus WriteMessageBody(Socket *socket, uint32_t &bytesWritten)
Definition: XrdClPostMasterInterfaces.hh:196
Message * in
Message that has been received.
Definition: XrdClPostMasterInterfaces.hh:255
static const uint16_t IpAddr
Definition: XrdClPostMasterInterfaces.hh:302
virtual uint32_t MessageReceived(Message &msg, uint16_t subStream, AnyObject &channelData)=0
Check if the message invokes a stream action.
virtual bool NeedEncryption(HandShakeData *handShakeData, AnyObject &channelData)=0
Action
Actions to be taken after a message is processed by the handler.
Definition: XrdClPostMasterInterfaces.hh:56
uint16_t up
Definition: XrdClPostMasterInterfaces.hh:272
Definition: XrdNetAddr.hh:41
Procedure execution status.
Definition: XrdClStatus.hh:113
Definition: XrdClPostMasterInterfaces.hh:69
StreamEvent
Events that may have occurred to the stream.
Definition: XrdClPostMasterInterfaces.hh:78
virtual void OnStatusReady(const Message *message, XRootDStatus status)=0
The requested action has been performed and the status is available.
virtual void Process()
Definition: XrdClPostMasterInterfaces.hh:125
uint16_t step
Handshake step.
Definition: XrdClPostMasterInterfaces.hh:253
virtual URL GetBindPreference(const URL &url, AnyObject &channelData)=0
Get bind preference for the next data stream.
Send a close request.
Definition: XrdClPostMasterInterfaces.hh:330
virtual uint16_t Examine(std::shared_ptr< Message > &msg)=0
static const uint16_t ProtocolVersion
returns the protocol version
Definition: XrdClPostMasterInterfaces.hh:292
virtual Status IsStreamBroken(time_t inactiveTime, AnyObject &channelData)=0
virtual Status Query(uint16_t query, AnyObject &result, AnyObject &channelData)=0
Query the channel.
virtual Status GetSignature(Message *toSign, Message *&sign, AnyObject &channelData)=0
Get signature for given message.
Definition: XrdClPostMasterInterfaces.hh:66
Data structure that carries the handshake information.
Definition: XrdClPostMasterInterfaces.hh:244
Definition: XrdClPostMasterInterfaces.hh:320
Stream has been broken and won&#39;t be recovered.
Definition: XrdClPostMasterInterfaces.hh:83
virtual bool HandShakeDone(HandShakeData *handShakeData, AnyObject &channelData)=0
virtual uint16_t InspectStatusRsp()=0
virtual ~TransportHandler()
Definition: XrdClPostMasterInterfaces.hh:334
Perform the handshake and the authentication for each physical stream.
Definition: XrdClPostMasterInterfaces.hh:310
Stream has been broken and won&#39;t be recovered.
Definition: XrdClPostMasterInterfaces.hh:219
none object for initializing empty Optional
Definition: XrdClOptional.hh:35
The stream is broken.
Definition: XrdClPostMasterInterfaces.hh:218
virtual ~MsgHandler()
Event types that the message handler may receive.
Definition: XrdClPostMasterInterfaces.hh:90
Request status.
Definition: XrdClXRootDResponses.hh:218
Channel event handler.
Definition: XrdClPostMasterInterfaces.hh:209
The stream has become connected.
Definition: XrdClPostMasterInterfaces.hh:217
A place holder.
Definition: XrdClPostMasterInterfaces.hh:59
virtual uint16_t SubStreamNumber(AnyObject &channelData)=0
Return a number of substreams per stream that should be created.
j template void())
Definition: XrdOucJson.hh:4121
virtual bool IsStreamTTLElapsed(time_t inactiveTime, AnyObject &channelData)=0
Check if the stream should be disconnected.
static const uint16_t IsEncrypted
returns true if the channel is encrypted
Definition: XrdClPostMasterInterfaces.hh:293
virtual bool IsRaw() const
Definition: XrdClPostMasterInterfaces.hh:184
static const uint16_t HostName
Definition: XrdClPostMasterInterfaces.hh:304
Ignore the message.
Definition: XrdClPostMasterInterfaces.hh:60
uint16_t down
Definition: XrdClPostMasterInterfaces.hh:273
The stream has become connected.
Definition: XrdClPostMasterInterfaces.hh:80
Definition: XrdClPostMasterInterfaces.hh:327
Definition: XrdClPostMasterInterfaces.hh:322
Definition: XrdClPostMasterInterfaces.hh:280
virtual time_t GetExpiration()=0
URL representation.
Definition: XrdClURL.hh:30
virtual void WaitBeforeExit()=0
Wait before exit.
No action.
Definition: XrdClPostMasterInterfaces.hh:319
virtual bool OnChannelEvent(ChannelEvent event, Status status)=0
virtual void InitializeChannel(const URL &url, AnyObject &channelData)=0
Initialize channel.
PathID(uint16_t u=0, uint16_t d=0)
Definition: XrdClPostMasterInterfaces.hh:271
Definition: XrdClPostMasterInterfaces.hh:61
ChannelEvent
Events that may have occurred to the channel.
Definition: XrdClPostMasterInterfaces.hh:215
virtual void OnReadyToSend(Message *msg)
Definition: XrdClPostMasterInterfaces.hh:174
virtual XRootDStatus HandShake(HandShakeData *handShakeData, AnyObject &channelData)=0
HandHake.
virtual XRootDStatus GetBody(Message &message, Socket *socket)=0
Definition: XrdClPostMasterInterfaces.hh:325
virtual void Disconnect(AnyObject &channelData, uint16_t subStreamId)=0
The stream has been disconnected, do the cleanups.
virtual XRootDStatus GetHeader(Message &message, Socket *socket)=0
there are more (non-raw) data to be read
Definition: XrdClPostMasterInterfaces.hh:72
Message * out
Message to be sent out.
Definition: XrdClPostMasterInterfaces.hh:254
The stream is broken.
Definition: XrdClPostMasterInterfaces.hh:81
A network socket.
Definition: XrdClSocket.hh:42
virtual PathID MultiplexSubStream(Message *msg, AnyObject &channelData, PathID *hint=0)=0
Stop sending requests [not yet implemented].
Definition: XrdClPostMasterInterfaces.hh:329
std::string streamName
Name of the stream.
Definition: XrdClPostMasterInterfaces.hh:262
Definition: XrdClPostMasterInterfaces.hh:63
static const uint16_t Auth
Transport name, returns std::string *.
Definition: XrdClPostMasterInterfaces.hh:283
static const uint16_t ServerFlags
returns server flags
Definition: XrdClPostMasterInterfaces.hh:291