mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-10 07:30:27 +00: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
@ -260,9 +260,9 @@ func (tun *TunAdapter) ifaceReader() error {
|
|||||||
}
|
}
|
||||||
dstNodeID, dstNodeIDMask = dstAddr.GetNodeIDandMask()
|
dstNodeID, dstNodeIDMask = dstAddr.GetNodeIDandMask()
|
||||||
// Do we have an active connection for this node ID?
|
// Do we have an active connection for this node ID?
|
||||||
tun.mutex.Lock()
|
tun.mutex.RLock()
|
||||||
if conn, isIn := tun.conns[*dstNodeID]; isIn {
|
if conn, isIn := tun.conns[*dstNodeID]; isIn {
|
||||||
tun.mutex.Unlock()
|
tun.mutex.RUnlock()
|
||||||
w, err := conn.Write(bs[:n])
|
w, err := conn.Write(bs[:n])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tun.log.Errorln("TUN/TAP conn write error:", err)
|
tun.log.Errorln("TUN/TAP conn write error:", err)
|
||||||
@ -273,14 +273,20 @@ func (tun *TunAdapter) ifaceReader() error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if conn, err := tun.dialer.DialByNodeIDandMask(dstNodeID, dstNodeIDMask); err == nil {
|
tun.mutex.RUnlock()
|
||||||
tun.conns[*dstNodeID] = &conn
|
func() {
|
||||||
tun.mutex.Unlock()
|
tun.mutex.Lock()
|
||||||
go tun.connReader(&conn)
|
defer tun.mutex.Unlock()
|
||||||
} else {
|
if conn, err := tun.dialer.DialByNodeIDandMask(dstNodeID, dstNodeIDMask); err == nil {
|
||||||
tun.mutex.Unlock()
|
tun.log.Debugln("Opening new session connection")
|
||||||
tun.log.Errorln("TUN/TAP dial error:", err)
|
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) {
|
/*if !r.cryptokey.isValidSource(srcAddr, addrlen) {
|
||||||
|
@ -35,7 +35,7 @@ func (d *Dialer) Dial(network, address string) (Conn, error) {
|
|||||||
return Conn{}, err
|
return Conn{}, err
|
||||||
}
|
}
|
||||||
copy(nodeID[:], dest)
|
copy(nodeID[:], dest)
|
||||||
for idx := 0; idx <= len; idx++ {
|
for idx := 0; idx < len; idx++ {
|
||||||
nodeMask[idx/8] |= 0x80 >> byte(idx%8)
|
nodeMask[idx/8] |= 0x80 >> byte(idx%8)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -65,8 +65,8 @@ func (d *Dialer) DialByNodeIDandMask(nodeID, nodeMask *crypto.NodeID) (Conn, err
|
|||||||
nodeMask: nodeMask,
|
nodeMask: nodeMask,
|
||||||
recv: make(chan *wire_trafficPacket, 32),
|
recv: make(chan *wire_trafficPacket, 32),
|
||||||
}
|
}
|
||||||
conn.core.router.doAdmin(func() {
|
conn.core.router.admin <- func() {
|
||||||
conn.startSearch()
|
conn.startSearch()
|
||||||
})
|
}
|
||||||
return conn, nil
|
return conn, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user