5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-26 01:21:37 +00:00

fix dial bug

This commit is contained in:
Arceliar 2019-08-26 00:38:14 -05:00
parent ab59129557
commit c97dd4ad28
2 changed files with 21 additions and 19 deletions

View File

@ -247,24 +247,26 @@ func (tun *TunAdapter) _handlePacket(recvd []byte, err error) {
} }
if !known { if !known {
go func() { go func() {
if conn, err := tun.dialer.DialByNodeIDandMask(dstNodeID, dstNodeIDMask); err == nil { conn, err := tun.dialer.DialByNodeIDandMask(dstNodeID, dstNodeIDMask)
tun.RecvFrom(nil, func() { tun.RecvFrom(nil, func() {
// We've been given a connection so prepare the session wrapper packets := tun.dials[*dstNodeID]
packets := tun.dials[*dstNodeID] delete(tun.dials, *dstNodeID)
delete(tun.dials, *dstNodeID) if err != nil {
var tc *tunConn return
var err error }
if tc, err = tun._wrap(conn); err != nil { // We've been given a connection so prepare the session wrapper
// Something went wrong when storing the connection, typically that var tc *tunConn
// something already exists for this address or subnet if tc, err = tun._wrap(conn); err != nil {
tun.log.Debugln("TUN/TAP iface wrap:", err) // Something went wrong when storing the connection, typically that
return // something already exists for this address or subnet
} tun.log.Debugln("TUN/TAP iface wrap:", err)
for _, packet := range packets { return
tc.writeFrom(nil, packet) }
} for _, packet := range packets {
}) tc.writeFrom(nil, packet)
} }
})
return
}() }()
} }
} }

View File

@ -252,7 +252,7 @@ const (
// notify the intf that we're currently sending // notify the intf that we're currently sending
func (intf *linkInterface) notifySending(size int, isLinkTraffic bool) { func (intf *linkInterface) notifySending(size int, isLinkTraffic bool) {
intf.RecvFrom(nil, func() { intf.RecvFrom(nil, func() {
if !isLinkTraffic && size > 0 { if !isLinkTraffic {
intf.inSwitch = false intf.inSwitch = false
} }
intf.sendTimer = time.AfterFunc(sendBlockedTime, intf.notifyBlockedSend) intf.sendTimer = time.AfterFunc(sendBlockedTime, intf.notifyBlockedSend)