Repeatedly resolving connect addresses to allow DynDNS

This commit is contained in:
Dennis Schwerdel 2016-05-11 10:54:00 +02:00
parent 55c2a14290
commit 5099003479
3 changed files with 14 additions and 15 deletions

View File

@ -4,6 +4,7 @@ This project follows [semantic versioning](http://semver.org).
### Unreleased ### Unreleased
- [changed] Repeatedly resolving connect addresses to allow DynDNS
- [changed] Listening on IPv4 and IPv6 - [changed] Listening on IPv4 and IPv6
- [changed] Using SO_REUSEADDR to allow frequent rebinding - [changed] Using SO_REUSEADDR to allow frequent rebinding
- [changed] Building and using local libsodium library automatically - [changed] Building and using local libsodium library automatically

View File

@ -68,12 +68,12 @@ impl PeerList {
} }
#[inline(always)] #[inline(always)]
fn contains_addr(&mut self, addr: &SocketAddr) -> bool { fn contains_addr(&self, addr: &SocketAddr) -> bool {
self.addresses.contains(addr) self.addresses.contains(addr)
} }
#[inline(always)] #[inline(always)]
fn contains_node(&mut self, node_id: &NodeId) -> bool { fn contains_node(&self, node_id: &NodeId) -> bool {
self.nodes.contains_key(node_id) self.nodes.contains_key(node_id)
} }
@ -134,7 +134,7 @@ pub struct GenericCloud<P: Protocol> {
addresses: Vec<Range>, addresses: Vec<Range>,
learning: bool, learning: bool,
broadcast: bool, broadcast: bool,
reconnect_peers: Vec<SocketAddr>, reconnect_peers: Vec<String>,
blacklist_peers: Vec<SocketAddr>, blacklist_peers: Vec<SocketAddr>,
table: Box<Table>, table: Box<Table>,
socket4: UdpSocket, socket4: UdpSocket,
@ -242,7 +242,11 @@ impl<P: Protocol> GenericCloud<P> {
self.peers.len() self.peers.len()
} }
pub fn connect<Addr: ToSocketAddrs+fmt::Display>(&mut self, addr: Addr, reconnect: bool) -> Result<(), Error> { pub fn add_reconnect_peer(&mut self, add: String) {
self.reconnect_peers.push(add)
}
pub fn connect<Addr: ToSocketAddrs+fmt::Display>(&mut self, addr: Addr) -> Result<(), Error> {
if let Ok(mut addrs) = addr.to_socket_addrs() { if let Ok(mut addrs) = addr.to_socket_addrs() {
while let Some(a) = addrs.next() { while let Some(a) = addrs.next() {
if self.peers.contains_addr(&a) || self.blacklist_peers.contains(&a) { if self.peers.contains_addr(&a) || self.blacklist_peers.contains(&a) {
@ -251,13 +255,6 @@ impl<P: Protocol> GenericCloud<P> {
} }
} }
debug!("Connecting to {}", addr); debug!("Connecting to {}", addr);
if reconnect {
if let Ok(mut addrs) = addr.to_socket_addrs() {
while let Some(a) = addrs.next() {
self.reconnect_peers.push(a);
}
}
}
let subnets = self.addresses.clone(); let subnets = self.addresses.clone();
let node_id = self.node_id.clone(); let node_id = self.node_id.clone();
let mut msg = Message::Init(0, node_id, subnets); let mut msg = Message::Init(0, node_id, subnets);
@ -291,7 +288,7 @@ impl<P: Protocol> GenericCloud<P> {
self.next_peerlist = now() + self.update_freq as Time; self.next_peerlist = now() + self.update_freq as Time;
} }
for addr in self.reconnect_peers.clone() { for addr in self.reconnect_peers.clone() {
try!(self.connect(addr, false)); try!(self.connect(&addr as &str));
} }
Ok(()) Ok(())
} }
@ -348,7 +345,7 @@ impl<P: Protocol> GenericCloud<P> {
Message::Peers(peers) => { Message::Peers(peers) => {
for p in &peers { for p in &peers {
if ! self.peers.contains_addr(p) && ! self.blacklist_peers.contains(p) { if ! self.peers.contains_addr(p) && ! self.blacklist_peers.contains(p) {
try!(self.connect(p, false)); try!(self.connect(p));
} }
} }
}, },

View File

@ -128,8 +128,9 @@ fn run<T: Protocol> (args: Args) {
if let Some(script) = args.flag_ifup { if let Some(script) = args.flag_ifup {
run_script(script, cloud.ifname()); run_script(script, cloud.ifname());
} }
for addr in &args.flag_connect { for addr in args.flag_connect {
try_fail!(cloud.connect(&addr as &str, true), "Failed to send message to {}: {}", &addr); try_fail!(cloud.connect(&addr as &str), "Failed to send message to {}: {}", &addr);
cloud.add_reconnect_peer(addr);
} }
cloud.run(); cloud.run();
if let Some(script) = args.flag_ifdown { if let Some(script) = args.flag_ifdown {