Quic requires an initial message to start the session so we need connect

This commit is contained in:
Asim Aslam 2019-08-08 00:19:16 +01:00
parent abc2ace409
commit 3fc7d9ea50
2 changed files with 15 additions and 15 deletions

View File

@ -144,15 +144,8 @@ func (t *tun) listen(link transport.Socket, listener bool) {
return return
} }
// first check Micro-Tunnel
switch msg.Header["Micro-Tunnel"] { switch msg.Header["Micro-Tunnel"] {
case "connect": case "connect", "close":
// assuming new connection
// TODO: do something with this
continue
case "close":
// assuming connection closed
// TODO: do something with this
continue continue
} }
@ -289,13 +282,11 @@ func (t *tun) connect() error {
continue continue
} }
err = c.Send(&transport.Message{ if err := c.Send(&transport.Message{
Header: map[string]string{ Header: map[string]string{
"Micro-Tunnel": "connect", "Micro-Tunnel": "connect",
}, },
}) }); err != nil {
if err != nil {
continue continue
} }
@ -399,6 +390,7 @@ func (t *tun) Dial(addr string) (Conn, error) {
if !ok { if !ok {
return nil, errors.New("error dialing " + addr) return nil, errors.New("error dialing " + addr)
} }
// set remote // set remote
c.remote = addr c.remote = addr
// set local // set local

View File

@ -3,6 +3,7 @@ package tunnel
import ( import (
"sync" "sync"
"testing" "testing"
"time"
"github.com/micro/go-micro/transport" "github.com/micro/go-micro/transport"
) )
@ -93,6 +94,8 @@ func TestTwoTunnel(t *testing.T) {
} }
defer tunB.Close() defer tunB.Close()
time.Sleep(time.Millisecond * 50)
// start tunA // start tunA
err = tunA.Connect() err = tunA.Connect()
if err != nil { if err != nil {
@ -100,14 +103,19 @@ func TestTwoTunnel(t *testing.T) {
} }
defer tunA.Close() defer tunA.Close()
time.Sleep(time.Millisecond * 50)
var wg sync.WaitGroup var wg sync.WaitGroup
// start accepting connections // start accepting connections
// on tunnel A
wg.Add(1) wg.Add(1)
go testAccept(t, tunB, &wg) go testAccept(t, tunA, &wg)
// send a message time.Sleep(time.Millisecond * 50)
testSend(t, tunA)
// dial and send via B
testSend(t, tunB)
// wait until done // wait until done
wg.Wait() wg.Wait()