-
Notifications
You must be signed in to change notification settings - Fork 0
peer: manual port-forward override for UPnP-less networks #503
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
Open
myleshorton
wants to merge
7
commits into
fisk/peer-connection-events-A
Choose a base branch
from
fisk/peer-manual-portforward
base: fisk/peer-connection-events-A
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0e1470d
peer: read PeerManualPortKey setting alongside RADIANCE_PEER_EXTERNAL…
b49872c
portforward: extract manual port forwarder to its own file
myleshorton d460569
peer/portforward/settings: address Copilot review on #500
myleshorton d517ef8
peer/portforward: address Copilot review on #500 (round 2)
myleshorton 7f8224d
peer/portforward: address Copilot review on #503
myleshorton eb55d0f
peer/portforward: address Copilot review on #503 (round 2)
myleshorton 79400ef
portforward: add ProbeUPnP for the pre-flight 'would SmC work here?' …
myleshorton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| package portforward | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "strconv" | ||
| ) | ||
|
|
||
| // ManualForwarder exposes the same Map/Unmap/StartRenewal/ExternalIP | ||
| // surface as Forwarder but does no UPnP work. The user is expected to | ||
| // have configured a port forward on their router by hand and supplied | ||
| // the port number out-of-band. This implementation reports the same | ||
| // value for both the external and internal port — callers needing | ||
| // distinct external/internal ports should use the UPnP-based Forwarder | ||
| // (which can negotiate them) or build their own portForwarder. | ||
| // | ||
| // Use case: networks where UPnP is disabled or unavailable (router has | ||
| // UPnP off for security, ISP-provided gateways without IGD, networks | ||
| // behind double-NAT). The UPnP-based Forwarder fails in those | ||
| // environments; this type lets callers bypass discovery entirely. | ||
| type ManualForwarder struct { | ||
| port uint16 | ||
| } | ||
|
|
||
| // NewManualForwarder builds a ManualForwarder for a pre-configured | ||
| // router port forward. port must be in 1..65535; the caller is | ||
| // responsible for validating its input before calling. | ||
| func NewManualForwarder(port uint16) *ManualForwarder { | ||
| return &ManualForwarder{port: port} | ||
| } | ||
|
|
||
| // ParseManualPort parses a string into a TCP port number. Values outside | ||
| // 1..65535 return an error so callers can log and fall through to UPnP | ||
| // discovery rather than register a non-listening port with the server. | ||
| func ParseManualPort(s string) (uint16, error) { | ||
| p, err := strconv.Atoi(s) | ||
| if err != nil { | ||
| return 0, fmt.Errorf("parse %q: %w", s, err) | ||
| } | ||
| if p < 1 || p > 65535 { | ||
| return 0, fmt.Errorf("port %d out of range (1..65535)", p) | ||
| } | ||
| return uint16(p), nil | ||
| } | ||
|
|
||
| // MapPort reports the configured port as both external and internal. The | ||
| // router-side rule is already in place; nothing to do at the protocol | ||
| // layer. Returns an error if the forwarder was constructed with port==0 | ||
| // (not a valid listen/registration port) so callers can fall through to | ||
| // UPnP rather than register a port no peer will listen on. | ||
| // | ||
| // Protocol is set to "TCP" to match the UPnP-based Forwarder, which | ||
| // hard-codes the same value. Samizdat-in inbound traffic is TCP-only; | ||
| // when UDP support is added the two forwarders should be widened | ||
| // together. | ||
| func (m *ManualForwarder) MapPort(_ context.Context, _ uint16, _ string) (*Mapping, error) { | ||
| if m.port == 0 { | ||
| return nil, fmt.Errorf("manual forwarder constructed with port=0") | ||
| } | ||
| return &Mapping{ | ||
| ExternalPort: m.port, | ||
| InternalPort: m.port, | ||
| Protocol: "TCP", | ||
| Method: "manual", | ||
| }, nil | ||
| } | ||
|
myleshorton marked this conversation as resolved.
|
||
|
|
||
| // UnmapPort is a no-op: the user owns the router rule and is responsible | ||
| // for removing it. | ||
| func (m *ManualForwarder) UnmapPort(_ context.Context) error { return nil } | ||
|
|
||
| // StartRenewal is a no-op: manually-configured rules don't carry a UPnP | ||
| // lease and don't need refreshing. | ||
| func (m *ManualForwarder) StartRenewal(_ context.Context) {} | ||
|
|
||
| // ExternalIP returns the empty string deliberately. With a manual port | ||
| // forward we have no UPnP gateway to ask for the WAN address, and | ||
| // probing a public IP service from the client adds a network roundtrip | ||
| // for information lantern-cloud already has — the server observes the | ||
| // peer's source address on the register call and uses that as the | ||
| // canonical external IP when this field is empty. | ||
| func (m *ManualForwarder) ExternalIP(_ context.Context) (string, error) { | ||
| return "", nil | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.