WIP: Testing Netmaps + client packet filter end to end

This commit is contained in:
James Sanderson 2025-01-30 16:04:29 +00:00
parent 138a83efe1
commit 39a4dfb85c
4 changed files with 28 additions and 0 deletions

View File

@ -201,6 +201,21 @@ func NewNoStart(opts Options) (_ *Auto, err error) {
}
func NewForTest(direct *Direct, observer Observer, ctx context.Context) *Auto {
c := &Auto{
direct: direct,
logf: func(fmt string, args ...any) {},
updateCh: make(chan struct{}, 1),
authDone: make(chan struct{}),
mapDone: make(chan struct{}),
updateDone: make(chan struct{}),
observer: observer,
mapCtx: ctx,
}
return c
}
// SetPaused controls whether HTTP activity should be paused.
//
// The client can be paused and unpaused repeatedly, unlike Start and Shutdown, which can only be used once.
@ -468,6 +483,10 @@ func (mrs mapRoutineState) UpdateNetmapDelta(muts []netmap.NodeMutation) bool {
return err == nil && ok
}
func (c *Auto) MapRoutineForTest() {
c.mapRoutine()
}
// mapRoutine is responsible for keeping a read-only streaming connection to the
// control server, and keeping the netmap up to date.
func (c *Auto) mapRoutine() {

View File

@ -1044,6 +1044,7 @@ func (c *Direct) sendMapRequest(ctx context.Context, isStreaming bool, nu Netmap
vlogf("netmap: decode error: %v", err)
return err
}
vlogf("raw netmap: %+v", resp)
watchdogTimer.Stop()
metricMapResponseMessages.Add(1)

View File

@ -117,6 +117,10 @@ func newMapSession(privateNodeKey key.NodePrivate, nu NetmapUpdater, controlKnob
return ms
}
func NewMapSessionForTestOnlyDoNotUse(privateNodeKey key.NodePrivate, nu NetmapUpdater, controlKnobs *controlknobs.Knobs) *mapSession {
return newMapSession(privateNodeKey, nu, controlKnobs)
}
// occasionallyPrintSummary logs summary at most once very 5 minutes. The
// summary is the Netmap.VeryConcise result from the last received map response.
func (ms *mapSession) occasionallyPrintSummary(summary string) {

View File

@ -1417,6 +1417,10 @@ func (b *LocalBackend) peerCapsLocked(src netip.Addr) tailcfg.PeerCapMap {
return nil
}
func (b *LocalBackend) GetFilterForTest() *filter.Filter {
return b.filterAtomic.Load()
}
// SetControlClientStatus is the callback invoked by the control client whenever it posts a new status.
// Among other things, this is where we update the netmap, packet filters, DNS and DERP maps.
func (b *LocalBackend) SetControlClientStatus(c controlclient.Client, st controlclient.Status) {