From 2406ef9999eec960e8faf754199e2e76f1b54ba3 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 12 Sep 2019 17:12:49 -0700 Subject: [PATCH] Missing fixes for the tunnel --- tunnel/default.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/tunnel/default.go b/tunnel/default.go index b3ba8cc7..4aa19902 100644 --- a/tunnel/default.go +++ b/tunnel/default.go @@ -218,8 +218,6 @@ func (t *tun) monitor() { log.Debugf("Tunnel failed to setup node link to %s: %v", node, err) continue } - // set the link id to the remote address - link.id = link.Remote() // save the link t.Lock() t.links[node] = link @@ -441,7 +439,7 @@ func (t *tun) listen(link *link) { } // set to remote node - link.id = id + link.id = link.Remote() // set as connected link.connected = true link.Unlock() @@ -483,10 +481,10 @@ func (t *tun) listen(link *link) { // otherwise its a session mapping of sorts case "keepalive": log.Debugf("Tunnel link %s received keepalive", link.Remote()) - t.Lock() + link.Lock() // save the keepalive link.lastKeepAlive = time.Now() - t.Unlock() + link.Unlock() continue // a new connection dialled outbound case "open": @@ -671,6 +669,8 @@ func (t *tun) discover(link *link) { }); err != nil { log.Debugf("Tunnel failed to send discover to link %s: %v", link.id, err) } + case <-link.closed: + return case <-t.closed: return } @@ -686,6 +686,8 @@ func (t *tun) keepalive(link *link) { select { case <-t.closed: return + case <-link.closed: + return case <-keepalive.C: // send keepalive message log.Debugf("Tunnel sending keepalive to link: %v", link.Remote()) @@ -764,6 +766,12 @@ func (t *tun) connect() error { // create a new link link := newLink(sock) + // start keepalive monitor + go t.keepalive(link) + + // discover things on the remote side + go t.discover(link) + // listen for inbound messages. // only save the link once connected. // we do this inside liste @@ -793,7 +801,7 @@ func (t *tun) connect() error { } // save the link - t.links[link.Remote()] = link + t.links[node] = link } // process outbound messages to be sent