Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ replace github.com/quic-go/qpack => github.com/quic-go/qpack v0.5.1
require (
github.com/alecthomas/assert/v2 v2.3.0
github.com/getlantern/lantern-server-provisioner v0.0.0-20251031121934-8ea031fccfa9
github.com/getlantern/radiance v0.0.0-20260805182705-0aebcab87c89
github.com/getlantern/radiance v0.0.0-20260805211630-2d796b8547f6
github.com/sagernet/sing-box v1.12.22
golang.org/x/mobile v0.0.0-20250711185624-d5bb5ecc55c0
golang.org/x/sys v0.45.0
Expand Down Expand Up @@ -171,7 +171,7 @@ require (
github.com/getlantern/domainfront v0.0.0-20260722204513-8c1f8acfa715 // indirect
github.com/getlantern/keepcurrent v0.0.0-20260616120552-f204338b01a3 // indirect
github.com/getlantern/kindling v0.0.0-20260727211028-573c1ef64464 // indirect
github.com/getlantern/lantern-box v0.0.107 // indirect
github.com/getlantern/lantern-box v0.0.108-0.20260805204936-b8cec7fadd27 // indirect
github.com/getlantern/lantern-water v0.0.0-20260520145825-958775d51395 // indirect
github.com/getlantern/osversion v0.0.0-20240418205916-2e84a4a4e175 // indirect
github.com/getlantern/pluriconfig v0.0.0-20251126214241-8cc8bc561535 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ github.com/getlantern/keepcurrent v0.0.0-20260616120552-f204338b01a3 h1:YPBbuyvd
github.com/getlantern/keepcurrent v0.0.0-20260616120552-f204338b01a3/go.mod h1:ag5g9aWUw2FJcX5RVRpJ9EBQBy5yJuy2WXDouIn/m4w=
github.com/getlantern/kindling v0.0.0-20260727211028-573c1ef64464 h1:vZtMtKDsGO0ccBr+aQRRDKgcwFTg4psy13HtMttuBVQ=
github.com/getlantern/kindling v0.0.0-20260727211028-573c1ef64464/go.mod h1:ZEPFiB6rH6MtMN1O7b5gE+LJpCsRFzAn4u8lbIxHh3w=
github.com/getlantern/lantern-box v0.0.107 h1:uTRoj5BKijO6Q2a9JZWunFL7Z29WDg8WzEuoliJ+kJg=
github.com/getlantern/lantern-box v0.0.107/go.mod h1:HHdmZsGwkiaweBycCYv1Jolk3jkrXbb/R5UUXtY2n3o=
github.com/getlantern/lantern-box v0.0.108-0.20260805204936-b8cec7fadd27 h1:21c/r8gqTz2LMKpZyq/MD74V7asQZVNt13pkwuOTFNQ=
github.com/getlantern/lantern-box v0.0.108-0.20260805204936-b8cec7fadd27/go.mod h1:HHdmZsGwkiaweBycCYv1Jolk3jkrXbb/R5UUXtY2n3o=
github.com/getlantern/lantern-server-provisioner v0.0.0-20251031121934-8ea031fccfa9 h1:6seyD2f9tz2am0YQd/Qn+q7LFiiQgnmxgwWFnVceGZw=
github.com/getlantern/lantern-server-provisioner v0.0.0-20251031121934-8ea031fccfa9/go.mod h1:s0VKrlJf/z+M0U8IKHFL2hfuflocRw3SINmMacrTlMA=
github.com/getlantern/lantern-water v0.0.0-20260520145825-958775d51395 h1:grfGavAUp2E9w9ZoJuM3FyWyQ0sCJ64V4ZMKtZKRqTc=
Expand All @@ -259,8 +259,8 @@ github.com/getlantern/pluriconfig v0.0.0-20251126214241-8cc8bc561535 h1:rtDmW8YL
github.com/getlantern/pluriconfig v0.0.0-20251126214241-8cc8bc561535/go.mod h1:WKJEdjMOD4IuTRYwjQHjT4bmqDl5J82RShMLxPAvi0Q=
github.com/getlantern/publicip v0.0.0-20260328175246-2c460fe80c6b h1:gMYJzEhLrmIqQ+JnjiYNm+UyUDalK3WUmVyecFwmV5g=
github.com/getlantern/publicip v0.0.0-20260328175246-2c460fe80c6b/go.mod h1:NpfXdK4ldEKkjQ4P1R+DBF4ua5VFOlxmgHROTnYrApg=
github.com/getlantern/radiance v0.0.0-20260805182705-0aebcab87c89 h1:ZgdE/qPjx7ptpv0msnu4NSReL9neFlXQzC7kDVYty6g=
github.com/getlantern/radiance v0.0.0-20260805182705-0aebcab87c89/go.mod h1:ZfvjwdgV6HbffcH7ZAkLsmt5Vs3TTd4AbWJMajOeyww=
github.com/getlantern/radiance v0.0.0-20260805211630-2d796b8547f6 h1:xT/CetZYUPMAQb+er2F++tLAWpAdPvnFLIXx4WzRv3g=
github.com/getlantern/radiance v0.0.0-20260805211630-2d796b8547f6/go.mod h1:o8LUDlE+kuDlMO4lB5UNXhUmktckkFmChimmPHQu0PI=
github.com/getlantern/samizdat v0.0.3-0.20260724223841-a5ee9ab56830 h1:RZd3CELOtQUEzIE5kPdEO9HYg+7JYbR3OTdC+3P/wng=
github.com/getlantern/samizdat v0.0.3-0.20260724223841-a5ee9ab56830/go.mod h1:uEeykQSW2/6rTjfPlj3MTTo59poSHXfAHTGgzYDkbr0=
github.com/getlantern/semconv v0.0.0-20260327040646-21845dda05cb h1:c5YM7b3a4r2J8Eh89KkI6M/iTFe6Bi+b8AJlfkKdFq4=
Expand Down
16 changes: 16 additions & 0 deletions lantern-core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ type SmartRouting interface {
IsSmartRoutingEnabled() bool
}

type PeerShare interface {
SetPeerShareEnabled(bool) error
IsPeerShareEnabled() bool
}

type VPN interface {
ConnectVPN(tag string) error
SelectServer(tag string) error
Expand All @@ -172,6 +177,7 @@ type Core interface {
SplitTunnel
Ads
SmartRouting
PeerShare
VPN
Client() *ipc.Client
}
Expand Down Expand Up @@ -457,6 +463,16 @@ func (lc *LanternCore) IsSmartRoutingEnabled() bool {
return b
}

func (lc *LanternCore) SetPeerShareEnabled(enabled bool) error {
_, err := lc.client.PatchSettings(lc.ctx, settings.Settings{settings.PeerShareEnabledKey: enabled})
return err
}

func (lc *LanternCore) IsPeerShareEnabled() bool {
b, _ := lc.settings()[settings.PeerShareEnabledKey].(bool)
return b
}

func (lc *LanternCore) IsTelemetryEnabled() bool {
b, _ := lc.settings()[settings.TelemetryKey].(bool)
return b
Expand Down
23 changes: 23 additions & 0 deletions lantern-core/ffi/ffi.go
Original file line number Diff line number Diff line change
Expand Up @@ -1406,6 +1406,29 @@ func isSmartRoutingEnabled() C.int {
return 0
}

//export setPeerProxyEnabled
func setPeerProxyEnabled(enabled C.int) *C.char {
return runOnGoStack(func() *C.char {
c, errStr := requireCore()
if errStr != nil {
return errStr
}
if err := c.SetPeerShareEnabled(enabled != 0); err != nil {
return SendError(err)
}
return C.CString("ok")
})
}

//export isPeerProxyEnabled
func isPeerProxyEnabled() C.int {
c, _ := requireCore()
if c != nil && c.IsPeerShareEnabled() {
Comment on lines +1425 to +1426

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Release the error string allocated on the unavailable-core path.

When the core is unavailable, requireCore allocates a C.CString at Line 61. Line 1425 discards the returned pointer. Repeated calls to isPeerProxyEnabled before initialization can therefore grow the native heap without bound.

Read lanternCore.Load() directly for this getter, or free the error string before returning 0.

🐛 Proposed fix
 func isPeerProxyEnabled() C.int {
-	c, _ := requireCore()
-	if c != nil && c.IsPeerShareEnabled() {
+	c := lanternCore.Load()
+	if c != nil && (*c).IsPeerShareEnabled() {
 		return 1
 	}
 	return 0
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
c, _ := requireCore()
if c != nil && c.IsPeerShareEnabled() {
c := lanternCore.Load()
if c != nil && (*c).IsPeerShareEnabled() {
return 1
}
return 0
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lantern-core/ffi/ffi.go` around lines 1425 - 1426, Update the
isPeerProxyEnabled getter around requireCore so the unavailable-core path does
not leak the allocated C error string: either call lanternCore.Load() directly
or capture and free the error pointer before returning 0, while preserving the
existing IsPeerShareEnabled check for an available core.

return 1
}
return 0
}

//export getSplitTunnelState
func getSplitTunnelState() *C.char {
return runOnGoStack(func() *C.char {
Expand Down
17 changes: 17 additions & 0 deletions lantern-core/mobile/mobile.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,23 @@ func SetSmartRoutingEnabled(enabled bool) error {
})
}

func SetPeerShareEnabled(enabled bool) error {
slog.Info("peer-share: SetPeerShareEnabled", "enabled", enabled)
return withCore(func(c lanterncore.Core) error {
return c.SetPeerShareEnabled(enabled)
})
}

func IsPeerShareEnabled() bool {
ok, err := withCoreR(func(c lanterncore.Core) (bool, error) {
return c.IsPeerShareEnabled(), nil
})
if err != nil {
return false
}
return ok
}

func IsSmartRoutingEnabled() bool {
ok, err := withCoreR(func(c lanterncore.Core) (bool, error) {
return c.IsSmartRoutingEnabled(), nil
Expand Down
Loading