waku-org/go-waku

View on GitHub
waku/v2/peermanager/peer_manager.go

Summary

Maintainability
D
1 day
Test Coverage
F
52%

File peer_manager.go has 613 lines of code (exceeds 500 allowed). Consider refactoring.
Open

package peermanager

import (
    "context"
    "errors"
Severity: Minor
Found in waku/v2/peermanager/peer_manager.go - About 4 hrs to fix

    PeerManager has 25 methods (exceeds 20 allowed). Consider refactoring.
    Open

    type PeerManager struct {
        peerConnector          *PeerConnectionStrategy
        metadata               *metadata.WakuMetadata
        relay                  *relay.WakuRelay
        maxPeers               int
    Severity: Minor
    Found in waku/v2/peermanager/peer_manager.go - About 2 hrs to fix

      Method PeerManager.prunePeerStore has a Cognitive Complexity of 34 (exceeds 20 allowed). Consider refactoring.
      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))
      Severity: Minor
      Found in waku/v2/peermanager/peer_manager.go - About 2 hrs to fix

      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

      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))
      Severity: Minor
      Found in waku/v2/peermanager/peer_manager.go - About 1 hr to fix

        Function NewPeerManager has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        func NewPeerManager(maxConnections int, maxPeers int, metadata *metadata.WakuMetadata, relay *relay.WakuRelay, relayEnabled bool, logger *zap.Logger) *PeerManager {
        Severity: Minor
        Found in waku/v2/peermanager/peer_manager.go - About 45 mins to fix

          Method PeerManager.addPeer has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          func (pm *PeerManager) addPeer(ID peer.ID, addrs []ma.Multiaddr, origin wps.Origin, pubSubTopics []string, protocols ...protocol.ID) error {
          Severity: Minor
          Found in waku/v2/peermanager/peer_manager.go - About 35 mins to fix

            Method PeerManager.checkAndUpdateTopicHealth has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring.
            Open

            func (pm *PeerManager) checkAndUpdateTopicHealth(topic *NodeTopicDetails) int {
                if topic == nil {
                    return 0
                }
            
            
            Severity: Minor
            Found in waku/v2/peermanager/peer_manager.go - About 35 mins to fix

            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

            There are no issues that match your filters.

            Category
            Status