Add CGo-safe JSON methods and wrap API methods with RunOffCgoStack#363
Add CGo-safe JSON methods and wrap API methods with RunOffCgoStack#363myleshorton merged 3 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds CGo-safe JSON helper methods to vpn.SplitTunnel, aligning split-tunnel JSON access with the existing “pre-marshalled JSON” patterns used elsewhere in the codebase and moving marshaling closer to where the split tunnel types live.
Changes:
- Add
(*SplitTunnel).ItemsJSON(filterType)to return filter items as JSON viacommon.RunOffCgoStack. - Add
(*SplitTunnel).EnabledAppsJSON()to return enabled app identifiers as JSON viacommon.RunOffCgoStack. - Disambiguate JSON packages by introducing
encoding/jsonfor simple marshaling and aliasingsing/common/jsonassingjsonfor rule set serialization.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Split tunnel: - Add Filter.Items(filterType) to consolidate the read-side switch - Add SplitTunnel.ItemsJSON and EnabledAppsJSON with RunOffCgoStack - Use atomicfile.ReadFile, common.IsWindows(), handle marshal errors - Add tests for both new methods API client: - Wrap UserData, FetchUserData, Login, Logout, DeleteAccount, and OAuthLoginCallback with RunOffCgoStack to avoid CGo write barrier panics when protobuf structs are allocated on the callback stack Fixes getlantern/engineering#3088 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
564f040 to
fb32d1c
Compare
…ustness - ItemsJSON: ensure non-nil slice so empty filters return [] not null - EnabledAppsJSON: use singjson.UnmarshalExtended for legacy file parse (consistent with loadRule which also uses extended JSON) - Windows dedup: lowercase only the dedup key, preserve original values - Tests: unmarshal JSON to []string and assert on slices instead of brittle string matching Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
I think those are the ones I just moved from core.go in lantern to consolidate. |
Per review: bundleId, bundleID, enabledApps, and apps were never valid split-tunnel config keys. Only processPath, processPathRegex, and packageName exist in legacy configs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Call chain verificationBoth methods added in this PR are called from the lantern app via companion PR lantern#8556, which replaces ~90 lines of duplicated logic with thin wrappers:
Both methods use |
Summary
Filter.Items(filterType)method to consolidate the read-side filter type switchSplitTunnel.ItemsJSONandSplitTunnel.EnabledAppsJSONwithRunOffCgoStack[]byte-returningAPIClientmethods withRunOffCgoStack:UserData,FetchUserData,Login,Logout,DeleteAccount,OAuthLoginCallbackServersJSON()pattern: radiance owns data + marshaling on a real Go goroutineMotivation
Gomobile-exported functions run on a CGo callback stack whose memory is not covered by the GC heap bitmap. When these methods allocate protobuf structs, maps, or slices and marshal them to
[]byte,bulkBarrierPreWritepanics when copying the return value across the C boundary.Companion PR
Test plan
Fixes getlantern/engineering#3088
🤖 Generated with Claude Code