Artifactspublic-v0

curl

master
ply4 git calls835 ms289 KiB2 cachedprotocol v2
183 lines5.8 KiBexecutableRaw
1#!/usr/bin/env python3
2#***************************************************************************
3# _ _ ____ _
4# Project ___| | | | _ \| |
5# / __| | | | |_) | |
6# | (__| |_| | _ <| |___
7# \___|\___/|_| \_\_____|
8#
9# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
11# This software is licensed as described in the file COPYING, which
12# you should have received as part of this distribution. The terms
13# are also available at https://curl.se/docs/copyright.html.
15# You may opt to use, copy, modify, merge, publish, distribute and/or sell
16# copies of the Software, and permit persons to whom the Software is
17# furnished to do so, under the terms of the COPYING file.
19# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20# KIND, either express or implied.
22# SPDX-License-Identifier: curl
24###########################################################################
26"""DICT server."""
28import argparse
29import logging
30import os
31import sys
33from util import ClosingFileHandler
35try: # Python 2
36 import SocketServer as socketserver # type: ignore
37except ImportError: # Python 3
38 import socketserver
41log = logging.getLogger(__name__)
42HOST = "localhost"
44# The strings that indicate the test framework is checking our aliveness
45VERIFIED_REQ = b"verifiedserver"
46VERIFIED_RSP = "WE ROOLZ: {pid}"
49def dictserver(options):
50 """Start up a TCP server with a DICT handler and serve DICT requests forever."""
51 if options.pidfile:
52 pid = os.getpid()
53 # see tests/server/util.c function write_pidfile
54 if os.name == "nt":
55 pid += 4194304
56 with open(options.pidfile, "w") as f:
57 f.write(str(pid))
59 local_bind = (options.host, options.port)
60 log.info("[DICT] Listening on %s", local_bind)
62 # Need to set the allow_reuse on the class, not on the instance.
63 socketserver.TCPServer.allow_reuse_address = True
64 server = socketserver.TCPServer(local_bind, DictHandler)
65 server.serve_forever()
67 return ScriptRC.SUCCESS
70class DictHandler(socketserver.BaseRequestHandler):
71 """Handler class for DICT connections."""
73 def handle(self):
74 """Respond to all queries with a 552."""
75 try:
76 # First, send a response to allow the server to continue.
77 rsp = "220 dictserver <xnooptions> <msgid@msgid>\n"
78 self.request.sendall(rsp.encode("utf-8"))
80 # Receive the request.
81 data = self.request.recv(1024).strip()
82 log.debug("[DICT] Incoming data: %r", data)
84 if VERIFIED_REQ in data:
85 log.debug("[DICT] Received verification request from test "
86 "framework")
87 pid = os.getpid()
88 # see tests/server/util.c function write_pidfile
89 if os.name == "nt":
90 pid += 4194304
91 response_data = VERIFIED_RSP.format(pid=pid)
92 else:
93 log.debug("[DICT] Received normal request")
94 response_data = "No matches"
96 # Send back a failure to find.
97 response = f"552 {response_data}\n"
98 log.debug("[DICT] Responding with %r", response)
99 self.request.sendall(response.encode("utf-8"))
101 except OSError:
102 log.exception("[DICT] OSError hit during request")
105def get_options():
106 parser = argparse.ArgumentParser()
108 parser.add_argument("--port", action="store", default=9016,
109 type=int, help="port to listen on")
110 parser.add_argument("--host", action="store", default=HOST,
111 help="host to listen on")
112 parser.add_argument("--verbose", action="store", type=int, default=0,
113 help="verbose output")
114 parser.add_argument("--pidfile", action="store",
115 help="filename for the PID")
116 parser.add_argument("--logfile", action="store",
117 help="filename for the log")
118 parser.add_argument("--srcdir", action="store", help="test directory")
119 parser.add_argument("--id", action="store", help="server ID")
120 parser.add_argument("--ipv4", action="store_true", default=0,
121 help="IPv4 flag")
123 return parser.parse_args()
126def setup_logging(options):
127 """Set up logging from the command line options."""
128 root_logger = logging.getLogger()
129 add_stdout = False
131 formatter = logging.Formatter("%(asctime)s %(levelname)-5.5s %(message)s")
133 # Write out to a logfile
134 if options.logfile:
135 handler = ClosingFileHandler(options.logfile)
136 handler.setFormatter(formatter)
137 handler.setLevel(logging.DEBUG)
138 root_logger.addHandler(handler)
139 else:
140 # The logfile was not specified. Add a stdout logger.
141 add_stdout = True
143 if options.verbose:
144 # Add a stdout logger as well in verbose mode
145 root_logger.setLevel(logging.DEBUG)
146 add_stdout = True
147 else:
148 root_logger.setLevel(logging.INFO)
150 if add_stdout:
151 stdout_handler = logging.StreamHandler(sys.stdout)
152 stdout_handler.setFormatter(formatter)
153 stdout_handler.setLevel(logging.DEBUG)
154 root_logger.addHandler(stdout_handler)
157class ScriptRC:
158 """Enum for script return codes."""
160 SUCCESS = 0
161 FAILURE = 1
162 EXCEPTION = 2
165if __name__ == '__main__':
166 # Get the options from the user.
167 options = get_options()
169 # Setup logging using the user options
170 setup_logging(options)
172 # Run main script.
173 try:
174 rc = dictserver(options)
175 except Exception:
176 log.exception('Error running server')
177 rc = ScriptRC.EXCEPTION
179 if options.pidfile and os.path.isfile(options.pidfile):
180 os.unlink(options.pidfile)
182 log.info("[DICT] Returning %d", rc)
183 sys.exit(rc)
Diagnostics4 git calls · 835 ms
CallStatusSizeTime0835 ms
discover200152 B2 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
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=3
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 KiB830 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=830
git.response.bytes=2322
git.response.cache=MISS
git.response.duration_ms=830
git.fetch.wants=bff6e80157e463d6ad1c838f589e3df313d0af7a
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=2322
git.pkt.payload.max=2301
git.sideband.band1.bytes=2300
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
a5e2c5a23c0b4afc
Request
6aee756c…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format