// More expressive send helper,  Allows to explicitly specify send and receive
// node ids
More expressive send helper,  Allows to explicitly specify send and receive
node ids
More expressive send helper Allows to explicitly specify send and receive node ids
async fn send_helper(
        &self,
        client_type: TransportClientType,
        src_node_id: NodeId,
        dest_node_id: NodeId,
        message: TransportPayload,
    ) -> Result<(), TransportErrorCode> {
        // Dispatch  or defer send a message to a node.
        // Dispatch happens only if all 3 conditions are met
        //.
        // 1. Destination  node has installed a port. i.e. destination node has created
        // Thread port.
        //
        // 2. Destination port has registered the client event handler.
        //
        // 3. Destination node has called start connections.
        //
        // For any other case the message processing deferred until
        // the conditions are met.
        // 1.
        let destination_node = {
            let hub_access = self.hub_access.lock().unwrap();
            // All node ports must be connected  to hub before test start.
            hub_access.ports[&dest_node_id].clone()
        };
        // 2.
        let event_handler = {
            let client_map = destination_node.client_map.write().unwrap();
            client_map
                .get(&client_type)
                .map(|s| s.event_handler.clone())
        };
        // 3.
        let event_handler = {
            let mut deferred = destination_node.deferred.lock().unwrap();
            let deferred = deferred.entry(src_node_id).or_default();
            // Stash
            if !deferred.started || event_handler.is_none() {
                println!(
                    "Node {} has no client of type {:?} registered",
                    destination_node.id, client_type
                );
                deferred.stash.push((client_type, message));
                return Ok(());
            } else {
                event_handler.unwrap()
            }
        };
        event_handler
            .send_message(
                FlowId {
                    client_type,
                    peer_id: src_node_id,
                    flow_tag: FlowTag::from(0),
                },
                message,
            )
            .await
            .expect("send message failed");
        Ok(())
    }
async fn send_helper ( & self , client_type : TransportClientType , src_node_id : NodeId , dest_node_id : NodeId , message : TransportPayload , ) -> Result < ( ) , TransportErrorCode > { // Dispatch  or defer send a message to a node. // Dispatch happens only if all 3 conditions are met //. // 1. Destination  node has installed a port. i.e. destination node has created // Thread port. // // 2. Destination port has registered the client event handler. // // 3. Destination node has called start connections. // // For any other case the message processing deferred until // the conditions are met. // 1. let destination_node = { let hub_access = self . hub_access . lock ( ) . unwrap ( ) ; // All node ports must be connected  to hub before test start. hub_access . ports [ & dest_node_id ] . clone ( ) } ; // 2. let event_handler = { let client_map = destination_node . client_map . write ( ) . unwrap ( ) ; client_map . get ( & client_type ) . map ( | s | s . event_handler . clone ( ) ) } ; // 3. let event_handler = { let mut deferred = destination_node . deferred . lock ( ) . unwrap ( ) ; let deferred = deferred . entry ( src_node_id ) . or_default ( ) ; // Stash if ! deferred . started || event_handler . is_none ( ) { println ! ( " " destination_node id client_type ) ; deferred . stash . push ( ( client_type , message ) ) ; return Ok ( ( ) ) ; } else { event_handler . unwrap ( ) } } ; event_handler . send_message ( FlowId { client_type , peer_id : src_node_id , flow_tag : FlowTag :: from ( 0 ) , } , message , ) . await . expect ( " " ) ; Ok ( ( ) ) }
More expressive send helper,  Allows to explicitly specify send and receive
node ids
More expressive send helper Allows to explicitly specify send and receive node ids
&self
client_type
TransportClientType
src_node_id
NodeId
dest_node_id
NodeId
message
TransportPayload