XRootD
Loading...
Searching...
No Matches
XrdHttpTpcTPC.hh
Go to the documentation of this file.
1#ifndef XRD_HTTP_TPC_TPC_HH
2#define XRD_HTTP_TPC_TPC_HH
3#include <memory>
4#include <string>
5#include <vector>
6#include <sys/time.h>
7
9
12
15
16#include <curl/curl.h>
17#include <openssl/ssl.h>
18
19class XrdOucErrInfo;
20class XrdOucStream;
21class XrdSfsFile;
23class XrdXrootdTpcMon;
24typedef void CURL;
25
26namespace TPC {
27class State;
28
29enum LogMask {
30 Debug = 0x01,
31 Info = 0x02,
32 Warning = 0x04,
33 Error = 0x08,
34 All = 0xff
35};
36
37enum class TpcType {
40};
41
43 void operator()(CURL *curl);
44};
45using ManagedCurlHandle = std::unique_ptr<CURL, CurlDeleter>;
46
47
49public:
50 TPCHandler(XrdSysError *log, const char *config, XrdOucEnv *myEnv);
51 virtual ~TPCHandler();
52
53 virtual bool MatchesPath(const char *verb, const char *path);
54 virtual int ProcessReq(XrdHttpExtReq &req);
55 // Abstract method in the base class, but does not seem to be used
56 virtual int Init(const char *cfgfile) {return 0;}
57 static constexpr std::string_view OSS_TASK_OPAQUE = "oss.task=httptpc";
58private:
59
60 static int sockopt_callback(void * clientp, curl_socket_t curlfd, curlsocktype purpose);
61 static int opensocket_callback(void *clientp,
62 curlsocktype purpose,
63 struct curl_sockaddr *address);
64
65 static int closesocket_callback(void *clientp, curl_socket_t fd);
66 static int ssl_ctx_callback(CURL *curl, void *ssl_ctx, void *clientp);
67 static int verify_callback(int preverify_ok, X509_STORE_CTX* ctx);
68
69 struct TPCLogRecord {
70
71 TPCLogRecord(XrdHttpExtReq & req, const TpcType tpcType) : bytes_transferred( -1 ), status( -1 ),
72 tpc_status(-1), streams( 1 ), isIPv6(false), mReq(req), pmarkManager(mReq,tpcType), mTpcType(tpcType)
73 {
74 gettimeofday(&begT, 0); // Set effective start time
75 }
76 ~TPCLogRecord();
77
78 std::string log_prefix;
79 std::string local;
80 std::string remote;
81 std::string name;
82 std::string clID;
83 static XrdXrootdTpcMon* tpcMonitor;
84 timeval begT;
85 off_t bytes_transferred;
86 int status;
87 int tpc_status;
88 unsigned int streams;
89 bool isIPv6;
90 XrdHttpExtReq & mReq;
91 XrdHttpTpc::PMarkManager pmarkManager;
92 XrdSysError * m_log;
93 TpcType mTpcType;
94 };
95
96 int ProcessOptionsReq(XrdHttpExtReq &req);
97
98 static std::string GetAuthz(XrdHttpExtReq &req);
99
100 // Configure curl handle's CA settings. The CA files present here should
101 // be valid for the lifetime of the process.
102 void ConfigureCurlCA(CURL *curl);
103
104 // Redirect the transfer according to the contents of an XrdOucErrInfo object.
105 int RedirectTransfer(CURL *curl, const std::string &redirect_resource, XrdHttpExtReq &req,
106 XrdOucErrInfo &error, TPCLogRecord &);
107
108 int OpenWaitStall(XrdSfsFile &fh, const std::string &resource, int mode,
109 int openMode, const XrdSecEntity &sec,
110 const std::string &authz);
111
112 int PerformHEADRequest(CURL *curl, XrdHttpExtReq &req, TPC::State &state,
113 bool &success, TPCLogRecord &rec, bool shouldReturnErrorToClient = true);
114
115 int GetRemoteFileInfoTPCPull(CURL *curl, XrdHttpExtReq &req, uint64_t & contentLength, std::map<std::string,std::string> & reprDigest, bool & success, TPCLogRecord &rec);
116
117 // Send a 'performance marker' back to the TPC client, informing it of our
118 // progress. The TPC client will use this information to determine whether
119 // the transfer is making sufficient progress and/or other monitoring info
120 // (such as whether the transfer is happening over IPv4, IPv6, or both).
121 int SendPerfMarker(XrdHttpExtReq &req, TPCLogRecord &rec, TPC::State &state);
122 int SendPerfMarker(XrdHttpExtReq &req, TPCLogRecord &rec, std::vector<State*> &state,
123 off_t bytes_transferred);
124
125 // Perform the libcurl transfer, periodically sending back chunked updates.
126 int RunCurlWithUpdates(CURL *curl, XrdHttpExtReq &req, TPC::State &state,
127 TPCLogRecord &rec);
128
129 // Experimental multi-stream version of RunCurlWithUpdates
130 int RunCurlWithStreams(XrdHttpExtReq &req, TPC::State &state,
131 size_t streams, TPCLogRecord &rec);
132 int RunCurlWithStreamsImpl(XrdHttpExtReq &req, TPC::State &state,
133 size_t streams, std::vector<TPC::State*> &streams_handles,
134 std::vector<ManagedCurlHandle> &curl_handles,
135 TPCLogRecord &rec);
136
137 int ProcessPushReq(const std::string & resource, XrdHttpExtReq &req);
138 int ProcessPullReq(const std::string &resource, XrdHttpExtReq &req);
139
140 bool ConfigureFSLib(XrdOucStream &Config, std::string &path1, bool &path1_alt,
141 std::string &path2, bool &path2_alt);
142 bool Configure(const char *configfn, XrdOucEnv *myEnv);
143 bool ConfigureLogger(XrdOucStream &Config);
144
145 // Generate a consistently-formatted log message.
146 void logTransferEvent(LogMask lvl, const TPCLogRecord &record,
147 const std::string &event, const std::string &message="");
148
149 std::string generateClientErr(std::stringstream &err_ss, const TPCLogRecord &rec, CURLcode cCode = CURLcode::CURLE_OK);
150
151 std::string prepareURL(XrdHttpExtReq &req);
152
164 bool mismatchReprDigest(const std::map<std::string,std::string> & passiveSrvReprDigest, XrdHttpExtReq & req, TPCLogRecord &rec);
165
166 static int m_marker_period;
167 static size_t m_block_size;
168 static size_t m_small_block_size;
169 bool m_desthttps;
170 bool m_fixed_route; // If 'true' the Destination IP in an HTTP-TPC is forced to be the same as the IP used to contact the server
171 // when 'false' any IP available can be selected
172 int m_timeout; // the 'timeout interval'; if no bytes have been received during this time period, abort the transfer.
173 int m_first_timeout; // the 'first timeout interval'; the amount of time we're willing to wait to get the first byte.
174 // Unless explicitly specified, this is 2x the timeout interval.
175 std::string m_cadir; // The directory to use for CAs.
176 std::string m_cafile; // The file to use for CAs in libcurl
177 static XrdSysMutex m_monid_mutex;
178 static uint64_t m_monid;
179 XrdSysError m_log;
180 XrdSfsFileSystem *m_sfs;
181 std::shared_ptr<XrdTlsTempCA> m_ca_file;
182
183 // 16 blocks in flight at 16 MB each, meaning that there will be up to 256MB
184 // in flight; this is equal to the bandwidth delay product of a 200ms transcontinental
185 // connection at 10Gbps.
186 static const int m_pipelining_multiplier = 16;
187
188 bool usingEC; // indicate if XrdEC is used
189
190 static bool allowMissingCRL;
191
192 // Time to connect the curl socket to the remote server uses the linux's default value
193 // of 60 seconds
194 static const long CONNECT_TIMEOUT = 60;
195
196 // hdr2cgimap
197 std::map<std::string,std::string> hdr2cgimap;
198};
199}
200#endif
void CURL
bool usingEC
Utility functions for XrdHTTP.
TPCHandler(XrdSysError *log, const char *config, XrdOucEnv *myEnv)
virtual int ProcessReq(XrdHttpExtReq &req)
virtual ~TPCHandler()
static constexpr std::string_view OSS_TASK_OPAQUE
virtual int Init(const char *cfgfile)
Initializes the external request handler.
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.
XrdHttpExtHandler()
Constructor.
std::unique_ptr< CURL, CurlDeleter > ManagedCurlHandle
void operator()(CURL *curl)