From e15389febb1a55ae5edb0678765e69e022515ff4 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 4 Sep 2019 20:18:26 +0100 Subject: [PATCH] Fix massive cruft in tunnel dial to set the link on discovered --- tunnel/default.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tunnel/default.go b/tunnel/default.go index add48eb8..860b6a96 100644 --- a/tunnel/default.go +++ b/tunnel/default.go @@ -2,6 +2,7 @@ package tunnel import ( "errors" + "math/rand" "strings" "sync" "time" @@ -529,7 +530,7 @@ func (t *tun) listen(link *link) { // bail if no session or listener has been found 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 // messages we don't know about continue @@ -837,6 +838,8 @@ func (t *tun) Dial(channel string, opts ...DialOption) (Session, error) { return wait } + var links []string + // non multicast so we need to find the link t.RLock() 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 if ok { c.discovered = true - break + links = append(links, link.id) } } t.RUnlock() + // discovered so set the link + if c.discovered { + // set the link + i := rand.Intn(len(links)) + c.link = links[i] + } + // shit fuck if !c.discovered { msg := c.newMessage("discover")