Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 11 additions & 0 deletions cmd/p2p/sensor/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
type peerData struct {
Name string `json:"name"`
ProtocolVersion uint `json:"protocol_version"`
BlockHash string `json:"block_hash,omitempty"`
BlockNumber uint64 `json:"block_number,omitempty"`
Received p2p.MessageCount `json:"received"`
Sent p2p.MessageCount `json:"sent"`
PacketsReceived p2p.MessageCount `json:"packets_received"`
Expand Down Expand Up @@ -59,7 +61,7 @@
// handleAPI sets up the API for interacting with the sensor. All endpoints
// return information about the sensor node and all connected peers, including
// the types and counts of eth packets sent and received by each peer.
func handleAPI(server *ethp2p.Server, conns *p2p.Conns) {

Check failure on line 64 in cmd/p2p/sensor/api.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 18 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=0xPolygon_polygon-cli&issues=AZ0EsRrQuLbE7AhQd-dq&open=AZ0EsRrQuLbE7AhQd-dq&pullRequest=862
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
Expand All @@ -85,9 +87,18 @@
continue
}

// Get latest block info for this peer
blockHash, blockNumber := conns.GetPeerLatestBlock(peerID)
var blockHashStr string
if blockNumber > 0 {
blockHashStr = blockHash.Hex()
}

peers[url] = peerData{
Name: conns.GetPeerName(peerID),
ProtocolVersion: conns.GetPeerVersion(peerID),
BlockHash: blockHashStr,
BlockNumber: blockNumber,
Received: messages.Received,
Sent: messages.Sent,
PacketsReceived: messages.PacketsReceived,
Expand Down
Loading
Loading