Repository navigation
apple: let a provider subclass answer its own app messages - #349
Merged
aimalygin merged 1 commit intoNov 24, 2026
Merged
Conversation
XrayPacketTunnelProvider keeps its runtime private and answers only the stats and close-connections requests, so a host app could not ask its tunnel for the connection, accounting, selection or health snapshot, pin a selector group or replace the routing policy without forking the provider. Add an open handleCustomAppMessage(_:core:) hook. handleAppMessage calls it with the active core for every message after the close-connections request and before the stats request; a non-nil result is sent back, nil falls through to the built-in handling. The default returns nil, so existing hosts see no change.
huzgnm
pushed a commit
to huzgnm/xray-rust
that referenced
this pull request
Nov 24, 2026
handleAppMessage dropped a message that is not valid UTF-8 before the hook aimalygin#349 added could see it, while the hook's documentation promises every message the provider does not handle itself. A host whose app and extension speak a binary format, a property list or protobuf, would have had its messages answered with nil. The provider now decodes the text only to recognise its own requests, which are text: a message that is not names none of them, goes to the hook, and without an answer from it gets nil as before. Hosts that do not override the hook see no change.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
XrayPacketTunnelProviderkeeps its runtime private and answers only the stats and close-connections requests, so a host app cannot ask its tunnel for the connection, accounting, selection or health snapshot, pin a selector group or replace the routing policy without forking the provider.This adds an open
handleCustomAppMessage(_:core:)hook.handleAppMessagecalls it with the active core for every message after the close-connections request and before the stats request; a non-nil result is sent back,nilfalls through to the built-in handling. The default returnsnil, so existing hosts see no change.I use it in an iOS client to show open connections with per-route traffic, show and pin the server a
leastPingbalancer picked, and apply routing changes withreplaceRoutingPolicywithout reconnecting. The README gets a short example; the CHANGELOG gets an Unreleased entry.Verification
niland the built-in requests are handled before / after it unchangedplatform/apple/README.md,CHANGELOG.mdCompatibility and security
Additive Swift API in
XrayAppleTunnel(one new open method with a default). No change to the C ABI, the Kotlin adapter, provider configuration keys or the built-in messages. A subclass decides what it exposes to its own app; nothing new leaves the extension by default.