Showing 300 of 401 total issues
Method criteriaInterest.equals
has 5 return statements (exceeds 4 allowed). Open
Open
func (c criteriaInterest) equals(other criteriaInterest) bool {
if c.peerID != other.peerID {
return false
}
Function MakeHost
has 5 return statements (exceeds 4 allowed). Open
Open
func MakeHost(ctx context.Context, port int, randomness io.Reader) (host.Host, error) {
// Creates a new RSA key pair for this host.
prvKey, _, err := crypto.GenerateKeyPairWithReader(crypto.RSA, 2048, randomness)
if err != nil {
log.Error(err.Error())
Function GenerateRandomSQLInsert
has 5 return statements (exceeds 4 allowed). Open
Open
func GenerateRandomSQLInsert(maxLength int) (string, error) {
// Random table name
tableName, err := GenerateRandomASCIIString(10)
if err != nil {
return "", err
Function RetrieveNodes
has 5 return statements (exceeds 4 allowed). Open
Open
func RetrieveNodes(ctx context.Context, url string, opts ...DNSDiscoveryOption) ([]DiscoveredNode, error) {
var discoveredNodes []DiscoveredNode
params := new(dnsDiscoveryParameters)
for _, opt := range opts {
Method MessageSender.Send
has 5 return statements (exceeds 4 allowed). Open
Open
func (ms *MessageSender) Send(req *Request) error {
logger := ms.logger.With(
zap.Stringer("envelopeHash", req.envelope.Hash()),
zap.String("pubsubTopic", req.envelope.PubsubTopic()),
zap.String("contentTopic", req.envelope.Message().ContentTopic),
Method MembershipFetcher.HandleGroupUpdates
has 5 return statements (exceeds 4 allowed). Open
Open
func (mf *MembershipFetcher) HandleGroupUpdates(ctx context.Context, handler RegistrationEventHandler) error {
fromBlock := mf.web3Config.RLNContract.DeployedBlockNumber
metadata, err := mf.GetMetadata()
if err != nil {
mf.log.Warn("could not load last processed block from metadata. Starting onchain sync from deployment block", zap.Error(err), zap.Uint64("deploymentBlock", mf.web3Config.RLNContract.DeployedBlockNumber))
Function Migrations
has 5 return statements (exceeds 4 allowed). Open
Open
func Migrations(db *sql.DB, logger *zap.Logger) error {
migrationDriver, err := migrationDriver(db)
if err != nil {
return err
}
Method DB.Register
has 5 return statements (exceeds 4 allowed). Open
Open
func (db *DB) Register(p peer.ID, ns string, signedPeerRecord []byte, ttl int) (uint64, error) {
pid := p.String()
expire := time.Now().Unix() + int64(ttl)
tx, err := db.db.Begin()
Function main
has 5 return statements (exceeds 4 allowed). Open
Open
func main() {
hostAddr, _ := net.ResolveTCPAddr("tcp", "0.0.0.0:0")
key, err := randomHex(32)
if err != nil {
log.Error("Could not generate random key", zap.Error(err))
Function TestNetworkPartition
has 5 return statements (exceeds 4 allowed). Open
Open
func TestNetworkPartition(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
defer cancel()
t.Log("Starting TestMessageRecovery")
Method PeerConnectionStrategy.consumeSubscription
has 5 return statements (exceeds 4 allowed). Open
Open
func (c *PeerConnectionStrategy) consumeSubscription(s subscription) {
for {
// for returning from the loop when peerConnector is paused.
select {
case <-c.Context().Done():
Method WakuNode.startRlnRelay
has 5 return statements (exceeds 4 allowed). Open
Open
func (w *WakuNode) startRlnRelay(ctx context.Context) error {
rlnRelay := w.rlnRelay.(*rln.WakuRLNRelay)
err := rlnRelay.Start(ctx)
if err != nil {
Method Config.Build
has 5 return statements (exceeds 4 allowed). Open
Open
func (w *Config) Build(ctx context.Context) error {
if w.configured {
return errors.New("already configured")
}
Method MembershipFetcher.getEvents
has 5 return statements (exceeds 4 allowed). Open
Open
func (mf *MembershipFetcher) getEvents(ctx context.Context, fromBlock uint64, toBlock uint64) ([]*contracts.RLNMemberRegistered, error) {
evts, err := mf.fetchEvents(ctx, fromBlock, toBlock)
if err != nil {
if tooMuchDataRequestedError(err) { // divide the range and try again
mid := (fromBlock + toBlock) / 2
Function decapsulateCircuitRelayAddr
has 5 return statements (exceeds 4 allowed). Open
Open
func decapsulateCircuitRelayAddr(ctx context.Context, addr ma.Multiaddr) (ma.Multiaddr, error) {
_, err := addr.ValueForProtocol(ma.P_CIRCUIT)
if err != nil {
return nil, errors.New("not a circuit relay address")
}
Method WakuFilterLightNode.IncorrectSubscribe
has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring. Open
Open
func (wf *WakuFilterLightNode) IncorrectSubscribe(ctx context.Context, contentFilter protocol.ContentFilter, opts ...FilterSubscribeOption) ([]*subscription.SubscriptionDetails, error) {
wf.RLock()
defer wf.RUnlock()
if err := wf.ErrOnNotRunning(); err != nil {
return nil, 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 WakuRelay.upsertTopic
has 5 return statements (exceeds 4 allowed). Open
Open
func (w *WakuRelay) upsertTopic(topic string) (*pubsub.Topic, error) {
topicData, ok := w.topics[topic]
if !ok { // Joins topic if node hasn't joined yet
err := w.pubsub.RegisterTopicValidator(topic, w.topicValidator(topic))
if err != nil {
Method WakuPeerExchange.handleResponse
has 5 return statements (exceeds 4 allowed). Open
Open
func (wakuPX *WakuPeerExchange) handleResponse(ctx context.Context, response *pb.PeerExchangeResponse, params *PeerExchangeRequestParameters) error {
var discoveredPeers []struct {
addrInfo peer.AddrInfo
enr *enode.Node
}
Method PushRpc.ValidateRequest
has 5 return statements (exceeds 4 allowed). Open
Open
func (x *PushRpc) ValidateRequest() error {
if x.RequestId == "" {
return errMissingRequestID
}
Method WakuLightPush.handleOpts
has 5 return statements (exceeds 4 allowed). Open
Open
func (wakuLP *WakuLightPush) handleOpts(ctx context.Context, message *wpb.WakuMessage, opts ...RequestOption) (*lightPushRequestParameters, error) {
params := new(lightPushRequestParameters)
params.host = wakuLP.h
params.log = wakuLP.log
params.pm = wakuLP.pm