mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-28 22:25:07 +03:00
Fix bug in mask generation for outbound dials, change iface reader mutexes to read-only locks unless RW is needed
This commit is contained in:
parent
ccf03fd3b6
commit
bbd1246f7b
2 changed files with 19 additions and 13 deletions
|
@ -260,9 +260,9 @@ func (tun *TunAdapter) ifaceReader() error {
|
|||
}
|
||||
dstNodeID, dstNodeIDMask = dstAddr.GetNodeIDandMask()
|
||||
// Do we have an active connection for this node ID?
|
||||
tun.mutex.Lock()
|
||||
tun.mutex.RLock()
|
||||
if conn, isIn := tun.conns[*dstNodeID]; isIn {
|
||||
tun.mutex.Unlock()
|
||||
tun.mutex.RUnlock()
|
||||
w, err := conn.Write(bs[:n])
|
||||
if err != nil {
|
||||
tun.log.Errorln("TUN/TAP conn write error:", err)
|
||||
|
@ -273,14 +273,20 @@ func (tun *TunAdapter) ifaceReader() error {
|
|||
continue
|
||||
}
|
||||
} else {
|
||||
if conn, err := tun.dialer.DialByNodeIDandMask(dstNodeID, dstNodeIDMask); err == nil {
|
||||
tun.conns[*dstNodeID] = &conn
|
||||
tun.mutex.Unlock()
|
||||
go tun.connReader(&conn)
|
||||
} else {
|
||||
tun.mutex.Unlock()
|
||||
tun.log.Errorln("TUN/TAP dial error:", err)
|
||||
}
|
||||
tun.mutex.RUnlock()
|
||||
func() {
|
||||
tun.mutex.Lock()
|
||||
defer tun.mutex.Unlock()
|
||||
if conn, err := tun.dialer.DialByNodeIDandMask(dstNodeID, dstNodeIDMask); err == nil {
|
||||
tun.log.Debugln("Opening new session connection")
|
||||
tun.log.Debugln("Node:", dstNodeID)
|
||||
tun.log.Debugln("Mask:", dstNodeIDMask)
|
||||
tun.conns[*dstNodeID] = &conn
|
||||
go tun.connReader(&conn)
|
||||
} else {
|
||||
tun.log.Errorln("TUN/TAP dial error:", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
/*if !r.cryptokey.isValidSource(srcAddr, addrlen) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue