waku-org/go-waku

View on GitHub

Showing 299 of 400 total issues

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

Function New has 5 return statements (exceeds 4 allowed).
Open

func New(path string, appInfo AppInfo, logger *zap.Logger) (*AppKeystore, error) {
    logger = logger.Named("rln-keystore")

    _, err := os.Stat(path)
    if err != nil {
Severity: Major
Found in waku/v2/protocol/rln/keystore/keystore.go - About 35 mins to fix

    Method MembershipFetcher.loadOldEvents has 5 return statements (exceeds 4 allowed).
    Open

    func (mf *MembershipFetcher) loadOldEvents(ctx context.Context, fromBlock, toBlock uint64, handler RegistrationEventHandler) error {
        for ; fromBlock+maxBatchSize < toBlock; fromBlock += maxBatchSize + 1 { // check if the end of the batch is within the toBlock range
            t1 := time.Now()
            events, err := mf.getEvents(ctx, fromBlock, fromBlock+maxBatchSize)
            if err != nil {
    Severity: Major
    Found in waku/v2/protocol/rln/group_manager/dynamic/membership_fetcher.go - About 35 mins to fix

      Function GenerateRandomSQLInsert has 5 return statements (exceeds 4 allowed).
      Open

      func GenerateRandomSQLInsert(maxLength int) (string, error) {
          // Random table name
          tableName, err := GenerateRandomASCIIString(10)
          if err != nil {
              return "", err
      Severity: Major
      Found in tests/utils.go - About 35 mins to fix

        Method WakuNode.getENRAddresses has 5 return statements (exceeds 4 allowed).
        Open

        func (w *WakuNode) getENRAddresses(ctx context.Context, addrs []ma.Multiaddr) (extAddr *net.TCPAddr, multiaddr []ma.Multiaddr, err error) {
            extAddr, err = selectMostExternalAddress(addrs)
            if err != nil {
                return nil, nil, err
            }
        Severity: Major
        Found in waku/v2/node/localnode.go - About 35 mins to fix

          Method Config.Build has 5 return statements (exceeds 4 allowed).
          Open

          func (w *Config) Build(ctx context.Context) error {
              if w.configured {
                  return errors.New("already configured")
              }
          
          
          Severity: Major
          Found in waku/v2/protocol/rln/web3/web3.go - About 35 mins to fix

            Method DBStore.Query has 5 return statements (exceeds 4 allowed).
            Open

            func (d *DBStore) Query(query *pb.HistoryQuery) (*pb.Index, []StoredMessage, error) {
                start := time.Now()
                defer func() {
                    elapsed := time.Since(start)
                    d.log.Info(fmt.Sprintf("Loading records from the DB took %s", elapsed))
            Severity: Major
            Found in waku/persistence/store.go - About 35 mins to fix

              Method PeerConnectionStrategy.consumeSubscription has 5 return statements (exceeds 4 allowed).
              Open

              func (c *PeerConnectionStrategy) consumeSubscription(s subscription) {
                  for {
                      // for returning from the loop when peerConnector is paused.
                      select {
                      case <-c.Context().Done():
              Severity: Major
              Found in waku/v2/peermanager/peer_connector.go - About 35 mins to fix

                Method Chat.publish has 5 return statements (exceeds 4 allowed).
                Open

                func (c *Chat) publish(ctx context.Context, message string) error {
                    msg := &pb.Chat2Message{
                        Timestamp: uint64(c.node.Timesource().Now().Unix()),
                        Nick:      c.nick,
                        Payload:   []byte(message),
                Severity: Major
                Found in examples/chat2/chat.go - About 35 mins to fix

                  Method Chat.requestMessageFromPeer has 5 return statements (exceeds 4 allowed).
                  Open

                  func (c *Chat) requestMessageFromPeer(peerID peer.ID, messageID string) (*pb.Message, error) {
                      ctx, cancel := context.WithTimeout(c.ctx, 30*time.Second)
                      defer cancel()
                  
                      stream, err := c.node.Host().NewStream(ctx, peerID, messageRequestProtocolID)
                  Severity: Major
                  Found in examples/chat2-reliable/peer_retrieval.go - About 35 mins to fix

                    Method Chat.publish has 5 return statements (exceeds 4 allowed).
                    Open

                    func (c *Chat) publish(ctx context.Context, message *pb.Message) error {
                        msgBytes, err := proto.Marshal(message)
                        if err != nil {
                            return err
                        }
                    Severity: Major
                    Found in examples/chat2-reliable/chat.go - About 35 mins to fix

                      Method criteriaInterest.equals has 5 return statements (exceeds 4 allowed).
                      Open

                      func (c criteriaInterest) equals(other criteriaInterest) bool {
                          if c.peerID != other.peerID {
                              return false
                          }
                      
                      
                      Severity: Major
                      Found in waku/v2/api/missing/criteria_interest.go - About 35 mins to fix

                        Function decapsulateCircuitRelayAddr has 5 return statements (exceeds 4 allowed).
                        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")
                            }
                        Severity: Major
                        Found in waku/v2/node/localnode.go - About 35 mins to fix

                          Method MembershipFetcher.getEvents has 5 return statements (exceeds 4 allowed).
                          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
                          Severity: Major
                          Found in waku/v2/protocol/rln/group_manager/dynamic/membership_fetcher.go - About 35 mins to fix

                            Method WakuRelay.upsertTopic has 5 return statements (exceeds 4 allowed).
                            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 {
                            Severity: Major
                            Found in waku/v2/protocol/relay/waku_relay.go - About 35 mins to fix

                              Function Start has 5 return statements (exceeds 4 allowed).
                              Open

                              func Start(instance *WakuInstance) error {
                                  if err := validateInstance(instance, MustBeStopped); err != nil {
                                      return err
                                  }
                              
                              
                              Severity: Major
                              Found in library/node.go - About 35 mins to fix

                                Method WakuFilterLightNode.IncorrectSubscribe has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring.
                                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
                                Severity: Minor
                                Found in waku/v2/protocol/filter/filter_proto_ident_test.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

                                Function encryptSymmetric has 5 return statements (exceeds 4 allowed).
                                Open

                                func encryptSymmetric(rawPayload []byte, key []byte) ([]byte, error) {
                                    if !validateDataIntegrity(key, aesKeyLength) {
                                        return nil, errors.New("invalid key provided for symmetric encryption, size: " + strconv.Itoa(len(key)))
                                    }
                                    block, err := aes.NewCipher(key)
                                Severity: Major
                                Found in waku/v2/payload/waku_payload.go - About 35 mins to fix

                                  Method WakuRelay.subscribeToPubsubTopic has 5 return statements (exceeds 4 allowed).
                                  Open

                                  func (w *WakuRelay) subscribeToPubsubTopic(topic string) (*pubsubTopicSubscriptionDetails, error) {
                                      w.topicsMutex.Lock()
                                      defer w.topicsMutex.Unlock()
                                      w.log.Info("subscribing to underlying pubsubTopic", zap.String("pubsubTopic", topic))
                                  
                                  
                                  Severity: Major
                                  Found in waku/v2/protocol/relay/waku_relay.go - About 35 mins to fix

                                    Method WakuLightPush.handleOpts has 5 return statements (exceeds 4 allowed).
                                    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
                                    Severity: Major
                                    Found in waku/v2/protocol/lightpush/waku_lightpush.go - About 35 mins to fix
                                      Severity
                                      Category
                                      Status
                                      Source
                                      Language