mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-10 07:30:27 +00:00
commit
b8592669b8
@ -225,11 +225,11 @@ func (tun *TunAdapter) reader() error {
|
||||
panic("Given empty dstNodeID and dstNodeIDMask - this shouldn't happen")
|
||||
}
|
||||
// Dial to the remote node
|
||||
packet := append(util.GetBytes(), bs[:n]...)
|
||||
go func() {
|
||||
// FIXME just spitting out a goroutine to do this is kind of ugly and means we drop packets until the dial finishes
|
||||
tun.mutex.Lock()
|
||||
_, known := tun.dials[*dstNodeID]
|
||||
packet := append(util.GetBytes(), bs[:n]...)
|
||||
tun.dials[*dstNodeID] = append(tun.dials[*dstNodeID], packet)
|
||||
for len(tun.dials[*dstNodeID]) > 32 {
|
||||
util.PutBytes(tun.dials[*dstNodeID][0])
|
||||
|
@ -211,7 +211,8 @@ func (c *Core) GetSessions() []Session {
|
||||
var sessions []Session
|
||||
getSessions := func() {
|
||||
for _, sinfo := range c.sessions.sinfos {
|
||||
// TODO? skipped known but timed out sessions?
|
||||
var session Session
|
||||
workerFunc := func() {
|
||||
session := Session{
|
||||
Coords: append([]byte{}, sinfo.coords...),
|
||||
MTU: sinfo.getMTU(),
|
||||
@ -221,6 +222,20 @@ func (c *Core) GetSessions() []Session {
|
||||
WasMTUFixed: sinfo.wasMTUFixed,
|
||||
}
|
||||
copy(session.PublicKey[:], sinfo.theirPermPub[:])
|
||||
}
|
||||
var skip bool
|
||||
func() {
|
||||
defer func() {
|
||||
if recover() != nil {
|
||||
skip = true
|
||||
}
|
||||
}()
|
||||
sinfo.doWorker(workerFunc)
|
||||
}()
|
||||
if skip {
|
||||
continue
|
||||
}
|
||||
// TODO? skipped known but timed out sessions?
|
||||
sessions = append(sessions, session)
|
||||
}
|
||||
}
|
||||
|
@ -236,6 +236,11 @@ func (c *Conn) Write(b []byte) (bytesWritten int, err error) {
|
||||
timer := getDeadlineTimer(&c.writeDeadline)
|
||||
defer util.TimerStop(timer)
|
||||
// Hand over to the session worker
|
||||
defer func() {
|
||||
if recover() != nil {
|
||||
err = errors.New("write failed")
|
||||
}
|
||||
}() // In case we're racing with a close
|
||||
select { // Send to worker
|
||||
case sinfo.worker <- workerFunc:
|
||||
case <-timer.C:
|
||||
|
Loading…
Reference in New Issue
Block a user