Function connect

Source
pub async fn connect<A: ToSocketAddrs>(
    address: A,
    network: Network,
    allow_v1_fallback: bool,
) -> Result<(ReadTransport<BufReader<ReadHalf<TcpStream>>>, WriteTransport<WriteHalf<TcpStream>>, TransportProtocol), TransportError>
Expand description

Establishes a TCP connection and negotiates the bitcoin protocol.

This function tries to connect to the specified address and negotiate the bitcoin protocol with the remote node. It first attempts to use the V2 protocol, and if that fails with a specific error suggesting fallback to V1 protocol (and allow_v1_fallback is true), it will retry the connection with the V1 protocol.

§Arguments

  • address - The address of a target node
  • network - The bitcoin network
  • allow_v1_fallback - Whether to allow fallback to V1 protocol if V2 negotiation fails

§Returns

Returns a tuple of read and write transports that can be used to communicate with the node.

§Errors

Returns a TransportError if the connection cannot be established or protocol negotiation fails.