mirror of
https://github.com/netbirdio/netbird.git
synced 2026-08-28 02:21:30 +02:00
Android startup opened a throwaway Sync stream to management before creating the TUN device, only to learn the initial routes, DNS config and the DNS feature flag. Server side this computed a full network map and broadcast a false connect/disconnect pair to every peer in the account on every Android start; client side it put a blocking network round trip on the critical startup path and failed the whole engine start when management was unreachable. None of its outputs are needed upfront anymore: the TUN is created empty and the first sync triggers a rebuild that pulls the fresh route and search domain state, the permanent DNS server starts with an empty config that the first sync populates, and the fake IP manager is created lazily when the DNS feature flag turns on. Remove readInitialSettings and its plumbing: the InitialRoutes and DNSFeatureFlag manager config fields, the android construction-time route setup, the initial-route bookkeeping in the notifiers and the now-unused GetNetworkMap client method.
152 lines
5.0 KiB
Go
152 lines
5.0 KiB
Go
package routemanager
|
|
|
|
import (
|
|
"context"
|
|
|
|
firewall "github.com/netbirdio/netbird/client/firewall/manager"
|
|
"github.com/netbirdio/netbird/client/iface"
|
|
"github.com/netbirdio/netbird/client/internal/listener"
|
|
"github.com/netbirdio/netbird/client/internal/routeselector"
|
|
"github.com/netbirdio/netbird/client/internal/statemanager"
|
|
"github.com/netbirdio/netbird/route"
|
|
)
|
|
|
|
// MockManager is the mock instance of a route manager
|
|
type MockManager struct {
|
|
ClassifyRoutesFunc func(routes []*route.Route) (map[route.ID]*route.Route, route.HAMap)
|
|
UpdateRoutesFunc func(updateSerial uint64, serverRoutes map[route.ID]*route.Route, clientRoutes route.HAMap, useNewDNSRoute bool) error
|
|
TriggerSelectionFunc func(haMap route.HAMap)
|
|
SelectRoutesFunc func(ids []route.NetID, appendRoute bool) error
|
|
DeselectRoutesFunc func(ids []route.NetID) error
|
|
GetRouteSelectorFunc func() *routeselector.RouteSelector
|
|
GetClientRoutesFunc func() route.HAMap
|
|
GetSelectedClientRoutesFunc func() route.HAMap
|
|
GetActiveClientRoutesFunc func() route.HAMap
|
|
GetClientRoutesWithNetIDFunc func() map[route.NetID][]*route.Route
|
|
StopFunc func(manager *statemanager.Manager)
|
|
}
|
|
|
|
func (m *MockManager) Init() error {
|
|
return nil
|
|
}
|
|
|
|
// CurrentRouteRange mock implementation of CurrentRouteRange from Manager interface
|
|
func (m *MockManager) CurrentRouteRange() []string {
|
|
return nil
|
|
}
|
|
|
|
// UpdateRoutes mock implementation of UpdateRoutes from Manager interface
|
|
func (m *MockManager) UpdateRoutes(updateSerial uint64, newRoutes map[route.ID]*route.Route, clientRoutes route.HAMap, useNewDNSRoute bool) error {
|
|
if m.UpdateRoutesFunc != nil {
|
|
return m.UpdateRoutesFunc(updateSerial, newRoutes, clientRoutes, useNewDNSRoute)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ClassifyRoutes mock implementation of ClassifyRoutes from Manager interface
|
|
func (m *MockManager) ClassifyRoutes(routes []*route.Route) (map[route.ID]*route.Route, route.HAMap) {
|
|
if m.ClassifyRoutesFunc != nil {
|
|
return m.ClassifyRoutesFunc(routes)
|
|
}
|
|
return nil, nil
|
|
}
|
|
|
|
func (m *MockManager) TriggerSelection(networks route.HAMap) {
|
|
if m.TriggerSelectionFunc != nil {
|
|
m.TriggerSelectionFunc(networks)
|
|
}
|
|
}
|
|
|
|
// SelectRoutes mock implementation of SelectRoutes from Manager interface
|
|
func (m *MockManager) SelectRoutes(ids []route.NetID, appendRoute bool) error {
|
|
if m.SelectRoutesFunc != nil {
|
|
return m.SelectRoutesFunc(ids, appendRoute)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// DeselectRoutes mock implementation of DeselectRoutes from Manager interface
|
|
func (m *MockManager) DeselectRoutes(ids []route.NetID) error {
|
|
if m.DeselectRoutesFunc != nil {
|
|
return m.DeselectRoutesFunc(ids)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// SelectAllRoutes mock implementation of SelectAllRoutes from Manager interface
|
|
func (m *MockManager) SelectAllRoutes() {
|
|
}
|
|
|
|
// DeselectAllRoutes mock implementation of DeselectAllRoutes from Manager interface
|
|
func (m *MockManager) DeselectAllRoutes() {
|
|
}
|
|
|
|
// GetRouteSelector mock implementation of GetRouteSelector from Manager interface
|
|
func (m *MockManager) GetRouteSelector() *routeselector.RouteSelector {
|
|
if m.GetRouteSelectorFunc != nil {
|
|
return m.GetRouteSelectorFunc()
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// GetClientRoutes mock implementation of GetClientRoutes from the Manager interface
|
|
func (m *MockManager) GetClientRoutes() route.HAMap {
|
|
if m.GetClientRoutesFunc != nil {
|
|
return m.GetClientRoutesFunc()
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// GetSelectedClientRoutes mock implementation of GetSelectedClientRoutes from the Manager interface
|
|
func (m *MockManager) GetSelectedClientRoutes() route.HAMap {
|
|
if m.GetSelectedClientRoutesFunc != nil {
|
|
return m.GetSelectedClientRoutesFunc()
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// GetActiveClientRoutes mock implementation of GetActiveClientRoutes from the Manager interface
|
|
func (m *MockManager) GetActiveClientRoutes() route.HAMap {
|
|
if m.GetActiveClientRoutesFunc != nil {
|
|
return m.GetActiveClientRoutesFunc()
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// GetClientRoutesWithNetID mock implementation of GetClientRoutesWithNetID from Manager interface
|
|
func (m *MockManager) GetClientRoutesWithNetID() map[route.NetID][]*route.Route {
|
|
if m.GetClientRoutesWithNetIDFunc != nil {
|
|
return m.GetClientRoutesWithNetIDFunc()
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Start mock implementation of Start from Manager interface
|
|
func (m *MockManager) Start(ctx context.Context, iface *iface.WGIface) {
|
|
}
|
|
|
|
// SetRouteChangeListener mock implementation of SetRouteChangeListener from Manager interface
|
|
func (m *MockManager) SetRouteChangeListener(listener listener.NetworkChangeListener) {
|
|
|
|
}
|
|
|
|
func (m *MockManager) SetFirewall(firewall.Manager) error {
|
|
panic("implement me")
|
|
}
|
|
|
|
// SetDNSForwarderPort mock implementation of SetDNSForwarderPort from Manager interface
|
|
func (m *MockManager) SetDNSForwarderPort(port uint16) {
|
|
}
|
|
|
|
// ReconcilePeerAllowedIPs mock implementation of ReconcilePeerAllowedIPs from Manager interface
|
|
func (m *MockManager) ReconcilePeerAllowedIPs(peerKey string) error {
|
|
return nil
|
|
}
|
|
|
|
// Stop mock implementation of Stop from Manager interface
|
|
func (m *MockManager) Stop(stateManager *statemanager.Manager) {
|
|
if m.StopFunc != nil {
|
|
m.StopFunc(stateManager)
|
|
}
|
|
}
|