Skip to content

Portmapper does not use Iroh bound interfaces #2871

@CGamesPlay

Description

@CGamesPlay

This is split from #2866 (comment). Applying the following patch and running the listen example in iroh-net demonstrates that the port mapper service uses interfaces on which it has not been configured. The patch disables relay and all discovery, and binds to loopback addresses, only.

git reset --hard fad3e24b3
cat patch.patch | git apply
RUST_LOG=trace cargo run --example listen

In the log, we notice the following selected lines, indicating that portmapper is using SSDP on the default interface, ignoring the configuration set by the Endpoint.

2024-10-31T01:52:20.276752Z DEBUG ep{me=rseo2uaniqtssr4r}:magicsock:portmapper.service: portmapper: portmap starting
2024-10-31T01:52:20.277091Z TRACE ep{me=rseo2uaniqtssr4r}:magicsock:portmapper.service: portmapper: tick: msg Some(UpdateLocalPort { local_port: Some(5000) })
2024-10-31T01:52:20.277943Z DEBUG ep{me=rseo2uaniqtssr4r}:magicsock:portmapper.service: portmapper: getting a port mapping for 192.168.20.59:5000 -> None
2024-10-31T01:52:20.278075Z DEBUG ep{me=rseo2uaniqtssr4r}:magicsock:portmapper.service:upnp: igd_next::aio::tokio: sending broadcast request to: 239.255.255.250:1900 on interface: Ok(0.0.0.0:52449)    
diff --git i/iroh-net/examples/listen.rs w/iroh-net/examples/listen.rs
index 1a3828c6e..731a2aca7 100644
--- i/iroh-net/examples/listen.rs
+++ w/iroh-net/examples/listen.rs
@@ -30,7 +30,10 @@ async fn main() -> anyhow::Result<()> {
         // Use `RelayMode::Custom` to pass in a `RelayMap` with custom relay urls.
         // Use `RelayMode::Disable` to disable holepunching and relaying over HTTPS
         // If you want to experiment with relaying using your own relay server, you must pass in the same custom relay url to both the `listen` code AND the `connect` code
-        .relay_mode(RelayMode::Default)
+        .relay_mode(RelayMode::Disabled)
+        .clear_discovery()
+        .bind_addr_v6("[::1]:5000".parse().unwrap())
+        .bind_addr_v4("127.0.0.1:5000".parse().unwrap())
         // you can choose a port to bind to, but passing in `0` will bind the socket to a random available port
         .bind()
         .await?;
@@ -39,29 +42,20 @@ async fn main() -> anyhow::Result<()> {
     println!("node id: {me}");
     println!("node listening addresses:");
 
-    let local_addrs = endpoint
+    for endpoint in endpoint
         .direct_addresses()
         .next()
         .await
         .context("no endpoints")?
         .into_iter()
-        .map(|endpoint| {
-            let addr = endpoint.addr.to_string();
-            println!("\t{addr}");
-            addr
-        })
-        .collect::<Vec<_>>()
-        .join(" ");
+    {
+        let addr = endpoint.addr.to_string();
+        println!("\t{addr}");
+    }
 
-    let relay_url = endpoint
-        .home_relay()
-        .expect("should be connected to a relay server, try calling `endpoint.local_endpoints()` or `endpoint.connect()` first, to ensure the endpoint has actually attempted a connection before checking for the connected relay server");
-    println!("node relay server url: {relay_url}");
-    println!("\nin a separate terminal run:");
+    let relay_url = endpoint.home_relay();
+    println!("node relay server url: {relay_url:?}");
 
-    println!(
-        "\tcargo run --example connect -- --node-id {me} --addrs \"{local_addrs}\" --relay-url {relay_url}\n"
-    );
     // accept incoming connections, returns a normal QUIC connection
     while let Some(incoming) = endpoint.accept().await {
         let mut connecting = match incoming.accept() {

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingc-iroh

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions