From f5cdbe485f5c560eb53734a2b25309409786b636 Mon Sep 17 00:00:00 2001 From: Josh Steadmon Date: Wed, 11 Nov 2020 15:29:24 -0800 Subject: docs: new capability to advertise session IDs In future patches, we will add the ability for Git servers and clients to advertise unique session IDs via protocol capabilities. This allows for easier debugging when both client and server logs are available. Signed-off-by: Josh Steadmon Signed-off-by: Junio C Hamano --- Documentation/technical/protocol-capabilities.txt | 17 +++++++++++++++-- Documentation/technical/protocol-v2.txt | 13 +++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Documentation/technical/protocol-capabilities.txt b/Documentation/technical/protocol-capabilities.txt index ba869a7d36..9dfade930d 100644 --- a/Documentation/technical/protocol-capabilities.txt +++ b/Documentation/technical/protocol-capabilities.txt @@ -27,8 +27,8 @@ and 'push-cert' capabilities are sent and recognized by the receive-pack (push to server) process. The 'ofs-delta' and 'side-band-64k' capabilities are sent and recognized -by both upload-pack and receive-pack protocols. The 'agent' capability -may optionally be sent in both protocols. +by both upload-pack and receive-pack protocols. The 'agent' and 'session-id' +capabilities may optionally be sent in both protocols. All other capabilities are only recognized by the upload-pack (fetch from server) process. @@ -365,3 +365,16 @@ If the upload-pack server advertises the 'filter' capability, fetch-pack may send "filter" commands to request a partial clone or partial fetch and request that the server omit various objects from the packfile. + +session-id= +----------------------- + +The server may advertise a session ID that can be used to identify this process +across multiple requests. The client may advertise its own session ID back to +the server as well. + +Session IDs should be unique to a given process. They must fit within a +packet-line, and must not contain non-printable or whitespace characters. The +current implementation uses trace2 session IDs (see +link:api-trace2.html[api-trace2] for details), but this may change and users of +the session ID should not rely on this fact. diff --git a/Documentation/technical/protocol-v2.txt b/Documentation/technical/protocol-v2.txt index e597b74da3..85daeb5d9e 100644 --- a/Documentation/technical/protocol-v2.txt +++ b/Documentation/technical/protocol-v2.txt @@ -492,3 +492,16 @@ form `object-format=X`) to notify the client that the server is able to deal with objects using hash algorithm X. If not specified, the server is assumed to only handle SHA-1. If the client would like to use a hash algorithm other than SHA-1, it should specify its object-format string. + +session-id= +~~~~~~~~~~~~~~~~~~~~~~~ + +The server may advertise a session ID that can be used to identify this process +across multiple requests. The client may advertise its own session ID back to +the server as well. + +Session IDs should be unique to a given process. They must fit within a +packet-line, and must not contain non-printable or whitespace characters. The +current implementation uses trace2 session IDs (see +link:api-trace2.html[api-trace2] for details), but this may change and users of +the session ID should not rely on this fact. -- cgit v1.2.3 From 81bd549010f609056362b1cd94feb2434beee194 Mon Sep 17 00:00:00 2001 From: Josh Steadmon Date: Wed, 11 Nov 2020 15:29:25 -0800 Subject: docs: new transfer.advertiseSID option Document a new config option that allows users to determine whether or not to advertise their session IDs to remote Git clients and servers. Signed-off-by: Josh Steadmon Signed-off-by: Junio C Hamano --- Documentation/config/transfer.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/config/transfer.txt b/Documentation/config/transfer.txt index f5b6245270..505126a780 100644 --- a/Documentation/config/transfer.txt +++ b/Documentation/config/transfer.txt @@ -69,3 +69,7 @@ transfer.unpackLimit:: When `fetch.unpackLimit` or `receive.unpackLimit` are not set, the value of this variable is used instead. The default value is 100. + +transfer.advertiseSID:: + Boolean. When true, client and server processes will advertise their + unique session IDs to their remote counterpart. Defaults to false. -- cgit v1.2.3 From e97e1cf464fa0c4646d41b9221ae88a7dca12493 Mon Sep 17 00:00:00 2001 From: Josh Steadmon Date: Wed, 11 Nov 2020 15:29:26 -0800 Subject: trace2: add a public function for getting the SID Add a public wrapper, trace2_session_id(), around tr2_sid_get(), which is intended to be private trace2 implementation. Signed-off-by: Josh Steadmon Signed-off-by: Junio C Hamano --- trace2.c | 5 +++++ trace2.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/trace2.c b/trace2.c index 2c6b570077..256120c7fd 100644 --- a/trace2.c +++ b/trace2.c @@ -792,3 +792,8 @@ void trace2_printf(const char *fmt, ...) va_end(ap); } #endif + +const char *trace2_session_id(void) +{ + return tr2_sid_get(); +} diff --git a/trace2.h b/trace2.h index b18bc5529c..ede18c2e06 100644 --- a/trace2.h +++ b/trace2.h @@ -500,4 +500,6 @@ void trace2_collect_process_info(enum trace2_process_info_reason reason); } while (0) #endif +const char *trace2_session_id(void); + #endif /* TRACE2_H */ -- cgit v1.2.3 From 791e1adf2236a9bb3e6a40da64c00614e39e15b7 Mon Sep 17 00:00:00 2001 From: Josh Steadmon Date: Wed, 11 Nov 2020 15:29:27 -0800 Subject: upload-pack: advertise session ID in v0 capabilities When transfer.advertiseSID is true, advertise upload-pack's session ID via the new session-id capability. Signed-off-by: Josh Steadmon Signed-off-by: Junio C Hamano --- upload-pack.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/upload-pack.c b/upload-pack.c index 3b858eb457..ebb4099268 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -110,6 +110,7 @@ struct upload_pack_data { unsigned done : 1; /* v2 only */ unsigned allow_ref_in_want : 1; /* v2 only */ unsigned allow_sideband_all : 1; /* v2 only */ + unsigned advertise_sid : 1; }; static void upload_pack_data_init(struct upload_pack_data *data) @@ -141,6 +142,7 @@ static void upload_pack_data_init(struct upload_pack_data *data) packet_writer_init(&data->writer, 1); data->keepalive = 5; + data->advertise_sid = 0; } static void upload_pack_data_clear(struct upload_pack_data *data) @@ -1178,6 +1180,11 @@ static void format_symref_info(struct strbuf *buf, struct string_list *symref) strbuf_addf(buf, " symref=%s:%s", item->string, (char *)item->util); } +static void format_session_id(struct strbuf *buf, struct upload_pack_data *d) { + if (d->advertise_sid) + strbuf_addf(buf, " session-id=%s", trace2_session_id()); +} + static int send_ref(const char *refname, const struct object_id *oid, int flag, void *cb_data) { @@ -1193,9 +1200,11 @@ static int send_ref(const char *refname, const struct object_id *oid, if (capabilities) { struct strbuf symref_info = STRBUF_INIT; + struct strbuf session_id = STRBUF_INIT; format_symref_info(&symref_info, &data->symref); - packet_write_fmt(1, "%s %s%c%s%s%s%s%s%s object-format=%s agent=%s\n", + format_session_id(&session_id, data); + packet_write_fmt(1, "%s %s%c%s%s%s%s%s%s%s object-format=%s agent=%s\n", oid_to_hex(oid), refname_nons, 0, capabilities, (data->allow_uor & ALLOW_TIP_SHA1) ? @@ -1205,9 +1214,11 @@ static int send_ref(const char *refname, const struct object_id *oid, data->stateless_rpc ? " no-done" : "", symref_info.buf, data->allow_filter ? " filter" : "", + session_id.buf, the_hash_algo->name, git_user_agent_sanitized()); strbuf_release(&symref_info); + strbuf_release(&session_id); } else { packet_write_fmt(1, "%s %s\n", oid_to_hex(oid), refname_nons); } @@ -1299,6 +1310,8 @@ static int upload_pack_config(const char *var, const char *value, void *cb_data) data->allow_sideband_all = git_config_bool(var, value); } else if (!strcmp("core.precomposeunicode", var)) { precomposed_unicode = git_config_bool(var, value); + } else if (!strcmp("transfer.advertisesid", var)) { + data->advertise_sid = git_config_bool(var, value); } if (current_config_scope() != CONFIG_SCOPE_LOCAL && -- cgit v1.2.3 From 8073d75bbf268da6da36f06ab2d1f0d9018bd74d Mon Sep 17 00:00:00 2001 From: Josh Steadmon Date: Wed, 11 Nov 2020 15:29:28 -0800 Subject: receive-pack: advertise session ID in v0 capabilities When transfer.advertiseSID is true, advertise receive-pack's session ID via the new session-id capability. Signed-off-by: Josh Steadmon Signed-off-by: Junio C Hamano --- builtin/receive-pack.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index bb9909c52e..6ed498b6c7 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -54,6 +54,7 @@ static int receive_unpack_limit = -1; static int transfer_unpack_limit = -1; static int advertise_atomic_push = 1; static int advertise_push_options; +static int advertise_sid; static int unpack_limit = 100; static off_t max_input_size; static int report_status; @@ -248,6 +249,11 @@ static int receive_pack_config(const char *var, const char *value, void *cb) return 0; } + if (strcmp(var, "transfer.advertisesid") == 0) { + advertise_sid = git_config_bool(var, value); + return 0; + } + return git_default_config(var, value, cb); } @@ -268,6 +274,8 @@ static void show_ref(const char *path, const struct object_id *oid) strbuf_addf(&cap, " push-cert=%s", push_cert_nonce); if (advertise_push_options) strbuf_addstr(&cap, " push-options"); + if (advertise_sid) + strbuf_addf(&cap, " session-id=%s", trace2_session_id()); strbuf_addf(&cap, " object-format=%s", the_hash_algo->name); strbuf_addf(&cap, " agent=%s", git_user_agent_sanitized()); packet_write_fmt(1, "%s %s%c%s\n", -- cgit v1.2.3 From 6b5b6e422ee3d84feccc1b09c18188fedaaed761 Mon Sep 17 00:00:00 2001 From: Josh Steadmon Date: Wed, 11 Nov 2020 15:29:29 -0800 Subject: serve: advertise session ID in v2 capabilities When transfer.advertiseSID is true, advertise the server's session ID for all protocol v2 connections via the new session-id capability. Signed-off-by: Josh Steadmon Signed-off-by: Junio C Hamano --- serve.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/serve.c b/serve.c index f6341206c4..8c0bb84f37 100644 --- a/serve.c +++ b/serve.c @@ -8,6 +8,8 @@ #include "serve.h" #include "upload-pack.h" +static int advertise_sid; + static int always_advertise(struct repository *r, struct strbuf *value) { @@ -30,6 +32,15 @@ static int object_format_advertise(struct repository *r, return 1; } +static int session_id_advertise(struct repository *r, struct strbuf *value) +{ + if (!advertise_sid) + return 0; + if (value) + strbuf_addstr(value, trace2_session_id()); + return 1; +} + struct protocol_capability { /* * The name of the capability. The server uses this name when @@ -66,6 +77,7 @@ static struct protocol_capability capabilities[] = { { "fetch", upload_pack_advertise, upload_pack_v2 }, { "server-option", always_advertise, NULL }, { "object-format", object_format_advertise, NULL }, + { "session-id", session_id_advertise, NULL }, }; static void advertise_capabilities(void) @@ -261,6 +273,8 @@ static int process_request(void) /* Main serve loop for protocol version 2 */ void serve(struct serve_options *options) { + git_config_get_bool("transfer.advertisesid", &advertise_sid); + if (options->advertise_capabilities || !options->stateless_rpc) { /* serve by default supports v2 */ packet_write_fmt(1, "version 2\n"); -- cgit v1.2.3 From 23bf486acae1a15bb214ab2004876533f6c73f96 Mon Sep 17 00:00:00 2001 From: Josh Steadmon Date: Wed, 11 Nov 2020 15:29:30 -0800 Subject: 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 Signed-off-by: Junio C Hamano --- t/t5705-session-id-in-capabilities.sh | 64 +++++++++++++++++++++++++++++++++++ transport.c | 10 ++++++ 2 files changed, 74 insertions(+) create mode 100755 t/t5705-session-id-in-capabilities.sh diff --git a/t/t5705-session-id-in-capabilities.sh b/t/t5705-session-id-in-capabilities.sh new file mode 100755 index 0000000000..9e782f4413 --- /dev/null +++ b/t/t5705-session-id-in-capabilities.sh @@ -0,0 +1,64 @@ +#!/bin/sh + +test_description='session ID in capabilities' + +. ./test-lib.sh + +REPO="$(pwd)/repo" +LOCAL_PRISTINE="$(pwd)/local_pristine" + +test_expect_success 'setup repos for session ID capability tests' ' + git init "$REPO" && + test_commit -C "$REPO" a && + git clone "file://$REPO" "$LOCAL_PRISTINE" && + test_commit -C "$REPO" b +' + +for PROTO in 0 1 2 +do + test_expect_success "session IDs not advertised by default (fetch v${PROTO})" ' + test_when_finished "rm -rf local tr2-client-events" && + cp -r "$LOCAL_PRISTINE" local && + GIT_TRACE2_EVENT="$(pwd)/tr2-client-events" \ + git -c protocol.version=$PROTO -C local fetch origin && + test -z "$(grep \"key\":\"server-sid\" tr2-client-events)" + ' + + test_expect_success "session IDs not advertised by default (push v${PROTO})" ' + test_when_finished "rm -rf local tr2-client-events" && + cp -r "$LOCAL_PRISTINE" local && + git -C local pull --no-rebase origin && + GIT_TRACE2_EVENT_NESTING=5 \ + GIT_TRACE2_EVENT="$(pwd)/tr2-client-events" \ + git -c protocol.version=$PROTO -C local push origin && + test -z "$(grep \"key\":\"server-sid\" tr2-client-events)" + ' +done + +test_expect_success 'enable SID advertisement' ' + git -C "$REPO" config transfer.advertiseSID true && + git -C "$LOCAL_PRISTINE" config transfer.advertiseSID true +' + +for PROTO in 0 1 2 +do + test_expect_success "session IDs advertised (fetch v${PROTO})" ' + test_when_finished "rm -rf local tr2-client-events" && + cp -r "$LOCAL_PRISTINE" local && + GIT_TRACE2_EVENT="$(pwd)/tr2-client-events" \ + git -c protocol.version=$PROTO -C local fetch origin && + grep \"key\":\"server-sid\" tr2-client-events + ' + + test_expect_success "session IDs advertised (push v${PROTO})" ' + test_when_finished "rm -rf local tr2-client-events" && + cp -r "$LOCAL_PRISTINE" local && + git -C local pull --no-rebase origin && + GIT_TRACE2_EVENT_NESTING=5 \ + GIT_TRACE2_EVENT="$(pwd)/tr2-client-events" \ + git -c protocol.version=$PROTO -C local push origin && + grep \"key\":\"server-sid\" tr2-client-events + ' +done + +test_done diff --git a/transport.c b/transport.c index 47da955e4f..679a35e7c1 100644 --- a/transport.c +++ b/transport.c @@ -286,6 +286,8 @@ static struct ref *handshake(struct transport *transport, int for_push, struct git_transport_data *data = transport->data; struct ref *refs = NULL; struct packet_reader reader; + int sid_len; + const char *server_sid; connect_setup(transport, for_push); @@ -297,6 +299,8 @@ static struct ref *handshake(struct transport *transport, int for_push, data->version = discover_version(&reader); switch (data->version) { case protocol_v2: + if (server_feature_v2("session-id", &server_sid)) + trace2_data_string("transfer", NULL, "server-sid", server_sid); if (must_list_refs) get_remote_refs(data->fd[1], &reader, &refs, for_push, ref_prefixes, @@ -310,6 +314,12 @@ static struct ref *handshake(struct transport *transport, int for_push, for_push ? REF_NORMAL : 0, &data->extra_have, &data->shallow); + server_sid = server_feature_value("session-id", &sid_len); + if (server_sid) { + char *sid = xstrndup(server_sid, sid_len); + trace2_data_string("transfer", NULL, "server-sid", sid); + free(sid); + } break; case protocol_unknown_version: BUG("unknown protocol version"); -- cgit v1.2.3 From 1e905bbc008dfc3c0ffe14b55bd920e188e51b4e Mon Sep 17 00:00:00 2001 From: Josh Steadmon Date: Wed, 11 Nov 2020 15:29:31 -0800 Subject: fetch-pack: advertise session ID in capabilities When the server sent a session-id capability and transfer.advertiseSID is true, advertise fetch-pack's own session ID back to the server. Signed-off-by: Josh Steadmon Signed-off-by: Junio C Hamano --- fetch-pack.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fetch-pack.c b/fetch-pack.c index b10c432315..23179b8dd0 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -35,6 +35,7 @@ static int fetch_fsck_objects = -1; static int transfer_fsck_objects = -1; static int agent_supported; static int server_supports_filtering; +static int advertise_sid; static struct shallow_lock shallow_lock; static const char *alternate_shallow_file; static struct strbuf fsck_msg_types = STRBUF_INIT; @@ -326,6 +327,8 @@ static int find_common(struct fetch_negotiator *negotiator, if (deepen_not_ok) strbuf_addstr(&c, " deepen-not"); if (agent_supported) strbuf_addf(&c, " agent=%s", git_user_agent_sanitized()); + if (advertise_sid) + strbuf_addf(&c, " session-id=%s", trace2_session_id()); if (args->filter_options.choice) strbuf_addstr(&c, " filter"); packet_buf_write(&req_buf, "want %s%s\n", remote_hex, c.buf); @@ -979,6 +982,9 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args, agent_len, agent_feature); } + if (!server_supports("session-id")) + advertise_sid = 0; + if (server_supports("shallow")) print_verbose(args, _("Server supports %s"), "shallow"); else if (args->depth > 0 || is_repository_shallow(r)) @@ -1191,6 +1197,8 @@ static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out, packet_buf_write(&req_buf, "command=fetch"); if (server_supports_v2("agent", 0)) packet_buf_write(&req_buf, "agent=%s", git_user_agent_sanitized()); + if (advertise_sid && server_supports_v2("session-id", 0)) + packet_buf_write(&req_buf, "session-id=%s", trace2_session_id()); if (args->server_options && args->server_options->nr && server_supports_v2("server-option", 1)) { int i; @@ -1711,6 +1719,7 @@ static void fetch_pack_config(void) git_config_get_bool("repack.usedeltabaseoffset", &prefer_ofs_delta); git_config_get_bool("fetch.fsckobjects", &fetch_fsck_objects); git_config_get_bool("transfer.fsckobjects", &transfer_fsck_objects); + git_config_get_bool("transfer.advertisesid", &advertise_sid); if (!uri_protocols.nr) { char *str; -- cgit v1.2.3 From 829594677c3cd02f7d88b3cd3c72ad06f68faa14 Mon Sep 17 00:00:00 2001 From: Josh Steadmon Date: Wed, 11 Nov 2020 15:29:32 -0800 Subject: 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 Signed-off-by: Junio C Hamano --- serve.c | 4 ++++ t/t5705-session-id-in-capabilities.sh | 18 ++++++++++++------ upload-pack.c | 8 ++++++++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/serve.c b/serve.c index 8c0bb84f37..eec2fe6f29 100644 --- a/serve.c +++ b/serve.c @@ -201,6 +201,7 @@ static int process_request(void) struct packet_reader reader; struct strvec keys = STRVEC_INIT; struct protocol_capability *command = NULL; + const char *client_sid; packet_reader_init(&reader, 0, NULL, 0, PACKET_READ_CHOMP_NEWLINE | @@ -264,6 +265,9 @@ static int process_request(void) check_algorithm(the_repository, &keys); + if (has_capability(&keys, "session-id", &client_sid)) + trace2_data_string("transfer", NULL, "client-sid", client_sid); + command->command(the_repository, &keys, &reader); strvec_clear(&keys); diff --git a/t/t5705-session-id-in-capabilities.sh b/t/t5705-session-id-in-capabilities.sh index 9e782f4413..afa2159657 100755 --- a/t/t5705-session-id-in-capabilities.sh +++ b/t/t5705-session-id-in-capabilities.sh @@ -17,11 +17,14 @@ test_expect_success 'setup repos for session ID capability tests' ' for PROTO in 0 1 2 do test_expect_success "session IDs not advertised by default (fetch v${PROTO})" ' - test_when_finished "rm -rf local tr2-client-events" && + test_when_finished "rm -rf local tr2-client-events tr2-server-events" && cp -r "$LOCAL_PRISTINE" local && GIT_TRACE2_EVENT="$(pwd)/tr2-client-events" \ - git -c protocol.version=$PROTO -C local fetch origin && - test -z "$(grep \"key\":\"server-sid\" tr2-client-events)" + git -c protocol.version=$PROTO -C local fetch \ + --upload-pack "GIT_TRACE2_EVENT=\"$(pwd)/tr2-server-events\" git-upload-pack" \ + origin && + test -z "$(grep \"key\":\"server-sid\" tr2-client-events)" && + test -z "$(grep \"key\":\"client-sid\" tr2-server-events)" ' test_expect_success "session IDs not advertised by default (push v${PROTO})" ' @@ -43,11 +46,14 @@ test_expect_success 'enable SID advertisement' ' for PROTO in 0 1 2 do test_expect_success "session IDs advertised (fetch v${PROTO})" ' - test_when_finished "rm -rf local tr2-client-events" && + test_when_finished "rm -rf local tr2-client-events tr2-server-events" && cp -r "$LOCAL_PRISTINE" local && GIT_TRACE2_EVENT="$(pwd)/tr2-client-events" \ - git -c protocol.version=$PROTO -C local fetch origin && - grep \"key\":\"server-sid\" tr2-client-events + git -c protocol.version=$PROTO -C local fetch \ + --upload-pack "GIT_TRACE2_EVENT=\"$(pwd)/tr2-server-events\" git-upload-pack" \ + origin && + grep \"key\":\"server-sid\" tr2-client-events && + grep \"key\":\"client-sid\" tr2-server-events ' test_expect_success "session IDs advertised (push v${PROTO})" ' diff --git a/upload-pack.c b/upload-pack.c index ebb4099268..dcd429dc01 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -1058,6 +1058,7 @@ static void receive_needs(struct upload_pack_data *data, const char *features; struct object_id oid_buf; const char *arg; + int feature_len; reset_timeout(data->timeout); if (packet_reader_read(reader) != PACKET_READ_NORMAL) @@ -1110,6 +1111,13 @@ static void receive_needs(struct upload_pack_data *data, parse_feature_request(features, "filter")) data->filter_capability_requested = 1; + arg = parse_feature_value(features, "session-id", &feature_len, NULL); + if (arg) { + char *client_sid = xstrndup(arg, feature_len); + trace2_data_string("transfer", NULL, "client-sid", client_sid); + free(client_sid); + } + o = parse_object(the_repository, &oid_buf); if (!o) { packet_writer_error(&data->writer, -- cgit v1.2.3 From 8c4870029dd084bc030e1b5383fa13358bcce236 Mon Sep 17 00:00:00 2001 From: Josh Steadmon Date: Wed, 11 Nov 2020 15:29:33 -0800 Subject: send-pack: advertise session ID in capabilities When the server sent a session-id capability and transfer.advertiseSID is true, advertise send-pack's own session ID back to the server. Signed-off-by: Josh Steadmon Signed-off-by: Junio C Hamano --- send-pack.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/send-pack.c b/send-pack.c index eb4a44270b..bda65c98f9 100644 --- a/send-pack.c +++ b/send-pack.c @@ -424,6 +424,7 @@ int send_pack(struct send_pack_args *args, int use_sideband = 0; int quiet_supported = 0; int agent_supported = 0; + int advertise_sid = 0; int use_atomic = 0; int atomic_supported = 0; int use_push_options = 0; @@ -435,6 +436,8 @@ int send_pack(struct send_pack_args *args, const char *push_cert_nonce = NULL; struct packet_reader reader; + git_config_get_bool("transfer.advertisesid", &advertise_sid); + /* Does the other end support the reporting? */ if (server_supports("report-status-v2")) status_report = 2; @@ -450,6 +453,8 @@ int send_pack(struct send_pack_args *args, quiet_supported = 1; if (server_supports("agent")) agent_supported = 1; + if (!server_supports("session-id")) + advertise_sid = 0; if (server_supports("no-thin")) args->use_thin_pack = 0; if (server_supports("atomic")) @@ -506,6 +511,8 @@ int send_pack(struct send_pack_args *args, strbuf_addf(&cap_buf, " object-format=%s", the_hash_algo->name); if (agent_supported) strbuf_addf(&cap_buf, " agent=%s", git_user_agent_sanitized()); + if (advertise_sid) + strbuf_addf(&cap_buf, " session-id=%s", trace2_session_id()); /* * NEEDSWORK: why does delete-refs have to be so specific to -- cgit v1.2.3 From a2a066d96aeaa13fe9124b84978d333243aa17c9 Mon Sep 17 00:00:00 2001 From: Josh Steadmon Date: Wed, 11 Nov 2020 15:29:34 -0800 Subject: receive-pack: log received client session ID When receive-pack receives a session-id capability from the client, log the received session ID via a trace2 data event. Signed-off-by: Josh Steadmon Signed-off-by: Junio C Hamano --- builtin/receive-pack.c | 7 +++++++ t/t5705-session-id-in-capabilities.sh | 20 ++++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 6ed498b6c7..deb5f859a9 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -2039,6 +2039,7 @@ static struct command *read_head_info(struct packet_reader *reader, if (linelen < reader->pktlen) { const char *feature_list = reader->line + linelen + 1; const char *hash = NULL; + const char *client_sid; int len = 0; if (parse_feature_request(feature_list, "report-status")) report_status = 1; @@ -2061,6 +2062,12 @@ static struct command *read_head_info(struct packet_reader *reader, } if (xstrncmpz(the_hash_algo->name, hash, len)) die("error: unsupported object format '%s'", hash); + client_sid = parse_feature_value(feature_list, "session-id", &len, NULL); + if (client_sid) { + char *sid = xstrndup(client_sid, len); + trace2_data_string("transfer", NULL, "client-sid", client_sid); + free(sid); + } } if (!strcmp(reader->line, "push-cert")) { diff --git a/t/t5705-session-id-in-capabilities.sh b/t/t5705-session-id-in-capabilities.sh index afa2159657..f1d189d5bc 100755 --- a/t/t5705-session-id-in-capabilities.sh +++ b/t/t5705-session-id-in-capabilities.sh @@ -28,13 +28,17 @@ do ' test_expect_success "session IDs not advertised by default (push v${PROTO})" ' - test_when_finished "rm -rf local tr2-client-events" && + test_when_finished "rm -rf local tr2-client-events tr2-server-events" && + test_when_finished "git -C local push --delete origin new-branch" && cp -r "$LOCAL_PRISTINE" local && git -C local pull --no-rebase origin && GIT_TRACE2_EVENT_NESTING=5 \ GIT_TRACE2_EVENT="$(pwd)/tr2-client-events" \ - git -c protocol.version=$PROTO -C local push origin && - test -z "$(grep \"key\":\"server-sid\" tr2-client-events)" + git -c protocol.version=$PROTO -C local push \ + --receive-pack "GIT_TRACE2_EVENT=\"$(pwd)/tr2-server-events\" git-receive-pack" \ + origin HEAD:new-branch && + test -z "$(grep \"key\":\"server-sid\" tr2-client-events)" && + test -z "$(grep \"key\":\"client-sid\" tr2-server-events)" ' done @@ -57,13 +61,17 @@ do ' test_expect_success "session IDs advertised (push v${PROTO})" ' - test_when_finished "rm -rf local tr2-client-events" && + test_when_finished "rm -rf local tr2-client-events tr2-server-events" && + test_when_finished "git -C local push --delete origin new-branch" && cp -r "$LOCAL_PRISTINE" local && git -C local pull --no-rebase origin && GIT_TRACE2_EVENT_NESTING=5 \ GIT_TRACE2_EVENT="$(pwd)/tr2-client-events" \ - git -c protocol.version=$PROTO -C local push origin && - grep \"key\":\"server-sid\" tr2-client-events + git -c protocol.version=$PROTO -C local push \ + --receive-pack "GIT_TRACE2_EVENT=\"$(pwd)/tr2-server-events\" git-receive-pack" \ + origin HEAD:new-branch && + grep \"key\":\"server-sid\" tr2-client-events && + grep \"key\":\"client-sid\" tr2-server-events ' done -- cgit v1.2.3