waku-org/go-waku

View on GitHub

Showing 400 of 400 total issues

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

func readLoop(ctx context.Context, wakuNode *node.WakuNode, contentTopic string) {
    sub, err := wakuNode.Relay().Subscribe(ctx, protocol.NewContentFilter(pubsubTopicStr, contentTopic))
    if err != nil {
        log.Error("Could not subscribe", zap.Error(err))
        return
Severity: Major
Found in examples/basic-relay/main.go and 1 other location - About 2 hrs to fix
examples/basic-light-client/main.go on lines 251..271

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

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

File flags.go has 526 lines of code (exceeds 500 allowed). Consider refactoring.
Open

package main

import (
    "time"

Severity: Minor
Found in cmd/waku/flags.go - About 2 hrs to fix

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

    func (pm *PeerManager) prunePeerStore() {
        peers := pm.host.Peerstore().Peers()
        numPeers := len(peers)
        if numPeers < pm.maxPeers {
            pm.logger.Debug("peerstore size within capacity, not pruning", zap.Int("capacity", pm.maxPeers), zap.Int("numPeers", numPeers))
    Severity: Minor
    Found in waku/v2/peermanager/peer_manager.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

    Method WakuNode.watchTopicShards has a Cognitive Complexity of 34 (exceeds 20 allowed). Consider refactoring.
    Open

    func (w *WakuNode) watchTopicShards(ctx context.Context) error {
        evtRelaySubscribed, err := w.Relay().Events().Subscribe(new(relay.EvtRelaySubscribed))
        if err != nil {
            return err
        }
    Severity: Minor
    Found in waku/v2/node/localnode.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 89 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-reliable/exec.go - About 2 hrs to fix

      Method Chat.parseInput has 88 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

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

        WakuRelay has 23 methods (exceeds 20 allowed). Consider refactoring.
        Open

        type WakuRelay struct {
            host                host.Host
            relayParams         *relayParameters
            pubsub              *pubsub.PubSub
            params              pubsub.GossipSubParams
        Severity: Minor
        Found in waku/v2/protocol/relay/waku_relay.go - About 2 hrs to fix

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

          func DefaultKeyMap() viewport.KeyMap {
              return viewport.KeyMap{
                  PageDown: key.NewBinding(
                      key.WithKeys("pgdown"),
                      key.WithHelp("pgdn", "page down"),
          Severity: Major
          Found in examples/chat2-reliable/ui.go and 1 other location - About 2 hrs to fix
          examples/chat2/ui.go on lines 317..344

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

          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

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

          func DefaultKeyMap() viewport.KeyMap {
              return viewport.KeyMap{
                  PageDown: key.NewBinding(
                      key.WithKeys("pgdown"),
                      key.WithHelp("pgdn", "page down"),
          Severity: Major
          Found in examples/chat2/ui.go and 1 other location - About 2 hrs to fix
          examples/chat2-reliable/ui.go on lines 317..344

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

          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

          Function Test500 has 86 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func Test500(t *testing.T) {
              maxMsgs := 500
              maxMsgBytes := int2Bytes(maxMsgs)
          
              ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
          Severity: Major
          Found in waku/v2/node/wakunode2_test.go - About 2 hrs to fix

            Function getGossipSubParams has 86 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func getGossipSubParams(cfg *GossipSubParams) pubsub.GossipSubParams {
                params := pubsub.DefaultGossipSubParams()
            
                if cfg.D != nil {
                    params.D = *cfg.D
            Severity: Major
            Found in library/config.go - About 2 hrs to fix

              Function getLegacyStoreParams has 85 lines of code (exceeds 50 allowed). Consider refactoring.
              Open

              func getLegacyStoreParams(r *http.Request) (*legacy_store.Query, []legacy_store.HistoryRequestOption, error) {
                  query := &legacy_store.Query{}
                  var options []legacy_store.HistoryRequestOption
                  var err error
                  peerAddrStr := r.URL.Query().Get("peerAddr")
              Severity: Major
              Found in cmd/waku/server/rest/legacy_store.go - About 2 hrs to fix

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

                func main() {
                
                    cliFlags := []cli.Flag{
                        ClusterID,
                        Shard,
                Severity: Major
                Found in examples/basic-relay/main.go and 1 other location - About 2 hrs to fix
                examples/basic-light-client/main.go on lines 60..90

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

                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 main() {
                
                    cliFlags := []cli.Flag{
                        ClusterID,
                        Shard,
                Severity: Major
                Found in examples/basic-light-client/main.go and 1 other location - About 2 hrs to fix
                examples/basic-relay/main.go on lines 58..88

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

                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

                Function NewNode has a Cognitive Complexity of 32 (exceeds 20 allowed). Consider refactoring.
                Open

                func NewNode(instance *WakuInstance, configJSON string) error {
                    if err := validateInstance(instance, NotConfigured); err != nil {
                        return err
                    }
                
                
                Severity: Minor
                Found in library/node.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 main has 81 lines of code (exceeds 50 allowed). Consider refactoring.
                Open

                func main() {
                    hostAddr1, _ := net.ResolveTCPAddr("tcp", "0.0.0.0:60000")
                    hostAddr2, _ := net.ResolveTCPAddr("tcp", "0.0.0.0:60001")
                
                    key1, err := randomHex(32)
                Severity: Major
                Found in examples/filter2/main.go - About 2 hrs to fix

                  Method WakuFilterLightNode.Unsubscribe has 80 lines of code (exceeds 50 allowed). Consider refactoring.
                  Open

                  func (wf *WakuFilterLightNode) Unsubscribe(ctx context.Context, contentFilter protocol.ContentFilter, opts ...FilterSubscribeOption) (*WakuFilterPushResult, error) {
                      wf.RLock()
                      defer wf.RUnlock()
                      if err := wf.ErrOnNotRunning(); err != nil {
                          return nil, err
                  Severity: Major
                  Found in waku/v2/protocol/filter/client.go - About 2 hrs to fix

                    Function TestPairingObj1Success has 80 lines of code (exceeds 50 allowed). Consider refactoring.
                    Open

                    func TestPairingObj1Success(t *testing.T) {
                        host1, relay1 := createRelayNode(t)
                        host2, relay2 := createRelayNode(t)
                    
                        defer host1.Close()
                    Severity: Major
                    Found in waku/v2/protocol/noise/pairing_test.go - About 2 hrs to fix

                      Chat has 21 methods (exceeds 20 allowed). Consider refactoring.
                      Open

                      func (c *Chat) initReliabilityProtocol() {
                          c.wg.Add(4)
                          c.setupMessageRequestHandler()
                      
                          go c.periodicBufferSweep()
                      Severity: Minor
                      Found in examples/chat2-reliable/reliability.go - About 2 hrs to fix

                        WakuFilterLightNode has 21 methods (exceeds 20 allowed). Consider refactoring.
                        Open

                        type WakuFilterLightNode struct {
                            *service.CommonService
                            h                host.Host
                            broadcaster      relay.Broadcaster //TODO: Move the broadcast functionality outside of relay client to a higher SDK layer.
                            onlineChecker    onlinechecker.OnlineChecker
                        Severity: Minor
                        Found in waku/v2/protocol/filter/client.go - About 2 hrs to fix
                          Severity
                          Category
                          Status
                          Source
                          Language