holepunch: fix incorrect message type for the SYNC message (#1478)

This commit is contained in:
Marten Seemann 2022-05-10 22:18:07 +02:00 committed by GitHub
parent 393e3518b3
commit f383f4681f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 9 deletions

View File

@ -112,8 +112,9 @@ func TestDirectDialWorks(t *testing.T) {
}
func TestEndToEndSimConnect(t *testing.T) {
tr := &mockEventTracer{}
h1, h2, relay, _ := makeRelayedHosts(t, nil, holepunch.WithTracer(tr), true)
h1tr := &mockEventTracer{}
h2tr := &mockEventTracer{}
h1, h2, relay, _ := makeRelayedHosts(t, holepunch.WithTracer(h1tr), holepunch.WithTracer(h2tr), true)
defer h1.Close()
defer h2.Close()
defer relay.Close()
@ -122,18 +123,22 @@ func TestEndToEndSimConnect(t *testing.T) {
ensureDirectConn(t, h1, h2)
// ensure no hole-punching streams are open on either side
ensureNoHolePunchingStream(t, h1, h2)
var events []*holepunch.Event
var h2Events []*holepunch.Event
require.Eventually(t,
func() bool {
events = tr.getEvents()
return len(events) == 3
h2Events = h2tr.getEvents()
return len(h2Events) == 3
},
time.Second,
10*time.Millisecond,
)
require.Equal(t, events[0].Type, holepunch.StartHolePunchEvtT)
require.Equal(t, events[1].Type, holepunch.HolePunchAttemptEvtT)
require.Equal(t, events[2].Type, holepunch.EndHolePunchEvtT)
require.Equal(t, holepunch.StartHolePunchEvtT, h2Events[0].Type)
require.Equal(t, holepunch.HolePunchAttemptEvtT, h2Events[1].Type)
require.Equal(t, holepunch.EndHolePunchEvtT, h2Events[2].Type)
h1Events := h1tr.getEvents()
require.Len(t, h1Events, 2)
require.Equal(t, holepunch.StartHolePunchEvtT, h1Events[0].Type)
require.Equal(t, holepunch.HolePunchAttemptEvtT, h1Events[1].Type)
}
func TestFailuresOnInitiator(t *testing.T) {

View File

@ -228,7 +228,7 @@ func (hp *holePuncher) initiateHolePunchImpl(str network.Stream) ([]ma.Multiaddr
return nil, 0, errors.New("didn't receive any public addresses in CONNECT")
}
if err := w.WriteMsg(&pb.HolePunch{Type: pb.HolePunch_CONNECT.Enum()}); err != nil {
if err := w.WriteMsg(&pb.HolePunch{Type: pb.HolePunch_SYNC.Enum()}); err != nil {
return nil, 0, fmt.Errorf("failed to send SYNC message for hole punching: %w", err)
}
return addrs, rtt, nil