Skip to content

Commit

Permalink
refactor: raintree logging methods
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanchriswhite committed May 19, 2023
1 parent 9e49bae commit 90d9311
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
31 changes: 31 additions & 0 deletions p2p/raintree/logging.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package raintree

import (
libp2pNetwork "github.com/libp2p/go-libp2p/core/network"

"github.com/pokt-network/pocket/logger"
"github.com/pokt-network/pocket/p2p/utils"
)

// logStream logs the incoming stream and its scope stats
func (rtr *rainTreeRouter) logStream(stream libp2pNetwork.Stream) {
rtr.logStreamScopeStats(stream)

remotePeer, err := utils.PeerFromLibp2pStream(stream)
if err != nil {
rtr.logger.Debug().Err(err).Msg("getting remote remotePeer")
} else {
utils.LogIncomingMsg(rtr.logger, rtr.getHostname(), remotePeer)
}
}

// logStreamScopeStats logs the incoming stream's scope stats
// (see: https://pkg.go.dev/github.com/libp2p/[email protected]/core/network#StreamScope)
func (rtr *rainTreeRouter) logStreamScopeStats(stream libp2pNetwork.Stream) {
if err := utils.LogScopeStatFactory(
&logger.Global.Logger,
"stream scope (read-side)",
)(stream.Scope()); err != nil {
rtr.logger.Debug().Err(err).Msg("logging stream scope stats")
}
}
21 changes: 2 additions & 19 deletions p2p/raintree/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,15 +326,8 @@ func (rtr *rainTreeRouter) readStream(stream libp2pNetwork.Stream) {
rtr.logger.Debug().Err(err).Msg("setting stream read deadline")
}

// debug logging: stream scope stats
// (see: https://pkg.go.dev/github.com/libp2p/[email protected]/core/network#StreamScope)
if err := utils.LogScopeStatFactory(
&logger.Global.Logger,
"stream scope (read-side)",
)(stream.Scope()); err != nil {
rtr.logger.Debug().Err(err).Msg("logging stream scope stats")
}
// ---
// log incoming stream
rtr.logStream(stream)

// read stream
data, err := io.ReadAll(stream)
Expand All @@ -351,16 +344,6 @@ func (rtr *rainTreeRouter) readStream(stream libp2pNetwork.Stream) {
rtr.logger.Debug().Err(err).Msg("resetting stream (read-side)")
}

// debug logging
remotePeer, err := utils.PeerFromLibp2pStream(stream)
if err != nil {
rtr.logger.Debug().Err(err).Msg("getting remote remotePeer")
} else {
utils.LogIncomingMsg(rtr.logger, rtr.getHostname(), remotePeer)
}
// ---

// TODO_THIS_COMMIT: refactor
// handle rain tree message
appMsgData, err := rtr.handleRainTreeMsg(data)
if err != nil {
Expand Down

0 comments on commit 90d9311

Please sign in to comment.