Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[P2P] refactor: message handling #763

Merged
merged 14 commits into from
May 31, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: comment improvements
  • Loading branch information
bryanchriswhite committed May 23, 2023
commit 47af1f28cd25fd9301511638c8617160b2654937
6 changes: 4 additions & 2 deletions p2p/raintree/router.go
Original file line number Diff line number Diff line change
@@ -325,11 +325,11 @@ func (rtr *rainTreeRouter) handleStream(stream libp2pNetwork.Stream) {

// readStream reads the incoming stream, extracts the serialized `PocketEnvelope`
// data from the incoming `RainTreeMessage`, and passes it to the application by
// calling the configured `rtr.handler`.
// calling the configured `rtr.handler`. Intended to be called in a go routine.
func (rtr *rainTreeRouter) readStream(stream libp2pNetwork.Stream) {
// Time out if no data is sent to free resources.
// NB: tests using libp2p's `mocknet` rely on this not returning an error.
if err := stream.SetReadDeadline(newReadStreamDeadline()); err != nil {
// NB: tests using libp2p's `mocknet` rely on this not returning an error.
// `SetReadDeadline` not supported by `mocknet` streams.
rtr.logger.Error().Err(err).Msg("setting stream read deadline")
}
@@ -348,6 +348,8 @@ func (rtr *rainTreeRouter) readStream(stream libp2pNetwork.Stream) {
}

// done reading; reset to signal this to remote peer
bryanchriswhite marked this conversation as resolved.
Show resolved Hide resolved
// NB: failing to reset the stream can easily max out the number of available
// network connections on the receiver's side.
if err := stream.Reset(); err != nil {
rtr.logger.Error().Err(err).Msg("resetting stream (read-side)")
}