Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Fixed node address detection on incoming connection (#6094)
Browse files Browse the repository at this point in the history
  • Loading branch information
arkpar authored Jul 19, 2017
1 parent 2f06653 commit 2d7aecf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
15 changes: 10 additions & 5 deletions util/network/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -857,11 +857,16 @@ impl Host {
// Add it to the node table
if !s.info.originated {
if let Ok(address) = s.remote_addr() {
let entry = NodeEntry { id: id, endpoint: NodeEndpoint { address: address, udp_port: address.port() } };
self.nodes.write().add_node(Node::new(entry.id.clone(), entry.endpoint.clone()));
let mut discovery = self.discovery.lock();
if let Some(ref mut discovery) = *discovery {
discovery.add_node(entry);
// We can't know remote listening ports, so just assume defaults and hope for the best.
let endpoint = NodeEndpoint { address: SocketAddr::new(address.ip(), DEFAULT_PORT), udp_port: DEFAULT_PORT };
let entry = NodeEntry { id: id, endpoint: endpoint };
let mut nodes = self.nodes.write();
if !nodes.contains(&entry.id) {
nodes.add_node(Node::new(entry.id.clone(), entry.endpoint.clone()));
let mut discovery = self.discovery.lock();
if let Some(ref mut discovery) = *discovery {
discovery.add_node(entry);
}
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions util/network/src/node_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ impl NodeTable {
self.nodes.get_mut(id)
}

/// Check if a node exists in the table.
pub fn contains(&self, id: &NodeId) -> bool {
self.nodes.contains_key(id)
}

/// Apply table changes coming from discovery
pub fn update(&mut self, mut update: TableUpdates, reserved: &HashSet<NodeId>) {
for (_, node) in update.added.drain() {
Expand Down

0 comments on commit 2d7aecf

Please sign in to comment.