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 <stdint.h>
31 #include <ctime>
32 
33 #include "XrdCl/XrdClStatus.hh"
34 #include "XrdCl/XrdClAnyObject.hh"
35 #include "XrdCl/XrdClURL.hh"
36 
37 class XrdNetAddr;
38 
39 namespace XrdCl
40 {
41  class Channel;
42  class Message;
43  class URL;
44  class Socket;
45 
46  //----------------------------------------------------------------------------
48  //----------------------------------------------------------------------------
49  class MsgHandler
50  {
51  public:
52  //------------------------------------------------------------------------
54  //------------------------------------------------------------------------
55  enum Action
56  {
57  None = 0x0000,
58  Take = 0x0001,
59  Ignore = 0x0002,
60  RemoveHandler = 0x0004,
61  Raw = 0x0008,
63  NoProcess = 0x0010,
66  Corrupted = 0x0020
69  };
72 
73  //------------------------------------------------------------------------
75  //------------------------------------------------------------------------
77  {
78  Ready = 1,
79  Broken = 2,
80  Timeout = 3,
82  };
83 
84  //------------------------------------------------------------------------
86  //------------------------------------------------------------------------
87 
88  virtual ~MsgHandler() {}
89 
90  //------------------------------------------------------------------------
96  //------------------------------------------------------------------------
97  virtual uint16_t Examine( Message *msg ) = 0;
98 
99  //------------------------------------------------------------------------
108  //------------------------------------------------------------------------
109  virtual uint16_t InspectStatusRsp( Message *msg ) = 0;
110 
111  //------------------------------------------------------------------------
115  //------------------------------------------------------------------------
116  virtual uint16_t GetSid() const = 0;
117 
118  //------------------------------------------------------------------------
122  //------------------------------------------------------------------------
123  virtual void Process( Message *msg ) { (void)msg; };
124 
125  //------------------------------------------------------------------------
135  //------------------------------------------------------------------------
137  Socket *socket,
138  uint32_t &bytesRead )
139  {
140  (void)msg; (void)socket; (void)bytesRead;
141  return Status( stOK, suDone );
142  };
143 
144  //------------------------------------------------------------------------
150  //------------------------------------------------------------------------
151  virtual uint8_t OnStreamEvent( StreamEvent event,
152  XRootDStatus status )
153  {
154  (void)event; (void)status;
155  return 0;
156  };
157 
158  //------------------------------------------------------------------------
160  //------------------------------------------------------------------------
161  virtual void OnStatusReady( const Message *message,
162  XRootDStatus status ) = 0;
163 
164  //------------------------------------------------------------------------
171  //------------------------------------------------------------------------
172  virtual void OnReadyToSend( Message *msg )
173  {
174  (void)msg;
175  };
176 
177  //------------------------------------------------------------------------
181  //------------------------------------------------------------------------
182  virtual bool IsRaw() const { return false; }
183 
184  //------------------------------------------------------------------------
186  //------------------------------------------------------------------------
187  virtual time_t GetExpiration() = 0;
188 
189  //------------------------------------------------------------------------
198  //------------------------------------------------------------------------
200  uint32_t &bytesWritten )
201  {
202  (void)socket; (void)bytesWritten;
203  return Status();
204  }
205  };
206 
207  //----------------------------------------------------------------------------
209  //----------------------------------------------------------------------------
211  {
212  public:
213  //------------------------------------------------------------------------
215  //------------------------------------------------------------------------
217  {
221  };
222 
223  //------------------------------------------------------------------------
225  //------------------------------------------------------------------------
226  virtual ~ChannelEventHandler() {};
227 
228  //------------------------------------------------------------------------
236  //------------------------------------------------------------------------
237  virtual bool OnChannelEvent( ChannelEvent event,
238  Status status ) = 0;
239  };
240 
241  //----------------------------------------------------------------------------
243  //----------------------------------------------------------------------------
244 
246  {
247  //--------------------------------------------------------------------------
249  //--------------------------------------------------------------------------
250  HandShakeData( const URL *addr, uint16_t subStream ):
251  step(0), out(0), in(0), url(addr), subStreamId( subStream ),
252  startTime( time(0) ), serverAddr(0)
253  {}
254  uint16_t step;
257  const URL *url;
258  uint16_t subStreamId;
259  time_t startTime;
260  const
262  std::string clientName;
263  std::string streamName;
264  };
265 
266  //----------------------------------------------------------------------------
269  //----------------------------------------------------------------------------
270  struct PathID
271  {
272  PathID( uint16_t u = 0, uint16_t d = 0 ): up(u), down(d) {}
273  uint16_t up;
274  uint16_t down;
275  };
276 
277  //----------------------------------------------------------------------------
280  //----------------------------------------------------------------------------
282  {
283  static const uint16_t Name = 1;
284  static const uint16_t Auth = 2;
285  };
286 
287  //----------------------------------------------------------------------------
289  //----------------------------------------------------------------------------
291  {
292  public:
293 
294  //------------------------------------------------------------------------
296  //------------------------------------------------------------------------
298  {
299  NoAction = 0x0000,
300  DigestMsg = 0x0001,
301  AbortStream = 0x0002,
303  CloseStream = 0x0004,
306  ResumeStream = 0x0008,
308  HoldStream = 0x0010,
310  RequestClose = 0x0020
311  };
312 
313 
314  virtual ~TransportHandler() {}
315 
316  //------------------------------------------------------------------------
327  //------------------------------------------------------------------------
328  virtual XRootDStatus GetHeader( Message *message, Socket *socket ) = 0;
329 
330  //------------------------------------------------------------------------
339  //------------------------------------------------------------------------
340  virtual XRootDStatus GetBody( Message *message, Socket *socket ) = 0;
341 
342  //------------------------------------------------------------------------
344  //------------------------------------------------------------------------
345  virtual void InitializeChannel( const URL &url,
346  AnyObject &channelData ) = 0;
347 
348  //------------------------------------------------------------------------
350  //------------------------------------------------------------------------
351  virtual void FinalizeChannel( AnyObject &channelData ) = 0;
352 
353  //------------------------------------------------------------------------
355  //------------------------------------------------------------------------
356  virtual XRootDStatus HandShake( HandShakeData *handShakeData,
357  AnyObject &channelData ) = 0;
358 
359  //------------------------------------------------------------------------
360  // @return true if handshake has been done and stream is connected,
361  // false otherwise
362  //------------------------------------------------------------------------
363  virtual bool HandShakeDone( HandShakeData *handShakeData,
364  AnyObject &channelData ) = 0;
365 
366  //------------------------------------------------------------------------
368  //------------------------------------------------------------------------
369  virtual bool IsStreamTTLElapsed( time_t inactiveTime,
370  AnyObject &channelData ) = 0;
371 
372  //------------------------------------------------------------------------
375  //------------------------------------------------------------------------
376  virtual Status IsStreamBroken( time_t inactiveTime,
377  AnyObject &channelData ) = 0;
378 
379  //------------------------------------------------------------------------
385  //------------------------------------------------------------------------
386  virtual PathID Multiplex( Message *msg,
387  AnyObject &channelData,
388  PathID *hint = 0 ) = 0;
389 
390  //------------------------------------------------------------------------
396  //------------------------------------------------------------------------
397  virtual PathID MultiplexSubStream( Message *msg,
398  AnyObject &channelData,
399  PathID *hint = 0 ) = 0;
400 
401  //------------------------------------------------------------------------
403  //------------------------------------------------------------------------
404  virtual uint16_t SubStreamNumber( AnyObject &channelData ) = 0;
405 
406  //------------------------------------------------------------------------
408  //------------------------------------------------------------------------
409  virtual void Disconnect( AnyObject &channelData,
410  uint16_t subStreamId ) = 0;
411 
412  //------------------------------------------------------------------------
414  //------------------------------------------------------------------------
415  virtual Status Query( uint16_t query,
416  AnyObject &result,
417  AnyObject &channelData ) = 0;
418 
419  //------------------------------------------------------------------------
421  //------------------------------------------------------------------------
422  virtual uint32_t MessageReceived( Message *msg,
423  uint16_t subStream,
424  AnyObject &channelData ) = 0;
425 
426  //------------------------------------------------------------------------
428  //------------------------------------------------------------------------
429  virtual void MessageSent( Message *msg,
430  uint16_t subStream,
431  uint32_t bytesSent,
432  AnyObject &channelData ) = 0;
433 
434  //------------------------------------------------------------------------
436  //------------------------------------------------------------------------
437  virtual void WaitBeforeExit() = 0;
438 
439  //------------------------------------------------------------------------
441  //------------------------------------------------------------------------
442  virtual bool NeedEncryption( HandShakeData *handShakeData,
443  AnyObject &channelData ) = 0;
444 
445  //------------------------------------------------------------------------
447  //------------------------------------------------------------------------
448  virtual Status GetSignature( Message *toSign, Message *&sign,
449  AnyObject &channelData ) = 0;
450 
451  //------------------------------------------------------------------------
453  //------------------------------------------------------------------------
454  virtual void DecFileInstCnt( AnyObject &channelData ) = 0;
455  };
456 }
457 
458 #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
virtual uint8_t OnStreamEvent(StreamEvent event, XRootDStatus status)
Definition: XrdClPostMasterInterfaces.hh:151
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:250
The message representation used throughout the system.
Definition: XrdClMessage.hh:29
virtual uint16_t GetSid() const =0
virtual uint16_t InspectStatusRsp(Message *msg)=0
const XrdNetAddr * serverAddr
Server address.
Definition: XrdClPostMasterInterfaces.hh:261
time_t startTime
Timestamp of when the handshake started.
Definition: XrdClPostMasterInterfaces.hh:259
virtual ~ChannelEventHandler()
Destructor.
Definition: XrdClPostMasterInterfaces.hh:226
StreamAction
Stream actions that may be triggered by incoming control messages.
Definition: XrdClPostMasterInterfaces.hh:297
const URL * url
Destination URL.
Definition: XrdClPostMasterInterfaces.hh:257
Definition: XrdClOperationTimeout.hh:19
virtual PathID Multiplex(Message *msg, AnyObject &channelData, PathID *hint=0)=0
Definition: XrdClPostMasterInterfaces.hh:270
const uint16_t suDone
Definition: XrdClStatus.hh:38
uint16_t subStreamId
Sub-stream id.
Definition: XrdClPostMasterInterfaces.hh:258
virtual uint32_t MessageReceived(Message *msg, uint16_t subStream, AnyObject &channelData)=0
Check if the message invokes a stream action.
Message handler.
Definition: XrdClPostMasterInterfaces.hh:49
virtual XRootDStatus ReadMessageBody(Message *msg, Socket *socket, uint32_t &bytesRead)
Definition: XrdClPostMasterInterfaces.hh:136
std::string clientName
Client name (an IPv6 representation)
Definition: XrdClPostMasterInterfaces.hh:262
static const uint16_t Name
Transport name, returns const char *.
Definition: XrdClPostMasterInterfaces.hh:283
virtual XRootDStatus WriteMessageBody(Socket *socket, uint32_t &bytesWritten)
Definition: XrdClPostMasterInterfaces.hh:199
Message * in
Message that has been received.
Definition: XrdClPostMasterInterfaces.hh:256
virtual bool NeedEncryption(HandShakeData *handShakeData, AnyObject &channelData)=0
Action
Actions to be taken after a message is processed by the handler.
Definition: XrdClPostMasterInterfaces.hh:55
uint16_t up
Definition: XrdClPostMasterInterfaces.hh:273
Definition: XrdNetAddr.hh:41
Procedure execution status.
Definition: XrdClStatus.hh:112
Definition: XrdClPostMasterInterfaces.hh:68
StreamEvent
Events that may have occurred to the stream.
Definition: XrdClPostMasterInterfaces.hh:76
virtual void OnStatusReady(const Message *message, XRootDStatus status)=0
The requested action has been performed and the status is available.
uint16_t step
Handshake step.
Definition: XrdClPostMasterInterfaces.hh:254
Send a close request.
Definition: XrdClPostMasterInterfaces.hh:310
virtual Status IsStreamBroken(time_t inactiveTime, AnyObject &channelData)=0
virtual bool IsRaw() const
Definition: XrdClPostMasterInterfaces.hh:182
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:65
Data structure that carries the handshake information.
Definition: XrdClPostMasterInterfaces.hh:245
Definition: XrdClPostMasterInterfaces.hh:300
Stream has been broken and won&#39;t be recovered.
Definition: XrdClPostMasterInterfaces.hh:81
virtual bool HandShakeDone(HandShakeData *handShakeData, AnyObject &channelData)=0
virtual ~TransportHandler()
Definition: XrdClPostMasterInterfaces.hh:314
Perform the handshake and the authentication for each physical stream.
Definition: XrdClPostMasterInterfaces.hh:290
Stream has been broken and won&#39;t be recovered.
Definition: XrdClPostMasterInterfaces.hh:220
none object for initializing empty Optional
Definition: XrdClOptional.hh:35
The stream is broken.
Definition: XrdClPostMasterInterfaces.hh:219
virtual ~MsgHandler()
Event types that the message handler may receive.
Definition: XrdClPostMasterInterfaces.hh:88
Request status.
Definition: XrdClXRootDResponses.hh:218
Definition: XrdClAnyObject.hh:25
Channel event handler.
Definition: XrdClPostMasterInterfaces.hh:210
The stream has become connected.
Definition: XrdClPostMasterInterfaces.hh:218
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.
Ignore the message.
Definition: XrdClPostMasterInterfaces.hh:59
uint16_t down
Definition: XrdClPostMasterInterfaces.hh:274
The stream has become connected.
Definition: XrdClPostMasterInterfaces.hh:78
virtual void Process(Message *msg)
Definition: XrdClPostMasterInterfaces.hh:123
Definition: XrdClPostMasterInterfaces.hh:307
Definition: XrdClPostMasterInterfaces.hh:302
Definition: XrdClPostMasterInterfaces.hh:281
virtual time_t GetExpiration()=0
Get a timestamp after which we give up.
URL representation.
Definition: XrdClURL.hh:30
virtual void WaitBeforeExit()=0
Wait before exit.
No action.
Definition: XrdClPostMasterInterfaces.hh:299
virtual bool OnChannelEvent(ChannelEvent event, Status status)=0
Take ownership over the message.
Definition: XrdClPostMasterInterfaces.hh:58
virtual XRootDStatus GetHeader(Message *message, Socket *socket)=0
virtual XRootDStatus GetBody(Message *message, Socket *socket)=0
virtual void InitializeChannel(const URL &url, AnyObject &channelData)=0
Initialize channel.
PathID(uint16_t u=0, uint16_t d=0)
Definition: XrdClPostMasterInterfaces.hh:272
Definition: XrdClPostMasterInterfaces.hh:60
ChannelEvent
Events that may have occurred to the channel.
Definition: XrdClPostMasterInterfaces.hh:216
virtual void OnReadyToSend(Message *msg)
Definition: XrdClPostMasterInterfaces.hh:172
virtual XRootDStatus HandShake(HandShakeData *handShakeData, AnyObject &channelData)=0
HandHake.
Definition: XrdClPostMasterInterfaces.hh:305
virtual void Disconnect(AnyObject &channelData, uint16_t subStreamId)=0
The stream has been disconnected, do the cleanups.
Message * out
Message to be sent out.
Definition: XrdClPostMasterInterfaces.hh:255
The stream is broken.
Definition: XrdClPostMasterInterfaces.hh:79
A network socket.
Definition: XrdClSocket.hh:41
virtual PathID MultiplexSubStream(Message *msg, AnyObject &channelData, PathID *hint=0)=0
virtual uint16_t Examine(Message *msg)=0
Stop sending requests [not yet implemented].
Definition: XrdClPostMasterInterfaces.hh:309
std::string streamName
Name of the stream.
Definition: XrdClPostMasterInterfaces.hh:263
Definition: XrdClPostMasterInterfaces.hh:62
static const uint16_t Auth
Transport name, returns std::string *.
Definition: XrdClPostMasterInterfaces.hh:284