From faa2e07555ce3bcd6c897b0d41fcf194cdcc67a8 Mon Sep 17 00:00:00 2001 From: axb-topos Date: Wed, 10 Aug 2022 17:44:27 +0300 Subject: [PATCH] chore: code-review fixes from PR #8 --- node/net/src/discovery_behavior.rs | 7 +++++-- node/net/src/lib.rs | 15 --------------- node/net/src/transmission_behavior.rs | 8 ++++---- 3 files changed, 9 insertions(+), 21 deletions(-) diff --git a/node/net/src/discovery_behavior.rs b/node/net/src/discovery_behavior.rs index be4b65292..a54f09be4 100644 --- a/node/net/src/discovery_behavior.rs +++ b/node/net/src/discovery_behavior.rs @@ -36,6 +36,9 @@ pub(crate) struct DiscoveryBehavior { routable_peers: HashSet, } +const TCE_TRANSMISSION_PROTOCOL: &str = "/trbp-transmission/1"; +const TCE_DISCOVERY_PROTOCOL: &str = "/tce-disco/1"; + impl DiscoveryBehavior { pub(crate) fn new( local_key: Keypair, @@ -46,13 +49,13 @@ impl DiscoveryBehavior { // identify let ident_config = - IdentifyConfig::new("/trbp-transmission/1".to_string(), local_key.public()) + IdentifyConfig::new(TCE_TRANSMISSION_PROTOCOL.to_string(), local_key.public()) .with_push_listen_addr_updates(true); let ident = Identify::new(ident_config); // kademlia let kad_config = KademliaConfig::default() - .set_protocol_name("/tce-disco/1".as_bytes()) + .set_protocol_name(TCE_DISCOVERY_PROTOCOL.as_bytes()) .set_replication_interval(Some(Duration::from_secs(30))) .set_publication_interval(Some(Duration::from_secs(30))) .set_provider_publication_interval(Some(Duration::from_secs(30))) diff --git a/node/net/src/lib.rs b/node/net/src/lib.rs index a83fc44dd..d27e25f6f 100644 --- a/node/net/src/lib.rs +++ b/node/net/src/lib.rs @@ -103,21 +103,6 @@ impl NetworkWorker { // Listen on all interfaces and whatever port the OS assigns swarm.listen_on(local_listen_addr).expect("Bind port"); - // gossip launch - // for known_peer in config.known_peers.clone() { - // log::info!( - // "---- adding gossip peer:{} at {}", - // &known_peer.0, - // &known_peer.1 - // ); - // - // // we need to dial peer so that gossipsub would be aware of it - // match swarm.dial(known_peer.1.clone()) { - // Ok(_) => log::debug!("Dialed {:?}", &known_peer.1), - // Err(e) => log::debug!("Dial {:?} failed: {:?}", &known_peer.1, e), - // } - // } - // networking loop loop { tokio::select! { diff --git a/node/net/src/transmission_behavior.rs b/node/net/src/transmission_behavior.rs index d8ebe078b..08728b6c4 100644 --- a/node/net/src/transmission_behavior.rs +++ b/node/net/src/transmission_behavior.rs @@ -28,7 +28,7 @@ use tokio::{ #[derive(NetworkBehaviour)] #[behaviour(event_process = true)] pub(crate) struct TransmissionBehavior { - pub rr: RequestResponse, + pub req_resp_protocol: RequestResponse, #[behaviour(ignore)] pub tx_events: mpsc::UnboundedSender, #[behaviour(ignore)] @@ -39,7 +39,7 @@ impl TransmissionBehavior { /// Factory pub(crate) fn new(events_sender: mpsc::UnboundedSender) -> Self { Self { - rr: RequestResponse::new( + req_resp_protocol: RequestResponse::new( TransmissionCodec(), iter::once((TransmissionProtocol(), ProtocolSupport::Full)), Default::default(), @@ -56,7 +56,7 @@ impl TransmissionBehavior { for peer_id in to { // publish let req_id = self - .rr + .req_resp_protocol .send_request(&peer_id, TransmissionRequest(data.clone())); // remember each (req_id) self.req_ids_to_ext_ids.insert(req_id); @@ -78,7 +78,7 @@ impl TransmissionBehavior { data: req_payload.0, })?; // send the response back, error handled in other event handling branches - self.rr + self.req_resp_protocol .send_response(resp_chan, TransmissionResponse(vec![]))?; Ok(()) }