use queried hostmap info for deletion logging

This commit is contained in:
Jack Doan 2025-05-12 09:33:42 -04:00
parent 47d4055e10
commit 87a4ec7d90

View File

@ -45,7 +45,7 @@ type connectionManager struct {
relayUsedLock *sync.RWMutex relayUsedLock *sync.RWMutex
// Track last communication with hosts // Track last communication with hosts
lastCommMap map[uint32]*LastCommunication lastCommMap map[uint32]time.Time
lastCommLock *sync.RWMutex lastCommLock *sync.RWMutex
inactivityTimer *LockingTimerWheel[uint32] inactivityTimer *LockingTimerWheel[uint32]
inactivityTimeout time.Duration inactivityTimeout time.Duration
@ -78,7 +78,7 @@ func newConnectionManager(ctx context.Context, l *logrus.Logger, intf *Interface
outLock: &sync.RWMutex{}, outLock: &sync.RWMutex{},
relayUsed: make(map[uint32]struct{}), relayUsed: make(map[uint32]struct{}),
relayUsedLock: &sync.RWMutex{}, relayUsedLock: &sync.RWMutex{},
lastCommMap: make(map[uint32]*LastCommunication), lastCommMap: make(map[uint32]time.Time),
lastCommLock: &sync.RWMutex{}, lastCommLock: &sync.RWMutex{},
inactivityTimeout: 1 * time.Minute, // Default inactivity timeout: 10 minutes inactivityTimeout: 1 * time.Minute, // Default inactivity timeout: 10 minutes
trafficTimer: NewLockingTimerWheel[uint32](time.Millisecond*500, max), trafficTimer: NewLockingTimerWheel[uint32](time.Millisecond*500, max),
@ -107,18 +107,7 @@ func (n *connectionManager) updateLastCommunication(localIndex uint32) {
now := time.Now() now := time.Now()
n.lastCommLock.Lock() n.lastCommLock.Lock()
lastComm, exists := n.lastCommMap[localIndex] n.lastCommMap[localIndex] = now
if !exists {
// First time we've seen this host
lastComm = &LastCommunication{
timestamp: now,
vpnIp: hostInfo.vpnIp,
}
n.lastCommMap[localIndex] = lastComm
} else {
// Update existing record
lastComm.timestamp = now
}
n.lastCommLock.Unlock() n.lastCommLock.Unlock()
// Reset the inactivity timer for this host // Reset the inactivity timer for this host
@ -229,7 +218,7 @@ func (n *connectionManager) checkInactiveTunnels() {
} }
// Calculate inactivity duration // Calculate inactivity duration
inactiveDuration := now.Sub(lastComm.timestamp) inactiveDuration := now.Sub(lastComm)
// Check if we've exceeded the inactivity timeout // Check if we've exceeded the inactivity timeout
if inactiveDuration >= n.inactivityTimeout { if inactiveDuration >= n.inactivityTimeout {
@ -244,7 +233,7 @@ func (n *connectionManager) checkInactiveTunnels() {
} }
// Log the inactivity and drop the tunnel // Log the inactivity and drop the tunnel
n.l.WithField("vpnIp", lastComm.vpnIp). n.l.WithField("vpnIp", hostInfo.vpnAddrs[0]).
WithField("localIndex", localIndex). WithField("localIndex", localIndex).
WithField("inactiveDuration", inactiveDuration). WithField("inactiveDuration", inactiveDuration).
WithField("timeout", n.inactivityTimeout). WithField("timeout", n.inactivityTimeout).
@ -311,7 +300,7 @@ func (n *connectionManager) ReloadConfig(c *config.C) {
for localIndex, lastComm := range n.lastCommMap { for localIndex, lastComm := range n.lastCommMap {
// Calculate remaining time based on last communication // Calculate remaining time based on last communication
now := time.Now() now := time.Now()
elapsed := now.Sub(lastComm.timestamp) elapsed := now.Sub(lastComm)
// If the elapsed time exceeds the new timeout, this will be caught // If the elapsed time exceeds the new timeout, this will be caught
// in the next inactivity check. Otherwise, add with remaining time. // in the next inactivity check. Otherwise, add with remaining time.
@ -683,12 +672,12 @@ func (n *connectionManager) sendPunch(hostinfo *HostInfo) {
if n.punchy.GetTargetEverything() { if n.punchy.GetTargetEverything() {
hostinfo.remotes.ForEach(n.hostMap.GetPreferredRanges(), func(addr netip.AddrPort, preferred bool) { hostinfo.remotes.ForEach(n.hostMap.GetPreferredRanges(), func(addr netip.AddrPort, preferred bool) {
n.metricsTxPunchy.Inc(1) n.metricsTxPunchy.Inc(1)
n.intf.outside.WriteTo([]byte{1}, addr) //n.intf.outside.WriteTo([]byte{1}, addr)
}) })
} else if hostinfo.remote.IsValid() { } else if hostinfo.remote.IsValid() {
n.metricsTxPunchy.Inc(1) n.metricsTxPunchy.Inc(1)
n.intf.outside.WriteTo([]byte{1}, hostinfo.remote) //n.intf.outside.WriteTo([]byte{1}, hostinfo.remote)
} }
} }