Skip to content

Commit 8cbb4d3

Browse files
garmr-ulfrjigar-f
andauthored
update to new radiance IPC API (#8417)
* update to new radiance API * update ad-block functions, add smart-routing functions * add smart-routing interface to lantern-core * clean up * update radiance * update radiance to main * fix merge mistake * update radiance --------- Co-authored-by: Jigar-f <jigar@getlantern.org>
1 parent 744a5a3 commit 8cbb4d3

9 files changed

Lines changed: 75 additions & 117 deletions

File tree

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ require (
2323
github.com/alecthomas/assert/v2 v2.3.0
2424
github.com/getlantern/golog v0.0.0-20230503153817-8e72de7e0a65
2525
github.com/getlantern/lantern-server-provisioner v0.0.0-20251031121934-8ea031fccfa9
26-
github.com/getlantern/radiance v0.0.0-20260113092341-a3ea14436e88
26+
github.com/getlantern/radiance v0.0.0-20260115194915-586fbb198516
2727
github.com/sagernet/sing-box v1.12.13
2828
golang.org/x/mobile v0.0.0-20250711185624-d5bb5ecc55c0
2929
golang.org/x/sys v0.40.0
@@ -165,7 +165,7 @@ require (
165165
github.com/getlantern/algeneva v0.0.0-20250307163401-1824e7b54f52 // indirect
166166
github.com/getlantern/amp v0.0.0-20251211213807-4cbc22624b9f // indirect
167167
github.com/getlantern/appdir v0.0.0-20250324200952-507a0625eb01 // indirect
168-
github.com/getlantern/common v1.2.1-0.20251223145917-671181028168 // indirect
168+
github.com/getlantern/common v1.2.1-0.20260113231444-c651c79beddf // indirect
169169
github.com/getlantern/dnstt v0.0.0-20250530230749-4d64f4edcf0f // indirect
170170
github.com/getlantern/fronted v0.0.0-20260105215156-9ae1d001d54f // indirect
171171
github.com/getlantern/geo v0.0.0-20241129152027-2fc88c10f91e // indirect

go.sum

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ github.com/getlantern/amp v0.0.0-20251211213807-4cbc22624b9f h1:EaMXfKXz+zPM6Jb1
192192
github.com/getlantern/amp v0.0.0-20251211213807-4cbc22624b9f/go.mod h1:qnMv9szb8JK3kA9W4N2FlYUMj1GkA0x7QEUEPD7tk4o=
193193
github.com/getlantern/appdir v0.0.0-20250324200952-507a0625eb01 h1:Mmeh4/DA1OKN9tVWRAvTL5efFx4c7v9/55hoK17NclA=
194194
github.com/getlantern/appdir v0.0.0-20250324200952-507a0625eb01/go.mod h1:3vR6+jQdWfWojZ77w+htCqEF5MO/Y2twJOpAvFuM9po=
195-
github.com/getlantern/common v1.2.1-0.20251223145917-671181028168 h1:u3oLCACdQJ3n4KmfntUVUiT/HOVOXpoVjD1EKaEnKEg=
196-
github.com/getlantern/common v1.2.1-0.20251223145917-671181028168/go.mod h1:eSSuV4bMPgQJnczBw+KWWqWNo1itzmVxC++qUBPRTt0=
195+
github.com/getlantern/common v1.2.1-0.20260113231444-c651c79beddf h1:V9WBvzGjScaGSe7yu4/dX+R3jQOK9xD64v8lSONbS/c=
196+
github.com/getlantern/common v1.2.1-0.20260113231444-c651c79beddf/go.mod h1:eSSuV4bMPgQJnczBw+KWWqWNo1itzmVxC++qUBPRTt0=
197197
github.com/getlantern/context v0.0.0-20190109183933-c447772a6520/go.mod h1:L+mq6/vvYHKjCX2oez0CgEAJmbq1fbb/oNJIWQkBybY=
198198
github.com/getlantern/context v0.0.0-20220418194847-3d5e7a086201 h1:oEZYEpZo28Wdx+5FZo4aU7JFXu0WG/4wJWese5reQSA=
199199
github.com/getlantern/context v0.0.0-20220418194847-3d5e7a086201/go.mod h1:Y9WZUHEb+mpra02CbQ/QczLUe6f0Dezxaw5DCJlJQGo=
@@ -243,8 +243,10 @@ github.com/getlantern/osversion v0.0.0-20240418205916-2e84a4a4e175 h1:JWH5BB2o0e
243243
github.com/getlantern/osversion v0.0.0-20240418205916-2e84a4a4e175/go.mod h1:h3S9LBmmzN/xM+lwYZHE4abzTtCTtidKtG+nxZcCZX0=
244244
github.com/getlantern/pluriconfig v0.0.0-20251126214241-8cc8bc561535 h1:rtDmW8YLAuT8r51ApR5z0d8/qjhHu3TW+divQ2C98Ac=
245245
github.com/getlantern/pluriconfig v0.0.0-20251126214241-8cc8bc561535/go.mod h1:WKJEdjMOD4IuTRYwjQHjT4bmqDl5J82RShMLxPAvi0Q=
246-
github.com/getlantern/radiance v0.0.0-20260113092341-a3ea14436e88 h1:aHW83fEMIYKAZuEygcC5X4AMPl+ndh1OrmpXHvAmR8M=
247-
github.com/getlantern/radiance v0.0.0-20260113092341-a3ea14436e88/go.mod h1:6el6Vi2wTVtE9n6JFfWf0Pqz0LYFX48g73xewsE/39w=
246+
github.com/getlantern/radiance v0.0.0-20260115175031-8a15f3904554 h1:D4IE1hI79sPrTHp5fJ5ng+eI49npsaA5h03iDUvE8P0=
247+
github.com/getlantern/radiance v0.0.0-20260115175031-8a15f3904554/go.mod h1:6yTHFlwLnaKHPDhbyYn1ohPb/8N3MiwRa9hBok6TquM=
248+
github.com/getlantern/radiance v0.0.0-20260115194915-586fbb198516 h1:nZbZpWW+1Nc4ap4Wx0FFtf+hpqpdpuhi88aKlYhoyVU=
249+
github.com/getlantern/radiance v0.0.0-20260115194915-586fbb198516/go.mod h1:6yTHFlwLnaKHPDhbyYn1ohPb/8N3MiwRa9hBok6TquM=
248250
github.com/getlantern/sing v0.7.14-0.20251208213946-adbf4abe8692 h1:pK9igrNx0ipBe6xGDgwVnob3JCFwOp2bmEizwanDVk4=
249251
github.com/getlantern/sing v0.7.14-0.20251208213946-adbf4abe8692/go.mod h1:ARkL0gM13/Iv5VCZmci/NuoOlePoIsW0m7BWfln/Hak=
250252
github.com/getlantern/sing-box-minimal v1.12.13-0.20251205011046-be268b083378 h1:qUUykWom/NFUfQhEVNJ7SsKXYTDP27nTCEoqY78FtOA=

lantern-core/cmd/lanternsvc/main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ import (
1616
"syscall"
1717
"unsafe"
1818

19-
"github.com/getlantern/lantern/lantern-core/common"
20-
"github.com/getlantern/lantern/lantern-core/wintunmgr"
2119
"golang.org/x/sys/windows"
2220
"golang.org/x/sys/windows/svc"
2321

22+
"github.com/getlantern/lantern/lantern-core/common"
23+
"github.com/getlantern/lantern/lantern-core/wintunmgr"
24+
2425
rcommon "github.com/getlantern/radiance/common"
2526
)
2627

@@ -45,7 +46,7 @@ func init() {
4546

4647
func main() {
4748
// Initialize radiance to ensure our directories and logging are set up.
48-
rcommon.Init("", "", "debug")
49+
rcommon.InitReadOnly("", "", "trace")
4950
consoleMode := flag.Bool("console", false, "Run in console mode instead of Windows service")
5051
flag.Parse()
5152

lantern-core/core.go

Lines changed: 15 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ const (
3333
EventTypeConfig EventType = "config"
3434
EventTypeServerLocation EventType = "server-location"
3535
DefaultLogLevel = "trace"
36-
defaultAdBlockURL = "https://raw.githubusercontent.com/REIJI007/AdBlock_Rule_For_Sing-box/main/adblock_reject.json"
37-
adBlockSettingsFile = "adblock.json"
3836
)
3937

4038
// LanternCore is the main structure accessing the Lantern backend.
@@ -45,7 +43,6 @@ type LanternCore struct {
4543
apiClient *api.APIClient
4644
initOnce sync.Once
4745
eventEmitter utils.FlutterEventEmitter
48-
adBlocker *adBlockerStub
4946
}
5047

5148
var (
@@ -130,13 +127,19 @@ type Ads interface {
130127
IsBlockAdsEnabled() bool
131128
}
132129

130+
type SmartRouting interface {
131+
SetSmartRoutingEnabled(bool) error
132+
IsSmartRoutingEnabled() bool
133+
}
134+
133135
type Core interface {
134136
App
135137
User
136138
Payment
137139
PrivateServer
138140
SplitTunnel
139141
Ads
142+
SmartRouting
140143
}
141144

142145
// Make sure LanternCore implements the Core interface
@@ -189,7 +192,6 @@ func (lc *LanternCore) initialize(opts *utils.Opts, eventEmitter utils.FlutterEv
189192
lc.serverManager = lc.rad.ServerManager()
190193
lc.apiClient = lc.rad.APIHandler()
191194
lc.eventEmitter = eventEmitter
192-
lc.adBlocker = newAdBlockerStub(settings.GetString(settings.DataPathKey), defaultAdBlockURL)
193195

194196
// Listen for config updates and notify Flutter
195197
events.Subscribe(func(evt config.NewConfigEvent) {
@@ -737,88 +739,24 @@ func (lc *LanternCore) RevokeServerManagerInvite(ip, port, accessToken, inviteNa
737739
}
738740

739741
func (lc *LanternCore) SetBlockAdsEnabled(enabled bool) error {
740-
if lc.adBlocker == nil {
741-
lc.adBlocker = newAdBlockerStub(settings.GetString(settings.DataPathKey), defaultAdBlockURL)
742-
}
743-
if err := lc.adBlocker.SetEnabled(enabled); err != nil {
744-
return err
745-
}
746-
return nil
742+
return vpn.SetAdBlock(enabled)
747743
}
748744

749745
func (lc *LanternCore) IsBlockAdsEnabled() bool {
750-
if lc.adBlocker == nil {
751-
return false
752-
}
753-
return lc.adBlocker.IsEnabled()
754-
}
755-
756-
func (lc *LanternCore) AddServerBasedOnURLs(urls string, skipCertVerification bool) error {
757-
slog.Debug("Adding server based on URLs", "urls", urls, "skipCertVerification", skipCertVerification)
758-
return lc.serverManager.AddServerBasedOnURLs(context.Background(), urls, skipCertVerification)
759-
}
760-
761-
type adBlockerStub struct {
762-
mu sync.RWMutex
763-
path string
764-
enabled bool
765-
url string
766-
}
767-
768-
type adBlockSettings struct {
769-
Enabled bool `json:"enabled"`
770-
URL string `json:"url,omitempty"`
746+
return vpn.AdBlockEnabled()
771747
}
772748

773-
func newAdBlockerStub(basePath, defaultURL string) *adBlockerStub {
774-
ab := &adBlockerStub{
775-
path: filepath.Join(basePath, adBlockSettingsFile),
776-
url: defaultURL,
777-
}
778-
ab.load()
779-
return ab
749+
func (lc *LanternCore) SetSmartRoutingEnabled(enabled bool) error {
750+
return vpn.SetSmartRouting(enabled)
780751
}
781752

782-
func (a *adBlockerStub) load() {
783-
a.mu.Lock()
784-
defer a.mu.Unlock()
785-
data, err := os.ReadFile(a.path)
786-
if err != nil || len(data) == 0 {
787-
return
788-
}
789-
var s adBlockSettings
790-
if err := json.Unmarshal(data, &s); err == nil {
791-
a.enabled = s.Enabled
792-
if s.URL != "" {
793-
a.url = s.URL
794-
}
795-
}
753+
func (lc *LanternCore) IsSmartRoutingEnabled() bool {
754+
return vpn.SmartRoutingEnabled()
796755
}
797756

798-
func (a *adBlockerStub) save() error {
799-
a.mu.RLock()
800-
defer a.mu.RUnlock()
801-
b, err := json.Marshal(adBlockSettings{
802-
Enabled: a.enabled,
803-
URL: a.url,
804-
})
805-
if err != nil {
806-
return err
807-
}
808-
return os.WriteFile(a.path, b, 0644)
809-
}
810-
811-
func (a *adBlockerStub) SetEnabled(v bool) error {
812-
a.mu.Lock()
813-
a.enabled = v
814-
a.mu.Unlock()
815-
return a.save()
816-
}
817-
818-
func (a *adBlockerStub) IsEnabled() bool {
819-
a.mu.RLock()
820-
defer a.mu.RUnlock()
821-
return a.enabled
757+
func (lc *LanternCore) AddServerBasedOnURLs(urls string, skipCertVerification bool) error {
758+
slog.Debug("Adding server based on URLs", "urls", urls, "skipCertVerification", skipCertVerification)
759+
return lc.serverManager.AddServerBasedOnURLs(context.Background(), urls, skipCertVerification)
822760
}
823761

824762
// splitCSVClean splits a comma-separated string into a stable list

lantern-core/ffi/ffi.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,3 +971,24 @@ func isBlockAdsEnabled() C.int {
971971
}
972972
return 0
973973
}
974+
975+
//export setSmartRoutingEnabled
976+
func setSmartRoutingEnabled(enabled C.int) *C.char {
977+
c, errStr := requireCore()
978+
if errStr != nil {
979+
return errStr
980+
}
981+
if err := c.SetSmartRoutingEnabled(enabled != 0); err != nil {
982+
return SendError(err)
983+
}
984+
return C.CString("ok")
985+
}
986+
987+
//export isSmartRoutingEnabled
988+
func isSmartRoutingEnabled() C.int {
989+
c, _ := requireCore()
990+
if c != nil && c.IsSmartRoutingEnabled() {
991+
return 1
992+
}
993+
return 0
994+
}

lantern-core/mobile/mobile.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ import (
1010
"github.com/sagernet/sing-box/experimental/libbox"
1111
_ "golang.org/x/mobile/bind"
1212

13+
"github.com/getlantern/radiance/common"
14+
1315
lanterncore "github.com/getlantern/lantern/lantern-core"
1416
"github.com/getlantern/lantern/lantern-core/utils"
1517
"github.com/getlantern/lantern/lantern-core/vpn_tunnel"
16-
"github.com/getlantern/radiance/common"
1718
)
1819

1920
var (
@@ -92,6 +93,23 @@ func IsBlockAdsEnabled() bool {
9293
return ok
9394
}
9495

96+
func SetSmartRoutingEnabled(enabled bool) error {
97+
slog.Info("smart-routing: SetSmartRoutingEnabled", "enabled", enabled)
98+
return withCore(func(c lanterncore.Core) error {
99+
return c.SetSmartRoutingEnabled(enabled)
100+
})
101+
}
102+
103+
func IsSmartRoutingEnabled() bool {
104+
ok, err := withCoreR(func(c lanterncore.Core) (bool, error) {
105+
return c.IsSmartRoutingEnabled(), nil
106+
})
107+
if err != nil {
108+
return false
109+
}
110+
return ok
111+
}
112+
95113
func AvailableFeatures() []byte {
96114
b, err := withCoreR(func(c lanterncore.Core) ([]byte, error) { return c.AvailableFeatures(), nil })
97115
if err != nil {

lantern-core/types/location.go

Lines changed: 0 additions & 24 deletions
This file was deleted.

lantern-core/vpn_tunnel/vpn_tunnel.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const (
2626
func StartVPN(platform libbox.PlatformInterface, opts *utils.Opts) error {
2727
// As soon user connects to VPN, we start listening for auto location changes.
2828
slog.Info("StartVPN called")
29-
if err := initCommon(opts); err != nil {
29+
if err := initCommon(opts, platform); err != nil {
3030
return fmt.Errorf("failed to initialize common: %w", err)
3131
}
3232
// it should use InternalTagLantern so it will connect to best lantern server by default.
@@ -48,7 +48,7 @@ func StopVPN() error {
4848
// VPN tunnel if it's not already running.
4949
func ConnectToServer(group, tag string, platIfce libbox.PlatformInterface, opts *utils.Opts) error {
5050
slog.Debug("ConnectToServer called", "group", group, "tag", tag)
51-
if err := initCommon(opts); err != nil {
51+
if err := initCommon(opts, platIfce); err != nil {
5252
return fmt.Errorf("failed to initialize common: %w", err)
5353
}
5454
switch group {
@@ -81,17 +81,18 @@ func GetSelectedServer() string {
8181
return status.SelectedServer
8282
}
8383

84-
func initCommon(opts *utils.Opts) error {
84+
func initCommon(opts *utils.Opts, platIfce libbox.PlatformInterface) error {
8585
// Since this will start as a new process, we need to ask for path and logger.
8686
// This ensures options are correctly set for the new process.
87-
if radianceCommon.IsIOS() || radianceCommon.IsMacOS() {
87+
platIfceFn := func() libbox.PlatformInterface { return platIfce }
88+
if radianceCommon.IsIOS() || radianceCommon.IsMacOS() || radianceCommon.IsAndroid() {
8889
slog.Debug("Initializing common for Apple platforms", "dataDir", opts.DataDir, "logDir:",
8990
opts.LogDir, "logLevel:", opts.LogLevel)
90-
if err := radianceCommon.Init(opts.DataDir, opts.LogDir, opts.LogLevel); err != nil {
91+
if _, err := vpn.InitIPC(opts.DataDir, opts.LogDir, opts.LogLevel, platIfceFn); err != nil {
9192
return fmt.Errorf("failed to initialize common: %w", err)
9293
}
9394
} else if radianceCommon.IsWindows() {
94-
if err := radianceCommon.Init("", "", "debug"); err != nil {
95+
if _, err := vpn.InitIPC("", "", opts.LogLevel, platIfceFn); err != nil {
9596
return fmt.Errorf("failed to initialize common: %w", err)
9697
}
9798
}

lib/features/home/data_usage.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class DataUsage extends ConsumerWidget {
2222
return const SizedBox.shrink();
2323
}
2424
final dataCap = dataCapResponse.usage!;
25+
appLogger.info("dataCap: $dataCap");
2526

2627
/// Do all math in BYTES
2728
final int totalBytes = dataCap.bytesAllotted;

0 commit comments

Comments
 (0)