mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-22 13:00:47 +00:00
reduce time keystore mutex is held and (apparently) fix a deadlock
This commit is contained in:
parent
ed85cf08f2
commit
3bfd891fd4
@ -48,10 +48,10 @@ func (k *keyStore) init(tun *TunAdapter) {
|
|||||||
|
|
||||||
func (k *keyStore) sendToAddress(addr address.Address, bs []byte) {
|
func (k *keyStore) sendToAddress(addr address.Address, bs []byte) {
|
||||||
k.mutex.Lock()
|
k.mutex.Lock()
|
||||||
defer k.mutex.Unlock()
|
|
||||||
if info := k.addrToInfo[addr]; info != nil {
|
if info := k.addrToInfo[addr]; info != nil {
|
||||||
k.tun.core.WriteTo(bs, iwt.Addr(info.key[:]))
|
|
||||||
k.resetTimeout(info)
|
k.resetTimeout(info)
|
||||||
|
k.mutex.Unlock()
|
||||||
|
k.tun.core.WriteTo(bs, iwt.Addr(info.key[:]))
|
||||||
} else {
|
} else {
|
||||||
var buf *buffer
|
var buf *buffer
|
||||||
if buf = k.addrBuffer[addr]; buf == nil {
|
if buf = k.addrBuffer[addr]; buf == nil {
|
||||||
@ -70,16 +70,17 @@ func (k *keyStore) sendToAddress(addr address.Address, bs []byte) {
|
|||||||
delete(k.addrBuffer, addr)
|
delete(k.addrBuffer, addr)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
k.mutex.Unlock()
|
||||||
k.tun.sendKeyLookup(addr.GetKey())
|
k.tun.sendKeyLookup(addr.GetKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k *keyStore) sendToSubnet(subnet address.Subnet, bs []byte) {
|
func (k *keyStore) sendToSubnet(subnet address.Subnet, bs []byte) {
|
||||||
k.mutex.Lock()
|
k.mutex.Lock()
|
||||||
defer k.mutex.Unlock()
|
|
||||||
if info := k.subnetToInfo[subnet]; info != nil {
|
if info := k.subnetToInfo[subnet]; info != nil {
|
||||||
k.tun.core.WriteTo(bs, iwt.Addr(info.key[:]))
|
|
||||||
k.resetTimeout(info)
|
k.resetTimeout(info)
|
||||||
|
k.mutex.Unlock()
|
||||||
|
k.tun.core.WriteTo(bs, iwt.Addr(info.key[:]))
|
||||||
} else {
|
} else {
|
||||||
var buf *buffer
|
var buf *buffer
|
||||||
if buf = k.subnetBuffer[subnet]; buf == nil {
|
if buf = k.subnetBuffer[subnet]; buf == nil {
|
||||||
@ -98,13 +99,13 @@ func (k *keyStore) sendToSubnet(subnet address.Subnet, bs []byte) {
|
|||||||
delete(k.subnetBuffer, subnet)
|
delete(k.subnetBuffer, subnet)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
k.mutex.Unlock()
|
||||||
k.tun.sendKeyLookup(subnet.GetKey())
|
k.tun.sendKeyLookup(subnet.GetKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k *keyStore) update(key ed25519.PublicKey) *keyInfo {
|
func (k *keyStore) update(key ed25519.PublicKey) *keyInfo {
|
||||||
k.mutex.Lock()
|
k.mutex.Lock()
|
||||||
defer k.mutex.Unlock()
|
|
||||||
var kArray keyArray
|
var kArray keyArray
|
||||||
copy(kArray[:], key)
|
copy(kArray[:], key)
|
||||||
var info *keyInfo
|
var info *keyInfo
|
||||||
@ -118,6 +119,7 @@ func (k *keyStore) update(key ed25519.PublicKey) *keyInfo {
|
|||||||
k.addrToInfo[info.address] = info
|
k.addrToInfo[info.address] = info
|
||||||
k.subnetToInfo[info.subnet] = info
|
k.subnetToInfo[info.subnet] = info
|
||||||
k.resetTimeout(info)
|
k.resetTimeout(info)
|
||||||
|
k.mutex.Unlock()
|
||||||
if buf := k.addrBuffer[info.address]; buf != nil {
|
if buf := k.addrBuffer[info.address]; buf != nil {
|
||||||
for _, bs := range buf.packets {
|
for _, bs := range buf.packets {
|
||||||
k.tun.core.WriteTo(bs, iwt.Addr(info.key[:]))
|
k.tun.core.WriteTo(bs, iwt.Addr(info.key[:]))
|
||||||
@ -130,8 +132,10 @@ func (k *keyStore) update(key ed25519.PublicKey) *keyInfo {
|
|||||||
}
|
}
|
||||||
delete(k.subnetBuffer, info.subnet)
|
delete(k.subnetBuffer, info.subnet)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
k.resetTimeout(info)
|
||||||
|
k.mutex.Unlock()
|
||||||
}
|
}
|
||||||
k.resetTimeout(info)
|
|
||||||
return info
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user