johnsonjh/gfcp

View on GitHub
gfcp_sess.go

Summary

Maintainability
F
6 days
Test Coverage

File gfcp_sess.go has 1283 lines of code (exceeds 500 allowed). Consider refactoring.
Open

// Copyright © 2021 Jeffrey H. Johnson <trnsz@pobox.com>.
// Copyright © 2015 Daniel Fu <daniel820313@gmail.com>.
// Copyright © 2019 Loki 'l0k18' Verloren <stalker.loki@protonmail.ch>.
// Copyright © 2021 Gridfinity, LLC. <admin@gridfinity.com>.
//
Severity: Major
Found in gfcp_sess.go - About 2 days to fix

    Method UDPSession.GFcpInput has a Cognitive Complexity of 67 (exceeds 20 allowed). Consider refactoring.
    Open

    func (
        s *UDPSession,
    ) GFcpInput(
        data []byte,
    ) {
    Severity: Minor
    Found in gfcp_sess.go - About 1 day 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 UDPSession.GFcpInput has 133 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (
        s *UDPSession,
    ) GFcpInput(
        data []byte,
    ) {
    Severity: Major
    Found in gfcp_sess.go - About 4 hrs to fix

      UDPSession has 27 methods (exceeds 20 allowed). Consider refactoring.
      Open

          UDPSession struct {
              updaterIdx int            // record slice index in updater
              conn       net.PacketConn // the underlying packet connection
              GFcp       *GFCP          // GFCP ARQ protocol
              l          *Listener      // pointing to the Listener object if it's been accepted by a Listener
      Severity: Minor
      Found in gfcp_sess.go - About 3 hrs to fix

        Method UDPSession.Read has 91 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (
            s *UDPSession,
        ) Read(
            b []byte,
        ) (
        Severity: Major
        Found in gfcp_sess.go - About 2 hrs to fix

          Function newUDPSession has 89 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func newUDPSession(
              conv uint32,
              dataShards,
              parityShards int,
              l *Listener,
          Severity: Major
          Found in gfcp_sess.go - About 2 hrs to fix

            Method UDPSession.WriteBuffers has a Cognitive Complexity of 33 (exceeds 20 allowed). Consider refactoring.
            Open

            func (
                s *UDPSession,
            ) WriteBuffers(
                v [][]byte,
            ) (
            Severity: Minor
            Found in gfcp_sess.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 UDPSession.WriteBuffers has 78 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func (
                s *UDPSession,
            ) WriteBuffers(
                v [][]byte,
            ) (
            Severity: Major
            Found in gfcp_sess.go - About 2 hrs to fix

              Method UDPSession.Read has a Cognitive Complexity of 25 (exceeds 20 allowed). Consider refactoring.
              Open

              func (
                  s *UDPSession,
              ) Read(
                  b []byte,
              ) (
              Severity: Minor
              Found in gfcp_sess.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

              Avoid deeply nested control flow statements.
              Open

                                  if ret := s.GFcp.Input(
                                      data[fecHeaderSizePlus2:],
                                      true,
                                      s.ackNoDelay,
                                  ); ret != 0 {
              Severity: Major
              Found in gfcp_sess.go - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                        if int(
                                            sz,
                                        ) <= len(
                                            r,
                                        ) && sz >= 2 {
                Severity: Major
                Found in gfcp_sess.go - About 45 mins to fix

                  Method UDPSession.Read has 6 return statements (exceeds 4 allowed).
                  Open

                  func (
                      s *UDPSession,
                  ) Read(
                      b []byte,
                  ) (
                  Severity: Major
                  Found in gfcp_sess.go - About 40 mins to fix

                    Function newUDPSession has 5 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                        conv uint32,
                        dataShards,
                        parityShards int,
                        l *Listener,
                        conn net.PacketConn,
                    Severity: Minor
                    Found in gfcp_sess.go - About 35 mins to fix

                      TODO found
                      Open

                                          // TODO(jhj): Switch to pointer to avoid allocation.
                      Severity: Minor
                      Found in gfcp_sess.go by fixme

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

                      func (
                          s *UDPSession,
                      ) SetWriteBuffer(
                          bytes int,
                      ) error {
                      Severity: Minor
                      Found in gfcp_sess.go and 1 other location - About 50 mins to fix
                      gfcp_sess.go on lines 656..673

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

                      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 (
                          s *UDPSession,
                      ) SetReadBuffer(
                          bytes int,
                      ) error {
                      Severity: Minor
                      Found in gfcp_sess.go and 1 other location - About 50 mins to fix
                      gfcp_sess.go on lines 677..694

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

                      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

                          if nc, ok := l.conn.(net.Conn); ok {
                              addr, _ := net.ResolveUDPAddr(
                                  "udp",
                                  nc.LocalAddr().String(),
                              )
                      Severity: Minor
                      Found in gfcp_sess.go and 1 other location - About 45 mins to fix
                      gfcp_sess.go on lines 630..647

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

                      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

                              if nc, ok := s.conn.(net.Conn); ok {
                                  addr, _ := net.ResolveUDPAddr(
                                      "udp",
                                      nc.LocalAddr().String(),
                                  )
                      Severity: Minor
                      Found in gfcp_sess.go and 1 other location - About 45 mins to fix
                      gfcp_sess.go on lines 1072..1089

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

                      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

                              if !s.rd.IsZero() {
                                  if time.Now().After(
                                      s.rd,
                                  ) {
                                      s.mu.Unlock()
                      Severity: Minor
                      Found in gfcp_sess.go and 1 other location - About 30 mins to fix
                      gfcp_sess.go on lines 393..407

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

                      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

                              if !s.wd.IsZero() {
                                  if time.Now().After(
                                      s.wd,
                                  ) {
                                      s.mu.Unlock()
                      Severity: Minor
                      Found in gfcp_sess.go and 1 other location - About 30 mins to fix
                      gfcp_sess.go on lines 287..301

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

                      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

                      There are no issues that match your filters.

                      Category
                      Status