waku/v2/peermanager/peer_manager.go
File peer_manager.go
has 613 lines of code (exceeds 500 allowed). Consider refactoring. Open
Open
package peermanager
import (
"context"
"errors"
PeerManager
has 25 methods (exceeds 20 allowed). Consider refactoring. Open
Open
type PeerManager struct {
peerConnector *PeerConnectionStrategy
metadata *metadata.WakuMetadata
relay *relay.WakuRelay
maxPeers int
Method PeerManager.prunePeerStore
has a Cognitive Complexity of 34 (exceeds 20 allowed). Consider refactoring. Open
Open
func (pm *PeerManager) prunePeerStore() {
peers := pm.host.Peerstore().Peers()
numPeers := len(peers)
if numPeers < pm.maxPeers {
pm.logger.Debug("peerstore size within capacity, not pruning", zap.Int("capacity", pm.maxPeers), zap.Int("numPeers", numPeers))
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method PeerManager.prunePeerStore
has 74 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (pm *PeerManager) prunePeerStore() {
peers := pm.host.Peerstore().Peers()
numPeers := len(peers)
if numPeers < pm.maxPeers {
pm.logger.Debug("peerstore size within capacity, not pruning", zap.Int("capacity", pm.maxPeers), zap.Int("numPeers", numPeers))
Function NewPeerManager
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
func NewPeerManager(maxConnections int, maxPeers int, metadata *metadata.WakuMetadata, relay *relay.WakuRelay, relayEnabled bool, logger *zap.Logger) *PeerManager {
Method PeerManager.addPeer
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
func (pm *PeerManager) addPeer(ID peer.ID, addrs []ma.Multiaddr, origin wps.Origin, pubSubTopics []string, protocols ...protocol.ID) error {
Method PeerManager.checkAndUpdateTopicHealth
has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring. Open
Open
func (pm *PeerManager) checkAndUpdateTopicHealth(topic *NodeTopicDetails) int {
if topic == nil {
return 0
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"