Skip to content

Commit 8295946

Browse files
steadmongitster
authored andcommitted
upload-pack, serve: log received client session ID
When upload-pack (protocol v0/v1) or a protocol v2 server receives a session-id capability from a client, log the received session ID via a trace2 data event. Signed-off-by: Josh Steadmon <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1e905bb commit 8295946

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

serve.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ static int process_request(void)
201201
struct packet_reader reader;
202202
struct strvec keys = STRVEC_INIT;
203203
struct protocol_capability *command = NULL;
204+
const char *client_sid;
204205

205206
packet_reader_init(&reader, 0, NULL, 0,
206207
PACKET_READ_CHOMP_NEWLINE |
@@ -264,6 +265,9 @@ static int process_request(void)
264265

265266
check_algorithm(the_repository, &keys);
266267

268+
if (has_capability(&keys, "session-id", &client_sid))
269+
trace2_data_string("transfer", NULL, "client-sid", client_sid);
270+
267271
command->command(the_repository, &keys, &reader);
268272

269273
strvec_clear(&keys);

t/t5705-session-id-in-capabilities.sh

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ test_expect_success 'setup repos for session ID capability tests' '
1717
for PROTO in 0 1 2
1818
do
1919
test_expect_success "session IDs not advertised by default (fetch v${PROTO})" '
20-
test_when_finished "rm -rf local tr2-client-events" &&
20+
test_when_finished "rm -rf local tr2-client-events tr2-server-events" &&
2121
cp -r "$LOCAL_PRISTINE" local &&
2222
GIT_TRACE2_EVENT="$(pwd)/tr2-client-events" \
23-
git -c protocol.version=$PROTO -C local fetch origin &&
24-
test -z "$(grep \"key\":\"server-sid\" tr2-client-events)"
23+
git -c protocol.version=$PROTO -C local fetch \
24+
--upload-pack "GIT_TRACE2_EVENT=\"$(pwd)/tr2-server-events\" git-upload-pack" \
25+
origin &&
26+
test -z "$(grep \"key\":\"server-sid\" tr2-client-events)" &&
27+
test -z "$(grep \"key\":\"client-sid\" tr2-server-events)"
2528
'
2629

2730
test_expect_success "session IDs not advertised by default (push v${PROTO})" '
@@ -43,11 +46,14 @@ test_expect_success 'enable SID advertisement' '
4346
for PROTO in 0 1 2
4447
do
4548
test_expect_success "session IDs advertised (fetch v${PROTO})" '
46-
test_when_finished "rm -rf local tr2-client-events" &&
49+
test_when_finished "rm -rf local tr2-client-events tr2-server-events" &&
4750
cp -r "$LOCAL_PRISTINE" local &&
4851
GIT_TRACE2_EVENT="$(pwd)/tr2-client-events" \
49-
git -c protocol.version=$PROTO -C local fetch origin &&
50-
grep \"key\":\"server-sid\" tr2-client-events
52+
git -c protocol.version=$PROTO -C local fetch \
53+
--upload-pack "GIT_TRACE2_EVENT=\"$(pwd)/tr2-server-events\" git-upload-pack" \
54+
origin &&
55+
grep \"key\":\"server-sid\" tr2-client-events &&
56+
grep \"key\":\"client-sid\" tr2-server-events
5157
'
5258

5359
test_expect_success "session IDs advertised (push v${PROTO})" '

upload-pack.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,7 @@ static void receive_needs(struct upload_pack_data *data,
10581058
const char *features;
10591059
struct object_id oid_buf;
10601060
const char *arg;
1061+
int feature_len;
10611062

10621063
reset_timeout(data->timeout);
10631064
if (packet_reader_read(reader) != PACKET_READ_NORMAL)
@@ -1110,6 +1111,13 @@ static void receive_needs(struct upload_pack_data *data,
11101111
parse_feature_request(features, "filter"))
11111112
data->filter_capability_requested = 1;
11121113

1114+
arg = parse_feature_value(features, "session-id", &feature_len, NULL);
1115+
if (arg) {
1116+
char *client_sid = xstrndup(arg, feature_len);
1117+
trace2_data_string("transfer", NULL, "client-sid", client_sid);
1118+
free(client_sid);
1119+
}
1120+
11131121
o = parse_object(the_repository, &oid_buf);
11141122
if (!o) {
11151123
packet_writer_error(&data->writer,

0 commit comments

Comments
 (0)