/// Accept an incoming connection and immediately perform the noise KK handshake
/// as a responder with our single private key and a set of possible public key for them.
/// This is used by servers to identify the origin of the message.
Accept an incoming connection and immediately perform the noise KK handshake
as a responder with our single private key and a set of possible public key for them.
This is used by servers to identify the origin of the message.
Accept an incoming connection and immediately perform the noise KK handshake as a responder with our single private key and a set of possible public key for them . This is used by servers to identify the origin of the message .
pub fn accept(
        listener: &TcpListener,
        my_noise_privkey: &NoisePrivKey,
        their_possible_pubkeys: &[NoisePubKey],
    ) -> Result<KKTransport, Error> {
        let (mut stream, _) = listener
            .accept()
            .map_err(|e| Error::Transport(format!("TCP accept failed: {:?}", e)))?;
        // read msg_1 from stream
        let mut msg_1 = [0u8; KK_MSG_1_SIZE];
        // FIXME: timeout?
        stream.read_exact(&mut msg_1).map_err(|e| {
            Error::Transport(format!("Failed to read message 1 from TcpStream: {:?}", e))
        })?;
        let msg_act_1 = KKMessageActOne(msg_1);
        let serv_act_1 =
            KKHandshakeActOne::responder(&my_noise_privkey, their_possible_pubkeys, &msg_act_1)
                .map_err(|e| Error::Noise(format!("Failed to respond in act 1: {:?}", e)))?;
        let (serv_act_2, msg_2) = KKHandshakeActTwo::responder(serv_act_1)
            .map_err(|e| Error::Noise(format!("Failed to respond in act 2: {:?}", e)))?;
        let channel = KKChannel::from_handshake(serv_act_2)
            .map_err(|e| Error::Noise(format!("Failed to construct KXChannel: {:?}", e)))?;
        // write msg_2 to stream
        stream.write_all(&msg_2.0).map_err(|e| {
            Error::Transport(format!("Failed to write message 2 to TcpStream: {:?}", e))
        })?;
        Ok(KKTransport { stream, channel })
    }
pub fn accept ( listener : & TcpListener , my_noise_privkey : & NoisePrivKey , their_possible_pubkeys : & [ NoisePubKey ] , ) -> Result < KKTransport , Error > { let ( mut stream , _ ) = listener . accept ( ) . map_err ( | e | Error :: Transport ( format ! ( " " e ) ) ) ? ; // read msg_1 from stream let mut msg_1 = [ 0u8 ; KK_MSG_1_SIZE ] ; // FIXME: timeout? stream . read_exact ( & mut msg_1 ) . map_err ( | e | { Error :: Transport ( format ! ( " " e ) ) } ) ? ; let msg_act_1 = KKMessageActOne ( msg_1 ) ; let serv_act_1 = KKHandshakeActOne :: responder ( & my_noise_privkey , their_possible_pubkeys , & msg_act_1 ) . map_err ( | e | Error :: Noise ( format ! ( " " e ) ) ) ? ; let ( serv_act_2 , msg_2 ) = KKHandshakeActTwo :: responder ( serv_act_1 ) . map_err ( | e | Error :: Noise ( format ! ( " " e ) ) ) ? ; let channel = KKChannel :: from_handshake ( serv_act_2 ) . map_err ( | e | Error :: Noise ( format ! ( " " e ) ) ) ? ; // write msg_2 to stream stream . write_all ( & msg_2 . 0 ) . map_err ( | e | { Error :: Transport ( format ! ( " " e ) ) } ) ? ; Ok ( KKTransport { stream , channel } ) }
Accept an incoming connection and immediately perform the noise KK handshake
as a responder with our single private key and a set of possible public key for them.
Accept an incoming connection and immediately perform the noise KK handshake as a responder with our single private key and a set of possible public key for them .
listener
&TcpListener
my_noise_privkey
&NoisePrivKey
their_possible_pubkeys
&[NoisePubKey]