/// Read a message from the other end of the encrypted communication channel.
/// Will return on connection interruption. Note that this blocks (without timeout)
/// until the socket is closed.
Read a message from the other end of the encrypted communication channel.
Will return on connection interruption. Note that this blocks (without timeout)
until the socket is closed.
Read a message from the other end of the encrypted communication channel . Will return on connection interruption . Note that this blocks ( without timeout ) until the socket is closed .
pub fn read(&mut self) -> Result<Vec<u8>, Error> {
        let mut encrypted_msg = vec![0u8; NOISE_MESSAGE_MAX_SIZE];
        let mut bytes_read = 0;
        // Note that read_to_end() will read thousands of bytes for whatever reason
        // so we emulate it here.
        loop {
            match self.stream.read(&mut encrypted_msg) {
                Ok(0) => break,
                Ok(n) => {
                    bytes_read += n;
                    if bytes_read > NOISE_MESSAGE_MAX_SIZE {
                        // In this case no need to go further, they broke the protocol!
                        return Err(Error::Transport(format!("Noise message too big.")));
                    }
                }
                Err(e) => match e.kind() {
                    io::ErrorKind::Interrupted
                    | io::ErrorKind::ConnectionReset
                    | io::ErrorKind::ConnectionAborted
                    | io::ErrorKind::BrokenPipe => return Ok(vec![]),
                    // That's actually bad
                    _ => return Err(Error::Transport(format!("Reading from stream: '{}'", e))),
                },
            };
        }
        encrypted_msg.truncate(bytes_read);
        let encrypted_msg = NoiseEncryptedMessage(encrypted_msg);
        self.channel.decrypt_message(&encrypted_msg)
    }
pub fn read ( & mut self ) -> Result < Vec < u8 > , Error > { let mut encrypted_msg = vec ! [ 0u8 NOISE_MESSAGE_MAX_SIZE ] ; let mut bytes_read = 0 ; // Note that read_to_end() will read thousands of bytes for whatever reason // so we emulate it here. loop { match self . stream . read ( & mut encrypted_msg ) { Ok ( 0 ) => break , Ok ( n ) => { bytes_read += n ; if bytes_read > NOISE_MESSAGE_MAX_SIZE { // In this case no need to go further, they broke the protocol! return Err ( Error :: Transport ( format ! ( " " ) ) ) ; } } Err ( e ) => match e . kind ( ) { io :: ErrorKind :: Interrupted | io :: ErrorKind :: ConnectionReset | io :: ErrorKind :: ConnectionAborted | io :: ErrorKind :: BrokenPipe => return Ok ( vec ! [ ] ) , // That's actually bad _ => return Err ( Error :: Transport ( format ! ( " " e ) ) ) , } , } ; } encrypted_msg . truncate ( bytes_read ) ; let encrypted_msg = NoiseEncryptedMessage ( encrypted_msg ) ; self . channel . decrypt_message ( & encrypted_msg ) }
Read a message from the other end of the encrypted communication channel.
Read a message from the other end of the encrypted communication channel .
&mut self