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 
28 #include <stdint.h>
29 #include <ctime>
30 
31 #include "XrdCl/XrdClStatus.hh"
32 #include "XrdCl/XrdClAnyObject.hh"
33 #include "XrdCl/XrdClURL.hh"
34 
35 namespace XrdCl
36 {
37  class Channel;
38  class Message;
39  class URL;
40 
41  //----------------------------------------------------------------------------
43  //----------------------------------------------------------------------------
45  {
46  public:
47  virtual ~MessageFilter() {}
48 
49  //------------------------------------------------------------------------
52  //------------------------------------------------------------------------
53  virtual bool Filter( const Message *msg ) = 0;
54  };
55 
56  //----------------------------------------------------------------------------
58  //----------------------------------------------------------------------------
60  {
61  public:
62  //------------------------------------------------------------------------
64  //------------------------------------------------------------------------
65  enum Action
66  {
67  Take = 0x0001,
68  Ignore = 0x0002,
69  RemoveHandler = 0x0004,
70  Raw = 0x0008,
72  NoProcess = 0x0010
75  };
78 
79  //------------------------------------------------------------------------
81  //------------------------------------------------------------------------
83  {
84  Ready = 1,
85  Broken = 2,
86  Timeout = 3,
88  };
89 
90  //------------------------------------------------------------------------
92  //------------------------------------------------------------------------
93 
94  virtual ~IncomingMsgHandler() {}
95 
96  //------------------------------------------------------------------------
102  //------------------------------------------------------------------------
103  virtual uint16_t Examine( Message *msg ) = 0;
104 
105  //------------------------------------------------------------------------
109  //------------------------------------------------------------------------
110  virtual void Process( Message *msg ) { (void)msg; };
111 
112  //------------------------------------------------------------------------
122  //------------------------------------------------------------------------
124  int socket,
125  uint32_t &bytesRead )
126  {
127  (void)msg; (void)socket; (void)bytesRead;
128  return Status( stOK, suDone );
129  };
130 
131  //------------------------------------------------------------------------
138  //------------------------------------------------------------------------
139  virtual uint8_t OnStreamEvent( StreamEvent event,
140  uint16_t streamNum,
141  Status status )
142  {
143  (void)event; (void)streamNum; (void)status;
144  return 0;
145  };
146  };
147 
148  //----------------------------------------------------------------------------
150  //----------------------------------------------------------------------------
152  {
153  public:
154  virtual ~OutgoingMsgHandler() {}
155 
156  //------------------------------------------------------------------------
158  //------------------------------------------------------------------------
159  virtual void OnStatusReady( const Message *message,
160  Status status ) = 0;
161 
162  //------------------------------------------------------------------------
170  //------------------------------------------------------------------------
171  virtual void OnReadyToSend( Message *msg, uint16_t streamNum )
172  {
173  (void)msg; (void)streamNum;
174  };
175 
176  //------------------------------------------------------------------------
180  //------------------------------------------------------------------------
181  virtual bool IsRaw() const { return false; }
182 
183  //------------------------------------------------------------------------
192  //------------------------------------------------------------------------
193  virtual Status WriteMessageBody( int socket,
194  uint32_t &bytesRead )
195  {
196  (void)socket; (void)bytesRead;
197  return Status();
198  }
199  };
200 
201  //----------------------------------------------------------------------------
203  //----------------------------------------------------------------------------
205  {
206  public:
207  //------------------------------------------------------------------------
209  //------------------------------------------------------------------------
211  {
215  };
216 
217  //------------------------------------------------------------------------
219  //------------------------------------------------------------------------
220  virtual ~ChannelEventHandler() {};
221 
222  //------------------------------------------------------------------------
230  //------------------------------------------------------------------------
231  virtual bool OnChannelEvent( ChannelEvent event,
232  Status status,
233  uint16_t stream ) = 0;
234  };
235 
236  //----------------------------------------------------------------------------
238  //----------------------------------------------------------------------------
240  {
241  //--------------------------------------------------------------------------
243  //--------------------------------------------------------------------------
244  HandShakeData( const URL *addr, uint16_t stream, uint16_t subStream ):
245  step(0), out(0), in(0), url(addr), streamId(stream),
246  subStreamId( subStream ), startTime( time(0) ), serverAddr(0)
247  {}
248  uint16_t step;
251  const URL *url;
252  uint16_t streamId;
253  uint16_t subStreamId;
254  time_t startTime;
255  const void *serverAddr;
256  std::string clientName;
257  std::string streamName;
258  };
259 
260  //----------------------------------------------------------------------------
263  //----------------------------------------------------------------------------
264  struct PathID
265  {
266  PathID( uint16_t u = 0, uint16_t d = 0 ): up(u), down(d) {}
267  uint16_t up;
268  uint16_t down;
269  };
270 
271  //----------------------------------------------------------------------------
274  //----------------------------------------------------------------------------
276  {
277  static const uint16_t Name = 1;
278  static const uint16_t Auth = 2;
279  };
280 
281  //----------------------------------------------------------------------------
283  //----------------------------------------------------------------------------
285  {
286  public:
287 
288  //------------------------------------------------------------------------
290  //------------------------------------------------------------------------
292  {
293  NoAction = 0x0000,
294  DigestMsg = 0x0001,
295  AbortStream = 0x0002,
297  CloseStream = 0x0004,
300  ResumeStream = 0x0008,
302  HoldStream = 0x0010
304  };
305 
306 
307  virtual ~TransportHandler() {}
308 
309  //------------------------------------------------------------------------
320  //------------------------------------------------------------------------
321  virtual Status GetHeader( Message *message, int socket ) = 0;
322 
323  //------------------------------------------------------------------------
332  //------------------------------------------------------------------------
333  virtual Status GetBody( Message *message, int socket ) = 0;
334 
335  //------------------------------------------------------------------------
337  //------------------------------------------------------------------------
338  virtual void InitializeChannel( AnyObject &channelData ) = 0;
339 
340  //------------------------------------------------------------------------
342  //------------------------------------------------------------------------
343  virtual void FinalizeChannel( AnyObject &channelData ) = 0;
344 
345  //------------------------------------------------------------------------
347  //------------------------------------------------------------------------
348  virtual Status HandShake( HandShakeData *handShakeData,
349  AnyObject &channelData ) = 0;
350 
351  //------------------------------------------------------------------------
353  //------------------------------------------------------------------------
354  virtual bool IsStreamTTLElapsed( time_t inactiveTime,
355  uint16_t streamId,
356  AnyObject &channelData ) = 0;
357 
358  //------------------------------------------------------------------------
361  //------------------------------------------------------------------------
362  virtual Status IsStreamBroken( time_t inactiveTime,
363  uint16_t streamId,
364  AnyObject &channelData ) = 0;
365 
366  //------------------------------------------------------------------------
372  //------------------------------------------------------------------------
373  virtual PathID Multiplex( Message *msg,
374  AnyObject &channelData,
375  PathID *hint = 0 ) = 0;
376 
377  //------------------------------------------------------------------------
383  //------------------------------------------------------------------------
384  virtual PathID MultiplexSubStream( Message *msg,
385  uint16_t streamId,
386  AnyObject &channelData,
387  PathID *hint = 0 ) = 0;
388 
389  //------------------------------------------------------------------------
391  //------------------------------------------------------------------------
392  virtual uint16_t StreamNumber( AnyObject &channelData ) = 0;
393 
394  //------------------------------------------------------------------------
396  //------------------------------------------------------------------------
397  virtual uint16_t SubStreamNumber( AnyObject &channelData ) = 0;
398 
399  //------------------------------------------------------------------------
401  //------------------------------------------------------------------------
402  virtual void Disconnect( AnyObject &channelData,
403  uint16_t streamId,
404  uint16_t subStreamId ) = 0;
405 
406  //------------------------------------------------------------------------
408  //------------------------------------------------------------------------
409  virtual Status Query( uint16_t query,
410  AnyObject &result,
411  AnyObject &channelData ) = 0;
412 
413  //------------------------------------------------------------------------
415  //------------------------------------------------------------------------
416  virtual uint32_t MessageReceived( Message *msg,
417  uint16_t streamId,
418  uint16_t subStream,
419  AnyObject &channelData ) = 0;
420 
421  //------------------------------------------------------------------------
423  //------------------------------------------------------------------------
424  virtual void MessageSent( Message *msg,
425  uint16_t streamId,
426  uint16_t subStream,
427  uint32_t bytesSent,
428  AnyObject &channelData ) = 0;
429  };
430 }
431 
432 #endif // __XRD_CL_POST_MASTER_INTERFACES_HH__
Definition: XrdClAnyObject.hh:32
const uint16_t stOK
Everything went OK.
Definition: XrdClStatus.hh:31
Definition: XrdClPostMasterInterfaces.hh:71
virtual bool OnChannelEvent(ChannelEvent event, Status status, uint16_t stream)=0
virtual void FinalizeChannel(AnyObject &channelData)=0
Finalize channel.
Take ownership over the message.
Definition: XrdClPostMasterInterfaces.hh:67
Message filter.
Definition: XrdClPostMasterInterfaces.hh:44
Definition: XrdClPostMasterInterfaces.hh:69
virtual ~IncomingMsgHandler()
Event types that the message handler may receive.
Definition: XrdClPostMasterInterfaces.hh:94
Stream has been broken and won't be recovered.
Definition: XrdClPostMasterInterfaces.hh:87
virtual bool IsRaw() const
Definition: XrdClPostMasterInterfaces.hh:181
virtual Status GetHeader(Message *message, int socket)=0
The message representation used throughout the system.
Definition: XrdClMessage.hh:29
time_t startTime
Timestamp of when the handshake started.
Definition: XrdClPostMasterInterfaces.hh:254
virtual Status WriteMessageBody(int socket, uint32_t &bytesRead)
Definition: XrdClPostMasterInterfaces.hh:193
virtual ~ChannelEventHandler()
Destructor.
Definition: XrdClPostMasterInterfaces.hh:220
StreamAction
Stream actions that may be triggered by incoming control messages.
Definition: XrdClPostMasterInterfaces.hh:291
const URL * url
Destination URL.
Definition: XrdClPostMasterInterfaces.hh:251
virtual PathID Multiplex(Message *msg, AnyObject &channelData, PathID *hint=0)=0
Definition: XrdClPostMasterInterfaces.hh:264
const uint16_t suDone
Definition: XrdClStatus.hh:38
uint16_t subStreamId
Sub-stream id.
Definition: XrdClPostMasterInterfaces.hh:253
std::string clientName
Client name (an IPv6 representation)
Definition: XrdClPostMasterInterfaces.hh:256
static const uint16_t Name
Transport name, returns const char *.
Definition: XrdClPostMasterInterfaces.hh:277
Message * in
Message that has been received.
Definition: XrdClPostMasterInterfaces.hh:250
const void * serverAddr
Server address in the form of sockaddr.
Definition: XrdClPostMasterInterfaces.hh:255
StreamEvent
Events that may have occurred to the stream.
Definition: XrdClPostMasterInterfaces.hh:82
uint16_t up
Definition: XrdClPostMasterInterfaces.hh:267
Procedure execution status.
Definition: XrdClStatus.hh:106
virtual uint16_t Examine(Message *msg)=0
virtual Status IsStreamBroken(time_t inactiveTime, uint16_t streamId, AnyObject &channelData)=0
uint16_t step
Handshake step.
Definition: XrdClPostMasterInterfaces.hh:248
virtual uint16_t StreamNumber(AnyObject &channelData)=0
Return a number of streams that should be created.
virtual Status Query(uint16_t query, AnyObject &result, AnyObject &channelData)=0
Query the channel.
virtual bool Filter(const Message *msg)=0
uint16_t streamId
Stream number.
Definition: XrdClPostMasterInterfaces.hh:252
Data structure that carries the handshake information.
Definition: XrdClPostMasterInterfaces.hh:239
virtual Status GetBody(Message *message, int socket)=0
Definition: XrdClPostMasterInterfaces.hh:294
virtual ~TransportHandler()
Definition: XrdClPostMasterInterfaces.hh:307
virtual Status HandShake(HandShakeData *handShakeData, AnyObject &channelData)=0
HandHake.
Perform the handshake and the authentication for each physical stream.
Definition: XrdClPostMasterInterfaces.hh:284
Stream has been broken and won't be recovered.
Definition: XrdClPostMasterInterfaces.hh:214
The stream is broken.
Definition: XrdClPostMasterInterfaces.hh:213
The declared timeout has occurred.
Definition: XrdClPostMasterInterfaces.hh:86
Channel event handler.
Definition: XrdClPostMasterInterfaces.hh:204
The stream has become connected.
Definition: XrdClPostMasterInterfaces.hh:212
The stream is broken.
Definition: XrdClPostMasterInterfaces.hh:85
Message handler.
Definition: XrdClPostMasterInterfaces.hh:59
virtual uint8_t OnStreamEvent(StreamEvent event, uint16_t streamNum, Status status)
Definition: XrdClPostMasterInterfaces.hh:139
virtual uint16_t SubStreamNumber(AnyObject &channelData)=0
Return a number of substreams per stream that should be created.
uint16_t down
Definition: XrdClPostMasterInterfaces.hh:268
virtual bool IsStreamTTLElapsed(time_t inactiveTime, uint16_t streamId, AnyObject &channelData)=0
Check if the stream should be disconnected.
Definition: XrdClPostMasterInterfaces.hh:301
Action
Actions to be taken after a message is processed by the handler.
Definition: XrdClPostMasterInterfaces.hh:65
Definition: XrdClPostMasterInterfaces.hh:296
Definition: XrdClPostMasterInterfaces.hh:275
URL representation.
Definition: XrdClURL.hh:30
No action.
Definition: XrdClPostMasterInterfaces.hh:293
virtual ~MessageFilter()
Definition: XrdClPostMasterInterfaces.hh:47
virtual Status ReadMessageBody(Message *msg, int socket, uint32_t &bytesRead)
Definition: XrdClPostMasterInterfaces.hh:123
virtual void InitializeChannel(AnyObject &channelData)=0
Initialize channel.
virtual void Process(Message *msg)
Definition: XrdClPostMasterInterfaces.hh:110
Ignore the message.
Definition: XrdClPostMasterInterfaces.hh:68
virtual void Disconnect(AnyObject &channelData, uint16_t streamId, uint16_t subStreamId)=0
The stream has been disconnected, do the cleanups.
The stream has become connected.
Definition: XrdClPostMasterInterfaces.hh:84
virtual ~OutgoingMsgHandler()
Definition: XrdClPostMasterInterfaces.hh:154
Definition: XrdClPostMasterInterfaces.hh:74
virtual void MessageSent(Message *msg, uint16_t streamId, uint16_t subStream, uint32_t bytesSent, AnyObject &channelData)=0
Notify the transport about a message having been sent.
Message status handler.
Definition: XrdClPostMasterInterfaces.hh:151
PathID(uint16_t u=0, uint16_t d=0)
Definition: XrdClPostMasterInterfaces.hh:266
virtual void OnStatusReady(const Message *message, Status status)=0
The requested action has been performed and the status is available.
virtual void OnReadyToSend(Message *msg, uint16_t streamNum)
Definition: XrdClPostMasterInterfaces.hh:171
ChannelEvent
Events that may have occurred to the channel.
Definition: XrdClPostMasterInterfaces.hh:210
virtual uint32_t MessageReceived(Message *msg, uint16_t streamId, uint16_t subStream, AnyObject &channelData)=0
Check if the message invokes a stream action.
Definition: XrdClPostMasterInterfaces.hh:299
HandShakeData(const URL *addr, uint16_t stream, uint16_t subStream)
Constructor.
Definition: XrdClPostMasterInterfaces.hh:244
Message * out
Message to be sent out.
Definition: XrdClPostMasterInterfaces.hh:249
Stop sending requests [not yet implemented].
Definition: XrdClPostMasterInterfaces.hh:303
std::string streamName
Name of the stream.
Definition: XrdClPostMasterInterfaces.hh:257
static const uint16_t Auth
Transport name, returns std::string *.
Definition: XrdClPostMasterInterfaces.hh:278
virtual PathID MultiplexSubStream(Message *msg, uint16_t streamId, AnyObject &channelData, PathID *hint=0)=0