Artifactspublic-v0

curl

master
ply4 git calls28 ms291 KiB3 cachedprotocol v2
441 lines14 KiBRaw
1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 * SPDX-License-Identifier: curl
22 *
23 ***************************************************************************/
24#include "curl_setup.h"
26#include "urldata.h"
27#include "curl_trc.h"
28#include "strerror.h"
29#include "cfilters.h"
30#include "connect.h"
31#include "cf-https-connect.h"
32#include "cf-setup.h"
33#include "multiif.h"
34#include "progress.h"
35#include "conncache.h"
36#include "multihandle.h"
37#include "select.h"
38#include "vdns/cf-dns.h"
39#include "curlx/strparse.h"
41#if !defined(CURL_DISABLE_ALTSVC) || defined(USE_HTTPSRR)
43enum alpnid Curl_alpn2alpnid(const unsigned char *name, size_t len)
45 if(len == 2) {
46 if(!memcmp(name, "h1", 2))
47 return ALPN_h1;
48 if(!memcmp(name, "h2", 2))
49 return ALPN_h2;
50 if(!memcmp(name, "h3", 2))
51 return ALPN_h3;
52 }
53 else if(len == 8 && !memcmp(name, "http/1.1", 8))
54 return ALPN_h1;
55 return ALPN_none; /* unknown, probably rubbish input */
58#endif
60/* Milliseconds left of the connect timeout. */
61static timediff_t connect_left_ms(struct Curl_easy *data,
62 const struct curltime *pnow)
64 timediff_t timeout_ms = (data->set.connecttimeout > 0) ?
65 data->set.connecttimeout : DEFAULT_CONNECT_TIMEOUT;
66 timediff_t elapsed_ms =
67 curlx_ptimediff_ms(pnow, &data->conn->created) -
68 data->conn->connect_start_ms;
69 timediff_t left_ms = timeout_ms - elapsed_ms;
70 DEBUGASSERT(data->conn->connect_start_ms >= 0);
71 return left_ms ? left_ms : -1; /* 0 is "no limit", fake 1 ms expiry */
74/*
75 * timeleft_now_ms() returns the amount of milliseconds left allowed for the
76 * transfer/connection. If the value is 0, there is no timeout (ie there is
77 * infinite time left). If the value is negative, the timeout time has already
78 * elapsed.
79 *
80 * @unittest 1303
81 */
82UNITTEST timediff_t timeleft_now_ms(struct Curl_easy *data,
83 const struct curltime *pnow);
84UNITTEST timediff_t timeleft_now_ms(struct Curl_easy *data,
85 const struct curltime *pnow)
87 timediff_t timeleft_ms = 0;
88 timediff_t ctimeleft_ms = 0;
90 if(data->conn && CURL_CONN_IN_SHUTDOWN(data->conn, FIRSTSOCKET))
91 return Curl_cshutdn_timeleft_ms(data, data->conn, FIRSTSOCKET);
92 else if(Curl_is_connecting(data)) {
93 /* transfer has not reached DO phase yet */
94 timediff_t ctimeout_ms = (data->set.connecttimeout > 0) ?
95 data->set.connecttimeout : DEFAULT_CONNECT_TIMEOUT;
96 ctimeleft_ms = ctimeout_ms -
97 Curl_pgrs_since_ms(data, pnow, TIMER_STARTSINGLE);
98 if(!ctimeleft_ms)
99 ctimeleft_ms = -1; /* 0 is "no limit", fake 1 ms expiry */
100 }
101 else if(data->conn && data->conn->connect_start_ms >= 0) {
102 /* ongoing connect of filters, pbly FTP second socket */
103 ctimeleft_ms = connect_left_ms(data, pnow);
104 }
105 else if(!data->set.timeout || data->set.connect_only) {
106 return 0; /* no timeout in place or checked, return "no limit" */
107 }
109 if(data->set.timeout) {
110 timeleft_ms = data->set.timeout -
111 Curl_pgrs_since_ms(data, pnow, TIMER_STARTOP);
112 if(!timeleft_ms)
113 timeleft_ms = -1; /* 0 is "no limit", fake 1 ms expiry */
114 }
116 if(!ctimeleft_ms)
117 return timeleft_ms;
118 else if(!timeleft_ms)
119 return ctimeleft_ms;
120 return CURLMIN(ctimeleft_ms, timeleft_ms);
123timediff_t Curl_timeleft_ms(struct Curl_easy *data)
125 return timeleft_now_ms(data, Curl_pgrs_now(data));
128timediff_t Curl_timeleft_now_ms(struct Curl_easy *data,
129 const struct curltime *pnow)
131 return timeleft_now_ms(data, pnow);
134/*
135 * Used to extract socket and connectdata struct for the most recent
136 * transfer on the given Curl_easy.
137 *
138 * The returned socket will be CURL_SOCKET_BAD in case of failure!
139 */
140curl_socket_t Curl_getconnectinfo(struct Curl_easy *data,
141 struct connectdata **connp)
143 /* this works for an easy handle:
144 * - that has been used for curl_easy_perform()
145 * - that is associated with a multi handle, and whose connection
146 * was detached with CURLOPT_CONNECT_ONLY
147 */
148 struct connectdata *conn = Curl_cpool_get_last_conn(data);
149 if(connp)
150 *connp = conn;
151 return conn ? conn->sock[FIRSTSOCKET] : CURL_SOCKET_BAD;
154void Curl_conncontrol(struct connectdata *conn, int ctrl)
156 if(!conn) {
157 DEBUGASSERT(0);
158 return;
159 }
160 switch(ctrl) {
161 case CONNCTRL_CONN_KEEP:
162 conn->bits.close = FALSE;
163 break;
164 case CONNCTRL_CONN_CLOSE:
165 conn->bits.close = TRUE;
166 break;
167 case CONNCTRL_STREAM_CLOSE:
168 /* stream close when multiplexing does not affect connection */
169 if(!Curl_conn_is_multiplex(conn, FIRSTSOCKET))
170 conn->bits.close = TRUE;
171 break;
172 default:
173 DEBUGASSERT(0);
174 break;
175 }
178CURLcode Curl_conn_setup(struct Curl_easy *data,
179 struct connectdata *conn,
180 int8_t sockindex,
181 int ssl_mode)
183 struct Curl_peer *first_peer = Curl_conn_get_first_peer(conn, sockindex);
184 CURLcode result = CURLE_OK;
185 uint8_t dns_queries;
187 DEBUGASSERT(data);
188 DEBUGASSERT(conn->scheme);
189 DEBUGASSERT(!conn->cfilter[sockindex]);
191 if(!first_peer)
192 return CURLE_FAILED_INIT;
194#ifndef CURL_DISABLE_HTTP
195 if(!conn->cfilter[sockindex] &&
196 conn->scheme->protocol == CURLPROTO_HTTPS) {
197 DEBUGASSERT(ssl_mode != CURL_CF_SSL_DISABLE);
198 result = Curl_cf_https_setup(
199 data, Curl_conn_get_destination(conn, sockindex), conn, sockindex);
200 if(result)
201 goto out;
202 }
203#endif /* !CURL_DISABLE_HTTP */
205 /* Still no cfilter set, apply default. */
206 if(!conn->cfilter[sockindex]) {
207 result = Curl_cf_setup_add(data, conn, sockindex,
208 conn->transport_wanted, ssl_mode);
209 if(result)
210 goto out;
211 }
213 /* Whatever the filter chain will be in the end, it will need the
214 * resolving of `first_peer`. Add that now so the resolve is started
215 * right away. */
216 dns_queries = Curl_resolv_dns_queries(data, conn->ip_version);
217 result = Curl_conn_dns_add_addr_resolve(data, conn, sockindex,
218 first_peer, dns_queries,
219 conn->transport_wanted);
220 if(result)
221 goto out;
223 DEBUGASSERT(conn->cfilter[sockindex]);
224out:
225 return result;
228#ifdef CURLVERBOSE
229static CURLcode conn_connect_trace(struct Curl_easy *data,
230 struct Curl_cfilter *cf)
232 if(Curl_trc_is_verbose(data)) {
233 struct ip_quadruple ipquad;
234 bool is_ipv6;
235 CURLcode result;
237 result = Curl_conn_cf_get_ip_info(cf, data, &is_ipv6, &ipquad);
238 if(result)
239 return result;
241 infof(data, "Established %sconnection to %s (%s port %u) from %s port %u ",
242 (cf->sockindex == SECONDARYSOCKET) ? "2nd " : "",
243 CURL_CONN_HOST_DISPNAME(data->conn),
244 ipquad.remote_ip, ipquad.remote_port,
245 ipquad.local_ip, ipquad.local_port);
246 }
247 return CURLE_OK;
249#endif
251/**
252 * Update connection statistics
253 */
254static void conn_report_stats(struct Curl_easy *data, int sockindex)
256 /* We do gather stats for the second socket...yet */
257 if(sockindex == FIRSTSOCKET) {
258 Curl_conn_cntrl_report_stats(data, data->conn, sockindex);
259 }
262void Curl_conn_report_failed(struct Curl_easy *data, int8_t sockindex)
264 if(!data->conn || (sockindex != FIRSTSOCKET))
265 return;
266 /* Only filters connected at IP level have info to update. Filters
267 * still racing for a connection, like happy eyeballing, pass it on
268 * to a connected one only. */
269 (void)Curl_conn_cf_cntrl(data->conn->cfilter[sockindex], data, TRUE,
270 CF_CTRL_CONN_INFO_UPDATE, 0, NULL);
271 conn_report_stats(data, sockindex);
274CURLcode Curl_conn_connect(struct Curl_easy *data,
275 int8_t sockindex,
276 bool blocking,
277 bool *done)
279#define CF_CONN_NUM_POLLS_ON_STACK 5
280 struct pollfd a_few_on_stack[CF_CONN_NUM_POLLS_ON_STACK];
281 struct easy_pollset ps;
282 struct curl_pollfds cpfds;
283 struct Curl_cfilter *cf;
284 CURLcode result = CURLE_OK;
286 DEBUGASSERT(data);
287 DEBUGASSERT(data->conn);
288 if(!CONN_SOCK_IDX_VALID(sockindex))
289 return CURLE_BAD_FUNCTION_ARGUMENT;
291 if(data->conn->scheme->flags & PROTOPT_NONETWORK) {
292 *done = TRUE;
293 return CURLE_OK;
294 }
296 cf = data->conn->cfilter[sockindex];
297 if(!cf) {
298 *done = FALSE;
299 return CURLE_FAILED_INIT;
300 }
302 *done = (bool)cf->connected;
303 if(*done)
304 return CURLE_OK;
306 if(data->conn->connect_start_ms < 0) {
307 data->conn->connect_start_ms =
308 curlx_ptimediff_ms(Curl_pgrs_now(data), &data->conn->created);
309 }
311 Curl_pollset_init(&ps);
312 Curl_pollfds_init(&cpfds, a_few_on_stack, CF_CONN_NUM_POLLS_ON_STACK);
313 while(!*done) {
314 if(Curl_conn_needs_flush(data, sockindex)) {
315 DEBUGF(infof(data, "Curl_conn_connect(index=%d), flush", sockindex));
316 result = Curl_conn_flush(data, sockindex);
317 if(result && (result != CURLE_AGAIN))
318 goto out;
319 }
321 result = cf->cft->do_connect(cf, data, done);
322 CURL_TRC_CF(data, cf, "Curl_conn_connect(block=%d) -> %d, done=%d",
323 blocking, (int)result, *done);
324 if(!result && *done) {
325 /* A final sanity check on connection security */
326 if((data->state.origin->scheme->flags & PROTOPT_SSL) &&
327 (sockindex == FIRSTSOCKET) &&
328 !Curl_conn_is_ssl(data->conn, FIRSTSOCKET)) {
329 DEBUGASSERT(0);
330 failf(data, "transfer requires SSL, but not connected via SSL");
331 result = CURLE_FAILED_INIT;
332 goto out;
333 }
334 /* Now that the complete filter chain is connected, let all filters
335 * persist information at the connection. E.g. cf-socket sets the
336 * socket and ip related information. */
337 Curl_conn_cntrl_update_info(data, data->conn);
338 conn_report_stats(data, sockindex);
339 Curl_cpool_conn_was_used(data, data->conn, Curl_pgrs_now(data));
340 VERBOSE(result = conn_connect_trace(data, cf));
341 VERBOSE(Curl_conn_trc_filters(data, sockindex, "connected"));
342 Curl_conn_remove_setup_filters(data, sockindex);
343 VERBOSE(Curl_conn_trc_filters(data, sockindex, "reduced to"));
344 data->conn->connect_start_ms = -1;
345 goto out;
346 }
347 else if(result) {
348 CURL_TRC_CF(data, cf, "Curl_conn_connect(), filter returned %d",
349 (int)result);
350 VERBOSE(Curl_conn_trc_filters(data, sockindex, "failed to connect"));
351 Curl_conn_report_failed(data, sockindex);
352 goto out;
353 }
355 if(!blocking)
356 goto out;
357 else {
358 /* check allowed time left */
359 const struct curltime *pnow = Curl_pgrs_now(data);
360 timediff_t timeout_ms = Curl_timeleft_now_ms(data, pnow);
361 curl_socket_t sockfd = Curl_conn_cf_get_socket(cf, data);
362 int rc;
364 if(timeout_ms < 0) {
365 /* no need to continue if time already is up */
366 failf(data, "connect timeout");
367 result = CURLE_OPERATION_TIMEDOUT;
368 goto out;
369 }
371 CURL_TRC_CF(data, cf, "Curl_conn_connect(block=1), do poll");
372 Curl_pollset_reset(&ps);
373 Curl_pollfds_reset(&cpfds);
374 /* In general, we want to send after connect, wait on that. */
375 if(sockfd != CURL_SOCKET_BAD)
376 result = Curl_pollset_set_out_only(data, &ps, sockfd);
377 if(!result)
378 result = Curl_conn_adjust_pollset(data, data->conn, &ps);
379 if(result)
380 goto out;
381 result = Curl_pollfds_add_ps(&cpfds, &ps);
382 if(result)
383 goto out;
385 rc = Curl_poll(cpfds.pfds, cpfds.n,
386 CURLMIN(timeout_ms ? timeout_ms : 1000,
387 (cpfds.n ? 1000 : 10)));
388 CURL_TRC_CF(data, cf, "Curl_conn_connect(block=1), Curl_poll() -> %d",
389 rc);
390 if(rc < 0) {
391 result = CURLE_COULDNT_CONNECT;
392 goto out;
393 }
394 /* continue iterating */
395 }
396 }
398out:
399 Curl_pollset_cleanup(&ps);
400 Curl_pollfds_cleanup(&cpfds);
401 return result;
404void Curl_conn_set_multiplex(struct connectdata *conn)
406 if(!conn->bits.multiplex) {
407 conn->bits.multiplex = TRUE;
408 if(conn->attached_multi) {
409 Curl_multi_connchanged(conn->attached_multi);
410 }
411 }
414struct Curl_peer *Curl_conn_get_origin(struct connectdata *conn,
415 int8_t sockindex)
417 return (sockindex == SECONDARYSOCKET) ?
418 conn->origin2 : conn->origin;
421struct Curl_peer *Curl_conn_get_destination(struct connectdata *conn,
422 int8_t sockindex)
424 return (sockindex == SECONDARYSOCKET) ?
425 (conn->via_peer2 ? conn->via_peer2 : conn->origin2) :
426 (conn->via_peer ? conn->via_peer : conn->origin);
429struct Curl_peer *Curl_conn_get_first_peer(struct connectdata *conn,
430 int8_t sockindex)
432#ifndef CURL_DISABLE_PROXY
433 if(conn->socks_proxy.peer)
434 return conn->socks_proxy.peer;
435 if(conn->http_proxy.peer)
436 return conn->http_proxy.peer;
437#endif
438 return (sockindex == SECONDARYSOCKET) ?
439 (conn->via_peer2 ? conn->via_peer2 : conn->origin2) :
440 (conn->via_peer ? conn->via_peer : conn->origin);
Diagnostics4 git calls · 28 ms
CallStatusSizeTime028 ms
discover200152 B1 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=1
git.response.bytes=152
git.server.agent=gitty/1.0
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch object-format
git.server.fetch=shallow filter sideband-all
git.protocol.version=2
git.pkt.frames=8
git.pkt.data=6
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=152
git.pkt.payload.max=34
ls-refs200149 B · hit2 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=149
git.response.cache=HIT
git.response.duration_ms=2
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=149
git.pkt.payload.max=78
git.ls_refs.count=2
git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=293470
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=blob:none
git.fetch.filter.requested=tree:0
git.fetch.filter.fallback=blob:none
git.fetch.filter.learned=false
git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=10
git.pkt.data=8
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=293470
git.pkt.payload.max=65516
git.sideband.band1.bytes=293354
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=87
git.pack.bytes=293354
git.pack.ofs_delta=0
git.pack.ref_delta=1
git.pack.chain.max=1
git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0
git.pack.full=86
Open pack map
fetch2004.6 KiB · hit24 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=24
git.response.bytes=4687
git.response.cache=HIT
git.response.duration_ms=24
git.fetch.wants=63f9602387c397ad16263801eb8760b1239642df
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=4687
git.pkt.payload.max=4666
git.sideband.band1.bytes=4665
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
Ref
refs/heads/master
Commit
31c911efe5652725e930f4d2e60c9060e5f6646d
cf-ray
a5e15f68fdc8725b
Request
9890be0a…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format