-
-
Notifications
You must be signed in to change notification settings - Fork 906
[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
22
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 20 commits
Commits
Show all changes
22 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 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,65 @@ | ||
//go:build android | ||
|
||
package android | ||
|
||
import ( | ||
"fmt" | ||
"github.com/netbirdio/netbird/client/internal/routemanager" | ||
"github.com/netbirdio/netbird/route" | ||
log "github.com/sirupsen/logrus" | ||
"golang.org/x/exp/maps" | ||
) | ||
|
||
func toggleRoute(id string, manager routemanager.Manager, | ||
operationName string, | ||
routeOperation func(routes []route.NetID, allRoutes []route.NetID) error) error { | ||
netID := route.NetID(id) | ||
routes := []route.NetID{netID} | ||
|
||
log.Debugf("%s with id: %s", operationName, id) | ||
|
||
if err := routeOperation(routes, maps.Keys(manager.GetClientRoutesWithNetID())); err != nil { | ||
log.Debugf("error when %s: %s", operationName, err) | ||
return fmt.Errorf("error %s: %w", operationName, err) | ||
} | ||
|
||
manager.TriggerSelection(manager.GetClientRoutes()) | ||
|
||
return nil | ||
} | ||
|
||
type routeCommand interface { | ||
toggleRoute() error | ||
} | ||
|
||
type selectRouteCommand struct { | ||
route string | ||
manager routemanager.Manager | ||
} | ||
|
||
func (s selectRouteCommand) toggleRoute() error { | ||
routeSelector := s.manager.GetRouteSelector() | ||
if routeSelector == nil { | ||
return fmt.Errorf("no route selector available") | ||
} | ||
|
||
routeOperation := func(routes []route.NetID, allRoutes []route.NetID) error { | ||
return routeSelector.SelectRoutes(routes, true, allRoutes) | ||
} | ||
|
||
return toggleRoute(s.route, s.manager, "selecting route", routeOperation) | ||
} | ||
|
||
type deselectRouteCommand struct { | ||
route string | ||
manager routemanager.Manager | ||
} | ||
|
||
func (d deselectRouteCommand) toggleRoute() error { | ||
routeSelector := d.manager.GetRouteSelector() | ||
if routeSelector == nil { | ||
return fmt.Errorf("no route selector available") | ||
} | ||
|
||
return toggleRoute(d.route, d.manager, "deselecting route", routeSelector.DeselectRoutes) | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.