Wade Simmons 1 年之前
父节点
当前提交
1be8dc43a7
共有 5 个文件被更改,包括 11 次插入9 次删除
  1. 1 1
      connection_manager.go
  2. 4 4
      dns_server.go
  3. 1 1
      handshake_manager.go
  4. 2 0
      mutex_debug.go
  5. 3 3
      timeout.go

+ 1 - 1
connection_manager.go

@@ -64,7 +64,7 @@ func newConnectionManager(ctx context.Context, l *logrus.Logger, intf *Interface
 		outLock:                 newSyncRWMutex("connection-manager-out"),
 		relayUsed:               make(map[uint32]struct{}),
 		relayUsedLock:           newSyncRWMutex("connection-manager-relay-used"),
-		trafficTimer:            NewLockingTimerWheel[uint32](time.Millisecond*500, max),
+		trafficTimer:            NewLockingTimerWheel[uint32]("connection-manager-timer", time.Millisecond*500, max),
 		intf:                    intf,
 		pendingDeletion:         make(map[uint32]struct{}),
 		checkInterval:           checkInterval,

+ 4 - 4
dns_server.go

@@ -5,7 +5,6 @@ import (
 	"net"
 	"strconv"
 	"strings"
-	"sync"
 
 	"github.com/miekg/dns"
 	"github.com/sirupsen/logrus"
@@ -20,15 +19,16 @@ var dnsServer *dns.Server
 var dnsAddr string
 
 type dnsRecords struct {
-	sync.RWMutex
+	syncRWMutex
 	dnsMap  map[string]string
 	hostMap *HostMap
 }
 
 func newDnsRecords(hostMap *HostMap) *dnsRecords {
 	return &dnsRecords{
-		dnsMap:  make(map[string]string),
-		hostMap: hostMap,
+		syncRWMutex: newSyncRWMutex("dns-records"),
+		dnsMap:      make(map[string]string),
+		hostMap:     hostMap,
 	}
 }
 

+ 1 - 1
handshake_manager.go

@@ -110,7 +110,7 @@ func NewHandshakeManager(l *logrus.Logger, mainHostMap *HostMap, lightHouse *Lig
 		outside:                outside,
 		config:                 config,
 		trigger:                make(chan iputil.VpnIp, config.triggerBuffer),
-		OutboundHandshakeTimer: NewLockingTimerWheel[iputil.VpnIp](config.tryInterval, hsTimeout(config.retries, config.tryInterval)),
+		OutboundHandshakeTimer: NewLockingTimerWheel[iputil.VpnIp]("handshake-manager-timer", config.tryInterval, hsTimeout(config.retries, config.tryInterval)),
 		messageMetrics:         config.messageMetrics,
 		metricInitiated:        metrics.GetOrRegisterCounter("handshake_manager.initiated", nil),
 		metricTimedOut:         metrics.GetOrRegisterCounter("handshake_manager.timed_out", nil),

+ 2 - 0
mutex_debug.go

@@ -21,9 +21,11 @@ var allowedConcurrentLocks = map[mutexKey][]mutexKey{
 	"connection-manager-in":         {"hostmap"},
 	"connection-manager-out":        {"connection-state-write", "connection-manager-in"},
 	"connection-manager-relay-used": {"handshake-hostinfo"},
+	"connection-manager-timer":      {"connection-manager-out"},
 	"connection-state-write":        {"hostmap"},
 	"firewall-conntrack":            {"handshake-hostinfo"},
 	"handshake-manager":             {"hostmap"},
+	"handshake-manager-timer":       {"handshake-manager"},
 	"hostmap":                       {"handshake-hostinfo"},
 	"lighthouse":                    {"handshake-manager"},
 	"relay-state":                   {"hostmap", "connection-manager-relay-used"},

+ 3 - 3
timeout.go

@@ -1,7 +1,6 @@
 package nebula
 
 import (
-	"sync"
 	"time"
 )
 
@@ -34,7 +33,7 @@ type TimerWheel[T any] struct {
 }
 
 type LockingTimerWheel[T any] struct {
-	m sync.Mutex
+	m syncMutex
 	t *TimerWheel[T]
 }
 
@@ -81,8 +80,9 @@ func NewTimerWheel[T any](min, max time.Duration) *TimerWheel[T] {
 }
 
 // NewLockingTimerWheel is version of TimerWheel that is safe for concurrent use with a small performance penalty
-func NewLockingTimerWheel[T any](min, max time.Duration) *LockingTimerWheel[T] {
+func NewLockingTimerWheel[T any](name string, min, max time.Duration) *LockingTimerWheel[T] {
 	return &LockingTimerWheel[T]{
+		m: newSyncMutex(name),
 		t: NewTimerWheel[T](min, max),
 	}
 }