Skip to content

Commit

Permalink
holepunch: fix incorrect message type for the SYNC message (#1478)
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed May 11, 2022
1 parent 4cabcba commit 530ef89
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
21 changes: 13 additions & 8 deletions p2p/protocol/holepunch/holepunch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion p2p/protocol/holepunch/holepuncher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 530ef89

Please sign in to comment.