From f848041c49cf76415d1b910952ce1b18f2df77c1 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 20 Aug 2019 17:20:21 +0100 Subject: [PATCH] Add a message type to the tunnel --- tunnel/default.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tunnel/default.go b/tunnel/default.go index c819c7a7..0c0ae43c 100644 --- a/tunnel/default.go +++ b/tunnel/default.go @@ -170,6 +170,9 @@ func (t *tun) process() { newMsg.Header[k] = v } + // set message head + newMsg.Header["Micro-Tunnel"] = "message" + // set the tunnel id on the outgoing message newMsg.Header["Micro-Tunnel-Id"] = msg.id @@ -229,6 +232,8 @@ func (t *tun) listen(link *link) { if token == t.token { link.loopback = true } + + // nothing more to do continue case "close": log.Debugf("Tunnel link %s closing connection", link.Remote()) @@ -239,8 +244,17 @@ func (t *tun) listen(link *link) { log.Debugf("Tunnel link %s received keepalive", link.Remote()) link.lastKeepAlive = time.Now() continue + case "message": + // process message + log.Debugf("Received %+v from %s", msg, link.Remote()) + default: + // blackhole it + continue } + // strip message header + delete(msg.Header, "Micro-Tunnel") + // the tunnel id id := msg.Header["Micro-Tunnel-Id"] delete(msg.Header, "Micro-Tunnel-Id") @@ -249,6 +263,9 @@ func (t *tun) listen(link *link) { session := msg.Header["Micro-Tunnel-Session"] delete(msg.Header, "Micro-Tunnel-Session") + // strip token header + delete(msg.Header, "Micro-Tunnel-Token") + // if the session id is blank there's nothing we can do // TODO: check this is the case, is there any reason // why we'd have a blank session? Is the tunnel @@ -260,8 +277,6 @@ func (t *tun) listen(link *link) { var s *socket var exists bool - log.Debugf("Received %+v from %s", msg, link.Remote()) - switch { case link.loopback: s, exists = t.getSocket(id, "listener")