From 5626798a0d61d3eab42edb0feacdda328620c580 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Mon, 12 Jul 2021 01:28:41 +0000 Subject: [PATCH] Bump rand, drop SockAddr size by an additional 4 bytes --- Cargo.toml | 2 +- src/datastore.rs | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7240bd1..ab04e15 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ bgp-rs = "0.6" tokio = "0.1" bytes = "0.4" futures = "0.1" -rand = "0.6" +rand = "0.8" regex = "1" num_cpus = "1" diff --git a/src/datastore.rs b/src/datastore.rs index 2798771..1f22210 100644 --- a/src/datastore.rs +++ b/src/datastore.rs @@ -132,13 +132,17 @@ struct Node { #[derive(Clone, PartialEq, Eq, Hash)] enum SockAddr { V4(SocketAddrV4), - V6((Ipv6Addr, u16)), + V6(([u16; 8], u16)), +} +#[inline] +fn segs_to_ip6(segs: &[u16; 8]) -> Ipv6Addr { + Ipv6Addr::new(segs[0], segs[1], segs[2], segs[3], segs[4], segs[5], segs[6], segs[7]) } impl From for SockAddr { fn from(addr: SocketAddr) -> SockAddr { match addr { SocketAddr::V4(sa) => SockAddr::V4(sa), - SocketAddr::V6(sa) => SockAddr::V6((sa.ip().clone(), sa.port())), + SocketAddr::V6(sa) => SockAddr::V6((sa.ip().segments(), sa.port())), } } } @@ -146,7 +150,7 @@ impl Into for &SockAddr { fn into(self) -> SocketAddr { match self { &SockAddr::V4(sa) => SocketAddr::V4(sa), - &SockAddr::V6(sa) => SocketAddr::V6(SocketAddrV6::new(sa.0, sa.1, 0, 0)) + &SockAddr::V6(sa) => SocketAddr::V6(SocketAddrV6::new(segs_to_ip6(&sa.0), sa.1, 0, 0)) } } } @@ -166,7 +170,7 @@ impl SockAddr { pub fn ip(&self) -> IpAddr { match *self { SockAddr::V4(sa) => IpAddr::V4(sa.ip().clone()), - SockAddr::V6((ip, _)) => IpAddr::V6(ip), + SockAddr::V6((ip, _)) => IpAddr::V6(segs_to_ip6(&ip)), } } } -- 2.39.5