/// Connect to server at given address, and enact Noise handshake with given private key.
Connect to server at given address, and enact Noise handshake with given private key.
Connect to server at given address and enact Noise handshake with given private key .
pub fn connect<A: ToSocketAddrs>(
        addr: A,
        my_noise_privkey: NoisePrivKey,
        their_noise_pubkey: NoisePubKey,
    ) -> Result<KKTransport, Error> {
        let mut stream = TcpStream::connect(addr)
            .map_err(|e| Error::Transport(format!("TCP connection failed: {:?}", e)))?;
        let (cli_act_1, msg_1) =
            KKHandshakeActOne::initiator(&my_noise_privkey, &their_noise_pubkey)
                .map_err(|e| Error::Noise(format!("Failed to initiate act 1: {:?}", e)))?;
        // write msg_1 to stream (e, es, ss)
        stream.write_all(&msg_1.0).map_err(|e| {
            Error::Transport(format!("Failed to write message 1 to TcpStream: {:?}", e))
        })?;
        // read msg_2 from stream (e, ee, se)
        let mut msg_2 = [0u8; KK_MSG_2_SIZE];
        stream.read_exact(&mut msg_2).map_err(|e| {
            Error::Transport(format!("Failed to read message 2 from TcpStream: {:?}", e))
        })?;
        let msg_act_2 = KKMessageActTwo(msg_2);
        let cli_act_2 = KKHandshakeActTwo::initiator(cli_act_1, &msg_act_2)
            .map_err(|e| Error::Noise(format!("Failed to initiate act 2: {:?}", e)))?;
        let channel = KKChannel::from_handshake(cli_act_2)
            .map_err(|e| Error::Noise(format!("Failed to construct KKChannel: {:?}", e)))?;
        Ok(KKTransport { stream, channel })
    }
pub fn connect < A : ToSocketAddrs > ( addr : A , my_noise_privkey : NoisePrivKey , their_noise_pubkey : NoisePubKey , ) -> Result < KKTransport , Error > { let mut stream = TcpStream :: connect ( addr ) . map_err ( | e | Error :: Transport ( format ! ( " " e ) ) ) ? ; let ( cli_act_1 , msg_1 ) = KKHandshakeActOne :: initiator ( & my_noise_privkey , & their_noise_pubkey ) . map_err ( | e | Error :: Noise ( format ! ( " " e ) ) ) ? ; // write msg_1 to stream (e, es, ss) stream . write_all ( & msg_1 . 0 ) . map_err ( | e | { Error :: Transport ( format ! ( " " e ) ) } ) ? ; // read msg_2 from stream (e, ee, se) let mut msg_2 = [ 0u8 ; KK_MSG_2_SIZE ] ; stream . read_exact ( & mut msg_2 ) . map_err ( | e | { Error :: Transport ( format ! ( " " e ) ) } ) ? ; let msg_act_2 = KKMessageActTwo ( msg_2 ) ; let cli_act_2 = KKHandshakeActTwo :: initiator ( cli_act_1 , & msg_act_2 ) . map_err ( | e | Error :: Noise ( format ! ( " " e ) ) ) ? ; let channel = KKChannel :: from_handshake ( cli_act_2 ) . map_err ( | e | Error :: Noise ( format ! ( " " e ) ) ) ? ; Ok ( KKTransport { stream , channel } ) }
Connect to server at given address, and enact Noise handshake with given private key.
Connect to server at given address and enact Noise handshake with given private key .
addr
A
my_noise_privkey
NoisePrivKey
their_noise_pubkey
NoisePubKey