-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[client] Support embed.Client on Android with netstack mode #5623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| //go:build android | ||
|
|
||
| package internal | ||
|
|
||
| import ( | ||
| "net/netip" | ||
|
|
||
| "github.com/netbirdio/netbird/client/internal/dns" | ||
| "github.com/netbirdio/netbird/client/internal/listener" | ||
| "github.com/netbirdio/netbird/client/internal/stdnet" | ||
| ) | ||
|
|
||
| // noopIFaceDiscover is a stub ExternalIFaceDiscover for embed.Client on Android. | ||
| // It returns an empty interface list, which means ICE P2P candidates won't be | ||
| // discovered — connections will fall back to relay. Applications that need P2P | ||
| // should provide a real implementation via runOnAndroidEmbed that uses | ||
| // Android's ConnectivityManager to enumerate network interfaces. | ||
| type noopIFaceDiscover struct{} | ||
|
|
||
| func (noopIFaceDiscover) IFaces() (string, error) { | ||
| // Return empty JSON array — no local interfaces advertised for ICE. | ||
| // This is intentional: without Android's ConnectivityManager, we cannot | ||
| // reliably enumerate interfaces (netlink is restricted on Android 11+). | ||
| // Relay connections still work; only P2P hole-punching is disabled. | ||
| return "[]", nil | ||
| } | ||
|
|
||
| // noopNetworkChangeListener is a stub for embed.Client on Android. | ||
| // Network change events are ignored since the embed client manages its own | ||
| // reconnection logic via the engine's built-in retry mechanism. | ||
| type noopNetworkChangeListener struct{} | ||
|
|
||
| func (noopNetworkChangeListener) OnNetworkChanged(string) { | ||
| // No-op: embed.Client relies on the engine's internal reconnection | ||
| // logic rather than OS-level network change notifications. | ||
| } | ||
|
|
||
| func (noopNetworkChangeListener) SetInterfaceIP(string) { | ||
| // No-op: in netstack mode, the overlay IP is managed by the userspace | ||
| // network stack, not by OS-level interface configuration. | ||
| } | ||
|
|
||
| // noopDnsReadyListener is a stub for embed.Client on Android. | ||
| // DNS readiness notifications are not needed in netstack/embed mode | ||
| // since system DNS is disabled and DNS resolution happens externally. | ||
| type noopDnsReadyListener struct{} | ||
|
|
||
| func (noopDnsReadyListener) OnReady() { | ||
| // No-op: embed.Client does not need DNS readiness notifications. | ||
| // System DNS is disabled in netstack mode. | ||
| } | ||
|
|
||
| var _ stdnet.ExternalIFaceDiscover = noopIFaceDiscover{} | ||
| var _ listener.NetworkChangeListener = noopNetworkChangeListener{} | ||
| var _ dns.ReadyListener = noopDnsReadyListener{} | ||
|
|
||
| func init() { | ||
| // Wire up the default override so embed.Client.Start() works on Android | ||
| // with netstack mode. Provides complete no-op stubs for all mobile | ||
| // dependencies so the engine's existing Android code paths work unchanged. | ||
| // Applications that need P2P ICE or real DNS should replace this by | ||
| // setting androidRunOverride before calling Start(). | ||
| androidRunOverride = func(c *ConnectClient, runningChan chan struct{}, logPath string) error { | ||
| return c.runOnAndroidEmbed( | ||
| noopIFaceDiscover{}, | ||
| noopNetworkChangeListener{}, | ||
| []netip.AddrPort{}, | ||
| noopDnsReadyListener{}, | ||
| runningChan, | ||
| logPath, | ||
| ) | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| //go:build android | ||
|
|
||
| package internal | ||
|
|
||
| import ( | ||
| "net/netip" | ||
|
|
||
| "github.com/netbirdio/netbird/client/internal/dns" | ||
| "github.com/netbirdio/netbird/client/internal/listener" | ||
| "github.com/netbirdio/netbird/client/internal/stdnet" | ||
| ) | ||
|
|
||
| // runOnAndroidEmbed is like RunOnAndroid but accepts a runningChan | ||
| // so embed.Client.Start() can detect when the engine is ready. | ||
| // It provides complete MobileDependency so the engine's existing | ||
| // Android code paths work unchanged. | ||
| func (c *ConnectClient) runOnAndroidEmbed( | ||
| iFaceDiscover stdnet.ExternalIFaceDiscover, | ||
| networkChangeListener listener.NetworkChangeListener, | ||
| dnsAddresses []netip.AddrPort, | ||
| dnsReadyListener dns.ReadyListener, | ||
| runningChan chan struct{}, | ||
| logPath string, | ||
| ) error { | ||
| mobileDependency := MobileDependency{ | ||
| IFaceDiscover: iFaceDiscover, | ||
| NetworkChangeListener: networkChangeListener, | ||
| HostDNSAddresses: dnsAddresses, | ||
| DnsReadyListener: dnsReadyListener, | ||
| } | ||
| return c.run(mobileDependency, runningChan, logPath) | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.