fn relay_loop(&self) -> Result<(), TransportErrorCode> {
        loop {
            if !self.active.load(Ordering::Relaxed) {
                info!(self.log, "Relay thread exiting");
                println!("Relay thread exiting (1)");
                return Ok(());
            }
            let msg;
            loop {
                let msg_res = self.receive();
                match msg_res {
                    Err(_e) => {
                        if !self.active.load(Ordering::Relaxed) {
                            // Channel is down, stop thread
                            info!(self.log, "Relay thread exiting");
                            return Ok(());
                        };
                    }
                    Ok(message) => {
                        msg = message;
                        break;
                    }
                };
            }

            if msg.flow_id.peer_id != self.prev {
                warn!(self.log, "relay(): unexpected flow id: {:?}", msg.flow_id);
                return Err(TransportErrorCode::FlowNotFound);
            }

            let flow_id = msg.flow_id;
            let msg_len = msg.payload.0.len();
            self.transport
                .send(self.client_type, &self.next, flow_id.flow_tag, msg.payload)
                .map_err(|e| {
                    warn!(
                        self.log,
                        "relay(): Failed to send(): peer = {:?}, flow = {:?}, err = {:?}",
                        self.next,
                        flow_id,
                        e
                    );
                    e
                })?;
            info!(
                self.log,
                "relay(): relayed from {:?} -> peer {:?}, msg_len = {}",
                flow_id,
                self.next,
                msg_len
            );
        }
    }
// Relay processing. Receives the messages and relays it to next peer.
Relay processing. Receives the messages and relays it to next peer.
Relay processing . Receives the messages and relays it to next peer .
fn relay_loop(&self) -> Result<(), TransportErrorCode> {
        loop {
            if !self.active.load(Ordering::Relaxed) {
                info!(self.log, "Relay thread exiting");
                println!("Relay thread exiting (1)");
                return Ok(());
            }
            let msg;
            loop {
                let msg_res = self.receive();
                match msg_res {
                    Err(_e) => {
                        if !self.active.load(Ordering::Relaxed) {
                            // Channel is down, stop thread
                            info!(self.log, "Relay thread exiting");
                            return Ok(());
                        };
                    }
                    Ok(message) => {
                        msg = message;
                        break;
                    }
                };
            }
            if msg.flow_id.peer_id != self.prev {
                warn!(self.log, "relay(): unexpected flow id: {:?}", msg.flow_id);
                return Err(TransportErrorCode::FlowNotFound);
            }
            let flow_id = msg.flow_id;
            let msg_len = msg.payload.0.len();
            self.transport
                .send(self.client_type, &self.next, flow_id.flow_tag, msg.payload)
                .map_err(|e| {
                    warn!(
                        self.log,
                        "relay(): Failed to send(): peer = {:?}, flow = {:?}, err = {:?}",
                        self.next,
                        flow_id,
                        e
                    );
                    e
                })?;
            info!(
                self.log,
                "relay(): relayed from {:?} -> peer {:?}, msg_len = {}",
                flow_id,
                self.next,
                msg_len
            );
        }
    }
fn relay_loop ( & self ) -> Result < ( ) , TransportErrorCode > { loop { if ! self . active . load ( Ordering :: Relaxed ) { info ! ( self log " " ) ; println ! ( " " ) ; return Ok ( ( ) ) ; } let msg ; loop { let msg_res = self . receive ( ) ; match msg_res { Err ( _e ) => { if ! self . active . load ( Ordering :: Relaxed ) { // Channel is down, stop thread info ! ( self log " " ) ; return Ok ( ( ) ) ; } ; } Ok ( message ) => { msg = message ; break ; } } ; } if msg . flow_id . peer_id != self . prev { warn ! ( self log " " msg flow_id ) ; return Err ( TransportErrorCode :: FlowNotFound ) ; } let flow_id = msg . flow_id ; let msg_len = msg . payload . 0 . len ( ) ; self . transport . send ( self . client_type , & self . next , flow_id . flow_tag , msg . payload ) . map_err ( | e | { warn ! ( self log " " self next flow_id e ) ; e } ) ? ; info ! ( self log " " flow_id self next msg_len ) ; } }
Relay processing.
Relay processing .
&self
&self