summaryrefslogtreecommitdiffhomepage
path: root/wgengine/magicsock/endpoint.go
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@tailscale.com>2023-10-06 06:50:13 -0700
committerBrad Fitzpatrick <bradfitz@tailscale.com>2023-10-06 06:59:17 -0700
commita794630f60dcb6f0c13eb2820f201c2a12c952ef (patch)
tree01023fb3f2df5553e60d93c303c34a4917498729 /wgengine/magicsock/endpoint.go
parentc761d102ea5c76bc955fdb2d0ac56c8096e86466 (diff)
downloadtailscale-bradfitz/sessionactivetimeout.tar.xz
tailscale-bradfitz/sessionactivetimeout.zip
wgengine/magicsock: add controlknob tunable for session timeout experimentsbradfitz/sessionactivetimeout
Updates #TODO Change-Id: Ifb7ee2b69545cbc457aa2bf4c4744f431edb36e2 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
Diffstat (limited to 'wgengine/magicsock/endpoint.go')
-rw-r--r--wgengine/magicsock/endpoint.go18
1 files changed, 14 insertions, 4 deletions
diff --git a/wgengine/magicsock/endpoint.go b/wgengine/magicsock/endpoint.go
index fb730eb56..b9567fe15 100644
--- a/wgengine/magicsock/endpoint.go
+++ b/wgengine/magicsock/endpoint.go
@@ -83,6 +83,13 @@ type endpoint struct {
isWireguardOnly bool // whether the endpoint is WireGuard only
}
+func (ep *endpoint) sessionActiveTimeout() time.Duration {
+ if ep == nil {
+ return sessionActiveTimeoutDefault
+ }
+ return ep.c.sessionActiveTimeout()
+}
+
// endpointDisco is the current disco key and short string for an endpoint. This
// structure is immutable.
type endpointDisco struct {
@@ -104,6 +111,8 @@ type sentPing struct {
// a endpoint. (The subject is the endpoint.endpointState
// map key)
type endpointState struct {
+ ep *endpoint
+
// all fields guarded by endpoint.mu
// lastPing is the last (outgoing) ping time.
@@ -169,7 +178,7 @@ func (st *endpointState) shouldDeleteLocked() bool {
return st.index == indexSentinelDeleted
default:
// This was an endpoint discovered at runtime.
- return time.Since(st.lastGotPing) > sessionActiveTimeout
+ return time.Since(st.lastGotPing) > st.ep.sessionActiveTimeout()
}
}
@@ -411,7 +420,7 @@ func (de *endpoint) heartbeat() {
return
}
- if mono.Since(de.lastSend) > sessionActiveTimeout {
+ if mono.Since(de.lastSend) > de.c.sessionActiveTimeout() {
// Session's idle. Stop heartbeating.
de.c.dlogf("[v1] magicsock: disco: ending heartbeats for idle session to %v (%v)", de.publicKey.ShortString(), de.discoShort())
return
@@ -876,7 +885,7 @@ func (de *endpoint) setEndpointsLocked(eps interface {
if st, ok := de.endpointState[ipp]; ok {
st.index = int16(i)
} else {
- de.endpointState[ipp] = &endpointState{index: int16(i)}
+ de.endpointState[ipp] = &endpointState{ep: de, index: int16(i)}
newIpps = append(newIpps, ipp)
}
}
@@ -924,6 +933,7 @@ func (de *endpoint) addCandidateEndpoint(ep netip.AddrPort, forRxPingTxID stun.T
// Newly discovered endpoint. Exciting!
de.c.dlogf("[v1] magicsock: disco: adding %v as candidate endpoint for %v (%s)", ep, de.discoShort(), de.publicKey.ShortString())
de.endpointState[ep] = &endpointState{
+ ep: de,
lastGotPing: time.Now(),
lastGotPingTxID: forRxPingTxID,
}
@@ -1261,7 +1271,7 @@ func (de *endpoint) populatePeerStatus(ps *ipnstate.PeerStatus) {
now := mono.Now()
ps.LastWrite = de.lastSend.WallTime()
- ps.Active = now.Sub(de.lastSend) < sessionActiveTimeout
+ ps.Active = now.Sub(de.lastSend) < de.c.sessionActiveTimeout()
if udpAddr, derpAddr, _ := de.addrForSendLocked(now); udpAddr.IsValid() && !derpAddr.IsValid() {
ps.CurAddr = udpAddr.String()