parent
1f0fa8b814
commit
7e201806b1
|
@ -963,6 +963,13 @@ func (c *Conn) setNearestDERP(derpNum int) (wantDERP bool) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// startDerpHomeConnectLocked starts connecting to our DERP home, if any.
|
||||||
|
//
|
||||||
|
// c.mu must be held.
|
||||||
|
func (c *Conn) startDerpHomeConnectLocked() {
|
||||||
|
c.goDerpConnect(c.myDerp)
|
||||||
|
}
|
||||||
|
|
||||||
// goDerpConnect starts a goroutine to start connecting to the given
|
// goDerpConnect starts a goroutine to start connecting to the given
|
||||||
// DERP node.
|
// DERP node.
|
||||||
//
|
//
|
||||||
|
@ -2125,7 +2132,9 @@ func (c *Conn) SetNetworkUp(up bool) {
|
||||||
c.logf("magicsock: SetNetworkUp(%v)", up)
|
c.logf("magicsock: SetNetworkUp(%v)", up)
|
||||||
c.networkUp.Set(up)
|
c.networkUp.Set(up)
|
||||||
|
|
||||||
if !up {
|
if up {
|
||||||
|
c.startDerpHomeConnectLocked()
|
||||||
|
} else {
|
||||||
c.closeAllDerpLocked("network-down")
|
c.closeAllDerpLocked("network-down")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2167,7 +2176,7 @@ func (c *Conn) SetPrivateKey(privateKey wgkey.Private) error {
|
||||||
// Key changed. Close existing DERP connections and reconnect to home.
|
// Key changed. Close existing DERP connections and reconnect to home.
|
||||||
if c.myDerp != 0 && !newKey.IsZero() {
|
if c.myDerp != 0 && !newKey.IsZero() {
|
||||||
c.logf("magicsock: private key changed, reconnecting to home derp-%d", c.myDerp)
|
c.logf("magicsock: private key changed, reconnecting to home derp-%d", c.myDerp)
|
||||||
c.goDerpConnect(c.myDerp)
|
c.startDerpHomeConnectLocked()
|
||||||
}
|
}
|
||||||
|
|
||||||
if newKey.IsZero() {
|
if newKey.IsZero() {
|
||||||
|
@ -2630,12 +2639,11 @@ func (c *Conn) Rebind() {
|
||||||
|
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
c.closeAllDerpLocked("rebind")
|
c.closeAllDerpLocked("rebind")
|
||||||
haveKey := !c.privateKey.IsZero()
|
if !c.privateKey.IsZero() {
|
||||||
|
c.startDerpHomeConnectLocked()
|
||||||
|
}
|
||||||
c.mu.Unlock()
|
c.mu.Unlock()
|
||||||
|
|
||||||
if haveKey {
|
|
||||||
c.goDerpConnect(c.myDerp)
|
|
||||||
}
|
|
||||||
c.resetEndpointStates()
|
c.resetEndpointStates()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue