waku-org/go-waku

View on GitHub

Showing 400 of 400 total issues

Method StoreQueryRequest.Validate has a Cognitive Complexity of 26 (exceeds 20 allowed). Consider refactoring.
Open

func (x *StoreQueryRequest) Validate() error {
    if x.RequestId == "" {
        return errMissingRequestID
    }

Severity: Minor
Found in waku/v2/protocol/store/pb/validation.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

Function TestRetrieveProvidePeerExchangePeers has 56 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func TestRetrieveProvidePeerExchangePeers(t *testing.T) {
    // H1
    host1, _, prvKey1 := tests.CreateHost(t)
    udpPort1, err := tests.FindFreePort(t, "127.0.0.1", 3)
    require.NoError(t, err)
Severity: Minor
Found in waku/v2/protocol/peer_exchange/waku_peer_exchange_test.go - About 1 hr to fix

    Function TestGetMessages has 56 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func TestGetMessages(t *testing.T) {
    
        db := MemoryDB(t)
    
        node1, err := node.New(node.WithWakuStore(), node.WithMessageProvider(db))
    Severity: Minor
    Found in cmd/waku/server/rest/legacy_store_test.go - About 1 hr to fix

      Function handleRelayTopics has 56 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func handleRelayTopics(ctx context.Context, wg *sync.WaitGroup, wakuNode *node.WakuNode, pubSubTopicMap map[string][]string) error {
          for nodeTopic, cTopics := range pubSubTopicMap {
              nodeTopic := nodeTopic
              _, err := wakuNode.Relay().Subscribe(ctx, wprotocol.NewContentFilter(nodeTopic, cTopics...), relay.WithoutConsumer())
              if err != nil {
      Severity: Minor
      Found in cmd/waku/relay.go - About 1 hr to fix

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

        func decodeMessage(contentTopic string, wakumsg *wpb.WakuMessage) (*pb.Message, error) {
            keyInfo := &payload.KeyInfo{
                Kind: payload.None,
            }
        
        
        Severity: Major
        Found in examples/chat2-reliable/chat.go and 1 other location - About 1 hr to fix
        examples/chat2/chat.go on lines 344..360

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 144.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

        func decodeMessage(contentTopic string, wakumsg *wpb.WakuMessage) (*pb.Chat2Message, error) {
            keyInfo := &payload.KeyInfo{
                Kind: payload.None,
            }
        
        
        Severity: Major
        Found in examples/chat2/chat.go and 1 other location - About 1 hr to fix
        examples/chat2-reliable/chat.go on lines 365..381

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 144.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

        func waku_encode_symmetric(messageJSON *C.char, symmetricKey *C.char, optionalSigningKey *C.char, cb C.WakuCallBack, userData unsafe.Pointer) C.int {
            return singleFnExecNoCtx(func() (string, error) {
                return library.EncodeSymmetric(C.GoString(messageJSON), C.GoString(symmetricKey), C.GoString(optionalSigningKey))
            }, cb, userData)
        }
        Severity: Major
        Found in library/c/api_encoding.go and 1 other location - About 1 hr to fix
        library/c/api_encoding.go on lines 37..41

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 143.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

        func waku_encode_asymmetric(messageJSON *C.char, publicKey *C.char, optionalSigningKey *C.char, cb C.WakuCallBack, userData unsafe.Pointer) C.int {
            return singleFnExecNoCtx(func() (string, error) {
                return library.EncodeAsymmetric(C.GoString(messageJSON), C.GoString(publicKey), C.GoString(optionalSigningKey))
            }, cb, userData)
        }
        Severity: Major
        Found in library/c/api_encoding.go and 1 other location - About 1 hr to fix
        library/c/api_encoding.go on lines 49..53

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 143.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Method WakuRLNRelaySuite.TestUpdateLogAndHasDuplicate has 55 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (s *WakuRLNRelaySuite) TestUpdateLogAndHasDuplicate() {
        
            rlnInstance, err := r.NewRLN()
            s.Require().NoError(err)
        
        
        Severity: Minor
        Found in waku/v2/protocol/rln/rln_relay_test.go - About 1 hr to fix

          Function TestDiscV5WithCapabilitiesFilter has 55 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func TestDiscV5WithCapabilitiesFilter(t *testing.T) {
          
              // H1
              host1, _, prvKey1 := tests.CreateHost(t)
              udpPort1, err := tests.FindFreeUDPPort(t, "127.0.0.1", 3)
          Severity: Minor
          Found in waku/v2/discv5/discover_test.go - About 1 hr to fix

            Function TestWakuStoreWithStaticSharding has 55 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func TestWakuStoreWithStaticSharding(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 12 return statements (exceeds 4 allowed).
              Open

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

                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

                        Similar blocks of code found in 2 locations. Consider refactoring.
                        Open

                        func waku_connect(ctx unsafe.Pointer, address *C.char, ms C.int, cb C.WakuCallBack, userData unsafe.Pointer) C.int {
                            instance, err := getInstance(ctx)
                            if err != nil {
                                onError(err, cb, userData)
                            }
                        Severity: Major
                        Found in library/c/api.go and 1 other location - About 1 hr to fix
                        library/c/api.go on lines 241..249

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 139.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Similar blocks of code found in 2 locations. Consider refactoring.
                        Open

                        func RelayShardList(record *enr.Record) (*protocol.RelayShards, error) {
                            var field []byte
                            if err := record.Load(enr.WithEntry(ShardingIndicesListEnrField, &field)); err != nil {
                                if enr.IsNotFound(err) {
                                    return nil, nil
                        Severity: Major
                        Found in waku/v2/protocol/enr/shards.go and 1 other location - About 1 hr to fix
                        waku/v2/protocol/enr/shards.go on lines 80..95

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 139.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Similar blocks of code found in 2 locations. Consider refactoring.
                        Open

                        func waku_connect_peerid(ctx unsafe.Pointer, peerID *C.char, ms C.int, cb C.WakuCallBack, userData unsafe.Pointer) C.int {
                            instance, err := getInstance(ctx)
                            if err != nil {
                                onError(err, cb, userData)
                            }
                        Severity: Major
                        Found in library/c/api.go and 1 other location - About 1 hr to fix
                        library/c/api.go on lines 228..236

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 139.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Similar blocks of code found in 2 locations. Consider refactoring.
                        Open

                        func RelayShardingBitVector(record *enr.Record) (*protocol.RelayShards, error) {
                            var field []byte
                            if err := record.Load(enr.WithEntry(ShardingBitVectorEnrField, &field)); err != nil {
                                if enr.IsNotFound(err) {
                                    return nil, nil
                        Severity: Major
                        Found in waku/v2/protocol/enr/shards.go and 1 other location - About 1 hr to fix
                        waku/v2/protocol/enr/shards.go on lines 63..78

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 139.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Severity
                        Category
                        Status
                        Source
                        Language