waku-org/go-waku

View on GitHub

Showing 299 of 400 total issues

Function NewNode has 12 return statements (exceeds 4 allowed).
Open

func NewNode(instance *WakuInstance, configJSON string) error {
    if err := validateInstance(instance, NotConfigured); err != nil {
        return err
    }

Severity: Major
Found in library/node.go - About 1 hr to fix

    Method WakuRelay.Publish has 12 return statements (exceeds 4 allowed).
    Open

    func (w *WakuRelay) Publish(ctx context.Context, message *pb.WakuMessage, opts ...PublishOption) (pb.MessageHash, error) {
        // Publish a `WakuMessage` to a PubSub topic.
        if w.pubsub == nil {
            return pb.MessageHash{}, errors.New("PubSub hasn't been set")
        }
    Severity: Major
    Found in waku/v2/protocol/relay/waku_relay.go - About 1 hr to fix

      Method DynamicGroupManager.handler has 54 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func (gm *DynamicGroupManager) handler(events []*contracts.RLNMemberRegistered, latestProcessBlock uint64) error {
          gm.lastBlockProcessedMutex.Lock()
          defer gm.lastBlockProcessedMutex.Unlock()
      
          toRemoveTable := om.New()
      Severity: Minor
      Found in waku/v2/protocol/rln/group_manager/dynamic/dynamic.go - About 1 hr to fix

        Method WakuNode.findRelayNodes has 54 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (w *WakuNode) findRelayNodes(ctx context.Context) {
            defer utils.LogOnPanic()
            defer w.wg.Done()
        
            // Feed peers more often right after the bootstrap, then backoff
        Severity: Minor
        Found in waku/v2/node/wakunode2.go - About 1 hr to fix

          Function NewDynamicGroupManager has 9 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              ethClientAddr string,
              memContractAddr common.Address,
              membershipIndexToLoad *uint,
              appKeystore *keystore.AppKeystore,
              keystorePassword string,
          Severity: Major
          Found in waku/v2/protocol/rln/group_manager/dynamic/dynamic.go - About 1 hr to fix

            Method Chat.parseInput has 11 return statements (exceeds 4 allowed).
            Open

            func (c *Chat) parseInput() {
                defer c.wg.Done()
            
                var disconnectedPeers []peer.ID
            
            
            Severity: Major
            Found in examples/chat2-reliable/chat.go - About 1 hr to fix

              Method DB.prepareStmts has 11 return statements (exceeds 4 allowed).
              Open

              func (db *DB) prepareStmts() error {
                  stmt, err := db.db.Prepare("INSERT INTO registrations VALUES (NULL, ?, ?, ?, ?)")
                  if err != nil {
                      return err
                  }
              Severity: Major
              Found in waku/v2/rendezvous/db.go - About 1 hr to fix

                Function getStoreParams has 11 return statements (exceeds 4 allowed).
                Open

                func getStoreParams(r *http.Request) (store.Criteria, []store.RequestOption, error) {
                    var options []store.RequestOption
                    var err error
                    peerAddrStr := r.URL.Query().Get("peerAddr")
                    var m multiaddr.Multiaddr
                Severity: Major
                Found in cmd/waku/server/rest/store.go - About 1 hr to fix

                  Method Chat.publish has 52 lines of code (exceeds 50 allowed). Consider refactoring.
                  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: Minor
                  Found in examples/chat2/chat.go - About 1 hr to fix

                    Function TestWakuLightPushCornerCases has 52 lines of code (exceeds 50 allowed). Consider refactoring.
                    Open

                    func TestWakuLightPushCornerCases(t *testing.T) {
                        ctx, cancel := context.WithCancel(context.Background())
                        defer cancel()
                    
                        testTopic := "/waku/2/go/lightpush/test"
                    Severity: Minor
                    Found in waku/v2/protocol/lightpush/waku_lightpush_test.go - About 1 hr to fix

                      Method WakuFilterLightNode.onRequest has 52 lines of code (exceeds 50 allowed). Consider refactoring.
                      Open

                      func (wf *WakuFilterLightNode) onRequest(ctx context.Context) func(network.Stream) {
                          return func(stream network.Stream) {
                              peerID := stream.Conn().RemotePeer()
                      
                              logger := wf.log.With(logging.HostID("peerID", peerID))
                      Severity: Minor
                      Found in waku/v2/protocol/filter/client.go - About 1 hr to fix

                        Method DB.prepareStmts has 51 lines of code (exceeds 50 allowed). Consider refactoring.
                        Open

                        func (db *DB) prepareStmts() error {
                            stmt, err := db.db.Prepare("INSERT INTO registrations VALUES (NULL, ?, ?, ?, ?)")
                            if err != nil {
                                return err
                            }
                        Severity: Minor
                        Found in waku/v2/rendezvous/db.go - About 1 hr to fix

                          Function Multiaddress has 51 lines of code (exceeds 50 allowed). Consider refactoring.
                          Open

                          func Multiaddress(node *enode.Node) (peer.ID, []multiaddr.Multiaddr, error) {
                              pubKey := utils.EcdsaPubKeyToSecp256k1PublicKey(node.Pubkey())
                              peerID, err := peer.IDFromPublicKey(pubKey)
                              if err != nil {
                                  return "", nil, err
                          Severity: Minor
                          Found in waku/v2/protocol/enr/enr.go - About 1 hr to fix

                            Method WakuLightPush.handleOpts has 51 lines of code (exceeds 50 allowed). Consider refactoring.
                            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: Minor
                            Found in waku/v2/protocol/lightpush/waku_lightpush.go - About 1 hr to fix

                              Function rlnFlags has 51 lines of code (exceeds 50 allowed). Consider refactoring.
                              Open

                              func rlnFlags() []cli.Flag {
                                  return []cli.Flag{
                                      &cli.BoolFlag{
                                          Name:        "rln-relay",
                                          Value:       false,
                              Severity: Minor
                              Found in cmd/waku/flags_rln.go - About 1 hr to fix

                                Method HistoryRetriever.createMessagesRequest has 8 arguments (exceeds 4 allowed). Consider refactoring.
                                Open

                                    ctx context.Context,
                                    peerID peer.ID,
                                    criteria store.FilterCriteria,
                                    cursor []byte,
                                    limit uint64,
                                Severity: Major
                                Found in waku/v2/api/history/history.go - About 1 hr to fix

                                  Method Chat.discoverNodes has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
                                  Open

                                  func (c *Chat) discoverNodes(connectionWg *sync.WaitGroup) {
                                      defer c.wg.Done()
                                      defer connectionWg.Done()
                                  
                                      <-c.uiReady // wait until UI is ready
                                  Severity: Minor
                                  Found in examples/chat2-reliable/chat.go - About 55 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 handleNWakuPreMigration has 9 return statements (exceeds 4 allowed).
                                  Open

                                  func handleNWakuPreMigration(db *sql.DB) (bool, error) {
                                      // Check if there's an user version in the DB, and if migration table does not exist.
                                      // Rename existing table, and move data afterwards
                                  
                                      var nwakuDBVersion int
                                  Severity: Major
                                  Found in waku/persistence/sqlite/nwaku.go - About 55 mins to fix

                                    Method Chat.parseInput has 9 return statements (exceeds 4 allowed).
                                    Open

                                    func (c *Chat) parseInput() {
                                        defer c.wg.Done()
                                        for {
                                            select {
                                            case <-c.ctx.Done():
                                    Severity: Major
                                    Found in examples/chat2/chat.go - About 55 mins to fix

                                      Method WakuMetadata.Connected has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
                                      Open

                                      func (wakuM *WakuMetadata) Connected(n network.Network, cc network.Conn) {
                                          go func() {
                                              defer utils.LogOnPanic()
                                              wakuM.log.Debug("peer connected", zap.Stringer("peer", cc.RemotePeer()))
                                              // Metadata verification is done only if a clusterID is specified
                                      Severity: Minor
                                      Found in waku/v2/protocol/metadata/waku_metadata.go - About 55 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

                                      Severity
                                      Category
                                      Status
                                      Source
                                      Language