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

Allow duplicate TCP connection between two nodes. Fixes #96. #97

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions src/connection_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,12 @@ impl ConnectionManager {
let is_broadcast_acceptor = self.beacon_guid.is_some();
let _ = thread::spawn(move || {
for endpoint in &endpoints {
for itr in listening.iter() {
let unconnected: bool =
lock_state(&ws, |state| Ok(state.connections.is_empty())).unwrap_or(false);
if unconnected || itr.is_master(endpoint) {
let ws = ws.clone();
let result = transport::connect(endpoint.clone())
.and_then(|trans| handle_connect(ws, trans,
is_broadcast_acceptor));
if result.is_ok() { return; }
}
for _ in listening.iter() {
let ws = ws.clone();
let result = transport::connect(endpoint.clone())
.and_then(|trans| handle_connect(ws, trans,
is_broadcast_acceptor));
if result.is_ok() { return; }
}
}
});
Expand Down
18 changes: 0 additions & 18 deletions src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,6 @@ impl Endpoint {
Endpoint::Tcp(address) => address,
}
}

/// Returns whether this endpoint should be chosen over `other` when deciding to connect.
pub fn is_master(&self, other: &Endpoint) -> bool {
match *self {
Endpoint::Tcp(my_address) => {
match *other {
Endpoint::Tcp(other_address) => {
if my_address.port() == other_address.port() {
return my_address.ip() < other_address.ip();
} else {
return my_address.port() < other_address.port();
}
}
}
}
}
return true;
}
}

impl Encodable for Endpoint {
Expand Down