network: remove handshake::Builder::with_addr
Use the listen_addr field already specified in the config. Also, derive Clone for Handshake<S>. Co-authored-by: Jane Lusby <jane@zfnd.org>
This commit is contained in:
parent
a5b6f39850
commit
fddba7a336
|
@ -34,39 +34,21 @@ use super::{Client, Connection, ErrorSlot, HandshakeError};
|
||||||
|
|
||||||
/// A [`Service`] that handshakes with a remote peer and constructs a
|
/// A [`Service`] that handshakes with a remote peer and constructs a
|
||||||
/// client/server pair.
|
/// client/server pair.
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct Handshake<S> {
|
pub struct Handshake<S> {
|
||||||
config: Config,
|
config: Config,
|
||||||
inbound_service: S,
|
inbound_service: S,
|
||||||
timestamp_collector: mpsc::Sender<MetaAddr>,
|
timestamp_collector: mpsc::Sender<MetaAddr>,
|
||||||
nonces: Arc<Mutex<HashSet<Nonce>>>,
|
nonces: Arc<Mutex<HashSet<Nonce>>>,
|
||||||
our_addr: SocketAddr,
|
|
||||||
user_agent: String,
|
user_agent: String,
|
||||||
our_services: PeerServices,
|
our_services: PeerServices,
|
||||||
relay: bool,
|
relay: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is manually implemented because we can't pass an
|
|
||||||
// S: Clone bound to #[derive(Clone)].
|
|
||||||
impl<S: Clone> Clone for Handshake<S> {
|
|
||||||
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<S> {
|
pub struct Builder<S> {
|
||||||
config: Option<Config>,
|
config: Option<Config>,
|
||||||
inbound_service: Option<S>,
|
inbound_service: Option<S>,
|
||||||
timestamp_collector: Option<mpsc::Sender<MetaAddr>>,
|
timestamp_collector: Option<mpsc::Sender<MetaAddr>>,
|
||||||
our_addr: Option<SocketAddr>,
|
|
||||||
our_services: Option<PeerServices>,
|
our_services: Option<PeerServices>,
|
||||||
user_agent: Option<String>,
|
user_agent: Option<String>,
|
||||||
relay: Option<bool>,
|
relay: Option<bool>,
|
||||||
|
@ -97,14 +79,6 @@ where
|
||||||
self
|
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.
|
/// Provide the services this node advertises to other peers. Optional.
|
||||||
///
|
///
|
||||||
/// If this is unset, the node will advertise itself as a client.
|
/// 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 nonces = Arc::new(Mutex::new(HashSet::new()));
|
||||||
let user_agent = self.user_agent.unwrap_or_else(|| "".to_string());
|
let user_agent = self.user_agent.unwrap_or_else(|| "".to_string());
|
||||||
let our_addr = self
|
let our_services = self.our_services.unwrap_or_else(PeerServices::empty);
|
||||||
.our_addr
|
|
||||||
.unwrap_or_else(|| "0.0.0.0:8233".parse().unwrap());
|
|
||||||
let our_services = self.our_services.unwrap_or(PeerServices::empty());
|
|
||||||
let relay = self.relay.unwrap_or(false);
|
let relay = self.relay.unwrap_or(false);
|
||||||
Ok(Handshake {
|
Ok(Handshake {
|
||||||
config,
|
config,
|
||||||
|
@ -156,7 +127,6 @@ where
|
||||||
timestamp_collector,
|
timestamp_collector,
|
||||||
nonces,
|
nonces,
|
||||||
user_agent,
|
user_agent,
|
||||||
our_addr,
|
|
||||||
our_services,
|
our_services,
|
||||||
relay,
|
relay,
|
||||||
})
|
})
|
||||||
|
@ -176,7 +146,6 @@ where
|
||||||
inbound_service: None,
|
inbound_service: None,
|
||||||
timestamp_collector: None,
|
timestamp_collector: None,
|
||||||
user_agent: None,
|
user_agent: None,
|
||||||
our_addr: None,
|
|
||||||
our_services: None,
|
our_services: None,
|
||||||
relay: None,
|
relay: None,
|
||||||
}
|
}
|
||||||
|
@ -211,7 +180,7 @@ where
|
||||||
let inbound_service = self.inbound_service.clone();
|
let inbound_service = self.inbound_service.clone();
|
||||||
let timestamp_collector = self.timestamp_collector.clone();
|
let timestamp_collector = self.timestamp_collector.clone();
|
||||||
let network = self.config.network;
|
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 user_agent = self.user_agent.clone();
|
||||||
let our_services = self.our_services;
|
let our_services = self.our_services;
|
||||||
let relay = self.relay;
|
let relay = self.relay;
|
||||||
|
|
|
@ -62,7 +62,6 @@ where
|
||||||
.with_config(config.clone())
|
.with_config(config.clone())
|
||||||
.with_inbound_service(inbound_service)
|
.with_inbound_service(inbound_service)
|
||||||
.with_timestamp_collector(timestamp_collector)
|
.with_timestamp_collector(timestamp_collector)
|
||||||
// XXX .with_addr(addr) once we can access our configured address
|
|
||||||
.with_advertised_services(PeerServices::NODE_NETWORK)
|
.with_advertised_services(PeerServices::NODE_NETWORK)
|
||||||
.with_user_agent(crate::constants::USER_AGENT.to_string())
|
.with_user_agent(crate::constants::USER_AGENT.to_string())
|
||||||
.want_transactions(true)
|
.want_transactions(true)
|
||||||
|
|
Loading…
Reference in New Issue