Skip to content

Commit

Permalink
p2p: fix missing error from SendReceive (#1304)
Browse files Browse the repository at this point in the history
Fixes issue with `PeerInfo` protocol reporting `zero` values like `SentAt`. This was due to missing returned error from `p2p.Sender.SendReceive`.

category: bug
ticket: #1295
  • Loading branch information
corverroos authored Oct 18, 2022
1 parent 428fa8a commit 4ebd38e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/peerinfo/peerinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func newInternal(tcpNode host.Host, peers []peer.ID, version string, lockHash []
// Register a simple handler that returns our info and ignores the request.
registerHandler("peerinfo", tcpNode, protocolID,
func() proto.Message { return new(pbv1.PeerInfo) },
func(ctx context.Context, peerID peer.ID, req proto.Message) (proto.Message, bool, error) {
func(context.Context, peer.ID, proto.Message) (proto.Message, bool, error) {
return &pbv1.PeerInfo{
CharonVersion: version,
LockHash: lockHash,
Expand Down
12 changes: 8 additions & 4 deletions p2p/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ func (s *Sender) addResult(ctx context.Context, peerID peer.ID, err error) {
s.states.Store(peerID, state) // Note there is a race if two results for the same peer is added at the same time, but this isn't critical.
}

// SendAsync returns nil sends a libp2p message asynchronously. It logs results on state change (success to/from failure).
// SendAsync returns nil and sends a libp2p message asynchronously.
// It logs results on state change (success to/from failure).
// It implements SendFunc.
func (s *Sender) SendAsync(parent context.Context, tcpNode host.Host, protoID protocol.ID, peerID peer.ID, msg proto.Message) error {
go func() {
Expand All @@ -119,17 +120,20 @@ func (s *Sender) SendAsync(parent context.Context, tcpNode host.Host, protoID pr
}

// SendReceive sends and receives a libp2p request and response message pair synchronously and then closes the stream.
// It returns false on any error and applies log filtering.
// The provided response proto will be populated if err is nil.
// It logs results on state change (success to/from failure).
// It implements SendReceiveFunc.
func (s *Sender) SendReceive(ctx context.Context, tcpNode host.Host, peerID peer.ID, req, resp proto.Message, protocols ...protocol.ID) error {
err := SendReceive(ctx, tcpNode, peerID, req, resp, protocols...)
s.addResult(ctx, peerID, err)

return nil
return err
}

// SendReceive sends and receives a libp2p request and response message
// pair synchronously and then closes the stream. It implements SendReceiveFunc.
// pair synchronously and then closes the stream.
// The provided response proto will be populated if err is nil.
// It implements SendReceiveFunc.
func SendReceive(ctx context.Context, tcpNode host.Host, peerID peer.ID,
req, resp proto.Message, protocols ...protocol.ID,
) error {
Expand Down

0 comments on commit 4ebd38e

Please sign in to comment.