96a925c040
* Extract out parse_peer * wip: handle_packet extract * Extract out active_peers.rs * wip: rework to struct from free function * udp_listener working * wip * more udp_listener * tun_device * wip * tun_device * Remove some old commented out stuff * tidy * Remove commented out line
26 lines
559 B
Rust
26 lines
559 B
Rust
use std::net::IpAddr;
|
|
|
|
use ip_network::IpNetwork;
|
|
use ip_network_table::IpNetworkTable;
|
|
|
|
#[derive(Default)]
|
|
pub struct NetworkTable<T> {
|
|
ips: IpNetworkTable<T>,
|
|
}
|
|
|
|
impl<T> NetworkTable<T> {
|
|
pub(crate) fn new() -> Self {
|
|
Self {
|
|
ips: IpNetworkTable::new(),
|
|
}
|
|
}
|
|
|
|
pub fn insert<N: Into<IpNetwork>>(&mut self, network: N, data: T) -> Option<T> {
|
|
self.ips.insert(network, data)
|
|
}
|
|
|
|
pub fn longest_match<I: Into<IpAddr>>(&self, ip: I) -> Option<(IpNetwork, &T)> {
|
|
self.ips.longest_match(ip)
|
|
}
|
|
}
|