-
-
Notifications
You must be signed in to change notification settings - Fork 929
[android] allow selection/deselection of network resources on android peers #4607
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
Open
doromaraujo
wants to merge
30
commits into
netbirdio:main
Choose a base branch
from
doromaraujo:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
f088b4a
Export RenewFD function for Android
pappz b2fbdfa
[client] add initial implementation of RenewTun for android device
doromaraujo c58ccc5
[android] add usage of routeSelector when retrieving networks
doromaraujo 6e57e55
[android] add route commands to toggle routes
doromaraujo 51b664c
[android] add state file path to android client constructor and struct
doromaraujo 880ec01
[client] add android check to use mobile dependency's StateFilePath
doromaraujo 9016f5d
[client] pass state file to be set as mobile dependency to RunOnAndroid
doromaraujo 53d706a
Revert changed todo message
doromaraujo 41fc5aa
[android] Add peer routes to peers and network domains to networks
doromaraujo 970e3de
[android] Add resolved IP addresses to network domains
doromaraujo 0190059
Merge branch 'main' into feature/android-allow-selecting-routes
doromaraujo eed622d
[android] Add rudimentary implementation of RenewableTUN
doromaraujo 369a560
[android] Add some nil checks to tun.Device implementations on Renewa…
doromaraujo e67cd45
[android] Add usage of RenewableTUN when renewing tun fd on android
doromaraujo 040ed99
[android] Use mutex when peeking, dequeueing and adding to devices list
doromaraujo 4e094f8
Merge branch 'netbirdio:main' into main
doromaraujo fb864e5
[test] Add missing RenewFd mock to MockWGIface used in engine_test
doromaraujo 971eea3
[client] Add missing RenewTun implementation
doromaraujo 546d022
[test] remove unused definition from MockWGIface struct
doromaraujo 039c940
[client] add go:build android to new android files
doromaraujo 90a7846
[client] sort imports, fix typo
doromaraujo 4ff93da
[android] add PlatformFiles interface to group config and state file …
doromaraujo 3e3c284
Merge remote-tracking branch 'upstream/main'
doromaraujo e1d4d24
[client] Move constructor to under type definition
doromaraujo 23c4277
[client] Export AddDevice function in RenewableTUN
doromaraujo 6dc4d57
[client] Wrap RenewableTUN's device with closeAwareDevice
doromaraujo 4fe4566
[client] replace closeAwareDevice bool with atomic.Bool
doromaraujo 96b39e1
[client] Change AddDevice logic
doromaraujo 59d051d
[client] Refactor RenewableTUN to wait for new
doromaraujo e85c0d6
[client] Add some commentary to RenewableTUN
doromaraujo 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| //go:build android | ||
|
|
||
| package android | ||
|
|
||
| import "fmt" | ||
|
|
||
| type ResolvedIPs struct { | ||
| resolvedIPs []string | ||
| } | ||
|
|
||
| func (r *ResolvedIPs) Add(ipAddress string) { | ||
| r.resolvedIPs = append(r.resolvedIPs, ipAddress) | ||
| } | ||
|
|
||
| func (r *ResolvedIPs) Get(i int) (string, error) { | ||
| if i < 0 || i >= len(r.resolvedIPs) { | ||
| return "", fmt.Errorf("%d is out of range", i) | ||
| } | ||
| return r.resolvedIPs[i], nil | ||
| } | ||
|
|
||
| func (r *ResolvedIPs) Size() int { | ||
| return len(r.resolvedIPs) | ||
| } | ||
|
|
||
| type NetworkDomain struct { | ||
| Address string | ||
| resolvedIPs ResolvedIPs | ||
| } | ||
|
|
||
| func (d *NetworkDomain) addResolvedIP(resolvedIP string) { | ||
| d.resolvedIPs.Add(resolvedIP) | ||
| } | ||
|
|
||
| func (d *NetworkDomain) GetResolvedIPs() *ResolvedIPs { | ||
| return &d.resolvedIPs | ||
| } | ||
|
|
||
| type NetworkDomains struct { | ||
| domains []NetworkDomain | ||
| } | ||
|
|
||
| func (n *NetworkDomains) Add(domain NetworkDomain) { | ||
| n.domains = append(n.domains, domain) | ||
| } | ||
|
|
||
| func (n *NetworkDomains) Get(i int) (*NetworkDomain, error) { | ||
| if i < 0 || i >= len(n.domains) { | ||
| return nil, fmt.Errorf("%d is out of range", i) | ||
| } | ||
| return &n.domains[i], nil | ||
| } | ||
|
|
||
| func (n *NetworkDomains) Size() int { | ||
| return len(n.domains) | ||
| } | ||
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,20 @@ | ||
| //go:build android | ||
|
|
||
| package android | ||
|
|
||
| import "fmt" | ||
|
|
||
| type PeerRoutes struct { | ||
| routes []string | ||
| } | ||
|
|
||
| func (p *PeerRoutes) Get(i int) (string, error) { | ||
| if i < 0 || i >= len(p.routes) { | ||
| return "", fmt.Errorf("%d is out of range", i) | ||
| } | ||
| return p.routes[i], nil | ||
| } | ||
|
|
||
| func (p *PeerRoutes) Size() int { | ||
| return len(p.routes) | ||
| } |
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,10 @@ | ||
| //go:build android | ||
|
|
||
| package android | ||
|
|
||
| // PlatformFiles groups paths to files used internally by the engine that can't be created/modified | ||
| // at their default locations due to android OS restrictions. | ||
| type PlatformFiles interface { | ||
| ConfigurationFilePath() string | ||
| StateFilePath() string | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid returning pointers to slice elements
Gethands out a pointer to an element stored by value inn.domains. As soon as anotherAddtriggers slice reallocation, that pointer will reference the old backing array, so any mutations (e.g., adding resolved IPs) drift out of sync with the data the slice actually holds. This leads to silent data loss and hard-to-debug races once the collection grows. Please keep pointers in the slice (e.g.,[]*NetworkDomain) or return copies so callers never retain invalid addresses.Apply this diff to eliminate the dangling-pointer hazard:
🤖 Prompt for AI Agents