Allow default port for peers

This commit is contained in:
Dennis Schwerdel 2020-11-07 12:25:12 +01:00
parent 46c8407db9
commit f210f75a25
2 changed files with 12 additions and 6 deletions

View File

@ -373,8 +373,14 @@ impl<D: Device, P: Protocol, S: Socket, TS: TimeSource> GenericCloud<D, P, S, TS
// Resolve entries anew
if let Some((ref address, ref mut next_resolve)) = entry.address {
if *next_resolve <= now {
if let Ok(addrs) = resolve(address as &str) {
entry.resolved = addrs;
match resolve(address as &str) {
Ok(addrs) => entry.resolved = addrs,
Err(_) => {
match resolve(&format!("{}:{}", address, DEFAULT_PORT)) {
Ok(addrs) => entry.resolved = addrs,
Err(err) => warn!("Failed to resolve {}: {}", address, err)
}
}
}
*next_resolve = now + RESOLVE_INTERVAL;
}

View File

@ -13,8 +13,8 @@ use crate::error::Error;
#[cfg(not(target_os = "linux"))] use time;
use signal::{trap::Trap, Signal};
use std::time::Instant;
use smallvec::SmallVec;
use std::time::Instant;
pub type Duration = u32;
@ -218,9 +218,8 @@ pub fn get_internal_ip() -> Ipv4Addr {
#[allow(unknown_lints, clippy::needless_pass_by_value)]
pub fn resolve<Addr: ToSocketAddrs + fmt::Debug>(addr: Addr) -> Result<SmallVec<[SocketAddr; 3]>, Error> {
let addrs = addr.to_socket_addrs().map_err(|_| Error::NameUnresolvable(format!("{:?}", addr)))?;
// Remove duplicates in addrs (why are there duplicates???)
let mut addrs = addrs.collect::<SmallVec<_>>();
let mut addrs =
addr.to_socket_addrs().map_err(|_| Error::NameUnresolvable(format!("{:?}", addr)))?.collect::<SmallVec<_>>();
// Try IPv4 first as it usually is faster
addrs.sort_by_key(|addr| {
match *addr {
@ -228,6 +227,7 @@ pub fn resolve<Addr: ToSocketAddrs + fmt::Debug>(addr: Addr) -> Result<SmallVec<
SocketAddr::V6(_) => 6
}
});
// Remove duplicates in addrs (why are there duplicates???)
addrs.dedup();
Ok(addrs)
}