From dfb0ebb8e18e15465b07f864cfcf9169c0c0801f Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Fri, 15 Oct 2021 15:34:03 +0200 Subject: Full mesh peering strategy uses our local address if necessary --- src/peering/fullmesh.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/peering/fullmesh.rs') 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, bootstrap_list: Vec<(NodeID, SocketAddr)>) -> Arc { + pub fn new( + netapp: Arc, + bootstrap_list: Vec<(NodeID, SocketAddr)>, + our_addr: Option, + ) -> Arc { 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()); -- cgit v1.2.3