xrootd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
XrdTpcTPC.hh
Go to the documentation of this file.
1 
2 #include <memory>
3 #include <string>
4 #include <vector>
5 
7 
10 
11 #include "XrdTls/XrdTlsTempCA.hh"
12 
13 #include <curl/curl.h>
14 
15 class XrdOucErrInfo;
16 class XrdOucStream;
17 class XrdSfsFile;
18 class XrdSfsFileSystem;
19 typedef void CURL;
20 
21 namespace TPC {
22 class State;
23 
24 enum LogMask {
25  Debug = 0x01,
26  Info = 0x02,
27  Warning = 0x04,
28  Error = 0x08,
29  All = 0xff
30 };
31 
32 
33 struct CurlDeleter {
34  void operator()(CURL *curl);
35 };
36 using ManagedCurlHandle = std::unique_ptr<CURL, CurlDeleter>;
37 
38 
39 class TPCHandler : public XrdHttpExtHandler {
40 public:
41  TPCHandler(XrdSysError *log, const char *config, XrdOucEnv *myEnv);
42  virtual ~TPCHandler();
43 
44  virtual bool MatchesPath(const char *verb, const char *path);
45  virtual int ProcessReq(XrdHttpExtReq &req);
46  // Abstract method in the base class, but does not seem to be used
47  virtual int Init(const char *cfgfile) {return 0;}
48 
49 private:
50 
51  static int sockopt_setcloexec_callback(void * clientp, curl_socket_t curlfd, curlsocktype purpose);
52 
53  struct TPCLogRecord {
54 
55  TPCLogRecord() : status( -1 ),
56  tpc_status(-1),
57  streams( 1 ),
58  bytes_transferred( -1 )
59  {
60  }
61 
62  std::string log_prefix;
63  std::string local;
64  std::string remote;
65  std::string name;
66  int status;
68  unsigned streams;
70  };
71 
73 
74  static std::string GetAuthz(XrdHttpExtReq &req);
75 
76  // Configure curl handle's CA settings. The CA files present here should
77  // be valid for the lifetime of the process.
78  void ConfigureCurlCA(CURL *curl);
79 
80  // Redirect the transfer according to the contents of an XrdOucErrInfo object.
81  int RedirectTransfer(CURL *curl, const std::string &redirect_resource, XrdHttpExtReq &req,
82  XrdOucErrInfo &error, TPCLogRecord &);
83 
84  int OpenWaitStall(XrdSfsFile &fh, const std::string &resource, int mode,
85  int openMode, const XrdSecEntity &sec,
86  const std::string &authz);
87 
88 #ifdef XRD_CHUNK_RESP
89  int DetermineXferSize(CURL *curl, XrdHttpExtReq &req, TPC::State &state,
90  bool &success, TPCLogRecord &);
91 
92  // Send a 'performance marker' back to the TPC client, informing it of our
93  // progress. The TPC client will use this information to determine whether
94  // the transfer is making sufficient progress and/or other monitoring info
95  // (such as whether the transfer is happening over IPv4, IPv6, or both).
96  int SendPerfMarker(XrdHttpExtReq &req, TPCLogRecord &rec, TPC::State &state);
97  int SendPerfMarker(XrdHttpExtReq &req, TPCLogRecord &rec, std::vector<State*> &state,
98  off_t bytes_transferred);
99 
100  // Perform the libcurl transfer, periodically sending back chunked updates.
101  int RunCurlWithUpdates(CURL *curl, XrdHttpExtReq &req, TPC::State &state,
102  TPCLogRecord &rec);
103 
104  // Experimental multi-stream version of RunCurlWithUpdates
105  int RunCurlWithStreams(XrdHttpExtReq &req, TPC::State &state,
106  size_t streams, TPCLogRecord &rec);
107  int RunCurlWithStreamsImpl(XrdHttpExtReq &req, TPC::State &state,
108  size_t streams, std::vector<TPC::State*> &streams_handles,
109  std::vector<ManagedCurlHandle> &curl_handles,
110  TPCLogRecord &rec);
111 #else
112  int RunCurlBasic(CURL *curl, XrdHttpExtReq &req, TPC::State &state,
113  const char *log_prefix);
114 #endif
115 
116  int ProcessPushReq(const std::string & resource, XrdHttpExtReq &req);
117  int ProcessPullReq(const std::string &resource, XrdHttpExtReq &req);
118 
119  bool ConfigureFSLib(XrdOucStream &Config, std::string &path1, bool &path1_alt,
120  std::string &path2, bool &path2_alt);
121  bool Configure(const char *configfn, XrdOucEnv *myEnv);
123 
124  // Generate a consistently-formatted log message.
125  void logTransferEvent(LogMask lvl, const TPCLogRecord &record,
126  const std::string &event, const std::string &message="");
127 
128  static int m_marker_period;
129  static size_t m_block_size;
130  static size_t m_small_block_size;
132  int m_timeout; // the 'timeout interval'; if no bytes have been received during this time period, abort the transfer.
133  int m_first_timeout; // the 'first timeout interval'; the amount of time we're willing to wait to get the first byte.
134  // Unless explicitly specified, this is 2x the timeout interval.
135  std::string m_cadir; // The directory to use for CAs.
136  std::string m_cafile; // The file to use for CAs in libcurl
138  static uint64_t m_monid;
140  XrdSfsFileSystem *m_sfs;
141  std::shared_ptr<XrdTlsTempCA> m_ca_file;
142 
143  // 16 blocks in flight at 16 MB each, meaning that there will be up to 256MB
144  // in flight; this is equal to the bandwidth delay product of a 200ms transcontinental
145  // connection at 10Gbps.
146 #ifdef USE_PIPELINING
147  static const int m_pipelining_multiplier = 16;
148 #else
149  static const int m_pipelining_multiplier = 1;
150 #endif
151 };
152 }
Definition: XrdTpcState.hh:20
std::string m_cafile
Definition: XrdTpcTPC.hh:136
std::string local
Definition: XrdTpcTPC.hh:63
LogMask
Definition: XrdTpcTPC.hh:24
Definition: XrdTpcTPC.hh:25
Definition: XrdTpcTPC.hh:53
unsigned streams
Definition: XrdTpcTPC.hh:68
bool m_desthttps
Definition: XrdTpcTPC.hh:131
virtual int ProcessReq(XrdHttpExtReq &req)
Definition: XrdOucStream.hh:46
Utility functions for XrdHTTP.
static size_t m_block_size
Definition: XrdTpcTPC.hh:129
int RunCurlBasic(CURL *curl, XrdHttpExtReq &req, TPC::State &state, const char *log_prefix)
int tpc_status
Definition: XrdTpcTPC.hh:67
Definition: XrdSysError.hh:89
std::string m_cadir
Definition: XrdTpcTPC.hh:135
static const int m_pipelining_multiplier
Definition: XrdTpcTPC.hh:149
bool ConfigureFSLib(XrdOucStream &Config, std::string &path1, bool &path1_alt, std::string &path2, bool &path2_alt)
Definition: XrdTpcTPC.hh:26
static std::string GetAuthz(XrdHttpExtReq &req)
Definition: XrdSysPthread.hh:164
bool Configure(const char *configfn, XrdOucEnv *myEnv)
virtual int Init(const char *cfgfile)
Initializes the external request handler.
Definition: XrdTpcTPC.hh:47
TPCHandler(XrdSysError *log, const char *config, XrdOucEnv *myEnv)
std::string log_prefix
Definition: XrdTpcTPC.hh:62
int OpenWaitStall(XrdSfsFile &fh, const std::string &resource, int mode, int openMode, const XrdSecEntity &sec, const std::string &authz)
XrdCmsConfig Config
Definition: XrdTpcTPC.hh:39
std::shared_ptr< XrdTlsTempCA > m_ca_file
Definition: XrdTpcTPC.hh:141
Definition: XrdOucErrInfo.hh:100
Definition: XrdTpcTPC.hh:28
int RedirectTransfer(CURL *curl, const std::string &redirect_resource, XrdHttpExtReq &req, XrdOucErrInfo &error, TPCLogRecord &)
virtual bool MatchesPath(const char *verb, const char *path)
Tells if the incoming path is recognized as one of the paths that have to be processed.
Definition: XrdOucEnv.hh:41
Definition: XrdHttpExtHandler.hh:79
int ProcessPullReq(const std::string &resource, XrdHttpExtReq &req)
TPCLogRecord()
Definition: XrdTpcTPC.hh:55
std::unique_ptr< CURL, CurlDeleter > ManagedCurlHandle
Definition: XrdTpcTPC.hh:36
static int m_marker_period
Definition: XrdTpcTPC.hh:128
Definition: XrdTpcTPC.hh:33
static uint64_t m_monid
Definition: XrdTpcTPC.hh:138
XrdSfsFileSystem * m_sfs
Definition: XrdTpcTPC.hh:140
void operator()(CURL *curl)
static XrdSysMutex m_monid_mutex
Definition: XrdTpcTPC.hh:137
int m_first_timeout
Definition: XrdTpcTPC.hh:133
static int sockopt_setcloexec_callback(void *clientp, curl_socket_t curlfd, curlsocktype purpose)
void logTransferEvent(LogMask lvl, const TPCLogRecord &record, const std::string &event, const std::string &message="")
int ProcessOptionsReq(XrdHttpExtReq &req)
Definition: XrdSecEntity.hh:63
bool ConfigureLogger(XrdOucStream &Config)
int ProcessPushReq(const std::string &resource, XrdHttpExtReq &req)
virtual ~TPCHandler()
Definition: XrdSfsInterface.hh:364
std::string remote
Definition: XrdTpcTPC.hh:64
int m_timeout
Definition: XrdTpcTPC.hh:132
Definition: XrdHttpExtHandler.hh:45
int status
Definition: XrdTpcTPC.hh:66
static size_t m_small_block_size
Definition: XrdTpcTPC.hh:130
void CURL
Definition: XrdTpcState.hh:13
std::string name
Definition: XrdTpcTPC.hh:65
Definition: XrdTpcTPC.hh:29
XrdSysError m_log
Definition: XrdTpcTPC.hh:139
Definition: XrdTpcTPC.hh:27
void ConfigureCurlCA(CURL *curl)
off_t bytes_transferred
Definition: XrdTpcTPC.hh:69