Skip to content

Commit

Permalink
more types
Browse files Browse the repository at this point in the history
  • Loading branch information
wadey committed Dec 19, 2023
1 parent 540a171 commit bcaefce
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions handshake_ix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down
1 change: 1 addition & 0 deletions handshake_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down
3 changes: 1 addition & 2 deletions hostmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package nebula
import (
"errors"
"net"
"sync"
"sync/atomic"
"time"

Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions mutex.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions remote_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"net/netip"
"sort"
"strconv"
"sync"
"sync/atomic"
"time"

Expand Down Expand Up @@ -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
Expand All @@ -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,
}
}

Expand Down

0 comments on commit bcaefce

Please sign in to comment.