Wade Simmons hai 1 ano
pai
achega
bcaefce4ac
Modificáronse 5 ficheiros con 14 adicións e 8 borrados
  1. 1 0
      handshake_ix.go
  2. 1 0
      handshake_manager.go
  3. 1 2
      hostmap.go
  4. 5 0
      mutex.go
  5. 6 6
      remote_list.go

+ 1 - 0
handshake_ix.go

@@ -135,6 +135,7 @@ func ixHandshakeStage1(f *Interface, addr *udp.Addr, via *ViaSender, packet []by
 		HandshakePacket:   make(map[uint8][]byte, 0),
 		lastHandshakeTime: hs.Details.Time,
 		relayState: RelayState{
+			syncRWMutex:   newSyncRWMutex(mutexKey{Type: mutexKeyTypeRelayState, ID: uint32(vpnIp)}),
 			relays:        map[iputil.VpnIp]struct{}{},
 			relayForByIp:  map[iputil.VpnIp]*Relay{},
 			relayForByIdx: map[uint32]*Relay{},

+ 1 - 0
handshake_manager.go

@@ -389,6 +389,7 @@ func (hm *HandshakeManager) StartHandshake(vpnIp iputil.VpnIp, cacheCb func(*Han
 		vpnIp:           vpnIp,
 		HandshakePacket: make(map[uint8][]byte, 0),
 		relayState: RelayState{
+			syncRWMutex:   newSyncRWMutex(mutexKey{Type: mutexKeyTypeRelayState, ID: uint32(vpnIp)}),
 			relays:        map[iputil.VpnIp]struct{}{},
 			relayForByIp:  map[iputil.VpnIp]*Relay{},
 			relayForByIdx: map[uint32]*Relay{},

+ 1 - 2
hostmap.go

@@ -3,7 +3,6 @@ package nebula
 import (
 	"errors"
 	"net"
-	"sync"
 	"sync/atomic"
 	"time"
 
@@ -67,7 +66,7 @@ type HostMap struct {
 // struct, make a copy of an existing value, edit the fileds in the copy, and
 // then store a pointer to the new copy in both realyForBy* maps.
 type RelayState struct {
-	sync.RWMutex
+	syncRWMutex
 
 	relays        map[iputil.VpnIp]struct{} // Set of VpnIp's of Hosts to use as relays to access this peer
 	relayForByIp  map[iputil.VpnIp]*Relay   // Maps VpnIps of peers for which this HostInfo is a relay to some Relay info

+ 5 - 0
mutex.go

@@ -8,8 +8,10 @@ const (
 	mutexKeyTypeHostMap mutexKeyType = "hostmap"
 
 	mutexKeyTypeLightHouse           = "lighthouse"
+	mutexKeyTypeRemoteList           = "remote-list"
 	mutexKeyTypeFirewallConntrack    = "firewall-conntrack"
 	mutexKeyTypeHostInfo             = "hostinfo"
+	mutexKeyTypeRelayState           = "relay-state"
 	mutexKeyTypeHandshakeHostInfo    = "handshake-hostinfo"
 	mutexKeyTypeHandshakeManager     = "handshake-manager"
 	mutexKeyTypeConnectionStateWrite = "connection-state-write-lock"
@@ -30,10 +32,13 @@ var allowedConcurrentLocks = map[mutexKeyType][]mutexKeyType{
 	mutexKeyTypeConnectionStateWrite: {mutexKeyTypeHostMap},
 
 	mutexKeyTypeLightHouse: {mutexKeyTypeHandshakeManager},
+	mutexKeyTypeRemoteList: {mutexKeyTypeLightHouse},
 
 	mutexKeyTypeConnectionManagerIn:        {mutexKeyTypeHostMap},
 	mutexKeyTypeConnectionManagerOut:       {mutexKeyTypeConnectionStateWrite, mutexKeyTypeConnectionManagerIn},
 	mutexKeyTypeConnectionManagerRelayUsed: {mutexKeyTypeHandshakeHostInfo},
+
+	mutexKeyTypeRelayState: {mutexKeyTypeHostMap, mutexKeyTypeConnectionManagerRelayUsed},
 }
 
 type mutexKey struct {

+ 6 - 6
remote_list.go

@@ -7,7 +7,6 @@ import (
 	"net/netip"
 	"sort"
 	"strconv"
-	"sync"
 	"sync/atomic"
 	"time"
 
@@ -190,7 +189,7 @@ func (hr *hostnamesResults) GetIPs() []netip.AddrPort {
 // It serves as a local cache of query replies, host update notifications, and locally learned addresses
 type RemoteList struct {
 	// Every interaction with internals requires a lock!
-	sync.RWMutex
+	syncRWMutex
 
 	// A deduplicated set of addresses. Any accessor should lock beforehand.
 	addrs []*udp.Addr
@@ -217,10 +216,11 @@ type RemoteList struct {
 // NewRemoteList creates a new empty RemoteList
 func NewRemoteList(shouldAdd func(netip.Addr) bool) *RemoteList {
 	return &RemoteList{
-		addrs:     make([]*udp.Addr, 0),
-		relays:    make([]*iputil.VpnIp, 0),
-		cache:     make(map[iputil.VpnIp]*cache),
-		shouldAdd: shouldAdd,
+		syncRWMutex: newSyncRWMutex(mutexKey{Type: mutexKeyTypeRemoteList}),
+		addrs:       make([]*udp.Addr, 0),
+		relays:      make([]*iputil.VpnIp, 0),
+		cache:       make(map[iputil.VpnIp]*cache),
+		shouldAdd:   shouldAdd,
 	}
 }