From fddba7a33665f1cff28601b692dcf04d9785055d Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Tue, 1 Sep 2020 12:37:44 -0700 Subject: [PATCH] network: remove handshake::Builder::with_addr Use the listen_addr field already specified in the config. Also, derive Clone for Handshake. Co-authored-by: Jane Lusby --- zebra-network/src/peer/handshake.rs | 37 ++---------------------- zebra-network/src/peer_set/initialize.rs | 1 - 2 files changed, 3 insertions(+), 35 deletions(-) diff --git a/zebra-network/src/peer/handshake.rs b/zebra-network/src/peer/handshake.rs index 9a1f1b5fd..41b9a6757 100644 --- a/zebra-network/src/peer/handshake.rs +++ b/zebra-network/src/peer/handshake.rs @@ -34,39 +34,21 @@ use super::{Client, Connection, ErrorSlot, HandshakeError}; /// A [`Service`] that handshakes with a remote peer and constructs a /// client/server pair. +#[derive(Clone)] pub struct Handshake { config: Config, inbound_service: S, timestamp_collector: mpsc::Sender, nonces: Arc>>, - our_addr: SocketAddr, user_agent: String, our_services: PeerServices, relay: bool, } -// This is manually implemented because we can't pass an -// S: Clone bound to #[derive(Clone)]. -impl Clone for Handshake { - fn clone(&self) -> Self { - Handshake { - config: self.config.clone(), - inbound_service: self.inbound_service.clone(), - timestamp_collector: self.timestamp_collector.clone(), - nonces: self.nonces.clone(), - our_addr: self.our_addr.clone(), - user_agent: self.user_agent.clone(), - our_services: self.our_services.clone(), - relay: self.relay.clone(), - } - } -} - pub struct Builder { config: Option, inbound_service: Option, timestamp_collector: Option>, - our_addr: Option, our_services: Option, user_agent: Option, relay: Option, @@ -97,14 +79,6 @@ where self } - /// Provide this node's address, to send to peers. Optional. - /// - /// If this is unset, the default of 0.0.0.0:8233 will be used. - pub fn with_addr(mut self, addr: SocketAddr) -> Self { - self.our_addr = Some(addr); - self - } - /// Provide the services this node advertises to other peers. Optional. /// /// If this is unset, the node will advertise itself as a client. @@ -145,10 +119,7 @@ where }); let nonces = Arc::new(Mutex::new(HashSet::new())); let user_agent = self.user_agent.unwrap_or_else(|| "".to_string()); - let our_addr = self - .our_addr - .unwrap_or_else(|| "0.0.0.0:8233".parse().unwrap()); - let our_services = self.our_services.unwrap_or(PeerServices::empty()); + let our_services = self.our_services.unwrap_or_else(PeerServices::empty); let relay = self.relay.unwrap_or(false); Ok(Handshake { config, @@ -156,7 +127,6 @@ where timestamp_collector, nonces, user_agent, - our_addr, our_services, relay, }) @@ -176,7 +146,6 @@ where inbound_service: None, timestamp_collector: None, user_agent: None, - our_addr: None, our_services: None, relay: None, } @@ -211,7 +180,7 @@ where let inbound_service = self.inbound_service.clone(); let timestamp_collector = self.timestamp_collector.clone(); let network = self.config.network; - let our_addr = self.our_addr.clone(); + let our_addr = self.config.listen_addr; let user_agent = self.user_agent.clone(); let our_services = self.our_services; let relay = self.relay; diff --git a/zebra-network/src/peer_set/initialize.rs b/zebra-network/src/peer_set/initialize.rs index 3666a9594..4980153b8 100644 --- a/zebra-network/src/peer_set/initialize.rs +++ b/zebra-network/src/peer_set/initialize.rs @@ -62,7 +62,6 @@ where .with_config(config.clone()) .with_inbound_service(inbound_service) .with_timestamp_collector(timestamp_collector) - // XXX .with_addr(addr) once we can access our configured address .with_advertised_services(PeerServices::NODE_NETWORK) .with_user_agent(crate::constants::USER_AGENT.to_string()) .want_transactions(true)