5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-30 06:41:36 +00:00

Merge pull request #446 from Arceliar/bugfixes

Bugfixes
This commit is contained in:
Arceliar 2019-06-29 19:00:11 -05:00 committed by GitHub
commit b8592669b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 10 deletions

View File

@ -225,11 +225,11 @@ func (tun *TunAdapter) reader() error {
panic("Given empty dstNodeID and dstNodeIDMask - this shouldn't happen") panic("Given empty dstNodeID and dstNodeIDMask - this shouldn't happen")
} }
// Dial to the remote node // Dial to the remote node
packet := append(util.GetBytes(), bs[:n]...)
go func() { go func() {
// FIXME just spitting out a goroutine to do this is kind of ugly and means we drop packets until the dial finishes // 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() tun.mutex.Lock()
_, known := tun.dials[*dstNodeID] _, known := tun.dials[*dstNodeID]
packet := append(util.GetBytes(), bs[:n]...)
tun.dials[*dstNodeID] = append(tun.dials[*dstNodeID], packet) tun.dials[*dstNodeID] = append(tun.dials[*dstNodeID], packet)
for len(tun.dials[*dstNodeID]) > 32 { for len(tun.dials[*dstNodeID]) > 32 {
util.PutBytes(tun.dials[*dstNodeID][0]) util.PutBytes(tun.dials[*dstNodeID][0])

View File

@ -211,16 +211,31 @@ func (c *Core) GetSessions() []Session {
var sessions []Session var sessions []Session
getSessions := func() { getSessions := func() {
for _, sinfo := range c.sessions.sinfos { for _, sinfo := range c.sessions.sinfos {
// TODO? skipped known but timed out sessions? var session Session
session := Session{ workerFunc := func() {
Coords: append([]byte{}, sinfo.coords...), session := Session{
MTU: sinfo.getMTU(), Coords: append([]byte{}, sinfo.coords...),
BytesSent: sinfo.bytesSent, MTU: sinfo.getMTU(),
BytesRecvd: sinfo.bytesRecvd, BytesSent: sinfo.bytesSent,
Uptime: time.Now().Sub(sinfo.timeOpened), BytesRecvd: sinfo.bytesRecvd,
WasMTUFixed: sinfo.wasMTUFixed, Uptime: time.Now().Sub(sinfo.timeOpened),
WasMTUFixed: sinfo.wasMTUFixed,
}
copy(session.PublicKey[:], sinfo.theirPermPub[:])
} }
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) sessions = append(sessions, session)
} }
} }

View File

@ -236,6 +236,11 @@ func (c *Conn) Write(b []byte) (bytesWritten int, err error) {
timer := getDeadlineTimer(&c.writeDeadline) timer := getDeadlineTimer(&c.writeDeadline)
defer util.TimerStop(timer) defer util.TimerStop(timer)
// Hand over to the session worker // 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 select { // Send to worker
case sinfo.worker <- workerFunc: case sinfo.worker <- workerFunc:
case <-timer.C: case <-timer.C: