Skip to content

Commit

Permalink
refactor: better method name
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkmc committed Apr 15, 2021
1 parent 4b38ef7 commit 10de9cb
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func (m *manager) CloseDataTransferChannel(ctx context.Context, chid datatransfe
// ConnectTo opens a connection to a peer on the data-transfer protocol,
// retrying if necessary
func (m *manager) ConnectTo(ctx context.Context, p peer.ID) error {
return m.dataTransferNetwork.OpenStreamTo(ctx, p)
return m.dataTransferNetwork.ConnectWithRetry(ctx, p)
}

// close an open channel and fire an error event
Expand Down
4 changes: 2 additions & 2 deletions network/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ type DataTransferNetwork interface {
// ConnectTo establishes a connection to the given peer
ConnectTo(context.Context, peer.ID) error

// OpenStreamTo establishes a connection to the given peer, retrying if
// ConnectWithRetry establishes a connection to the given peer, retrying if
// necessary, and opens a stream on the data-transfer protocol to verify
// the peer will accept messages on the protocol
OpenStreamTo(ctx context.Context, p peer.ID) error
ConnectWithRetry(ctx context.Context, p peer.ID) error

// ID returns the peer id of this libp2p host
ID() peer.ID
Expand Down
8 changes: 6 additions & 2 deletions network/libp2p_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,19 @@ func (dtnet *libp2pDataTransferNetwork) ConnectTo(ctx context.Context, p peer.ID
return dtnet.host.Connect(ctx, peer.AddrInfo{ID: p})
}

// OpenStreamTo establishes a connection to the given peer, retrying if
// ConnectWithRetry establishes a connection to the given peer, retrying if
// necessary, and opens a stream on the data-transfer protocol to verify
// the peer will accept messages on the protocol
func (dtnet *libp2pDataTransferNetwork) OpenStreamTo(ctx context.Context, p peer.ID) error {
func (dtnet *libp2pDataTransferNetwork) ConnectWithRetry(ctx context.Context, p peer.ID) error {
// Open a stream over the data-transfer protocol, to make sure that the
// peer is listening on the protocol
s, err := dtnet.openStream(ctx, p, dtnet.dtProtocols...)
if err != nil {
return err
}

// We don't actually use the stream, we just open it to verify it's
// possible to connect over the data-transfer protocol, so we close it here
return s.Close()
}

Expand Down
2 changes: 1 addition & 1 deletion testutil/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (fn *FakeNetwork) ConnectTo(_ context.Context, _ peer.ID) error {
panic("not implemented")
}

func (fn *FakeNetwork) OpenStreamTo(ctx context.Context, p peer.ID) error {
func (fn *FakeNetwork) ConnectWithRetry(ctx context.Context, p peer.ID) error {
panic("implement me")
}

Expand Down

0 comments on commit 10de9cb

Please sign in to comment.