Skip to content

Commit 23bf486

Browse files
steadmongitster
authored andcommitted
transport: log received server session ID
When a client receives a session-id capability from a protocol v0, v1, or v2 server, 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 6b5b6e4 commit 23bf486

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/sh
2+
3+
test_description='session ID in capabilities'
4+
5+
. ./test-lib.sh
6+
7+
REPO="$(pwd)/repo"
8+
LOCAL_PRISTINE="$(pwd)/local_pristine"
9+
10+
test_expect_success 'setup repos for session ID capability tests' '
11+
git init "$REPO" &&
12+
test_commit -C "$REPO" a &&
13+
git clone "file://$REPO" "$LOCAL_PRISTINE" &&
14+
test_commit -C "$REPO" b
15+
'
16+
17+
for PROTO in 0 1 2
18+
do
19+
test_expect_success "session IDs not advertised by default (fetch v${PROTO})" '
20+
test_when_finished "rm -rf local tr2-client-events" &&
21+
cp -r "$LOCAL_PRISTINE" local &&
22+
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)"
25+
'
26+
27+
test_expect_success "session IDs not advertised by default (push v${PROTO})" '
28+
test_when_finished "rm -rf local tr2-client-events" &&
29+
cp -r "$LOCAL_PRISTINE" local &&
30+
git -C local pull --no-rebase origin &&
31+
GIT_TRACE2_EVENT_NESTING=5 \
32+
GIT_TRACE2_EVENT="$(pwd)/tr2-client-events" \
33+
git -c protocol.version=$PROTO -C local push origin &&
34+
test -z "$(grep \"key\":\"server-sid\" tr2-client-events)"
35+
'
36+
done
37+
38+
test_expect_success 'enable SID advertisement' '
39+
git -C "$REPO" config transfer.advertiseSID true &&
40+
git -C "$LOCAL_PRISTINE" config transfer.advertiseSID true
41+
'
42+
43+
for PROTO in 0 1 2
44+
do
45+
test_expect_success "session IDs advertised (fetch v${PROTO})" '
46+
test_when_finished "rm -rf local tr2-client-events" &&
47+
cp -r "$LOCAL_PRISTINE" local &&
48+
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
51+
'
52+
53+
test_expect_success "session IDs advertised (push v${PROTO})" '
54+
test_when_finished "rm -rf local tr2-client-events" &&
55+
cp -r "$LOCAL_PRISTINE" local &&
56+
git -C local pull --no-rebase origin &&
57+
GIT_TRACE2_EVENT_NESTING=5 \
58+
GIT_TRACE2_EVENT="$(pwd)/tr2-client-events" \
59+
git -c protocol.version=$PROTO -C local push origin &&
60+
grep \"key\":\"server-sid\" tr2-client-events
61+
'
62+
done
63+
64+
test_done

transport.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ static struct ref *handshake(struct transport *transport, int for_push,
286286
struct git_transport_data *data = transport->data;
287287
struct ref *refs = NULL;
288288
struct packet_reader reader;
289+
int sid_len;
290+
const char *server_sid;
289291

290292
connect_setup(transport, for_push);
291293

@@ -297,6 +299,8 @@ static struct ref *handshake(struct transport *transport, int for_push,
297299
data->version = discover_version(&reader);
298300
switch (data->version) {
299301
case protocol_v2:
302+
if (server_feature_v2("session-id", &server_sid))
303+
trace2_data_string("transfer", NULL, "server-sid", server_sid);
300304
if (must_list_refs)
301305
get_remote_refs(data->fd[1], &reader, &refs, for_push,
302306
ref_prefixes,
@@ -310,6 +314,12 @@ static struct ref *handshake(struct transport *transport, int for_push,
310314
for_push ? REF_NORMAL : 0,
311315
&data->extra_have,
312316
&data->shallow);
317+
server_sid = server_feature_value("session-id", &sid_len);
318+
if (server_sid) {
319+
char *sid = xstrndup(server_sid, sid_len);
320+
trace2_data_string("transfer", NULL, "server-sid", sid);
321+
free(sid);
322+
}
313323
break;
314324
case protocol_unknown_version:
315325
BUG("unknown protocol version");

0 commit comments

Comments
 (0)