Fix massive cruft in tunnel dial to set the link on discovered

This commit is contained in:
Asim Aslam 2019-09-04 20:18:26 +01:00
parent d8a1b47954
commit e15389febb

View File

@ -2,6 +2,7 @@ package tunnel
import ( import (
"errors" "errors"
"math/rand"
"strings" "strings"
"sync" "sync"
"time" "time"
@ -529,7 +530,7 @@ func (t *tun) listen(link *link) {
// bail if no session or listener has been found // bail if no session or listener has been found
if !exists { if !exists {
log.Debugf("Tunnel skipping no session exists") log.Debugf("Tunnel skipping no session %s %s exists", channel, sessionId)
// drop it, we don't care about // drop it, we don't care about
// messages we don't know about // messages we don't know about
continue continue
@ -837,6 +838,8 @@ func (t *tun) Dial(channel string, opts ...DialOption) (Session, error) {
return wait return wait
} }
var links []string
// non multicast so we need to find the link // non multicast so we need to find the link
t.RLock() t.RLock()
for _, link := range t.links { for _, link := range t.links {
@ -847,11 +850,18 @@ func (t *tun) Dial(channel string, opts ...DialOption) (Session, error) {
// we have at least one channel mapping // we have at least one channel mapping
if ok { if ok {
c.discovered = true c.discovered = true
break links = append(links, link.id)
} }
} }
t.RUnlock() t.RUnlock()
// discovered so set the link
if c.discovered {
// set the link
i := rand.Intn(len(links))
c.link = links[i]
}
// shit fuck // shit fuck
if !c.discovered { if !c.discovered {
msg := c.newMessage("discover") msg := c.newMessage("discover")