From addbdce2964574ee5449762b69e3a5aea844a31a Mon Sep 17 00:00:00 2001 From: David Crawshaw Date: Thu, 19 Mar 2020 17:55:14 +1100 Subject: [PATCH] wgengine, ipn: include number of active DERPs in status Use this when making the ipn state transition from Starting to Running. This way a network of quiet nodes with no active handshaking will still transition to Active. Signed-off-by: David Crawshaw --- ipn/backend.go | 1 + ipn/local.go | 3 ++- wgengine/magicsock/magicsock.go | 8 ++++++++ wgengine/userspace.go | 1 + wgengine/wgengine.go | 1 + 5 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ipn/backend.go b/ipn/backend.go index eee2b1b87..19c809a0a 100644 --- a/ipn/backend.go +++ b/ipn/backend.go @@ -33,6 +33,7 @@ func (s State) String() string { type EngineStatus struct { RBytes, WBytes wgengine.ByteCount NumLive int + LiveDERPs int // number of active DERP connections LivePeers map[tailcfg.NodeKey]wgengine.PeerStatus } diff --git a/ipn/local.go b/ipn/local.go index 99878fdd4..0e6faace5 100644 --- a/ipn/local.go +++ b/ipn/local.go @@ -520,6 +520,7 @@ func (b *LocalBackend) parseWgStatus(s *wgengine.Status) EngineStatus { RBytes: rx, WBytes: tx, NumLive: live, + LiveDERPs: s.DERPs, LivePeers: peers, } } @@ -710,7 +711,7 @@ func (b *LocalBackend) nextState() State { // (if we get here, we know MachineAuthorized == true) return Starting } else if state == Starting { - if b.EngineStatus().NumLive > 0 { + if st := b.EngineStatus(); st.NumLive > 0 || st.LiveDERPs > 0 { return Running } else { return state diff --git a/wgengine/magicsock/magicsock.go b/wgengine/magicsock/magicsock.go index e57b73376..6c92d01e2 100644 --- a/wgengine/magicsock/magicsock.go +++ b/wgengine/magicsock/magicsock.go @@ -1080,6 +1080,14 @@ func (c *Conn) cleanStaleDerp() { } } +// DERPs reports the number of active DERP connections. +func (c *Conn) DERPs() int { + c.mu.Lock() + defer c.mu.Unlock() + + return len(c.activeDerp) +} + func (c *Conn) SetMark(value uint32) error { return nil } func (c *Conn) LastMark() uint32 { return 0 } diff --git a/wgengine/userspace.go b/wgengine/userspace.go index 3985a4333..2092af963 100644 --- a/wgengine/userspace.go +++ b/wgengine/userspace.go @@ -530,6 +530,7 @@ func (e *userspaceEngine) getStatus() (*Status, error) { return &Status{ LocalAddrs: append([]string(nil), e.endpoints...), Peers: peers, + DERPs: e.magicConn.DERPs(), }, nil } diff --git a/wgengine/wgengine.go b/wgengine/wgengine.go index baf9f35a8..a3bcb9a86 100644 --- a/wgengine/wgengine.go +++ b/wgengine/wgengine.go @@ -32,6 +32,7 @@ type PeerStatus struct { type Status struct { Peers []PeerStatus LocalAddrs []string // TODO(crawshaw): []wgcfg.Endpoint? + DERPs int // number of active DERP connections } // StatusCallback is the type of status callbacks used by