|
||||
File indexing completed on 2025-01-18 10:15:37
0001 //------------------------------------------------------------------------------ 0002 // Copyright (c) 2011-2014 by European Organization for Nuclear Research (CERN) 0003 // Author: Lukasz Janyst <ljanyst@cern.ch> 0004 //------------------------------------------------------------------------------ 0005 // This file is part of the XRootD software suite. 0006 // 0007 // XRootD is free software: you can redistribute it and/or modify 0008 // it under the terms of the GNU Lesser General Public License as published by 0009 // the Free Software Foundation, either version 3 of the License, or 0010 // (at your option) any later version. 0011 // 0012 // XRootD is distributed in the hope that it will be useful, 0013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0015 // GNU General Public License for more details. 0016 // 0017 // You should have received a copy of the GNU Lesser General Public License 0018 // along with XRootD. If not, see <http://www.gnu.org/licenses/>. 0019 // 0020 // In applying this licence, CERN does not waive the privileges and immunities 0021 // granted to it by virtue of its status as an Intergovernmental Organization 0022 // or submit itself to any jurisdiction. 0023 //------------------------------------------------------------------------------ 0024 0025 #ifndef __XRD_CL_XROOTD_TRANSPORT_HH__ 0026 #define __XRD_CL_XROOTD_TRANSPORT_HH__ 0027 0028 #include "XrdCl/XrdClPostMaster.hh" 0029 #include "XrdCl/XrdClMessage.hh" 0030 #include "XProtocol/XProtocol.hh" 0031 #include "XrdSec/XrdSecInterface.hh" 0032 #include "XrdOuc/XrdOucEnv.hh" 0033 0034 class XrdSysPlugin; 0035 class XrdSecProtect; 0036 0037 namespace XrdCl 0038 { 0039 class Tls; 0040 class Socket; 0041 struct XRootDChannelInfo; 0042 struct PluginUnloadHandler; 0043 0044 //---------------------------------------------------------------------------- 0045 //! XRootD transport handler 0046 //---------------------------------------------------------------------------- 0047 class XRootDTransport: public TransportHandler 0048 { 0049 public: 0050 //------------------------------------------------------------------------ 0051 //! Constructor 0052 //------------------------------------------------------------------------ 0053 XRootDTransport(); 0054 0055 //------------------------------------------------------------------------ 0056 //! Destructor 0057 //------------------------------------------------------------------------ 0058 ~XRootDTransport(); 0059 0060 //------------------------------------------------------------------------ 0061 //! Read a message header from the socket, the socket is non-blocking, 0062 //! so if there is not enough data the function should return suRetry 0063 //! in which case it will be called again when more data arrives, with 0064 //! the data previously read stored in the message buffer 0065 //! 0066 //! @param message the message buffer 0067 //! @param socket the socket 0068 //! @return stOK & suDone if the whole message has been processed 0069 //! stOK & suRetry if more data is needed 0070 //! stError on failure 0071 //------------------------------------------------------------------------ 0072 virtual XRootDStatus GetHeader( Message &message, Socket *socket ); 0073 0074 //------------------------------------------------------------------------ 0075 //! Read the message body from the socket, the socket is non-blocking, 0076 //! the method may be called multiple times - see GetHeader for details 0077 //! 0078 //! @param message the message buffer containing the header 0079 //! @param socket the socket 0080 //! @return stOK & suDone if the whole message has been processed 0081 //! stOK & suRetry if more data is needed 0082 //! stError on failure 0083 //------------------------------------------------------------------------ 0084 virtual XRootDStatus GetBody( Message &message, Socket *socket ); 0085 0086 //------------------------------------------------------------------------ 0087 //! Read more of the message body from the socket, the socket is 0088 //! non-blocking the method may be called multiple times - see GetHeader 0089 //! for details 0090 //! 0091 //! @param message the message buffer containing the header 0092 //! @param socket the socket 0093 //! @return stOK & suDone if the whole message has been processed 0094 //! stOK & suRetry if more data is needed 0095 //! stError on failure 0096 //------------------------------------------------------------------------ 0097 virtual XRootDStatus GetMore( Message &message, Socket *socket ); 0098 0099 //------------------------------------------------------------------------ 0100 //! Initialize channel 0101 //------------------------------------------------------------------------ 0102 virtual void InitializeChannel( const URL &url, 0103 AnyObject &channelData ); 0104 0105 //------------------------------------------------------------------------ 0106 //! Finalize channel 0107 //------------------------------------------------------------------------ 0108 virtual void FinalizeChannel( AnyObject &channelData ); 0109 0110 //------------------------------------------------------------------------ 0111 //! HandShake 0112 //------------------------------------------------------------------------ 0113 virtual XRootDStatus HandShake( HandShakeData *handShakeData, 0114 AnyObject &channelData ); 0115 0116 //------------------------------------------------------------------------ 0117 // @return true if handshake has been done and stream is connected, 0118 // false otherwise 0119 //------------------------------------------------------------------------ 0120 virtual bool HandShakeDone( HandShakeData *handShakeData, 0121 AnyObject &channelData ); 0122 0123 //------------------------------------------------------------------------ 0124 //! Check if the stream should be disconnected 0125 //------------------------------------------------------------------------ 0126 virtual bool IsStreamTTLElapsed( time_t time, 0127 AnyObject &channelData ); 0128 0129 //------------------------------------------------------------------------ 0130 //! Check the stream is broken - ie. TCP connection got broken and 0131 //! went undetected by the TCP stack 0132 //------------------------------------------------------------------------ 0133 virtual Status IsStreamBroken( time_t inactiveTime, 0134 AnyObject &channelData ); 0135 0136 //------------------------------------------------------------------------ 0137 //! Return the ID for the up stream this message should be sent by 0138 //! and the down stream which the answer should be expected at. 0139 //! Modify the message itself if necessary. 0140 //! If hint is non-zero then the message should be modified such that 0141 //! the answer will be returned via the hinted stream. 0142 //------------------------------------------------------------------------ 0143 virtual PathID Multiplex( Message *msg, 0144 AnyObject &channelData, 0145 PathID *hint = 0 ); 0146 0147 //------------------------------------------------------------------------ 0148 //! Return the ID for the up substream this message should be sent by 0149 //! and the down substream which the answer should be expected at. 0150 //! Modify the message itself if necessary. 0151 //! If hint is non-zero then the message should be modified such that 0152 //! the answer will be returned via the hinted stream. 0153 //------------------------------------------------------------------------ 0154 virtual PathID MultiplexSubStream( Message *msg, 0155 AnyObject &channelData, 0156 PathID *hint = 0 ); 0157 0158 //------------------------------------------------------------------------ 0159 //! Return a number of substreams per stream that should be created 0160 //------------------------------------------------------------------------ 0161 virtual uint16_t SubStreamNumber( AnyObject &channelData ); 0162 0163 //------------------------------------------------------------------------ 0164 //! Return the information whether a control connection needs to be 0165 //! valid before establishing other connections 0166 //------------------------------------------------------------------------ 0167 virtual bool NeedControlConnection() 0168 { 0169 return true; 0170 } 0171 0172 //------------------------------------------------------------------------ 0173 //! Marshal the outgoing message 0174 //------------------------------------------------------------------------ 0175 inline static XRootDStatus MarshallRequest( Message *msg ) 0176 { 0177 MarshallRequest( msg->GetBuffer() ); 0178 msg->SetIsMarshalled( true ); 0179 return XRootDStatus(); 0180 } 0181 0182 //------------------------------------------------------------------------ 0183 //! Marshal the outgoing message 0184 //------------------------------------------------------------------------ 0185 static XRootDStatus MarshallRequest( char *msg ); 0186 0187 //------------------------------------------------------------------------ 0188 //! Unmarshall the request - sometimes the requests need to be rewritten, 0189 //! so we need to unmarshall them 0190 //------------------------------------------------------------------------ 0191 static XRootDStatus UnMarshallRequest( Message *msg ); 0192 0193 //------------------------------------------------------------------------ 0194 //! Unmarshall the body of the incoming message 0195 //------------------------------------------------------------------------ 0196 static XRootDStatus UnMarshallBody( Message *msg, uint16_t reqType ); 0197 0198 //------------------------------------------------------------------------ 0199 //! Unmarshall the body of the status response 0200 //------------------------------------------------------------------------ 0201 static XRootDStatus UnMarshalStatusBody( Message &msg, uint16_t reqType ); 0202 0203 //------------------------------------------------------------------------ 0204 //! Unmarshall the correction-segment of the status response for pgwrite 0205 //------------------------------------------------------------------------ 0206 static XRootDStatus UnMarchalStatusMore( Message &msg ); 0207 0208 //------------------------------------------------------------------------ 0209 //! Unmarshall the header incoming message 0210 //------------------------------------------------------------------------ 0211 static void UnMarshallHeader( Message &msg ); 0212 0213 //------------------------------------------------------------------------ 0214 //! Log server error response 0215 //------------------------------------------------------------------------ 0216 static void LogErrorResponse( const Message &msg ); 0217 0218 //------------------------------------------------------------------------ 0219 //! Number of currently connected data streams 0220 //------------------------------------------------------------------------ 0221 static uint16_t NbConnectedStrm( AnyObject &channelData ); 0222 0223 //------------------------------------------------------------------------ 0224 //! The stream has been disconnected, do the cleanups 0225 //------------------------------------------------------------------------ 0226 virtual void Disconnect( AnyObject &channelData, 0227 uint16_t subStreamId ); 0228 0229 //------------------------------------------------------------------------ 0230 //! Query the channel 0231 //------------------------------------------------------------------------ 0232 virtual Status Query( uint16_t query, 0233 AnyObject &result, 0234 AnyObject &channelData ); 0235 0236 0237 //------------------------------------------------------------------------ 0238 //! Get the description of a message 0239 //------------------------------------------------------------------------ 0240 static void GenerateDescription( char *msg, std::ostringstream &o ); 0241 0242 //------------------------------------------------------------------------ 0243 //! Get the description of a message 0244 //------------------------------------------------------------------------ 0245 inline static void SetDescription( Message *msg ) 0246 { 0247 std::ostringstream o; 0248 GenerateDescription( msg->GetBuffer(), o ); 0249 msg->SetDescription( o.str() ); 0250 } 0251 0252 //------------------------------------------------------------------------ 0253 //! Check if the message invokes a stream action 0254 //------------------------------------------------------------------------ 0255 virtual uint32_t MessageReceived( Message &msg, 0256 uint16_t subStream, 0257 AnyObject &channelData ); 0258 0259 //------------------------------------------------------------------------ 0260 //! Notify the transport about a message having been sent 0261 //------------------------------------------------------------------------ 0262 virtual void MessageSent( Message *msg, 0263 uint16_t subStream, 0264 uint32_t bytesSent, 0265 AnyObject &channelData ); 0266 0267 //------------------------------------------------------------------------ 0268 //! Get signature for given message 0269 //------------------------------------------------------------------------ 0270 virtual Status GetSignature( Message *toSign, Message *&sign, 0271 AnyObject &channelData ); 0272 0273 //------------------------------------------------------------------------ 0274 //! Get signature for given message 0275 //------------------------------------------------------------------------ 0276 virtual Status GetSignature( Message *toSign, Message *&sign, 0277 XRootDChannelInfo *info ); 0278 0279 //------------------------------------------------------------------------ 0280 //! Decrement file object instance count bound to this channel 0281 //------------------------------------------------------------------------ 0282 virtual void DecFileInstCnt( AnyObject &channelData ); 0283 0284 //------------------------------------------------------------------------ 0285 //! Wait until the program can safely exit 0286 //------------------------------------------------------------------------ 0287 virtual void WaitBeforeExit(); 0288 0289 //------------------------------------------------------------------------ 0290 //! @return : true if encryption should be turned on, false otherwise 0291 //------------------------------------------------------------------------ 0292 virtual bool NeedEncryption( HandShakeData *handShakeData, 0293 AnyObject &channelData ); 0294 0295 //------------------------------------------------------------------------ 0296 //! Get bind preference for the next data stream 0297 //------------------------------------------------------------------------ 0298 virtual URL GetBindPreference( const URL &url, 0299 AnyObject &channelData ); 0300 0301 private: 0302 0303 //------------------------------------------------------------------------ 0304 // Hand shake the main stream 0305 //------------------------------------------------------------------------ 0306 XRootDStatus HandShakeMain( HandShakeData *handShakeData, 0307 AnyObject &channelData ); 0308 0309 //------------------------------------------------------------------------ 0310 // Hand shake a parallel stream 0311 //------------------------------------------------------------------------ 0312 XRootDStatus HandShakeParallel( HandShakeData *handShakeData, 0313 AnyObject &channelData ); 0314 0315 //------------------------------------------------------------------------ 0316 // Generate the message to be sent as an initial handshake 0317 // (handshake + kXR_protocol) 0318 //------------------------------------------------------------------------ 0319 Message *GenerateInitialHSProtocol( HandShakeData *hsData, 0320 XRootDChannelInfo *info, 0321 kXR_char expect ); 0322 0323 //------------------------------------------------------------------------ 0324 // Generate the protocol message 0325 //------------------------------------------------------------------------ 0326 Message *GenerateProtocol( HandShakeData *hsData, 0327 XRootDChannelInfo *info, 0328 kXR_char expect ); 0329 0330 //------------------------------------------------------------------------ 0331 // Initialize protocol request 0332 //------------------------------------------------------------------------ 0333 void InitProtocolReq( ClientProtocolRequest *request, 0334 XRootDChannelInfo *info, 0335 kXR_char expect ); 0336 0337 //------------------------------------------------------------------------ 0338 // Process the server initial handshake response 0339 //------------------------------------------------------------------------ 0340 XRootDStatus ProcessServerHS( HandShakeData *hsData, 0341 XRootDChannelInfo *info ); 0342 0343 //------------------------------------------------------------------------ 0344 // Process the protocol response 0345 //------------------------------------------------------------------------ 0346 XRootDStatus ProcessProtocolResp( HandShakeData *hsData, 0347 XRootDChannelInfo *info ); 0348 0349 //------------------------------------------------------------------------ 0350 // Process the protocol body: 0351 // * 'B' : bind preferences 0352 // * 'S' : security requirements 0353 //------------------------------------------------------------------------ 0354 XRootDStatus ProcessProtocolBody( char *bodybuff, 0355 size_t bodysize, 0356 XRootDChannelInfo *info ); 0357 0358 //------------------------------------------------------------------------ 0359 // Generate the bind message 0360 //------------------------------------------------------------------------ 0361 Message *GenerateBind( HandShakeData *hsData, 0362 XRootDChannelInfo *info ); 0363 0364 //------------------------------------------------------------------------ 0365 // Generate the bind message 0366 //------------------------------------------------------------------------ 0367 XRootDStatus ProcessBindResp( HandShakeData *hsData, 0368 XRootDChannelInfo *info ); 0369 0370 //------------------------------------------------------------------------ 0371 // Generate the login message 0372 //------------------------------------------------------------------------ 0373 Message *GenerateLogIn( HandShakeData *hsData, 0374 XRootDChannelInfo *info ); 0375 0376 //------------------------------------------------------------------------ 0377 // Process the login response 0378 //------------------------------------------------------------------------ 0379 XRootDStatus ProcessLogInResp( HandShakeData *hsData, 0380 XRootDChannelInfo *info ); 0381 0382 //------------------------------------------------------------------------ 0383 // Do the authentication 0384 //------------------------------------------------------------------------ 0385 XRootDStatus DoAuthentication( HandShakeData *hsData, 0386 XRootDChannelInfo *info ); 0387 0388 //------------------------------------------------------------------------ 0389 // Get the initial credentials using one of the protocols 0390 //------------------------------------------------------------------------ 0391 XRootDStatus GetCredentials( XrdSecCredentials *&credentials, 0392 HandShakeData *hsData, 0393 XRootDChannelInfo *info ); 0394 0395 //------------------------------------------------------------------------ 0396 // Clean up the data structures created for the authentication process 0397 //------------------------------------------------------------------------ 0398 Status CleanUpAuthentication( XRootDChannelInfo *info ); 0399 0400 //------------------------------------------------------------------------ 0401 // Clean up the data structures created for the protection purposes 0402 //------------------------------------------------------------------------ 0403 Status CleanUpProtection( XRootDChannelInfo *info ); 0404 0405 //------------------------------------------------------------------------ 0406 // Get the authentication function handle 0407 //------------------------------------------------------------------------ 0408 XrdSecGetProt_t GetAuthHandler(); 0409 0410 //------------------------------------------------------------------------ 0411 // Generate the end session message 0412 //------------------------------------------------------------------------ 0413 Message *GenerateEndSession( HandShakeData *hsData, 0414 XRootDChannelInfo *info ); 0415 0416 //------------------------------------------------------------------------ 0417 // Process the end session response 0418 //------------------------------------------------------------------------ 0419 Status ProcessEndSessionResp( HandShakeData *hsData, 0420 XRootDChannelInfo *info ); 0421 0422 //------------------------------------------------------------------------ 0423 // Get a string representation of the server flags 0424 //------------------------------------------------------------------------ 0425 static std::string ServerFlagsToStr( uint32_t flags ); 0426 0427 //------------------------------------------------------------------------ 0428 // Get a string representation of file handle 0429 //------------------------------------------------------------------------ 0430 static std::string FileHandleToStr( const unsigned char handle[4] ); 0431 0432 friend struct PluginUnloadHandler; 0433 PluginUnloadHandler *pSecUnloadHandler; 0434 }; 0435 } 0436 0437 #endif // __XRD_CL_XROOTD_TRANSPORT_HANDLER_HH__
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |