waku-org/go-waku

View on GitHub

Showing 244 of 303 total issues

Function Test500 has a Cognitive Complexity of 31 (exceeds 20 allowed). Consider refactoring.
Open

func Test500(t *testing.T) {
    maxMsgs := 500
    maxMsgBytes := int2Bytes(maxMsgs)

    ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
Severity: Minor
Found in waku/v2/node/wakunode2_test.go - About 2 hrs 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 Execute has 23 return statements (exceeds 4 allowed).
Open

func Execute(options NodeOptions) error {
    // Set encoding for logs (console, json, ...)
    // Note that libp2p reads the encoding from GOLOG_LOG_FMT env var.
    utils.InitLogger(options.LogEncoding, options.LogOutput)

Severity: Major
Found in cmd/waku/node.go - About 2 hrs to fix

    Method WakuStore.Request has 77 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (s *WakuStore) Request(ctx context.Context, criteria Criteria, opts ...RequestOption) (*Result, error) {
        params := new(Parameters)
    
        optList := DefaultOptions()
        optList = append(optList, opts...)
    Severity: Major
    Found in waku/v2/protocol/store/client.go - About 2 hrs to fix

      Function execute has 77 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func execute(options Options) {
          var err error
          hostAddr, _ := net.ResolveTCPAddr("tcp", fmt.Sprintf("0.0.0.0:%d", options.Port))
      
          if options.NodeKey == nil {
      Severity: Major
      Found in examples/chat2/exec.go - About 2 hrs to fix

        Function TestDecoupledStoreFromRelay has 75 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func TestDecoupledStoreFromRelay(t *testing.T) {
            ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
            defer cancel()
        
            // NODE1: Relay Node + Filter Server
        Severity: Minor
        Found in waku/v2/node/wakunode2_test.go - About 2 hrs to fix

          Function TestStaticShardingLimits has 75 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func TestStaticShardingLimits(t *testing.T) {
          
              log := utils.Logger()
          
              if os.Getenv("RUN_FLAKY_TESTS") != "true" {
          Severity: Minor
          Found in waku/v2/node/wakunode2_test.go - About 2 hrs to fix

            Method WakuFilterLightNode.IncorrectSubscribe has 75 lines of code (exceeds 50 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 2 hrs to fix

              Method Pairing.responderHandshake has 74 lines of code (exceeds 50 allowed). Consider refactoring.
              Open

              func (p *Pairing) responderHandshake(ctx context.Context, msgCh <-chan *pb.WakuMessage) (doneCh chan error) {
                  doneCh = make(chan error, 1)
              
                  func() {
                      defer close(doneCh)
              Severity: Minor
              Found in waku/v2/protocol/noise/pairing.go - About 1 hr to fix

                Function TestWakuRelayAutoShard has 73 lines of code (exceeds 50 allowed). Consider refactoring.
                Open

                func TestWakuRelayAutoShard(t *testing.T) {
                    testcTopic := "/toychat/2/huilong/proto"
                    testcTopic1 := "/toychat/1/huilong/proto"
                
                    port, err := tests.FindFreePort(t, "", 5)
                Severity: Minor
                Found in waku/v2/protocol/relay/waku_relay_test.go - About 1 hr to fix

                  Function TestWakuRLNOptions has 72 lines of code (exceeds 50 allowed). Consider refactoring.
                  Open

                  func TestWakuRLNOptions(t *testing.T) {
                      topicHealthStatusChan := make(chan peermanager.TopicHealthStatus, 100)
                  
                      key, err := tests.RandomHex(32)
                      require.NoError(t, err)
                  Severity: Minor
                  Found in waku/v2/node/wakuoptions_test.go - About 1 hr to fix

                    Method WakuPeerExchange.Request has 72 lines of code (exceeds 50 allowed). Consider refactoring.
                    Open

                    func (wakuPX *WakuPeerExchange) Request(ctx context.Context, numPeers int, opts ...RequestOption) error {
                        params := new(PeerExchangeRequestParameters)
                        params.host = wakuPX.h
                        params.log = wakuPX.log
                        params.pm = wakuPX.pm
                    Severity: Minor
                    Found in waku/v2/protocol/peer_exchange/client.go - About 1 hr to fix

                      Function main has 72 lines of code (exceeds 50 allowed). Consider refactoring.
                      Open

                      func main() {
                          // Removing noisy logs
                          lvl, err := logging.LevelFromString("error")
                          if err != nil {
                              panic(err)
                      Severity: Minor
                      Found in examples/noise/main.go - About 1 hr to fix

                        Function TestWakuStoreResult has 71 lines of code (exceeds 50 allowed). Consider refactoring.
                        Open

                        func TestWakuStoreResult(t *testing.T) {
                            ctx, cancel := context.WithCancel(context.Background())
                            defer cancel()
                        
                            host1, err := libp2p.New(libp2p.DefaultTransports, libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/0"))
                        Severity: Minor
                        Found in waku/v2/protocol/legacy_store/waku_store_protocol_test.go - About 1 hr to fix

                          Method WakuRLNRelay.ValidateMessage has 70 lines of code (exceeds 50 allowed). Consider refactoring.
                          Open

                          func (rlnRelay *WakuRLNRelay) ValidateMessage(msg *pb.WakuMessage, optionalTime *time.Time) (messageValidationResult, error) {
                              if msg == nil {
                                  return validationError, errors.New("nil message")
                              }
                          
                          
                          Severity: Minor
                          Found in waku/v2/protocol/rln/waku_rln_relay.go - About 1 hr to fix

                            Method PeerManager.selectServicePeer has a Cognitive Complexity of 29 (exceeds 20 allowed). Consider refactoring.
                            Open

                            func (pm *PeerManager) selectServicePeer(criteria PeerSelectionCriteria) (PeerSet, error) {
                                peers := make(PeerSet)
                                var err error
                                for retryCnt := 0; retryCnt < 1; retryCnt++ {
                                    //Try to fetch from serviceSlot
                            Severity: Minor
                            Found in waku/v2/peermanager/peer_selection.go - About 1 hr 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 DB.Discover has 67 lines of code (exceeds 50 allowed). Consider refactoring.
                            Open

                            func (db *DB) Discover(ns string, cookie []byte, limit int) ([]dbi.RegistrationRecord, []byte, error) {
                                now := time.Now().Unix()
                            
                                var (
                                    counter int64
                            Severity: Minor
                            Found in waku/v2/rendezvous/db.go - About 1 hr to fix

                              Method WakuRLNRelaySuite.TestValidateMessage has 67 lines of code (exceeds 50 allowed). Consider refactoring.
                              Open

                              func (s *WakuRLNRelaySuite) TestValidateMessage() {
                                  groupKeyPairs, _, err := r.CreateMembershipList(100)
                                  s.Require().NoError(err)
                              
                                  ctx, cancel := context.WithCancel(context.Background())
                              Severity: Minor
                              Found in waku/v2/protocol/rln/rln_relay_test.go - About 1 hr to fix

                                Function TestDiscV5WithShardFilter has 67 lines of code (exceeds 50 allowed). Consider refactoring.
                                Open

                                func TestDiscV5WithShardFilter(t *testing.T) {
                                
                                    // Following topic syntax for shard /waku/2/rs/<cluster_id>/<shard_number>
                                    pubSubTopic := "/waku/2/rs/10/1"
                                
                                
                                Severity: Minor
                                Found in waku/v2/discv5/discover_test.go - About 1 hr to fix

                                  Function getConfig has 66 lines of code (exceeds 50 allowed). Consider refactoring.
                                  Open

                                  func getConfig(configJSON string) (WakuConfig, error) {
                                      var config WakuConfig
                                      if configJSON != "" {
                                          err := json.Unmarshal([]byte(configJSON), &config)
                                          if err != nil {
                                  Severity: Minor
                                  Found in library/config.go - About 1 hr to fix

                                    Function TestQueryOptions has 65 lines of code (exceeds 50 allowed). Consider refactoring.
                                    Open

                                    func TestQueryOptions(t *testing.T) {
                                        ctx, cancel := context.WithCancel(context.Background())
                                        defer cancel()
                                    
                                        pubSubTopic := "/waku/2/go/store/test"
                                    Severity: Minor
                                    Found in waku/v2/protocol/legacy_store/waku_store_client_test.go - About 1 hr to fix
                                      Severity
                                      Category
                                      Status
                                      Source
                                      Language