Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(iroh-net): Nat-PMP probes and mappings #1283

Merged
merged 10 commits into from
Jul 20, 2023
Merged

Conversation

divagant-martian
Copy link
Contributor

@divagant-martian divagant-martian commented Jul 19, 2023

Description

  • Doctor command port getting a port mapping accepts nat pmp.
  • Implement nat pmp protocol's requests and responses for udp mappings and external address queries with their encoding + decoding + tests.
  • Connect new mapping protocol with the rest
  • Correct some docs.

Notes & open questions

Suggested way of trying:

A Mapping

env RUST_LOG=trace cargo run doctor port-map nat_pmp 2446

A probe

env RUST_LOG=trace cargo run doctor port-map-probe --enable-nat-pmp

Change checklist

  • Self-review.
  • Documentation updates if relevant.
  • Tests if relevant.

@divagant-martian divagant-martian self-assigned this Jul 19, 2023
@divagant-martian divagant-martian changed the title [WIP] Nat-PMP Nat-PMP Jul 19, 2023
@divagant-martian divagant-martian marked this pull request as ready for review July 19, 2023 22:54
@divagant-martian divagant-martian changed the title Nat-PMP feat[iroh-net): Nat-PMP probes and mappings Jul 19, 2023
@divagant-martian divagant-martian linked an issue Jul 19, 2023 that may be closed by this pull request
4 tasks
@divagant-martian divagant-martian changed the title feat[iroh-net): Nat-PMP probes and mappings feat(iroh-net): Nat-PMP probes and mappings Jul 20, 2023
@dignifiedquire
Copy link
Contributor

dignifiedquire commented Jul 20, 2023

Running the commands on my machine I am getting

> RUST_LOG=trace cargo run doctor port-map nat_pmp 2446
2023-07-20T13:03:23.164141Z DEBUG iroh::config: make_config:
Config {
    defaults: {},
    overrides: {},
    sources: [],
    cache: Value {
        origin: None,
        kind: Table(
            {},
        ),
    },
}

2023-07-20T13:03:23.164887Z  INFO iroh::commands: Metrics server not started, no address provided
2023-07-20T13:03:23.166452Z DEBUG portmapper.service: iroh_net::portmapper: portmap starting
2023-07-20T13:03:23.166623Z TRACE portmapper.service: iroh_net::portmapper: tick: msg Some(UpdateLocalPort { local_port: Some(2446) })
2023-07-20T13:03:23.168735Z DEBUG portmapper.service: iroh_net::portmapper: getting a port mapping for 192.168.178.31:2446 -> None
2023-07-20T13:03:23.180682Z TRACE portmapper.service: iroh_net::portmapper: tick: mapping ready
2023-07-20T13:03:23.180769Z DEBUG portmapper.service: iroh_net::portmapper: failed to get a port mapping Invalid version received
2023-07-20T13:03:33.169541Z DEBUG iroh_net::util: portmap_service completed
Error: Timed out waiting for a port mapping

and

> RUST_LOG=trace cargo run doctor port-map-probe --enable-nat-pmp
2023-07-20T13:02:57.501823Z DEBUG iroh::config: make_config:
Config {
    defaults: {},
    overrides: {},
    sources: [],
    cache: Value {
        origin: None,
        kind: Table(
            {},
        ),
    },
}

2023-07-20T13:02:57.502407Z  INFO iroh::commands: Metrics server not started, no address provided
probing port mapping protocols with Config { enable_upnp: false, enable_pcp: false, enable_nat_pmp: true }
2023-07-20T13:02:57.503547Z DEBUG portmapper.service: iroh_net::portmapper: portmap starting
2023-07-20T13:02:57.503682Z TRACE portmapper.service: iroh_net::portmapper: tick: msg Some(Probe { result_tx: _ })
2023-07-20T13:02:57.513680Z DEBUG portmapper.service:portmapper.probe: iroh_net::portmapper::nat_pmp: probe failed: Response is malformed
2023-07-20T13:02:57.513818Z TRACE portmapper.service:portmapper.probe: iroh_net::portmapper: tick: nat_pmp probe ready
2023-07-20T13:02:57.514121Z TRACE portmapper.service: iroh_net::portmapper: tick: probe ready
2023-07-20T13:02:57.514185Z DEBUG portmapper.service: iroh_net::portmapper: probe output portmap={ UPnP: false, PMP: false, PCP: false }
portmap={ UPnP: false, PMP: false, PCP: false }
2023-07-20T13:02:57.514257Z TRACE portmapper.service: iroh_net::portmapper: tick: msg None
2023-07-20T13:02:57.514261Z DEBUG iroh_net::util: portmap_service completed
2023-07-20T13:02:57.514268Z DEBUG portmapper.service: iroh_net::portmapper: portmap service channel dropped. Likely shutting down.

