pub struct IpMappedAddresses(/* private fields */);Expand description
A Map of IpMappedAddresses to SocketAddr.
Implementations§
Source§impl IpMappedAddresses
impl IpMappedAddresses
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty IpMappedAddresses.
Sourcepub fn get_or_register(&self, ip_addr: SocketAddr) -> IpMappedAddr
pub fn get_or_register(&self, ip_addr: SocketAddr) -> IpMappedAddr
Adds a SocketAddr to the map and returns the generated IpMappedAddr.
Implementations§
Source§impl IpMappedAddresses
impl IpMappedAddresses
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty IpMappedAddresses.
Sourcepub fn get_or_register(&self, socket_addr: SocketAddr) -> IpMappedAddr
pub fn get_or_register(&self, socket_addr: SocketAddr) -> IpMappedAddr
Adds a SocketAddr to the map and returns the generated IpMappedAddr.
If this SocketAddr already exists in the map, it returns its
associated IpMappedAddr.
Otherwise a new IpMappedAddr is generated for it and returned.
Sourcepub fn get_mapped_addr(&self, ip_addr: &SocketAddr) -> Option<IpMappedAddr>
pub fn get_mapped_addr(&self, ip_addr: &SocketAddr) -> Option<IpMappedAddr>
Returns the IpMappedAddr for the given SocketAddr.
Sourcepub fn get_ip_addr(&self, mapped_addr: &IpMappedAddr) -> Option<SocketAddr>
pub fn get_ip_addr(&self, mapped_addr: &IpMappedAddr) -> Option<SocketAddr>
Returns the SocketAddr for the given IpMappedAddr.
Sourcepub fn get_mapped_addr(&self, socket_addr: &SocketAddr) -> Option<IpMappedAddr>
pub fn get_mapped_addr(&self, socket_addr: &SocketAddr) -> Option<IpMappedAddr>
Returns the IpMappedAddr for the given SocketAddr.
Sourcepub fn get_ip_addr(&self, mapped_addr: &IpMappedAddr) -> Option<SocketAddr>
pub fn get_ip_addr(&self, mapped_addr: &IpMappedAddr) -> Option<SocketAddr>
Returns the SocketAddr for the given IpMappedAddr.
Trait Implementations§
Source§impl Clone for IpMappedAddresses
impl Clone for IpMappedAddresses
Source§fn clone(&self) -> IpMappedAddresses
fn clone(&self) -> IpMappedAddresses
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for IpMappedAddresses
impl Debug for IpMappedAddresses
Source§impl Default for IpMappedAddresses
impl Default for IpMappedAddresses
Source§fn default() -> IpMappedAddresses
fn default() -> IpMappedAddresses
Auto Trait Implementations§
impl Freeze for IpMappedAddresses
impl RefUnwindSafe for IpMappedAddresses
impl Send for IpMappedAddresses
impl Sync for IpMappedAddresses
impl Unpin for IpMappedAddresses
impl UnwindSafe for IpMappedAddresses
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
diff --git a/pr/3049/docs/src/iroh_net_report/ip_mapped_addrs.rs.html b/pr/3049/docs/src/iroh_net_report/ip_mapped_addrs.rs.html
index db28c604c8..4acab350bd 100644
--- a/pr/3049/docs/src/iroh_net_report/ip_mapped_addrs.rs.html
+++ b/pr/3049/docs/src/iroh_net_report/ip_mapped_addrs.rs.html
@@ -123,7 +123,13 @@
122
123
124
-125use std::{
+125
+126
+127
+128
+129
+130
+131
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
diff --git a/pr/3049/docs/src/iroh_net_report/ip_mapped_addrs.rs.html b/pr/3049/docs/src/iroh_net_report/ip_mapped_addrs.rs.html
index db28c604c8..4acab350bd 100644
--- a/pr/3049/docs/src/iroh_net_report/ip_mapped_addrs.rs.html
+++ b/pr/3049/docs/src/iroh_net_report/ip_mapped_addrs.rs.html
@@ -123,7 +123,13 @@
122
123
124
-125use std::{
+125
+126
+127
+128
+129
+130
+131
use std::{
+125
+126
+127
+128
+129
+130
+131use std::{
collections::BTreeMap,
net::{IpAddr, Ipv6Addr, SocketAddr},
sync::{
@@ -210,7 +216,11 @@
#[derive(Debug, Default)]
pub struct Inner {
by_mapped_addr: BTreeMap<IpMappedAddr, SocketAddr>,
- by_socket_addr: BTreeMap<SocketAddr, IpMappedAddr>,
+ /// Because [`SocketAddrV6`] contains extra fields besides the IP
+ /// address and port (ie, flow_info and scope_id), the a [`SocketAddrV6`]
+ /// with the same IP addr and port might Hash to something different.
+ /// So to get a hashable key for the map, we are using `(IpAddr, u6)`.
+ by_ip_port: BTreeMap<(IpAddr, u16), IpMappedAddr>,
}
impl IpMappedAddresses {
@@ -225,21 +235,23 @@
/// associated [`IpMappedAddr`].
///
/// Otherwise a new [`IpMappedAddr`] is generated for it and returned.
- pub fn get_or_register(&self, ip_addr: SocketAddr) -> IpMappedAddr {
+ pub fn get_or_register(&self, socket_addr: SocketAddr) -> IpMappedAddr {
+ let ip_port = (socket_addr.ip(), socket_addr.port());
let mut inner = self.0.lock().expect("poisoned");
- if let Some(mapped_addr) = inner.by_socket_addr.get(&ip_addr) {
+ if let Some(mapped_addr) = inner.by_ip_port.get(&ip_port) {
return *mapped_addr;
}
let ip_mapped_addr = IpMappedAddr::generate();
- inner.by_mapped_addr.insert(ip_mapped_addr, ip_addr);
- inner.by_socket_addr.insert(ip_addr, ip_mapped_addr);
+ inner.by_mapped_addr.insert(ip_mapped_addr, socket_addr);
+ inner.by_ip_port.insert(ip_port, ip_mapped_addr);
ip_mapped_addr
}
/// Returns the [`IpMappedAddr`] for the given [`SocketAddr`].
- pub fn get_mapped_addr(&self, ip_addr: &SocketAddr) -> Option<IpMappedAddr> {
+ pub fn get_mapped_addr(&self, socket_addr: &SocketAddr) -> Option<IpMappedAddr> {
+ let ip_port = (socket_addr.ip(), socket_addr.port());
let inner = self.0.lock().expect("poisoned");
- inner.by_socket_addr.get(ip_addr).copied()
+ inner.by_ip_port.get(&ip_port).copied()
}
/// Returns the [`SocketAddr`] for the given [`IpMappedAddr`].