Merge pull request #732 from micro/massive-cruft
Fix massive cruft in tunnel dial to set the link on discovered
This commit is contained in:
commit
e33bd17894
@ -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,20 @@ 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
|
||||||
|
// TODO: pick the link efficiently based
|
||||||
|
// on link status and saturation.
|
||||||
|
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")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user