wgengine/magicsock: don't mutexly reach inside Conn to tweak DERP settings.

Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
David Anderson 2020-03-06 16:20:05 -08:00 committed by Dave Anderson
parent f6dd2128d9
commit fdee5fb639
2 changed files with 5 additions and 8 deletions

View File

@ -124,6 +124,8 @@ type Options struct {
// EndpointsFunc optionally provides a func to be called when // EndpointsFunc optionally provides a func to be called when
// endpoints change. The called func does not own the slice. // endpoints change. The called func does not own the slice.
EndpointsFunc func(endpoint []string) EndpointsFunc func(endpoint []string)
derpTLSConfig *tls.Config // normally nil; used by tests
} }
func (o *Options) endpointsFunc() func([]string) { func (o *Options) endpointsFunc() func([]string) {
@ -173,6 +175,7 @@ func Listen(opts Options) (*Conn, error) {
wantDerp: true, wantDerp: true,
derpRecvCh: make(chan derpReadResult), derpRecvCh: make(chan derpReadResult),
udpRecvCh: make(chan udpReadResult), udpRecvCh: make(chan udpReadResult),
derpTLSConfig: opts.derpTLSConfig,
} }
c.ignoreSTUNPackets() c.ignoreSTUNPackets()
c.pconn.Reset(packetConn.(*net.UDPConn)) c.pconn.Reset(packetConn.(*net.UDPConn))

View File

@ -308,32 +308,26 @@ func TestTwoDevicePing(t *testing.T) {
EndpointsFunc: func(eps []string) { EndpointsFunc: func(eps []string) {
epCh1 <- eps epCh1 <- eps
}, },
derpTLSConfig: &tls.Config{InsecureSkipVerify: true},
}) })
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer conn1.Close() defer conn1.Close()
conn1.derpMu.Lock()
conn1.derpTLSConfig = &tls.Config{InsecureSkipVerify: true}
conn1.derpMu.Unlock()
epCh2 := make(chan []string, 16) epCh2 := make(chan []string, 16)
conn2, err := Listen(Options{ conn2, err := Listen(Options{
STUN: []string{stunAddr.String()}, STUN: []string{stunAddr.String()},
EndpointsFunc: func(eps []string) { EndpointsFunc: func(eps []string) {
epCh2 <- eps epCh2 <- eps
}, },
derpTLSConfig: &tls.Config{InsecureSkipVerify: true},
}) })
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer conn2.Close() defer conn2.Close()
conn2.derpMu.Lock()
conn2.derpTLSConfig = &tls.Config{InsecureSkipVerify: true}
conn2.derpMu.Unlock()
ports := []uint16{conn1.LocalPort(), conn2.LocalPort()} ports := []uint16{conn1.LocalPort(), conn2.LocalPort()}
cfgs := makeConfigs(t, ports) cfgs := makeConfigs(t, ports)