mirror of
https://github.com/netbirdio/netbird.git
synced 2025-06-21 02:08:40 +02:00
Remove unused ctx
This commit is contained in:
parent
55e7ca96df
commit
a22a6f6d26
@ -133,7 +133,7 @@ func (e *ConnMgr) SetExcludeList(ctx context.Context, peerIDs map[string]bool) {
|
||||
excludedPeers = append(excludedPeers, lazyPeerCfg)
|
||||
}
|
||||
|
||||
added := e.lazyConnMgr.ExcludePeer(e.lazyCtx, excludedPeers)
|
||||
added := e.lazyConnMgr.ExcludePeer(excludedPeers)
|
||||
for _, peerID := range added {
|
||||
var peerConn *peer.Conn
|
||||
var exists bool
|
||||
|
@ -26,6 +26,8 @@ const (
|
||||
|
||||
checkInterval = keepAliveInterval // todo: 5 * time.Second
|
||||
keepAliveCheckPeriod = keepAliveInterval
|
||||
|
||||
inactivityThreshold = 3 // number of checks to consider peer inactive
|
||||
)
|
||||
|
||||
const (
|
||||
@ -98,14 +100,19 @@ func (m *Manager) Start(ctx context.Context) {
|
||||
if len(idlePeers) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
m.notifyInactivePeers(ctx, idlePeers)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Manager) notifyInactivePeers(ctx context.Context, inactivePeers []string) {
|
||||
select {
|
||||
case m.InactivePeersChan <- idlePeers:
|
||||
case m.InactivePeersChan <- inactivePeers:
|
||||
case <-ctx.Done():
|
||||
continue
|
||||
return
|
||||
default:
|
||||
continue
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@ -120,8 +127,8 @@ func (m *Manager) checkStats(now time.Time) ([]string, error) {
|
||||
for peer, info := range m.interestedPeers {
|
||||
stat, found := stats[peer]
|
||||
if !found {
|
||||
// when peer is in connecting state
|
||||
info.log.Warnf("peer not found in wg stats")
|
||||
continue
|
||||
}
|
||||
|
||||
// First measurement: initialize
|
||||
@ -137,7 +144,7 @@ func (m *Manager) checkStats(now time.Time) ([]string, error) {
|
||||
continue
|
||||
}
|
||||
|
||||
// sometimes we measure false inactivity, so we need to check if we have activity in a row
|
||||
// sometimes we measure false inactivity, so we need to check if we have inactivity in a row
|
||||
if isInactive(stat, info) {
|
||||
info.inActivityInRow++
|
||||
} else {
|
||||
@ -145,7 +152,7 @@ func (m *Manager) checkStats(now time.Time) ([]string, error) {
|
||||
}
|
||||
|
||||
info.log.Infof("peer inactivity counter: %d", info.inActivityInRow)
|
||||
if info.inActivityInRow >= 3 {
|
||||
if info.inActivityInRow >= inactivityThreshold {
|
||||
info.log.Infof("peer is inactive for %d checks, marking as inactive", info.inActivityInRow)
|
||||
idlePeers = append(idlePeers, peer)
|
||||
info.inActivityInRow = 0
|
||||
@ -159,6 +166,14 @@ func (m *Manager) checkStats(now time.Time) ([]string, error) {
|
||||
|
||||
func isInactive(stat configurer.WGStats, info *peerInfo) bool {
|
||||
rxSyncPrevPeriod := stat.RxBytes - info.lastRxBytesAtLastIdleCheck
|
||||
|
||||
// when the peer reconnected we lose the rx bytes from between the reset and the last check.
|
||||
// We will suppose the peer was active
|
||||
if rxSyncPrevPeriod < 0 {
|
||||
info.log.Debugf("rxBytes decreased, resetting last rxBytes at last idle check")
|
||||
return false
|
||||
}
|
||||
|
||||
switch rxSyncPrevPeriod {
|
||||
case 0:
|
||||
info.log.Debugf("peer inactive, received 0 bytes")
|
||||
|
@ -157,7 +157,7 @@ func (m *Manager) Start(ctx context.Context) {
|
||||
// Adds them back to the managed list and start the inactivity listener if they are removed from the exclude list. In
|
||||
// this case, we suppose that the connection status is connected or connecting.
|
||||
// If the peer is not exists yet in the managed list then the responsibility is the upper layer to call the AddPeer function
|
||||
func (m *Manager) ExcludePeer(ctx context.Context, peerConfigs []lazyconn.PeerConfig) []string {
|
||||
func (m *Manager) ExcludePeer(peerConfigs []lazyconn.PeerConfig) []string {
|
||||
m.managedPeersMu.Lock()
|
||||
defer m.managedPeersMu.Unlock()
|
||||
|
||||
@ -517,4 +517,5 @@ func (m *Manager) onPeerDisconnected(peerConnID peerid.ConnID) {
|
||||
}
|
||||
|
||||
// todo reset inactivity monitor
|
||||
mp.peerCfg.Log.Infof("--- peer disconnected, stopping inactivity monitor?")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user