mirror of https://github.com/dswd/vpncloud.git
Not overriding recently learned addresses in switch mode
This commit is contained in:
parent
c41a49c0b7
commit
6e828b7ae8
|
@ -7,6 +7,8 @@ This project follows [semantic versioning](http://semver.org).
|
||||||
- [added] Support for automatic port forwarding via UPnP
|
- [added] Support for automatic port forwarding via UPnP
|
||||||
- [added] Added `-s` shorthand for `--subnet`
|
- [added] Added `-s` shorthand for `--subnet`
|
||||||
- [added] Support for YAML config file via `--config`
|
- [added] Support for YAML config file via `--config`
|
||||||
|
- [changed] Not overriding recently learnt addresses in switch mode
|
||||||
|
- [changed] Caching resolved addresses to increase performance
|
||||||
- [changed] Configurable magic header is now used instead of Network-ID (**incompatible**)
|
- [changed] Configurable magic header is now used instead of Network-ID (**incompatible**)
|
||||||
- [changed] Clarified documentation on TUN netmasks
|
- [changed] Clarified documentation on TUN netmasks
|
||||||
- [changed] Added timestamps to output
|
- [changed] Added timestamps to output
|
||||||
|
|
10
src/cloud.rs
10
src/cloud.rs
|
@ -29,6 +29,10 @@ use super::poll::{self, Poll};
|
||||||
|
|
||||||
type Hash = BuildHasherDefault<FnvHasher>;
|
type Hash = BuildHasherDefault<FnvHasher>;
|
||||||
|
|
||||||
|
const MAX_RECONNECT_INTERVAL: u16 = 3600;
|
||||||
|
const RESOLVE_INTERVAL: Time = 300;
|
||||||
|
|
||||||
|
|
||||||
struct PeerList {
|
struct PeerList {
|
||||||
timeout: Duration,
|
timeout: Duration,
|
||||||
peers: HashMap<SocketAddr, (Time, NodeId, Vec<SocketAddr>), Hash>,
|
peers: HashMap<SocketAddr, (Time, NodeId, Vec<SocketAddr>), Hash>,
|
||||||
|
@ -404,7 +408,7 @@ impl<P: Protocol> GenericCloud<P> {
|
||||||
if let Ok(addrs) = resolve(&entry.address as &str) {
|
if let Ok(addrs) = resolve(&entry.address as &str) {
|
||||||
entry.resolved = addrs;
|
entry.resolved = addrs;
|
||||||
}
|
}
|
||||||
entry.next_resolve = now + 60;
|
entry.next_resolve = now + RESOLVE_INTERVAL;
|
||||||
}
|
}
|
||||||
// Ignore if next attempt is already in the future
|
// Ignore if next attempt is already in the future
|
||||||
if entry.next > now {
|
if entry.next > now {
|
||||||
|
@ -417,8 +421,8 @@ impl<P: Protocol> GenericCloud<P> {
|
||||||
entry.timeout *= 2;
|
entry.timeout *= 2;
|
||||||
}
|
}
|
||||||
// Maximum interval is one hour
|
// Maximum interval is one hour
|
||||||
if entry.timeout > 3600 {
|
if entry.timeout > MAX_RECONNECT_INTERVAL {
|
||||||
entry.timeout = 3600;
|
entry.timeout = MAX_RECONNECT_INTERVAL;
|
||||||
}
|
}
|
||||||
// Schedule next connection attempt
|
// Schedule next connection attempt
|
||||||
entry.next = now + entry.timeout as Time;
|
entry.next = now + entry.timeout as Time;
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::collections::hash_map::Entry;
|
||||||
use std::hash::BuildHasherDefault;
|
use std::hash::BuildHasherDefault;
|
||||||
|
|
||||||
use fnv::FnvHasher;
|
use fnv::FnvHasher;
|
||||||
|
@ -99,9 +100,21 @@ impl Table for SwitchTable {
|
||||||
/// Learns the given address, inserting it in the hash map
|
/// Learns the given address, inserting it in the hash map
|
||||||
#[inline]
|
#[inline]
|
||||||
fn learn(&mut self, key: Address, _prefix_len: Option<u8>, addr: SocketAddr) {
|
fn learn(&mut self, key: Address, _prefix_len: Option<u8>, addr: SocketAddr) {
|
||||||
let value = SwitchTableValue{address: addr, timeout: now()+self.timeout as Time};
|
let deadline = now() + self.timeout as Time;
|
||||||
if self.table.insert(key, value).is_none() {
|
match self.table.entry(key) {
|
||||||
info!("Learned address {} => {}", key, addr);
|
Entry::Vacant(entry) => {
|
||||||
|
entry.insert(SwitchTableValue{address: addr, timeout: deadline});
|
||||||
|
info!("Learned address {} => {}", key, addr);
|
||||||
|
},
|
||||||
|
Entry::Occupied(mut entry) => {
|
||||||
|
let mut entry = entry.get_mut();
|
||||||
|
if entry.timeout + 10 >= deadline {
|
||||||
|
// Do not override recently learnt entries
|
||||||
|
return
|
||||||
|
}
|
||||||
|
entry.timeout = deadline;
|
||||||
|
entry.address = addr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue