Unlock the hostmap quickly, lock hostinfo instead (#459)
This commit is contained in:
parent
95f4c8a01b
commit
d004fae4f9
17
hostmap.go
17
hostmap.go
|
@ -313,25 +313,18 @@ func (hm *HostMap) PromoteBestQueryVpnIP(vpnIp uint32, ifce *Interface) (*HostIn
|
||||||
func (hm *HostMap) queryVpnIP(vpnIp uint32, promoteIfce *Interface) (*HostInfo, error) {
|
func (hm *HostMap) queryVpnIP(vpnIp uint32, promoteIfce *Interface) (*HostInfo, error) {
|
||||||
hm.RLock()
|
hm.RLock()
|
||||||
if h, ok := hm.Hosts[vpnIp]; ok {
|
if h, ok := hm.Hosts[vpnIp]; ok {
|
||||||
|
hm.RUnlock()
|
||||||
// Do not attempt promotion if you are a lighthouse
|
// Do not attempt promotion if you are a lighthouse
|
||||||
if promoteIfce != nil && !promoteIfce.lightHouse.amLighthouse {
|
if promoteIfce != nil && !promoteIfce.lightHouse.amLighthouse {
|
||||||
h.TryPromoteBest(hm.preferredRanges, promoteIfce)
|
h.TryPromoteBest(hm.preferredRanges, promoteIfce)
|
||||||
}
|
}
|
||||||
hm.RUnlock()
|
|
||||||
return h, nil
|
return h, nil
|
||||||
|
|
||||||
} else {
|
}
|
||||||
//return &net.UDPAddr{}, nil, errors.New("Unable to find host")
|
|
||||||
hm.RUnlock()
|
hm.RUnlock()
|
||||||
/*
|
|
||||||
if lightHouse != nil {
|
|
||||||
lightHouse.Query(vpnIp)
|
|
||||||
return nil, errors.New("Unable to find host")
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
return nil, errors.New("unable to find host")
|
return nil, errors.New("unable to find host")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func (hm *HostMap) queryUnsafeRoute(ip uint32) uint32 {
|
func (hm *HostMap) queryUnsafeRoute(ip uint32) uint32 {
|
||||||
r := hm.unsafeRoutes.MostSpecificContains(ip)
|
r := hm.unsafeRoutes.MostSpecificContains(ip)
|
||||||
|
@ -415,6 +408,10 @@ func (i *HostInfo) BindConnectionState(cs *ConnectionState) {
|
||||||
func (i *HostInfo) TryPromoteBest(preferredRanges []*net.IPNet, ifce *Interface) {
|
func (i *HostInfo) TryPromoteBest(preferredRanges []*net.IPNet, ifce *Interface) {
|
||||||
c := atomic.AddUint32(&i.promoteCounter, 1)
|
c := atomic.AddUint32(&i.promoteCounter, 1)
|
||||||
if c%PromoteEvery == 0 {
|
if c%PromoteEvery == 0 {
|
||||||
|
// The lock here is currently protecting i.remote access
|
||||||
|
i.RLock()
|
||||||
|
defer i.RUnlock()
|
||||||
|
|
||||||
// return early if we are already on a preferred remote
|
// return early if we are already on a preferred remote
|
||||||
rIP := i.remote.IP
|
rIP := i.remote.IP
|
||||||
for _, l := range preferredRanges {
|
for _, l := range preferredRanges {
|
||||||
|
|
Loading…
Reference in New Issue