fn on_handshake(&mut self, message: &[u8]) {
        let req: Result<SessionHandshake, bincode::Error> = common::deserialize_bincode(message);
        match req {
            Ok(handshake) => {
                info!("Got client version {}", handshake.version);
                let supported = VersionReq::parse(PROTOCOL_VERSION).unwrap();
                match Version::parse(&handshake.version) {
                    Ok(client) => {
                        if !supported.matches(&client) {
                            self.abort_connection(&format!(
                                "Unsupported protocol: {}",
                                handshake.version
                            ));
                            return;
                        }
                    }
                    Err(err) => {
                        self.abort_connection(&format!("Invalid protocol version: {:?}", err));
                    }
                }

                // In fake-tokens mode, add the presented token to the token manager.
                #[cfg(feature = "fake-tokens")]
                {
                    info!(
                        "Running in fake-tokens mode... handshake token is '{}'",
                        handshake.token
                    );
                    self.token_manager.lock().register(
                        &handshake.token,
                        OriginAttributes::new("fake-identity", HashSet::new()),
                    );
                }

                // Check that we are presented with a valid token, and store the identity if
                // this is the case.
                if let Some(attr) = self
                    .token_manager
                    .lock()
                    .get_origin_attributes(&handshake.token)
                {
                    self.origin_attributes = Some(attr);
                }

                if self.origin_attributes.is_none() {
                    self.abort_connection(&format!("Invalid token: {}", handshake.token));
                }

                // Everything is fine, send a success SessionAck.
                let resp = SessionAck { success: true };
                self.state = SessionState::Request;
                self.session_helper.send_message(&resp);
            }
            Err(err) => {
                // Unable to get handshake, close the connection.
                self.abort_connection(&format!("Error decoding handshake: {:?}", err));
            }
        }
    }
/// Receives and process a handshake message.
Receives and process a handshake message.
Receives and process a handshake message .
fn on_handshake(&mut self, message: &[u8]) {
        let req: Result<SessionHandshake, bincode::Error> = common::deserialize_bincode(message);
        match req {
            Ok(handshake) => {
                info!("Got client version {}", handshake.version);
                let supported = VersionReq::parse(PROTOCOL_VERSION).unwrap();
                match Version::parse(&handshake.version) {
                    Ok(client) => {
                        if !supported.matches(&client) {
                            self.abort_connection(&format!(
                                "Unsupported protocol: {}",
                                handshake.version
                            ));
                            return;
                        }
                    }
                    Err(err) => {
                        self.abort_connection(&format!("Invalid protocol version: {:?}", err));
                    }
                }
                // In fake-tokens mode, add the presented token to the token manager.
                #[cfg(feature = "fake-tokens")]
                {
                    info!(
                        "Running in fake-tokens mode... handshake token is '{}'",
                        handshake.token
                    );
                    self.token_manager.lock().register(
                        &handshake.token,
                        OriginAttributes::new("fake-identity", HashSet::new()),
                    );
                }
                // Check that we are presented with a valid token, and store the identity if
                // this is the case.
                if let Some(attr) = self
                    .token_manager
                    .lock()
                    .get_origin_attributes(&handshake.token)
                {
                    self.origin_attributes = Some(attr);
                }
                if self.origin_attributes.is_none() {
                    self.abort_connection(&format!("Invalid token: {}", handshake.token));
                }
                // Everything is fine, send a success SessionAck.
                let resp = SessionAck { success: true };
                self.state = SessionState::Request;
                self.session_helper.send_message(&resp);
            }
            Err(err) => {
                // Unable to get handshake, close the connection.
                self.abort_connection(&format!("Error decoding handshake: {:?}", err));
            }
        }
    }
fn on_handshake ( & mut self , message : & [ u8 ] ) { let req : Result < SessionHandshake , bincode :: Error > = common :: deserialize_bincode ( message ) ; match req { Ok ( handshake ) => { info ! ( " " handshake version ) ; let supported = VersionReq :: parse ( PROTOCOL_VERSION ) . unwrap ( ) ; match Version :: parse ( & handshake . version ) { Ok ( client ) => { if ! supported . matches ( & client ) { self . abort_connection ( & format ! ( " " handshake version ) ) ; return ; } } Err ( err ) => { self . abort_connection ( & format ! ( " " err ) ) ; } } // In fake-tokens mode, add the presented token to the token manager. # [ cfg ( feature " " ) ] { info ! ( " " handshake token ) ; self . token_manager . lock ( ) . register ( & handshake . token , OriginAttributes :: new ( " " , HashSet :: new ( ) ) , ) ; } // Check that we are presented with a valid token, and store the identity if // this is the case. if let Some ( attr ) = self . token_manager . lock ( ) . get_origin_attributes ( & handshake . token ) { self . origin_attributes = Some ( attr ) ; } if self . origin_attributes . is_none ( ) { self . abort_connection ( & format ! ( " " handshake token ) ) ; } // Everything is fine, send a success SessionAck. let resp = SessionAck { success : true } ; self . state = SessionState :: Request ; self . session_helper . send_message ( & resp ) ; } Err ( err ) => { // Unable to get handshake, close the connection. self . abort_connection ( & format ! ( " " err ) ) ; } } }
Receives and process a handshake message.
Receives and process a handshake message .
&mut self
message
&[u8]
&mut self
message
&[u8]