From 3fc7d9ea503ff042cce90a6f643fbf7e16b7c250 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 8 Aug 2019 00:19:16 +0100 Subject: [PATCH] Quic requires an initial message to start the session so we need connect --- tunnel/default.go | 16 ++++------------ tunnel/tunnel_test.go | 14 +++++++++++--- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/tunnel/default.go b/tunnel/default.go index ff86bb6b..7d2d3984 100644 --- a/tunnel/default.go +++ b/tunnel/default.go @@ -144,15 +144,8 @@ func (t *tun) listen(link transport.Socket, listener bool) { return } - // first check Micro-Tunnel switch msg.Header["Micro-Tunnel"] { - case "connect": - // assuming new connection - // TODO: do something with this - continue - case "close": - // assuming connection closed - // TODO: do something with this + case "connect", "close": continue } @@ -289,13 +282,11 @@ func (t *tun) connect() error { continue } - err = c.Send(&transport.Message{ + if err := c.Send(&transport.Message{ Header: map[string]string{ "Micro-Tunnel": "connect", }, - }) - - if err != nil { + }); err != nil { continue } @@ -399,6 +390,7 @@ func (t *tun) Dial(addr string) (Conn, error) { if !ok { return nil, errors.New("error dialing " + addr) } + // set remote c.remote = addr // set local diff --git a/tunnel/tunnel_test.go b/tunnel/tunnel_test.go index b29af5bc..1580d4a9 100644 --- a/tunnel/tunnel_test.go +++ b/tunnel/tunnel_test.go @@ -3,6 +3,7 @@ package tunnel import ( "sync" "testing" + "time" "github.com/micro/go-micro/transport" ) @@ -93,6 +94,8 @@ func TestTwoTunnel(t *testing.T) { } defer tunB.Close() + time.Sleep(time.Millisecond * 50) + // start tunA err = tunA.Connect() if err != nil { @@ -100,14 +103,19 @@ func TestTwoTunnel(t *testing.T) { } defer tunA.Close() + time.Sleep(time.Millisecond * 50) + var wg sync.WaitGroup // start accepting connections + // on tunnel A wg.Add(1) - go testAccept(t, tunB, &wg) + go testAccept(t, tunA, &wg) - // send a message - testSend(t, tunA) + time.Sleep(time.Millisecond * 50) + + // dial and send via B + testSend(t, tunB) // wait until done wg.Wait()