git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] connect, protocol: log negotiated protocol version

From
Taylor Blau <me@ttaylorr.com>
Date
Aug 3, 2021, 21:12 UTC
Message-ID
<YQmxSxTswHE/gTet@nand.local>
In-Reply-To
<f79ab95af6da3da710da2112cfcae4a042b7f7fb.1628020616.git.steadmon@google.com>
On Tue, Aug 03, 2021 at 01:13:02PM -0700, Josh Steadmon wrote:
> [...] Therefore, log the negotiated wire protocol version via trace2,
> for both clients and servers.
Seems useful, thanks.
> Do people have a preference for logging this as an integer (and
> therefore having "unknown protocol version" show up as "-1", or should I
> add a protocol_version_to_string function so that we can format it
> properly? For now I've erred on the side of having a smaller diff.

I probably have a slight preference for converting the protocol_version to a string and passing that along to trace2_data_string() instead. That would let you more cleanly log "<unknown>", without needing to expose implementation details like which enum has what value.

Show 9 quoted lines
> diff --git a/connect.c b/connect.c
> index 70b13389ba..6e23e3ff2d 100644
> --- a/connect.c
> +++ b/connect.c
> @@ -164,6 +164,7 @@ enum protocol_version discover_version(struct packet_reader *reader)
>  		BUG("unknown protocol version");
>  	}
>
> +	trace2_data_intmax("transfer", NULL, "negotiated-version", version);

Small nit-pick, this could come between the two switch statements, not at the end of the function (since we know what we are going to return before we switch on version.

(I was a little surprised to see that these functions now have the side-effect of writing to trace2, since I would have instead expected to see new lines added at the callers. But this makes it more convenient, and I do not feel strongly about it)

In any case, connect.c:discover_version() is handling the client side, but...

Show 12 quoted lines
> diff --git a/protocol.c b/protocol.c
> index 052d7edbb9..3791d8499e 100644
> --- a/protocol.c
> +++ b/protocol.c
> @@ -89,5 +89,6 @@ enum protocol_version determine_protocol_version_client(const char *server_respo
>  			die("protocol error: server explicitly said version 0");
>  	}
>
> +	trace2_data_intmax("transfer", NULL, "negotiated-version", version);
>  	return version;
>  }
> --

This function is used by discover_version to parse the server's response. If you are trying to log what protocol was agreed on from the server's perspective, I think you are looking instead for determine_protocol_version_server().

If you aren't (and are only interested in the client's point-of-view), then I am pretty sure that this latter hunk is redundant.

Thanks, Taylor

Previous: Josh SteadmonNext: Josh Steadmon
Message 2 of 16 in “connect, protocol: log negotiated protocol version”
  1. connect, protocol: log negotiated protocol versionJosh Steadmon, Aug 3, 2021
  2. Taylor BlauAug 3, 2021
  3. Josh SteadmonAug 4, 2021
  4. Junio C HamanoAug 4, 2021
  5. 0/2 log negotiated protocol version.Josh Steadmon, Aug 4, 2021
  6. 1/2 protocol: add protocol version formatting functionJosh Steadmon, Aug 4, 2021
  7. Ævar Arnfjörð BjarmasonAug 4, 2021
  8. 2/2 connect, protocol: log negotiated protocol versionJosh Steadmon, Aug 4, 2021
  9. Eric SunshineAug 4, 2021
  10. Josh SteadmonAug 6, 2021
  11. Ævar Arnfjörð BjarmasonAug 4, 2021
  12. Taylor BlauAug 5, 2021
  13. Ævar Arnfjörð BjarmasonAug 5, 2021
  14. Josh SteadmonAug 6, 2021
  15. connect, protocol: log negotiated protocol versionJosh Steadmon, Aug 10, 2021
  16. Taylor BlauAug 16, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.