improve mycelium argument
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
fn find_best_route<'a>(&self, routes: &'a RouteList)
|
||||
-> Option<&'a RouteEntry>
|
||||
{
|
||||
let source_table = self.source_table.read().unwrap();
|
||||
let current = routes.selected();
|
||||
let best = routes
|
||||
.iter()
|
||||
.filter(|re| !re.metric().is_infinite()
|
||||
&& source_table.route_feasible(re))
|
||||
.min_by_key(|re|
|
||||
re.metric() + Metric::from(re.neighbour().link_cost()));
|
||||
|
||||
if let (Some(best), Some(current)) = (best, current) {
|
||||
// Only switch if the metric is significantly better
|
||||
// OR if the route is directly connected (metric 0).
|
||||
if (best.source() != current.source()
|
||||
|| best.neighbour() != current.neighbour())
|
||||
&& !(best.metric()
|
||||
+ Metric::from(best.neighbour().link_cost())
|
||||
< current.metric()
|
||||
+ Metric::from(current.neighbour().link_cost())
|
||||
- SIGNIFICANT_METRIC_IMPROVEMENT
|
||||
|| best.metric().is_direct())
|
||||
{
|
||||
return Some(current); // keep existing route
|
||||
}
|
||||
}
|
||||
best
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
/// Time between HELLO messages, in seconds
|
||||
const HELLO_INTERVAL: u64 = 20;
|
||||
/// Max time used in UPDATE packets.
|
||||
const UPDATE_INTERVAL: Duration =
|
||||
Duration::from_secs(HELLO_INTERVAL * 3 * 5); // 300 s
|
||||
|
||||
/// The amount a metric of a route needs to improve
|
||||
/// before we will consider switching to it.
|
||||
const SIGNIFICANT_METRIC_IMPROVEMENT: Metric = Metric::new(10);
|
||||
@@ -0,0 +1,39 @@
|
||||
type FirewallConntrack struct {
|
||||
sync.Mutex
|
||||
|
||||
Conns map[firewall.Packet]*conn
|
||||
TimerWheel *TimerWheel[firewall.Packet]
|
||||
}
|
||||
|
||||
func (f *Firewall) inConns(
|
||||
fp firewall.Packet, h *HostInfo,
|
||||
caPool *cert.CAPool,
|
||||
localCache firewall.ConntrackCache,
|
||||
) bool {
|
||||
if localCache != nil {
|
||||
if _, ok := localCache[fp]; ok {
|
||||
return true
|
||||
}
|
||||
}
|
||||
conntrack := f.Conntrack
|
||||
conntrack.Lock()
|
||||
|
||||
// Purge every time we test
|
||||
ep, has := conntrack.TimerWheel.Purge()
|
||||
if has {
|
||||
f.evict(ep)
|
||||
}
|
||||
|
||||
c, ok := conntrack.Conns[fp]
|
||||
if !ok {
|
||||
conntrack.Unlock()
|
||||
return false
|
||||
}
|
||||
// ... update expiry ...
|
||||
conntrack.Unlock()
|
||||
|
||||
if localCache != nil {
|
||||
localCache[fp] = struct{}{}
|
||||
}
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user