Skip to content

Commit 0c84c5a

Browse files
Adam Fiskclaude
authored andcommitted
peer: read PeerManualPortKey setting alongside RADIANCE_PEER_EXTERNAL_PORT
Adds settings.PeerManualPortKey so the user-facing Advanced UI can persist the manual port forward without an env var. Resolution order in peer.Client.Start's NewForwarder: 1. settings.PeerManualPortKey (Advanced UI in lantern Flutter) 2. RADIANCE_PEER_EXTERNAL_PORT env var (developer / power-user) 3. UPnP discovery (default) The setting is wired through lantern-core's PatchSettings(PeerShareEnabledKey...) path on a separate branch — the new `setPeerManualPort` FFI export over there calls PatchSettings({PeerManualPortKey: <int>}) which lands in radiance's settings store and gets picked up on the next peer.Client.Start. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 3debe39 commit 0c84c5a

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

common/settings/settings.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ const (
5656
AdBlockKey _key = "ad_block" // bool
5757
AutoConnectKey _key = "auto_connect" // bool
5858
PeerShareEnabledKey _key = "peer_share_enabled" // bool
59+
// PeerManualPortKey is the TCP port number the user has manually
60+
// forwarded on their router (single-port 1:1 NAT). When non-zero,
61+
// peer.Client.Start uses portforward.ManualForwarder with this port
62+
// instead of probing UPnP. Surfaced as an Advanced setting in the
63+
// Share My Connection UI for users on networks where UPnP is
64+
// disabled or unavailable.
65+
PeerManualPortKey _key = "peer_manual_port" // int (0 = use UPnP)
5966
SelectedServerKey _key = "selected_server" // [servers.Server] Server.Options is not stored
6067

6168
PreferredLocationKey _key = "preferred_location" // [common.PreferredLocation]

peer/peer.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
box "github.com/getlantern/lantern-box"
1818
"github.com/getlantern/lantern-box/tracker/peerconn"
1919
"github.com/getlantern/radiance/common/env"
20+
"github.com/getlantern/radiance/common/settings"
2021
"github.com/getlantern/radiance/events"
2122
"github.com/getlantern/radiance/portforward"
2223
)
@@ -204,9 +205,28 @@ func NewClient(cfg Config) (*Client, error) {
204205
}
205206
if cfg.NewForwarder == nil {
206207
cfg.NewForwarder = func(ctx context.Context) (portForwarder, error) {
208+
// Manual port-forward override. Use case: networks where
209+
// UPnP is disabled or unavailable (router has UPnP off for
210+
// security, ISP-provided gateways without IGD, networks
211+
// behind double-NAT) but the user has manually configured
212+
// a port forward on their router. We trust the user's
213+
// config — no UPnP roundtrip — and report the configured
214+
// port as both the external and internal port (the 1:1
215+
// case every consumer router exposes).
216+
//
217+
// Resolution order:
218+
// 1. settings.PeerManualPortKey (Advanced UI)
219+
// 2. RADIANCE_PEER_EXTERNAL_PORT env var (developer /
220+
// power-user override)
221+
// 3. fall through to UPnP discovery
222+
if port := uint16(settings.GetInt(settings.PeerManualPortKey)); port != 0 {
223+
slog.Info("peer client using manual port forward",
224+
"port", port, "source", "setting")
225+
return &manualPortForwarder{port: port}, nil
226+
}
207227
if p := manualPort(); p != 0 {
208228
slog.Info("peer client using manual port forward",
209-
"port", p, "env", env.PeerExternalPort.String())
229+
"port", p, "source", env.PeerExternalPort.String())
210230
return &manualPortForwarder{port: p}, nil
211231
}
212232
// Explicitly return a nil interface on error — `return

0 commit comments

Comments
 (0)