mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-18 10:58:39 +00:00
wgengine/magicsock: rename opts.PacketListener to TestOnlyPacketListener.
The docstring said it was meant for use in tests, but it's specifically a special codepath that is _only_ used in tests, so make the claim stronger. Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
parent
8049063d35
commit
58c1f7d51a
@ -279,7 +279,7 @@ type Conn struct {
|
|||||||
epFunc func([]tailcfg.Endpoint)
|
epFunc func([]tailcfg.Endpoint)
|
||||||
derpActiveFunc func()
|
derpActiveFunc func()
|
||||||
idleFunc func() time.Duration // nil means unknown
|
idleFunc func() time.Duration // nil means unknown
|
||||||
packetListener nettype.PacketListener
|
testOnlyPacketListener nettype.PacketListener
|
||||||
noteRecvActivity func(tailcfg.DiscoKey) // or nil, see Options.NoteRecvActivity
|
noteRecvActivity func(tailcfg.DiscoKey) // or nil, see Options.NoteRecvActivity
|
||||||
simulatedNetwork bool
|
simulatedNetwork bool
|
||||||
|
|
||||||
@ -524,9 +524,9 @@ type Options struct {
|
|||||||
// it's been since a TUN packet was sent or received.
|
// it's been since a TUN packet was sent or received.
|
||||||
IdleFunc func() time.Duration
|
IdleFunc func() time.Duration
|
||||||
|
|
||||||
// PacketListener optionally specifies how to create PacketConns.
|
// TestOnlyPacketListener optionally specifies how to create PacketConns.
|
||||||
// It's meant for testing.
|
// Only used by tests.
|
||||||
PacketListener nettype.PacketListener
|
TestOnlyPacketListener nettype.PacketListener
|
||||||
|
|
||||||
// NoteRecvActivity, if provided, is a func for magicsock to
|
// NoteRecvActivity, if provided, is a func for magicsock to
|
||||||
// call whenever it receives a packet from a a
|
// call whenever it receives a packet from a a
|
||||||
@ -603,7 +603,7 @@ func NewConn(opts Options) (*Conn, error) {
|
|||||||
c.epFunc = opts.endpointsFunc()
|
c.epFunc = opts.endpointsFunc()
|
||||||
c.derpActiveFunc = opts.derpActiveFunc()
|
c.derpActiveFunc = opts.derpActiveFunc()
|
||||||
c.idleFunc = opts.IdleFunc
|
c.idleFunc = opts.IdleFunc
|
||||||
c.packetListener = opts.PacketListener
|
c.testOnlyPacketListener = opts.TestOnlyPacketListener
|
||||||
c.noteRecvActivity = opts.NoteRecvActivity
|
c.noteRecvActivity = opts.NoteRecvActivity
|
||||||
c.simulatedNetwork = opts.SimulatedNetwork
|
c.simulatedNetwork = opts.SimulatedNetwork
|
||||||
c.portMapper = portmapper.NewClient(logger.WithPrefix(c.logf, "portmapper: "), c.onPortMapChanged)
|
c.portMapper = portmapper.NewClient(logger.WithPrefix(c.logf, "portmapper: "), c.onPortMapChanged)
|
||||||
@ -2688,8 +2688,8 @@ func (c *Conn) listenPacket(network string, host netaddr.IP, port uint16) (net.P
|
|||||||
s = host.String()
|
s = host.String()
|
||||||
}
|
}
|
||||||
addr := net.JoinHostPort(s, fmt.Sprint(port))
|
addr := net.JoinHostPort(s, fmt.Sprint(port))
|
||||||
if c.packetListener != nil {
|
if c.testOnlyPacketListener != nil {
|
||||||
return c.packetListener.ListenPacket(ctx, network, addr)
|
return c.testOnlyPacketListener.ListenPacket(ctx, network, addr)
|
||||||
}
|
}
|
||||||
return netns.Listener().ListenPacket(ctx, network, addr)
|
return netns.Listener().ListenPacket(ctx, network, addr)
|
||||||
}
|
}
|
||||||
|
@ -146,7 +146,7 @@ func newMagicStack(t testing.TB, logf logger.Logf, l nettype.PacketListener, der
|
|||||||
epCh := make(chan []tailcfg.Endpoint, 100) // arbitrary
|
epCh := make(chan []tailcfg.Endpoint, 100) // arbitrary
|
||||||
conn, err := NewConn(Options{
|
conn, err := NewConn(Options{
|
||||||
Logf: logf,
|
Logf: logf,
|
||||||
PacketListener: l,
|
TestOnlyPacketListener: l,
|
||||||
EndpointsFunc: func(eps []tailcfg.Endpoint) {
|
EndpointsFunc: func(eps []tailcfg.Endpoint) {
|
||||||
epCh <- eps
|
epCh <- eps
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user