XRootD
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,
63  Raw = 0x0008,
66  NoProcess = 0x0010,
69  Corrupted = 0x0020,
72  More = 0x0040
73  };
74 
75  //------------------------------------------------------------------------
77  //------------------------------------------------------------------------
79  {
80  Ready = 1,
81  Broken = 2,
82  Timeout = 3,
83  FatalError = 4
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  //------------------------------------------------------------------------
181  //------------------------------------------------------------------------
182  virtual void OnWaitingToSend( Message *msg )
183  {
184  (void)msg;
185  };
186 
187  //------------------------------------------------------------------------
191  //------------------------------------------------------------------------
192  virtual bool IsRaw() const { return false; }
193 
194  //------------------------------------------------------------------------
203  //------------------------------------------------------------------------
205  uint32_t &bytesWritten )
206  {
207  (void)socket; (void)bytesWritten;
208  return Status();
209  }
210 
211  virtual time_t GetExpiration() = 0;
212  };
213 
214  //----------------------------------------------------------------------------
216  //----------------------------------------------------------------------------
218  {
219  public:
220  //------------------------------------------------------------------------
222  //------------------------------------------------------------------------
224  {
227  FatalError = 4
228  };
229 
230  //------------------------------------------------------------------------
232  //------------------------------------------------------------------------
233  virtual ~ChannelEventHandler() {};
234 
235  //------------------------------------------------------------------------
242  //------------------------------------------------------------------------
243  virtual bool OnChannelEvent( ChannelEvent event,
244  Status status ) = 0;
245  };
246 
247  //----------------------------------------------------------------------------
249  //----------------------------------------------------------------------------
250 
252  {
253  //--------------------------------------------------------------------------
255  //--------------------------------------------------------------------------
256  HandShakeData( const URL *addr, uint16_t subStream ):
257  step(0), out(0), in(0), url(addr), subStreamId( subStream ),
258  startTime( time(0) ), serverAddr(0)
259  {}
260  uint16_t step;
263  const URL *url;
264  uint16_t subStreamId;
265  time_t startTime;
266  const
268  std::string clientName;
269  std::string streamName;
270  };
271 
272  //----------------------------------------------------------------------------
275  //----------------------------------------------------------------------------
276  struct PathID
277  {
278  PathID( uint16_t u = 0, uint16_t d = 0 ): up(u), down(d) {}
279  uint16_t up;
280  uint16_t down;
281  };
282 
283  //----------------------------------------------------------------------------
286  //----------------------------------------------------------------------------
288  {
289  static const uint16_t Name = 1;
290  static const uint16_t Auth = 2;
291  };
292 
293  //----------------------------------------------------------------------------
295  //----------------------------------------------------------------------------
296  struct XRootDQuery
297  {
298  static const uint16_t ServerFlags = 1002;
299  static const uint16_t ProtocolVersion = 1003;
300  static const uint16_t IsEncrypted = 1004;
301  };
302 
303  //----------------------------------------------------------------------------
306  //----------------------------------------------------------------------------
307  struct StreamQuery
308  {
309  static const uint16_t IpAddr = 2001;
310  static const uint16_t IpStack = 2002;
311  static const uint16_t HostName = 2003;
312  };
313 
314  //----------------------------------------------------------------------------
316  //----------------------------------------------------------------------------
318  {
319  public:
320 
321  //------------------------------------------------------------------------
323  //------------------------------------------------------------------------
325  {
326  NoAction = 0x0000,
327  DigestMsg = 0x0001,
329  AbortStream = 0x0002,
332  CloseStream = 0x0004,
334  ResumeStream = 0x0008,
336  HoldStream = 0x0010,
337  RequestClose = 0x0020
338  };
339 
340 
341  virtual ~TransportHandler() {}
342 
343  //------------------------------------------------------------------------
354  //------------------------------------------------------------------------
355  virtual XRootDStatus GetHeader( Message &message, Socket *socket ) = 0;
356 
357  //------------------------------------------------------------------------
366  //------------------------------------------------------------------------
367  virtual XRootDStatus GetBody( Message &message, Socket *socket ) = 0;
368 
369  //------------------------------------------------------------------------
379  //------------------------------------------------------------------------
380  virtual XRootDStatus GetMore( Message &message, Socket *socket ) = 0;
381 
382  //------------------------------------------------------------------------
384  //------------------------------------------------------------------------
385  virtual void InitializeChannel( const URL &url,
386  AnyObject &channelData ) = 0;
387 
388  //------------------------------------------------------------------------
390  //------------------------------------------------------------------------
391  virtual void FinalizeChannel( AnyObject &channelData ) = 0;
392 
393  //------------------------------------------------------------------------
395  //------------------------------------------------------------------------
396  virtual XRootDStatus HandShake( HandShakeData *handShakeData,
397  AnyObject &channelData ) = 0;
398 
399  //------------------------------------------------------------------------
400  // @return true if handshake has been done and stream is connected,
401  // false otherwise
402  //------------------------------------------------------------------------
403  virtual bool HandShakeDone( HandShakeData *handShakeData,
404  AnyObject &channelData ) = 0;
405 
406  //------------------------------------------------------------------------
408  //------------------------------------------------------------------------
409  virtual bool IsStreamTTLElapsed( time_t inactiveTime,
410  AnyObject &channelData ) = 0;
411 
412  //------------------------------------------------------------------------
415  //------------------------------------------------------------------------
416  virtual Status IsStreamBroken( time_t inactiveTime,
417  AnyObject &channelData ) = 0;
418 
419  //------------------------------------------------------------------------
425  //------------------------------------------------------------------------
426  virtual PathID Multiplex( Message *msg,
427  AnyObject &channelData,
428  PathID *hint = 0 ) = 0;
429 
430  //------------------------------------------------------------------------
436  //------------------------------------------------------------------------
438  AnyObject &channelData,
439  PathID *hint = 0 ) = 0;
440 
441  //------------------------------------------------------------------------
443  //------------------------------------------------------------------------
444  virtual uint16_t SubStreamNumber( AnyObject &channelData ) = 0;
445 
446  //------------------------------------------------------------------------
448  //------------------------------------------------------------------------
449  virtual void Disconnect( AnyObject &channelData,
450  uint16_t subStreamId ) = 0;
451 
452  //------------------------------------------------------------------------
454  //------------------------------------------------------------------------
455  virtual Status Query( uint16_t query,
456  AnyObject &result,
457  AnyObject &channelData ) = 0;
458 
459  //------------------------------------------------------------------------
461  //------------------------------------------------------------------------
462  virtual uint32_t MessageReceived( Message &msg,
463  uint16_t subStream,
464  AnyObject &channelData ) = 0;
465 
466  //------------------------------------------------------------------------
468  //------------------------------------------------------------------------
469  virtual void MessageSent( Message *msg,
470  uint16_t subStream,
471  uint32_t bytesSent,
472  AnyObject &channelData ) = 0;
473 
474  //------------------------------------------------------------------------
476  //------------------------------------------------------------------------
477  virtual void WaitBeforeExit() = 0;
478 
479  //------------------------------------------------------------------------
481  //------------------------------------------------------------------------
482  virtual bool NeedEncryption( HandShakeData *handShakeData,
483  AnyObject &channelData ) = 0;
484 
485  //------------------------------------------------------------------------
487  //------------------------------------------------------------------------
488  virtual Status GetSignature( Message *toSign, Message *&sign,
489  AnyObject &channelData ) = 0;
490 
491  //------------------------------------------------------------------------
493  //------------------------------------------------------------------------
494  virtual void DecFileInstCnt( AnyObject &channelData ) = 0;
495 
496  //------------------------------------------------------------------------
498  //------------------------------------------------------------------------
499  virtual URL GetBindPreference( const URL &url,
500  AnyObject &channelData ) = 0;
501  };
502 }
503 
504 #endif // __XRD_CL_POST_MASTER_INTERFACES_HH__
virtual bool OnChannelEvent(ChannelEvent event, Status status)=0
ChannelEvent
Events that may have occurred to the channel.
@ StreamReady
The stream has become connected.
@ FatalError
Stream has been broken and won't be recovered.
The message representation used throughout the system.
Definition: XrdClMessage.hh:32
virtual ~MsgHandler()
Event types that the message handler may receive.
virtual uint16_t Examine(std::shared_ptr< Message > &msg)=0
virtual XRootDStatus ReadMessageBody(Message *msg, Socket *socket, uint32_t &bytesRead)
virtual XRootDStatus WriteMessageBody(Socket *socket, uint32_t &bytesWritten)
virtual uint16_t GetSid() const =0
virtual void OnWaitingToSend(Message *msg)
Called to indicate the message is waiting to be sent.
Action
Actions to be taken after a message is processed by the handler.
@ More
there are more (non-raw) data to be read
@ Ignore
Ignore the message.
virtual void OnReadyToSend(Message *msg)
virtual uint8_t OnStreamEvent(StreamEvent event, XRootDStatus status)
virtual time_t GetExpiration()=0
StreamEvent
Events that may have occurred to the stream.
@ FatalError
Stream has been broken and won't be recovered.
@ Ready
The stream has become connected.
@ Broken
The stream is broken.
virtual uint16_t InspectStatusRsp()=0
virtual void OnStatusReady(const Message *message, XRootDStatus status)=0
The requested action has been performed and the status is available.
virtual bool IsRaw() const
A network socket.
Definition: XrdClSocket.hh:43
Perform the handshake and the authentication for each physical stream.
StreamAction
Stream actions that may be triggered by incoming control messages.
@ RequestClose
Send a close request.
@ HoldStream
Stop sending requests [not yet implemented].
virtual bool NeedEncryption(HandShakeData *handShakeData, AnyObject &channelData)=0
virtual uint32_t MessageReceived(Message &msg, uint16_t subStream, AnyObject &channelData)=0
Check if the message invokes a stream action.
virtual uint16_t SubStreamNumber(AnyObject &channelData)=0
Return a number of substreams per stream that should be created.
virtual bool IsStreamTTLElapsed(time_t inactiveTime, AnyObject &channelData)=0
Check if the stream should be disconnected.
virtual PathID Multiplex(Message *msg, AnyObject &channelData, PathID *hint=0)=0
virtual Status Query(uint16_t query, AnyObject &result, AnyObject &channelData)=0
Query the channel.
virtual PathID MultiplexSubStream(Message *msg, AnyObject &channelData, PathID *hint=0)=0
virtual XRootDStatus GetBody(Message &message, Socket *socket)=0
virtual void FinalizeChannel(AnyObject &channelData)=0
Finalize channel.
virtual void Disconnect(AnyObject &channelData, uint16_t subStreamId)=0
The stream has been disconnected, do the cleanups.
virtual bool HandShakeDone(HandShakeData *handShakeData, AnyObject &channelData)=0
virtual void WaitBeforeExit()=0
Wait before exit.
virtual void InitializeChannel(const URL &url, AnyObject &channelData)=0
Initialize channel.
virtual XRootDStatus GetHeader(Message &message, Socket *socket)=0
virtual void DecFileInstCnt(AnyObject &channelData)=0
Decrement file object instance count bound to this channel.
virtual URL GetBindPreference(const URL &url, AnyObject &channelData)=0
Get bind preference for the next data stream.
virtual Status IsStreamBroken(time_t inactiveTime, AnyObject &channelData)=0
virtual XRootDStatus HandShake(HandShakeData *handShakeData, AnyObject &channelData)=0
HandHake.
virtual void MessageSent(Message *msg, uint16_t subStream, uint32_t bytesSent, AnyObject &channelData)=0
Notify the transport about a message having been sent.
virtual XRootDStatus GetMore(Message &message, Socket *socket)=0
virtual Status GetSignature(Message *toSign, Message *&sign, AnyObject &channelData)=0
Get signature for given message.
URL representation.
Definition: XrdClURL.hh:31
const uint16_t stOK
Everything went OK.
Definition: XrdClStatus.hh:31
const uint16_t suDone
Definition: XrdClStatus.hh:38
none object for initializing empty Optional
Data structure that carries the handshake information.
uint16_t step
Handshake step.
time_t startTime
Timestamp of when the handshake started.
std::string streamName
Name of the stream.
std::string clientName
Client name (an IPv6 representation)
HandShakeData(const URL *addr, uint16_t subStream)
Constructor.
const URL * url
Destination URL.
const XrdNetAddr * serverAddr
Server address.
Message * in
Message that has been received.
uint16_t subStreamId
Sub-stream id.
Message * out
Message to be sent out.
PathID(uint16_t u=0, uint16_t d=0)
Procedure execution status.
Definition: XrdClStatus.hh:115
static const uint16_t IpAddr
static const uint16_t HostName
static const uint16_t IpStack
static const uint16_t Name
Transport name, returns const char *.
static const uint16_t Auth
Transport name, returns std::string *.
XRootD related protocol queries.
static const uint16_t ServerFlags
returns server flags
static const uint16_t ProtocolVersion
returns the protocol version
static const uint16_t IsEncrypted
returns true if the channel is encrypted