Artifactspublic-v0

curl

master
ply4 git calls28 ms289 KiB3 cachedprotocol v2
241 lines6.5 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#ifndef CURL_DISABLE_PROXY
28#include "urldata.h"
29#include "cfilters.h"
30#include "cf-haproxy.h"
31#include "connect.h"
32#include "curl_addrinfo.h"
33#include "curl_trc.h"
34#include "select.h"
37typedef enum {
38 HAPROXY_INIT, /* init/default/no tunnel state */
39 HAPROXY_SEND, /* data_out being sent */
40 HAPROXY_DONE /* all work done */
41} haproxy_state;
43struct cf_haproxy_ctx {
44 int state;
45 struct dynbuf data_out;
46};
48static void cf_haproxy_ctx_free(struct cf_haproxy_ctx *ctx)
50 if(ctx) {
51 curlx_dyn_free(&ctx->data_out);
52 curlx_free(ctx);
53 }
56static CURLcode cf_haproxy_date_out_set(struct Curl_cfilter *cf,
57 struct Curl_easy *data)
59 /* We fake a client connection report to the upstream server
60 * with the HAProxy protocol, reporting the client's source
61 * and destination IP addresses and ports.
62 * addresses: either the ones used to talk to the upstream
63 * OR the value supplied by the user
64 * ports: the ports used in the upstream connection */
65 const char *client_source_ip;
66 const char *client_dest_ip;
67 struct cf_haproxy_ctx *ctx = cf->ctx;
68 CURLcode result;
69 struct ip_quadruple ipquad;
70 bool is_ipv6;
72 DEBUGASSERT(ctx);
73 DEBUGASSERT(ctx->state == HAPROXY_INIT);
74#ifdef USE_UNIX_SOCKETS
75 if(Curl_conn_get_first_peer(cf->conn, cf->sockindex)->unix_socket)
76 /* the buffer is large enough to hold this! */
77 result = curlx_dyn_addn(&ctx->data_out, STRCONST("PROXY UNKNOWN\r\n"));
78 else {
79#endif /* USE_UNIX_SOCKETS */
80 result = Curl_conn_cf_get_ip_info(cf->next, data, &is_ipv6, &ipquad);
81 if(result)
82 return result;
84 client_source_ip = CURL_EASY_STR(data, STRING_HAPROXY_CLIENT_IP);
85 if(client_source_ip) {
86 client_dest_ip = client_source_ip;
87 is_ipv6 = !Curl_is_ipv4addr(client_source_ip);
88 }
89 else {
90 client_source_ip = ipquad.local_ip;
91 client_dest_ip = ipquad.remote_ip;
92 }
94 result = curlx_dyn_addf(&ctx->data_out, "PROXY %s %s %s %d %d\r\n",
95 is_ipv6 ? "TCP6" : "TCP4",
96 client_source_ip, client_dest_ip,
97 ipquad.local_port, ipquad.remote_port);
99#ifdef USE_UNIX_SOCKETS
100 }
101#endif /* USE_UNIX_SOCKETS */
102 return result;
105static CURLcode cf_haproxy_connect(struct Curl_cfilter *cf,
106 struct Curl_easy *data,
107 bool *done)
109 struct cf_haproxy_ctx *ctx = cf->ctx;
110 CURLcode result;
111 size_t len;
113 DEBUGASSERT(ctx);
114 if(cf->connected) {
115 *done = TRUE;
116 return CURLE_OK;
117 }
119 result = cf->next->cft->do_connect(cf->next, data, done);
120 if(result || !*done)
121 return result;
123 switch(ctx->state) {
124 case HAPROXY_INIT:
125 result = cf_haproxy_date_out_set(cf, data);
126 if(result)
127 goto out;
128 ctx->state = HAPROXY_SEND;
129 FALLTHROUGH();
130 case HAPROXY_SEND:
131 len = curlx_dyn_len(&ctx->data_out);
132 if(len > 0) {
133 size_t nwritten;
134 result = Curl_conn_cf_send(cf->next, data,
135 curlx_dyn_uptr(&ctx->data_out), len, FALSE,
136 &nwritten);
137 if(result) {
138 if(result != CURLE_AGAIN)
139 goto out;
140 result = CURLE_OK;
141 nwritten = 0;
142 }
143 curlx_dyn_tail(&ctx->data_out, len - nwritten);
144 if(curlx_dyn_len(&ctx->data_out) > 0) {
145 result = CURLE_OK;
146 goto out;
147 }
148 }
149 ctx->state = HAPROXY_DONE;
150 FALLTHROUGH();
151 default:
152 curlx_dyn_free(&ctx->data_out);
153 break;
154 }
156out:
157 *done = (!result) && (ctx->state == HAPROXY_DONE);
158 cf->connected = *done;
159 return result;
162static void cf_haproxy_destroy(struct Curl_cfilter *cf,
163 struct Curl_easy *data)
165 CURL_TRC_CF(data, cf, "destroy");
166 cf_haproxy_ctx_free(cf->ctx);
169static CURLcode cf_haproxy_adjust_pollset(struct Curl_cfilter *cf,
170 struct Curl_easy *data,
171 struct easy_pollset *ps)
173 if(cf->next->connected && !cf->connected) {
174 /* If we are not connected, but the filter "below" is
175 * and not waiting on something, we are sending. */
176 return Curl_pollset_set_out_only(
177 data, ps, Curl_conn_cf_get_socket(cf, data));
178 }
179 return CURLE_OK;
182struct Curl_cftype Curl_cft_haproxy = {
183 "HAPROXY",
184 CF_TYPE_PROXY | CF_TYPE_SETUP,
185 0,
186 cf_haproxy_destroy,
187 cf_haproxy_connect,
188 Curl_cf_def_shutdown,
189 cf_haproxy_adjust_pollset,
190 Curl_cf_def_data_pending,
191 Curl_cf_def_send,
192 Curl_cf_def_recv,
193 Curl_cf_def_cntrl,
194 Curl_cf_def_conn_is_alive,
195 Curl_cf_def_conn_keep_alive,
196 Curl_cf_def_query,
197};
199static CURLcode cf_haproxy_create(struct Curl_cfilter **pcf,
200 struct Curl_easy *data)
202 struct Curl_cfilter *cf = NULL;
203 struct cf_haproxy_ctx *ctx;
204 CURLcode result;
206 (void)data;
207 ctx = curlx_calloc(1, sizeof(*ctx));
208 if(!ctx) {
209 result = CURLE_OUT_OF_MEMORY;
210 goto out;
211 }
212 ctx->state = HAPROXY_INIT;
213 curlx_dyn_init(&ctx->data_out, DYN_HAXPROXY);
215 result = Curl_cf_create(&cf, &Curl_cft_haproxy, ctx);
216 if(result)
217 goto out;
218 ctx = NULL;
220out:
221 cf_haproxy_ctx_free(ctx);
222 *pcf = result ? NULL : cf;
223 return result;
226CURLcode Curl_cf_haproxy_insert_after(struct Curl_cfilter *cf_at,
227 struct Curl_easy *data)
229 struct Curl_cfilter *cf;
230 CURLcode result;
232 result = cf_haproxy_create(&cf, data);
233 if(result)
234 goto out;
235 Curl_conn_cf_insert_after(cf_at, cf);
237out:
238 return result;
241#endif /* !CURL_DISABLE_PROXY */
Diagnostics4 git calls · 28 ms
CallStatusSizeTime028 ms
discover200152 B2 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
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 · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=23
git.response.bytes=293470
git.response.cache=HIT
git.response.duration_ms=3
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
fetch2002.3 KiB · hit23 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=2400
git.response.cache=HIT
git.response.duration_ms=23
git.fetch.wants=e3286107a328930c668c1f25dd144f6462941b32
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=2400
git.pkt.payload.max=2379
git.sideband.band1.bytes=2378
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
a5e259d9aa57a23e
Request
ace33e43…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format