mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 13:05:46 +00:00
wgengine/magicsock: remove Start method from Conn.
Over time, other magicsock refactors have made Start effectively a no-op, except that some other functions choose to panic if called before Start. Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
parent
1a899344bd
commit
4c27e2fa22
@ -276,7 +276,6 @@ type Conn struct {
|
|||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
muCond *sync.Cond
|
muCond *sync.Cond
|
||||||
|
|
||||||
started bool // Start was called
|
|
||||||
closed bool // Close was called
|
closed bool // Close was called
|
||||||
|
|
||||||
// derpCleanupTimer is the timer that fires to occasionally clean
|
// derpCleanupTimer is the timer that fires to occasionally clean
|
||||||
@ -546,17 +545,6 @@ func NewConn(opts Options) (*Conn, error) {
|
|||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Conn) Start() {
|
|
||||||
c.mu.Lock()
|
|
||||||
if c.started {
|
|
||||||
panic("duplicate Start call")
|
|
||||||
}
|
|
||||||
c.started = true
|
|
||||||
c.mu.Unlock()
|
|
||||||
|
|
||||||
c.ReSTUN("initial")
|
|
||||||
}
|
|
||||||
|
|
||||||
// ignoreSTUNPackets sets a STUN packet processing func that does nothing.
|
// ignoreSTUNPackets sets a STUN packet processing func that does nothing.
|
||||||
func (c *Conn) ignoreSTUNPackets() {
|
func (c *Conn) ignoreSTUNPackets() {
|
||||||
c.stunReceiveFunc.Store(func([]byte, netaddr.IPPort) {})
|
c.stunReceiveFunc.Store(func([]byte, netaddr.IPPort) {})
|
||||||
@ -1981,9 +1969,7 @@ func (c *Conn) SetPrivateKey(privateKey wgkey.Private) error {
|
|||||||
if oldKey.IsZero() {
|
if oldKey.IsZero() {
|
||||||
c.everHadKey = true
|
c.everHadKey = true
|
||||||
c.logf("magicsock: SetPrivateKey called (init)")
|
c.logf("magicsock: SetPrivateKey called (init)")
|
||||||
if c.started {
|
|
||||||
go c.ReSTUN("set-private-key")
|
go c.ReSTUN("set-private-key")
|
||||||
}
|
|
||||||
} else if newKey.IsZero() {
|
} else if newKey.IsZero() {
|
||||||
c.logf("magicsock: SetPrivateKey called (zeroed)")
|
c.logf("magicsock: SetPrivateKey called (zeroed)")
|
||||||
c.closeAllDerpLocked("zero-private-key")
|
c.closeAllDerpLocked("zero-private-key")
|
||||||
@ -2050,10 +2036,8 @@ func (c *Conn) SetDERPMap(dm *tailcfg.DERPMap) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.started {
|
|
||||||
go c.ReSTUN("derp-map-update")
|
go c.ReSTUN("derp-map-update")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func nodesEqual(x, y []*tailcfg.Node) bool {
|
func nodesEqual(x, y []*tailcfg.Node) bool {
|
||||||
if len(x) != len(y) {
|
if len(x) != len(y) {
|
||||||
@ -2476,9 +2460,6 @@ func (c *Conn) onPortMapChanged() { c.ReSTUN("portmap-changed") }
|
|||||||
func (c *Conn) ReSTUN(why string) {
|
func (c *Conn) ReSTUN(why string) {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
defer c.mu.Unlock()
|
defer c.mu.Unlock()
|
||||||
if !c.started {
|
|
||||||
panic("call to ReSTUN before Start")
|
|
||||||
}
|
|
||||||
if c.closed {
|
if c.closed {
|
||||||
// raced with a shutdown.
|
// raced with a shutdown.
|
||||||
return
|
return
|
||||||
|
@ -154,7 +154,6 @@ func newMagicStack(t testing.TB, logf logger.Logf, l nettype.PacketListener, der
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("constructing magicsock: %v", err)
|
t.Fatalf("constructing magicsock: %v", err)
|
||||||
}
|
}
|
||||||
conn.Start()
|
|
||||||
conn.SetDERPMap(derpMap)
|
conn.SetDERPMap(derpMap)
|
||||||
if err := conn.SetPrivateKey(privateKey); err != nil {
|
if err := conn.SetPrivateKey(privateKey); err != nil {
|
||||||
t.Fatalf("setting private key in magicsock: %v", err)
|
t.Fatalf("setting private key in magicsock: %v", err)
|
||||||
@ -353,7 +352,6 @@ func TestNewConn(t *testing.T) {
|
|||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
conn.SetDERPMap(stuntest.DERPMapOf(stunAddr.String()))
|
conn.SetDERPMap(stuntest.DERPMapOf(stunAddr.String()))
|
||||||
conn.SetPrivateKey(wgkey.Private(key.NewPrivate()))
|
conn.SetPrivateKey(wgkey.Private(key.NewPrivate()))
|
||||||
conn.Start()
|
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
var pkt [64 << 10]byte
|
var pkt [64 << 10]byte
|
||||||
@ -465,7 +463,6 @@ func TestDeviceStartStop(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
conn.Start()
|
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
tun := tuntest.NewChannelTUN()
|
tun := tuntest.NewChannelTUN()
|
||||||
|
@ -403,7 +403,6 @@ func NewUserspaceEngine(logf logger.Logf, conf Config) (_ Engine, reterr error)
|
|||||||
e.logf("Starting link monitor...")
|
e.logf("Starting link monitor...")
|
||||||
e.linkMon.Start()
|
e.linkMon.Start()
|
||||||
e.logf("Starting magicsock...")
|
e.logf("Starting magicsock...")
|
||||||
e.magicConn.Start()
|
|
||||||
close(e.magicConnStarted)
|
close(e.magicConnStarted)
|
||||||
|
|
||||||
go e.pollResolver()
|
go e.pollResolver()
|
||||||
|
Loading…
Reference in New Issue
Block a user