waku-org/go-waku

View on GitHub

Showing 300 of 401 total issues

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 MakeHost has 5 return statements (exceeds 4 allowed).
    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())
    Severity: Major
    Found in tests/utils.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

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

        func RetrieveNodes(ctx context.Context, url string, opts ...DNSDiscoveryOption) ([]DiscoveredNode, error) {
            var discoveredNodes []DiscoveredNode
        
            params := new(dnsDiscoveryParameters)
            for _, opt := range opts {
        Severity: Major
        Found in waku/v2/dnsdisc/enr.go - About 35 mins to fix

          Method MessageSender.Send has 5 return statements (exceeds 4 allowed).
          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),
          Severity: Major
          Found in waku/v2/api/publish/message_sender.go - About 35 mins to fix

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

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

              func Migrations(db *sql.DB, logger *zap.Logger) error {
                  migrationDriver, err := migrationDriver(db)
                  if err != nil {
                      return err
                  }
              Severity: Major
              Found in waku/persistence/sqlite/sqlite.go - About 35 mins to fix

                Method DB.Register has 5 return statements (exceeds 4 allowed).
                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()
                Severity: Major
                Found in waku/v2/rendezvous/db.go - About 35 mins to fix

                  Function main has 5 return statements (exceeds 4 allowed).
                  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))
                  Severity: Major
                  Found in examples/rln/main.go - About 35 mins to fix

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

                    func TestNetworkPartition(t *testing.T) {
                        ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
                        defer cancel()
                    
                        t.Log("Starting TestMessageRecovery")
                    Severity: Major
                    Found in examples/chat2-reliable/chat_reliability_test.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 WakuNode.startRlnRelay has 5 return statements (exceeds 4 allowed).
                        Open

                        func (w *WakuNode) startRlnRelay(ctx context.Context) error {
                            rlnRelay := w.rlnRelay.(*rln.WakuRLNRelay)
                        
                            err := rlnRelay.Start(ctx)
                            if err != nil {
                        Severity: Major
                        Found in waku/v2/node/wakunode2_rln.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 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

                              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 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

                                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

                                  Method WakuPeerExchange.handleResponse has 5 return statements (exceeds 4 allowed).
                                  Open

                                  func (wakuPX *WakuPeerExchange) handleResponse(ctx context.Context, response *pb.PeerExchangeResponse, params *PeerExchangeRequestParameters) error {
                                      var discoveredPeers []struct {
                                          addrInfo peer.AddrInfo
                                          enr      *enode.Node
                                      }
                                  Severity: Major
                                  Found in waku/v2/protocol/peer_exchange/client.go - About 35 mins to fix

                                    Method PushRpc.ValidateRequest has 5 return statements (exceeds 4 allowed).
                                    Open

                                    func (x *PushRpc) ValidateRequest() error {
                                        if x.RequestId == "" {
                                            return errMissingRequestID
                                        }
                                    
                                    
                                    Severity: Major
                                    Found in waku/v2/protocol/lightpush/pb/validation.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