@b5
Copy link
Member

b5 commented Jul 20, 2023

Works for me!

My Results:

$ env RUST_LOG=trace cargo run doctor port-map nat_pmp 2446
    Finished dev [unoptimized + debuginfo] target(s) in 0.21s
     Running `target/debug/iroh doctor port-map nat_pmp 2446`
2023-07-20T13:50:29.450490Z DEBUG iroh::config: make_config:
Config {
    defaults: {},
    overrides: {},
    sources: [],
    cache: Value {
        origin: None,
        kind: Table(
            {},
        ),
    },
}

2023-07-20T13:50:29.451193Z  INFO iroh::commands: Metrics server not started, no address provided
2023-07-20T13:50:29.452626Z DEBUG portmapper.service: iroh_net::portmapper: portmap starting
2023-07-20T13:50:29.452958Z TRACE portmapper.service: iroh_net::portmapper: tick: msg Some(UpdateLocalPort { local_port: Some(2446) })
2023-07-20T13:50:29.454929Z DEBUG portmapper.service: iroh_net::portmapper: getting a port mapping for 192.168.68.83:2446 -> None
2023-07-20T13:50:29.461216Z TRACE portmapper.service: iroh_net::portmapper: tick: mapping ready
2023-07-20T13:50:29.461278Z TRACE portmapper.service: iroh_net::portmapper::current_mapping: new port mapping Some(NatPmp(Mapping { local_ip: 192.168.68.83, local_port: 2446, gateway: 192.168.68.1, external_port: 2446, external_addr: $REACTED, lifetime_seconds: 7200 }))
Port mapping ready: $REACTED:2446
2023-07-20T13:50:29.461503Z DEBUG iroh_net::util: portmap_service completed

and

$ env RUST_LOG=trace cargo run doctor port-map-probe --enable-nat-pmp
    Finished dev [unoptimized + debuginfo] target(s) in 0.22s
     Running `target/debug/iroh doctor port-map-probe --enable-nat-pmp`
2023-07-20T13:53:24.294030Z DEBUG iroh::config: make_config:
Config {
    defaults: {},
    overrides: {},
    sources: [],
    cache: Value {
        origin: None,
        kind: Table(
            {},
        ),
    },
}

2023-07-20T13:53:24.294756Z  INFO iroh::commands: Metrics server not started, no address provided
probing port mapping protocols with Config { enable_upnp: false, enable_pcp: false, enable_nat_pmp: true }
2023-07-20T13:53:24.296361Z DEBUG portmapper.service: iroh_net::portmapper: portmap starting
2023-07-20T13:53:24.296545Z TRACE portmapper.service: iroh_net::portmapper: tick: msg Some(Probe { result_tx: _ })
2023-07-20T13:53:24.301050Z TRACE portmapper.service:portmapper.probe: iroh_net::portmapper::nat_pmp: probe response: PublicAddress { epoch_time: 232031, public_ip: $REDACTED }
2023-07-20T13:53:24.301116Z TRACE portmapper.service:portmapper.probe: iroh_net::portmapper: tick: nat_pmp probe ready
2023-07-20T13:53:24.301396Z TRACE portmapper.service: iroh_net::portmapper: tick: probe ready
2023-07-20T13:53:24.301536Z DEBUG portmapper.service: iroh_net::portmapper: probe output portmap={ UPnP: false, PMP: true, PCP: false }
portmap={ UPnP: false, PMP: true, PCP: false }
2023-07-20T13:53:24.301627Z DEBUG iroh_net::util: portmap_service completed

Copy link
Contributor

@dignifiedquire dignifiedquire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work

@divagant-martian divagant-martian merged commit 5c38730 into main Jul 20, 2023
@divagant-martian divagant-martian deleted the nat-pmp-probe branch July 20, 2023 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

iroh-net: implement portmapping
3 participants