xrootd
XrdClXRootDTransport.hh
Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 // Copyright (c) 2011-2012 by European Organization for Nuclear Research (CERN)
00003 // Author: Lukasz Janyst <ljanyst@cern.ch>
00004 //------------------------------------------------------------------------------
00005 // XRootD is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU Lesser General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // XRootD is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public License
00016 // along with XRootD.  If not, see <http://www.gnu.org/licenses/>.
00017 //------------------------------------------------------------------------------
00018 
00019 #ifndef __XRD_CL_XROOTD_TRANSPORT_HH__
00020 #define __XRD_CL_XROOTD_TRANSPORT_HH__
00021 
00022 #include "XrdCl/XrdClPostMaster.hh"
00023 #include "XProtocol/XProtocol.hh"
00024 #include "XrdSec/XrdSecInterface.hh"
00025 #include "XrdOuc/XrdOucEnv.hh"
00026 
00027 namespace XrdCl
00028 {
00029   struct XRootDChannelInfo;
00030 
00031   //----------------------------------------------------------------------------
00033   //----------------------------------------------------------------------------
00034   struct XRootDQuery
00035   {
00036     static const uint16_t SIDManager      = 1001; 
00037     static const uint16_t ServerFlags     = 1002; 
00038     static const uint16_t ProtocolVersion = 1003; 
00039   };
00040 
00041   //----------------------------------------------------------------------------
00043   //----------------------------------------------------------------------------
00044   class XRootDTransport: public TransportHandler
00045   {
00046     public:
00047       //------------------------------------------------------------------------
00049       //------------------------------------------------------------------------
00050       XRootDTransport();
00051 
00052       //------------------------------------------------------------------------
00054       //------------------------------------------------------------------------
00055       ~XRootDTransport();
00056 
00057       //------------------------------------------------------------------------
00068       //------------------------------------------------------------------------
00069       virtual Status GetHeader( Message *message, int socket );
00070 
00071       //------------------------------------------------------------------------
00080       //------------------------------------------------------------------------
00081       virtual Status GetBody( Message *message, int socket );
00082 
00083       //------------------------------------------------------------------------
00085       //------------------------------------------------------------------------
00086       virtual void InitializeChannel( AnyObject &channelData );
00087 
00088       //------------------------------------------------------------------------
00090       //------------------------------------------------------------------------
00091       virtual void FinalizeChannel( AnyObject &channelData );
00092 
00093       //------------------------------------------------------------------------
00095       //------------------------------------------------------------------------
00096       virtual Status HandShake( HandShakeData *handShakeData,
00097                                 AnyObject     &channelData );
00098 
00099       //------------------------------------------------------------------------
00101       //------------------------------------------------------------------------
00102       virtual bool IsStreamTTLElapsed( time_t     time,
00103                                        AnyObject &channelData );
00104 
00105       //------------------------------------------------------------------------
00111       //------------------------------------------------------------------------
00112       virtual PathID Multiplex( Message   *msg,
00113                                 AnyObject &channelData,
00114                                 PathID    *hint = 0 );
00115 
00116       //------------------------------------------------------------------------
00122       //------------------------------------------------------------------------
00123       virtual PathID MultiplexSubStream( Message   *msg,
00124                                          AnyObject &channelData,
00125                                          PathID    *hint = 0 );
00126 
00127       //------------------------------------------------------------------------
00129       //------------------------------------------------------------------------
00130       virtual uint16_t StreamNumber( AnyObject &channelData );
00131 
00132       //------------------------------------------------------------------------
00134       //------------------------------------------------------------------------
00135       virtual uint16_t SubStreamNumber( AnyObject &channelData );
00136 
00137       //------------------------------------------------------------------------
00140       //------------------------------------------------------------------------
00141       virtual bool NeedControlConnection()
00142       {
00143         return true;
00144       }
00145 
00146       //------------------------------------------------------------------------
00148       //------------------------------------------------------------------------
00149       static Status MarshallRequest( Message *msg );
00150 
00151       //------------------------------------------------------------------------
00154       //------------------------------------------------------------------------
00155       static Status UnMarshallRequest( Message *msg );
00156 
00157       //------------------------------------------------------------------------
00159       //------------------------------------------------------------------------
00160       static Status UnMarshallBody( Message *msg, uint16_t reqType );
00161 
00162       //------------------------------------------------------------------------
00164       //------------------------------------------------------------------------
00165       static void UnMarshallHeader( Message *msg );
00166 
00167       //------------------------------------------------------------------------
00169       //------------------------------------------------------------------------
00170       static void LogErrorResponse( const Message &msg );
00171 
00172       //------------------------------------------------------------------------
00174       //------------------------------------------------------------------------
00175       virtual void Disconnect( AnyObject &channelData,
00176                                uint16_t   streamId,
00177                                uint16_t   subStreamId );
00178 
00179       //------------------------------------------------------------------------
00181       //------------------------------------------------------------------------
00182       virtual Status Query( uint16_t   query,
00183                             AnyObject &result,
00184                             AnyObject &channelData );
00185 
00186       //------------------------------------------------------------------------
00188       //------------------------------------------------------------------------
00189       static void SetDescription( Message *msg );
00190 
00191       //------------------------------------------------------------------------
00193       //------------------------------------------------------------------------
00194       virtual uint32_t StreamAction( Message *msg, AnyObject &channelData );
00195 
00196     private:
00197 
00198       //------------------------------------------------------------------------
00199       // Hand shake the main stream
00200       //------------------------------------------------------------------------
00201       Status HandShakeMain( HandShakeData *handShakeData,
00202                             AnyObject     &channelData );
00203 
00204       //------------------------------------------------------------------------
00205       // Hand shake a parallel stream
00206       //------------------------------------------------------------------------
00207       Status HandShakeParallel( HandShakeData *handShakeData,
00208                                 AnyObject     &channelData );
00209 
00210       //------------------------------------------------------------------------
00211       // Generate the message to be sent as an initial handshake
00212       //------------------------------------------------------------------------
00213       Message *GenerateInitialHS( HandShakeData     *hsData,
00214                                   XRootDChannelInfo *info );
00215 
00216       //------------------------------------------------------------------------
00217       // Generate the message to be sent as an initial handshake
00218       // (handshake + kXR_protocol)
00219       //------------------------------------------------------------------------
00220       Message *GenerateInitialHSProtocol( HandShakeData     *hsData,
00221                                           XRootDChannelInfo *info );
00222 
00223       //------------------------------------------------------------------------
00224       // Process the server initial handshake response
00225       //------------------------------------------------------------------------
00226       Status ProcessServerHS( HandShakeData     *hsData,
00227                               XRootDChannelInfo *info );
00228 
00229       //-----------------------------------------------------------------------
00230       // Process the protocol response
00231       //------------------------------------------------------------------------
00232       Status ProcessProtocolResp( HandShakeData     *hsData,
00233                                   XRootDChannelInfo *info );
00234 
00235       //------------------------------------------------------------------------
00236       // Generate the bind message
00237       //------------------------------------------------------------------------
00238       Message *GenerateBind( HandShakeData     *hsData,
00239                              XRootDChannelInfo *info );
00240 
00241       //------------------------------------------------------------------------
00242       // Generate the bind message
00243       //------------------------------------------------------------------------
00244       Status ProcessBindResp( HandShakeData     *hsData,
00245                               XRootDChannelInfo *info );
00246 
00247       //------------------------------------------------------------------------
00248       // Generate the login  message
00249       //------------------------------------------------------------------------
00250       Message *GenerateLogIn( HandShakeData     *hsData,
00251                               XRootDChannelInfo *info );
00252 
00253       //------------------------------------------------------------------------
00254       // Process the login response
00255       //------------------------------------------------------------------------
00256       Status ProcessLogInResp( HandShakeData     *hsData,
00257                                XRootDChannelInfo *info );
00258 
00259       //------------------------------------------------------------------------
00260       // Do the authentication
00261       //------------------------------------------------------------------------
00262       Status DoAuthentication( HandShakeData     *hsData,
00263                                XRootDChannelInfo *info );
00264 
00265       //------------------------------------------------------------------------
00266       // Get the initial credentials using one of the protocols
00267       //------------------------------------------------------------------------
00268       Status GetCredentials( XrdSecCredentials *&credentials,
00269                              HandShakeData      *hsData,
00270                              XRootDChannelInfo  *info );
00271 
00272       //------------------------------------------------------------------------
00273       // Clean up the data structures created for the authentication process
00274       //------------------------------------------------------------------------
00275       Status CleanUpAuthentication( XRootDChannelInfo *info );
00276 
00277       //------------------------------------------------------------------------
00278       // Get the authentication function handle
00279       //------------------------------------------------------------------------
00280       typedef XrdSecProtocol *(*XrdSecGetProt_t)( const char             *,
00281                                                   const sockaddr         &,
00282                                                   const XrdSecParameters &,
00283                                                   XrdOucErrInfo          * );
00284 
00285       XrdSecGetProt_t GetAuthHandler();
00286 
00287       //------------------------------------------------------------------------
00288       // Get a string representation of the server flags
00289       //------------------------------------------------------------------------
00290       static std::string ServerFlagsToStr( uint32_t flags );
00291 
00292       //------------------------------------------------------------------------
00293       // Get a string representation of file handle
00294       //------------------------------------------------------------------------
00295       static std::string FileHandleToStr( const unsigned char handle[4] );
00296 
00297       void            *pSecLibHandle;
00298       XrdSecGetProt_t  pAuthHandler;
00299   };
00300 }
00301 
00302 #endif // __XRD_CL_XROOTD_TRANSPORT_HANDLER_HH__