gossip/handler.go
Method ProtocolManager.handleMsg
has a Cognitive Complexity of 127 (exceeds 20 allowed). Consider refactoring. Open
Open
func (pm *ProtocolManager) handleMsg(p *peer) error {
// Read the next message from the remote peer, and ensure it's fully consumed
msg, err := p.rw.ReadMsg()
if err != nil {
return err
- 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 ProtocolManager.handleMsg
has 233 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (pm *ProtocolManager) handleMsg(p *peer) error {
// Read the next message from the remote peer, and ensure it's fully consumed
msg, err := p.rw.ReadMsg()
if err != nil {
return err
File handler.go
has 740 lines of code (exceeds 500 allowed). Consider refactoring. Open
Open
package gossip
import (
"fmt"
"math"
Method ProtocolManager.handleMsg
has 21 return statements (exceeds 4 allowed). Open
Open
func (pm *ProtocolManager) handleMsg(p *peer) error {
// Read the next message from the remote peer, and ensure it's fully consumed
msg, err := p.rw.ReadMsg()
if err != nil {
return err
Method ProtocolManager.makeFetcher
has 61 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (pm *ProtocolManager) makeFetcher(checkers *eventcheck.Checkers) (*fetcher.Fetcher, *ordering.EventBuffer) {
// checkers
firstCheck := func(e *inter.Event) error {
if err := checkers.Basiccheck.Validate(e); err != nil {
return err
Function NewProtocolManager
has 9 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
config *Config,
notifier dagNotifier,
txpool txPool,
engineMu *sync.RWMutex,
checkers *eventcheck.Checkers,
Method ProtocolManager.makeFetcher
has 11 return statements (exceeds 4 allowed). Open
Open
func (pm *ProtocolManager) makeFetcher(checkers *eventcheck.Checkers) (*fetcher.Fetcher, *ordering.EventBuffer) {
// checkers
firstCheck := func(e *inter.Event) error {
if err := checkers.Basiccheck.Validate(e); err != nil {
return err
Method ProtocolManager.onNewEpochLoop
has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring. Open
Open
func (pm *ProtocolManager) onNewEpochLoop() {
defer pm.loopsWg.Done()
for {
select {
case myEpoch := <-pm.newEpochsCh:
- 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
Avoid deeply nested control flow statements. Open
Open
if fullRecipients < 4 {
fullRecipients = 4
}