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
}
// 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

View File

@ -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()