aboutsummaryrefslogtreecommitdiff
path: root/src/peering/fullmesh.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2021-10-15 15:34:03 +0200
committerAlex Auvolat <alex@adnab.me>2021-10-15 15:34:03 +0200
commitdfb0ebb8e18e15465b07f864cfcf9169c0c0801f (patch)
tree125a27108ba7138d242869a8c9a9f64b77bb85be /src/peering/fullmesh.rs
parent48d6a72ebd39c0d80e9fd794b55825da1d776420 (diff)
downloadnetapp-dfb0ebb8e18e15465b07f864cfcf9169c0c0801f.tar.gz
netapp-dfb0ebb8e18e15465b07f864cfcf9169c0c0801f.zip
Full mesh peering strategy uses our local address if necessary
Diffstat (limited to 'src/peering/fullmesh.rs')
-rw-r--r--src/peering/fullmesh.rs20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/peering/fullmesh.rs b/src/peering/fullmesh.rs
index 5f17718..22657dd 100644
--- a/src/peering/fullmesh.rs
+++ b/src/peering/fullmesh.rs
@@ -163,7 +163,11 @@ impl FullMeshPeeringStrategy {
/// The strategy will not be run until `.run()` is called and awaited.
/// Once that happens, the peering strategy will try to connect
/// to all of the nodes specified in the bootstrap list.
- pub fn new(netapp: Arc<NetApp>, bootstrap_list: Vec<(NodeID, SocketAddr)>) -> Arc<Self> {
+ pub fn new(
+ netapp: Arc<NetApp>,
+ bootstrap_list: Vec<(NodeID, SocketAddr)>,
+ our_addr: Option<SocketAddr>,
+ ) -> Arc<Self> {
let mut known_hosts = KnownHosts::new();
for (id, addr) in bootstrap_list {
if id != netapp.id {
@@ -179,6 +183,18 @@ impl FullMeshPeeringStrategy {
}
}
+ if let Some(addr) = our_addr {
+ known_hosts.list.insert(
+ netapp.id,
+ PeerInfoInternal {
+ addr,
+ state: PeerConnState::Ourself,
+ last_seen: None,
+ ping: VecDeque::new(),
+ },
+ );
+ }
+
let strat = Arc::new(Self {
netapp: netapp.clone(),
known_hosts: RwLock::new(known_hosts),
@@ -188,6 +204,8 @@ impl FullMeshPeeringStrategy {
peer_list_endpoint: netapp.endpoint("__netapp/peering/fullmesh.rs/PeerList".into()),
});
+ strat.update_public_peer_list(&strat.known_hosts.read().unwrap());
+
strat.ping_endpoint.set_handler(strat.clone());
strat.peer_list_endpoint.set_handler(strat.clone());