From 31cb11019711fa9dfb4e511a7eea5d0b0de4241d Mon Sep 17 00:00:00 2001 From: ramfox Date: Fri, 31 Jan 2025 21:09:17 +0000 Subject: [PATCH] deploy: a5051280164b51e32178ddf176ba55cf50233922 --- .../struct.IpMappedAddresses.html | 8 +++--- .../iroh_net_report/ip_mapped_addrs.rs.html | 28 +++++++++++++------ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/pr/3049/docs/iroh_net_report/struct.IpMappedAddresses.html b/pr/3049/docs/iroh_net_report/struct.IpMappedAddresses.html index 837e0ff176..449aa6e7fe 100644 --- a/pr/3049/docs/iroh_net_report/struct.IpMappedAddresses.html +++ b/pr/3049/docs/iroh_net_report/struct.IpMappedAddresses.html @@ -1,11 +1,11 @@ IpMappedAddresses in iroh_net_report - Rust
iroh_net_report

Struct IpMappedAddresses

Source
pub struct IpMappedAddresses(/* private fields */);
Expand description

Implementations§

Source§

impl IpMappedAddresses

Source

pub fn new() -> Self

Creates an empty IpMappedAddresses.

-
Source

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

Source

pub fn new() -> Self

Creates an empty IpMappedAddresses.

+
Source

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.

-
Source

pub fn get_mapped_addr(&self, ip_addr: &SocketAddr) -> Option<IpMappedAddr>

Returns the IpMappedAddr for the given SocketAddr.

-
Source

pub fn get_ip_addr(&self, mapped_addr: &IpMappedAddr) -> Option<SocketAddr>

Returns the SocketAddr for the given IpMappedAddr.

+
Source

pub fn get_mapped_addr(&self, socket_addr: &SocketAddr) -> Option<IpMappedAddr>

Returns the IpMappedAddr for the given SocketAddr.

+
Source

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

Source§

fn clone(&self) -> IpMappedAddresses

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for IpMappedAddresses

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for IpMappedAddresses

Source§

fn default() -> IpMappedAddresses

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where 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 -125
use std::{
+125
+126
+127
+128
+129
+130
+131

use 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`].