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