mirror of
https://github.com/netbirdio/netbird.git
synced 2024-12-14 10:50:45 +01:00
small refactor for better code quality in swift
This commit is contained in:
parent
8b8e4bbc6a
commit
ec8eb76b42
@ -214,7 +214,9 @@ func (e *Engine) Start() error {
|
||||
}
|
||||
}
|
||||
|
||||
e.routeManager = routemanager.NewManager(e.ctx, e.config.WgPrivateKey.PublicKey().String(), e.wgInterface, e.statusRecorder, routes, wgAddr)
|
||||
log.Debugf("Initial routes contain %d routes", len(routes))
|
||||
e.routeManager = routemanager.NewManager(e.ctx, e.config.WgPrivateKey.PublicKey().String(), e.wgInterface, e.statusRecorder, routes)
|
||||
e.mobileDep.RouteListener.SetInterfaceIP(wgAddr)
|
||||
e.routeManager.SetRouteChangeListener(e.mobileDep.RouteListener)
|
||||
|
||||
switch runtime.GOOS {
|
||||
@ -225,8 +227,8 @@ func (e *Engine) Start() error {
|
||||
})
|
||||
case "ios":
|
||||
err = e.wgInterface.CreateOniOS(e.mobileDep.FileDescriptor)
|
||||
log.Debugf("wireguardAddress: %s", wgAddr)
|
||||
e.mobileDep.RouteListener.OnNewRouteSetting("", "100.127.93.142/16")
|
||||
log.Debugf("sending initial route range %s to iOS", strings.Join(e.routeManager.InitialRouteRange(), ","))
|
||||
e.mobileDep.RouteListener.OnNewRouteSetting(strings.Join(e.routeManager.InitialRouteRange(), ","))
|
||||
default:
|
||||
err = e.wgInterface.Create()
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ type DefaultManager struct {
|
||||
}
|
||||
|
||||
// NewManager returns a new route manager
|
||||
func NewManager(ctx context.Context, pubKey string, wgInterface *iface.WGIface, statusRecorder *peer.Status, initialRoutes []*route.Route, wgAddr string) *DefaultManager {
|
||||
func NewManager(ctx context.Context, pubKey string, wgInterface *iface.WGIface, statusRecorder *peer.Status, initialRoutes []*route.Route) *DefaultManager {
|
||||
srvRouter, err := newServerRouter(ctx, wgInterface)
|
||||
if err != nil {
|
||||
log.Errorf("server router is not supported: %s", err)
|
||||
@ -50,7 +50,7 @@ func NewManager(ctx context.Context, pubKey string, wgInterface *iface.WGIface,
|
||||
statusRecorder: statusRecorder,
|
||||
wgInterface: wgInterface,
|
||||
pubKey: pubKey,
|
||||
notifier: newNotifier(wgAddr),
|
||||
notifier: newNotifier(),
|
||||
}
|
||||
|
||||
log.Debug("initializing route manager")
|
||||
|
@ -13,12 +13,11 @@ import (
|
||||
// RouteListener is a callback interface for mobile system
|
||||
type RouteListener interface {
|
||||
// OnNewRouteSetting invoke when new route setting has been arrived
|
||||
OnNewRouteSetting(string, string)
|
||||
OnNewRouteSetting(string)
|
||||
SetInterfaceIP(string)
|
||||
}
|
||||
|
||||
type notifier struct {
|
||||
// ownIPAddr is the ip address of the netbird interface including the netmask
|
||||
ownIPAddr string
|
||||
initialRouteRangers []string
|
||||
routeRangers []string
|
||||
|
||||
@ -26,11 +25,8 @@ type notifier struct {
|
||||
routeListenerMux sync.Mutex
|
||||
}
|
||||
|
||||
func newNotifier(ip string) *notifier {
|
||||
log.Debugf("creating notifier with own ip: %s", ip)
|
||||
return ¬ifier{
|
||||
ownIPAddr: ip,
|
||||
}
|
||||
func newNotifier() *notifier {
|
||||
return ¬ifier{}
|
||||
}
|
||||
|
||||
func (n *notifier) setListener(listener RouteListener) {
|
||||
@ -77,8 +73,8 @@ func (n *notifier) notify() {
|
||||
}
|
||||
|
||||
go func(l RouteListener) {
|
||||
log.Debugf("notifying route listener with route ranges: %s and own ip: %s", strings.Join(n.routeRangers, ","), n.ownIPAddr)
|
||||
l.OnNewRouteSetting(strings.Join(n.routeRangers, ","), n.ownIPAddr)
|
||||
log.Debugf("notifying route listener with route ranges: %s", strings.Join(n.routeRangers, ","))
|
||||
l.OnNewRouteSetting(strings.Join(n.routeRangers, ","))
|
||||
}(n.routeListener)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user