waku-org/go-waku

View on GitHub

Showing 400 of 400 total issues

Function getStoreParams has 111 lines of code (exceeds 50 allowed). Consider refactoring.
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 3 hrs to fix

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

    func main() {
        // Defaults
        options.LogLevel = "INFO"
        options.LogEncoding = "console"
    
    
    Severity: Major
    Found in cmd/waku/main.go - About 3 hrs to fix

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

                      if strings.HasPrefix(line, "/connect") {
                          peer := strings.TrimPrefix(line, "/connect ")
                          c.wg.Add(1)
                          go func(peer string) {
                              defer c.wg.Done()
      Severity: Major
      Found in examples/chat2-reliable/chat.go and 1 other location - About 3 hrs to fix
      examples/chat2/chat.go on lines 173..201

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

      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

                      if strings.HasPrefix(line, "/connect") {
                          peer := strings.TrimPrefix(line, "/connect ")
                          c.wg.Add(1)
                          go func(peer string) {
                              defer c.wg.Done()
      Severity: Major
      Found in examples/chat2/chat.go and 1 other location - About 3 hrs to fix
      examples/chat2-reliable/chat.go on lines 195..223

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

      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 TestFailedBatchExecution(t *testing.T) {
          ctx, cancel := context.WithTimeout(context.TODO(), 5*time.Second)
          defer cancel()
      
          storenodeID, err := peer.Decode("16Uiu2HAkw3x97MbbZSWHbdF5bob45vcZvPPK4s4Mjyv2mxyB9GS3")
      Severity: Major
      Found in waku/v2/api/history/history_test.go and 1 other location - About 3 hrs to fix
      waku/v2/api/history/history_test.go on lines 197..223

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

      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 TestSuccessBatchExecution(t *testing.T) {
          ctx, cancel := context.WithTimeout(context.TODO(), 5*time.Second)
          defer cancel()
      
          storenodeID, err := peer.Decode("16Uiu2HAkw3x97MbbZSWHbdF5bob45vcZvPPK4s4Mjyv2mxyB9GS3")
      Severity: Major
      Found in waku/v2/api/history/history_test.go and 1 other location - About 3 hrs to fix
      waku/v2/api/history/history_test.go on lines 225..251

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

      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 newTestCases has 107 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func newTestCases() []*testCase {
          return []*testCase{
              {
                  description: "SameResponse",
                  servers:     mockedServers,
      Severity: Major
      Found in waku/v2/timesource/ntp_test.go - About 3 hrs to fix

        Function handleRelayTopics has a Cognitive Complexity of 38 (exceeds 20 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 3 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 Chat.parseInput has 106 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

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

          Method WakuNode.startKeepAlive has 105 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func (w *WakuNode) startKeepAlive(ctx context.Context, randomPeersPingDuration time.Duration, allPeersPingDuration time.Duration) {
              defer utils.LogOnPanic()
              defer w.wg.Done()
          
              if !w.opts.enableRelay {
          Severity: Major
          Found in waku/v2/node/keepalive.go - About 3 hrs to fix

            Method WakuStore.Query has 105 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func (store *WakuStore) Query(ctx context.Context, query Query, opts ...HistoryRequestOption) (*Result, error) {
                params := new(HistoryRequestParameters)
                params.s = store
            
                optList := DefaultOptions()
            Severity: Major
            Found in waku/v2/protocol/legacy_store/waku_store_client.go - About 3 hrs to fix

              Method HistoryRetriever.Query has a Cognitive Complexity of 37 (exceeds 20 allowed). Consider refactoring.
              Open

              func (hr *HistoryRetriever) Query(
                  ctx context.Context,
                  criteria store.FilterCriteria,
                  storenodeID peer.ID,
                  pageLimit uint64,
              Severity: Minor
              Found in waku/v2/api/history/history.go - About 3 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 TestSubscriptionsNotify has 101 lines of code (exceeds 50 allowed). Consider refactoring.
              Open

              func TestSubscriptionsNotify(t *testing.T) {
                  fmap := NewSubscriptionMap(utils.Logger())
                  p1 := createPeerID(t)
                  p2 := createPeerID(t)
                  var subscriptions = []*SubscriptionDetails{
              Severity: Major
              Found in waku/v2/protocol/subscription/subscriptions_map_test.go - About 3 hrs to fix

                Function TestFilterGetMessages has 97 lines of code (exceeds 50 allowed). Consider refactoring.
                Open

                func TestFilterGetMessages(t *testing.T) {
                    pubsubTopic := "/waku/2/test/proto"
                    contentTopic := "/waku/2/app/1"
                
                    // get nodes add connect them
                Severity: Major
                Found in cmd/waku/server/rest/filter_test.go - About 2 hrs to fix

                  Function NewNode has 96 lines of code (exceeds 50 allowed). Consider refactoring.
                  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 2 hrs to fix

                    PeerManager has 25 methods (exceeds 20 allowed). Consider refactoring.
                    Open

                    type PeerManager struct {
                        peerConnector          *PeerConnectionStrategy
                        metadata               *metadata.WakuMetadata
                        relay                  *relay.WakuRelay
                        maxPeers               int
                    Severity: Minor
                    Found in waku/v2/peermanager/peer_manager.go - About 2 hrs to fix

                      Method WakuFilterLightNode.Unsubscribe has a Cognitive Complexity of 35 (exceeds 20 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: Minor
                      Found in waku/v2/protocol/filter/client.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

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

                      func FindFreePort(t *testing.T, host string, maxAttempts int) (int, error) {
                          t.Helper()
                      
                          if host == "" {
                              host = "localhost"
                      Severity: Major
                      Found in tests/utils.go and 1 other location - About 2 hrs to fix
                      tests/utils.go on lines 99..126

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

                      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 FindFreeUDPPort(t *testing.T, host string, maxAttempts int) (int, error) {
                          t.Helper()
                      
                          if host == "" {
                              host = "localhost"
                      Severity: Major
                      Found in tests/utils.go and 1 other location - About 2 hrs to fix
                      tests/utils.go on lines 69..96

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

                      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 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-light-client/main.go and 1 other location - About 2 hrs to fix
                      examples/basic-relay/main.go on lines 204..224

                      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

                      Severity
                      Category
                      Status
                      Source
                      Language