From c840cee404cfd25c67bdd3e10c084036834554ec Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 1 Dec 2019 19:36:16 +0000 Subject: [PATCH] A variety of fixes to try combat the multicast issue --- network/default.go | 10 +++++----- tunnel/default.go | 17 +++++++++++------ tunnel/listener.go | 2 +- tunnel/session.go | 5 ----- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/network/default.go b/network/default.go index 5d4a9711..0b19a848 100644 --- a/network/default.go +++ b/network/default.go @@ -939,17 +939,17 @@ func (n *network) Connect() error { log.Debugf("Network failed to resolve nodes: %v", err) } - // initialize the tunnel to resolved nodes - n.tunnel.Init( - tunnel.Nodes(nodes...), - ) - // connect network tunnel if err := n.tunnel.Connect(); err != nil { n.Unlock() return err } + // initialize the tunnel to resolved nodes + n.tunnel.Init( + tunnel.Nodes(nodes...), + ) + // return if already connected if n.connected { // unlock first diff --git a/tunnel/default.go b/tunnel/default.go index fc24ee9d..1a3e3c35 100644 --- a/tunnel/default.go +++ b/tunnel/default.go @@ -502,22 +502,26 @@ func (t *tun) listen(link *link) { // TODO: handle the close message // maybe report io.EOF or kill the link - // close the link entirely + // if there is no channel then we close the link + // as its a signal from the other side to close the connection if len(channel) == 0 { log.Debugf("Tunnel link %s received close message", link.Remote()) return } - // the entire listener was closed so remove it from the mapping + // the entire listener was closed by the remote side so we need to + // remove the channel mapping for it. should we also close sessions? if sessionId == "listener" { link.delChannel(channel) continue } + // assuming there's a channel and session // try get the dialing socket - _, exists := t.getSession(channel, sessionId) - if exists { - // delete and continue + s, exists := t.getSession(channel, sessionId) + if exists && s.mode == Unicast && !loopback { + // only delete this if its unicast + // but not if its a loopback conn t.delSession(channel, sessionId) continue } @@ -673,6 +677,7 @@ func (t *tun) listen(link *link) { typ: mtype, channel: channel, session: sessionId, + mode: s.mode, data: tmsg, link: link.id, loopback: loopback, @@ -703,7 +708,7 @@ func (t *tun) discover(link *link) { "Micro-Tunnel-Id": t.id, }, }); err != nil { - log.Debugf("Tunnel failed to send discover to link %s: %v", link.id, err) + log.Debugf("Tunnel failed to send discover to link %s: %v", link.Remote(), err) } case <-link.closed: return diff --git a/tunnel/listener.go b/tunnel/listener.go index 62883777..7ba6074e 100644 --- a/tunnel/listener.go +++ b/tunnel/listener.go @@ -88,7 +88,7 @@ func (t *tunListener) process() { // the link the message was received on link: m.link, // set the connection mode - mode: t.session.mode, + mode: m.mode, // close chan closed: make(chan bool), // recv called by the acceptor diff --git a/tunnel/session.go b/tunnel/session.go index a0dbef93..4b8721aa 100644 --- a/tunnel/session.go +++ b/tunnel/session.go @@ -413,11 +413,6 @@ func (s *session) Close() error { default: close(s.closed) - // don't broadcast the close for multicast - if s.mode != Unicast { - return nil - } - // append to backlog msg := s.newMessage("close") // no error response on close