zebra icon indicating copy to clipboard operation
zebra copied to clipboard

Return peer metadata from `connect_isolated` functions

Open teor2345 opened this issue 2 years ago • 1 comments

Motivation

We want to support development of an alternate DNS seeder based on zebra-network.

Requirements

There's some peer metadata which we need access to (from the connect_isolated-style functions) in order to reproduce the seeder filtering algorithms and I'm unsure how to make that happen:

  • The value of the PeerServices bitset
  • The numeric protocol version number (the stuff that looks like 170100)
  • The textual user-agent string (the stuff that looks like /MagicBean:5.0.0/)

I see there's a negotiate_version in handshake.rs that seems to do the version handshaking and it returns a tuple (remote_version, remote_services, remote_canonical_addr) (which is almost all we want, it's missing the text user-agent string).

The place where negotiate_version is called is impl<S, PeerTransport, C> Service<HandshakeRequest<PeerTransport>> for Handshake<S, C>; but I'm not sure how the latter gets called exactly, and it doesn't return/pass through the remote version/services info.

Originally posted by @superbaud in https://github.com/zcash/zcash/issues/3881#issuecomment-1162096689

teor2345 avatar Jun 22 '22 23:06 teor2345

Copied from https://github.com/zcash/zcash/issues/3881#issuecomment-1163762182

The current design is roughly:

  • AddrV1 and AddrV2 - serialized outbound connection address in addr and addr2 messages
  • MetaAddr - outbound peer connection addresses and last connection status, serialized from AddrV1 and AddrV2
  • LoadTrackedClient - contains current protocol version for an active inbound or outbound connection

So I think we might want to do something like:

  • split the Version out of LoadTrackedClient into a new PeerConnectionInfo struct
  • add whatever other fields we want
  • add PeerConnectionInfo to LoadTrackedClient and MetaAddr (as last_connection_info)
  • return LoadTrackedClient from connect_isolated* (and rename that struct to ConnectedClient)

teor2345 avatar Jun 22 '22 23:06 teor2345