dennis-tra/pcp

View on GitHub

Showing 24 of 24 total issues

Method PakeProtocol.onKeyExchange has 72 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (p *PakeProtocol) onKeyExchange(s network.Stream) {
    defer s.Close()
    defer p.node.ResetOnShutdown(s)()

    log.Infor("Authenticating peer...")
Severity: Minor
Found in pkg/node/pake.go - About 1 hr to fix

    Method TransferProtocol.Transfer has 65 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (t *TransferProtocol) Transfer(ctx context.Context, peerID peer.ID, basePath string) error {
        // Open a new stream to our peer.
        s, err := t.node.NewStream(ctx, peerID, ProtocolTransfer)
        if err != nil {
            return err
    Severity: Minor
    Found in pkg/node/transfer.go - About 1 hr to fix

      Method TransferProtocol.Transfer has 16 return statements (exceeds 4 allowed).
      Open

      func (t *TransferProtocol) Transfer(ctx context.Context, peerID peer.ID, basePath string) error {
          // Open a new stream to our peer.
          s, err := t.node.NewStream(ctx, peerID, ProtocolTransfer)
          if err != nil {
              return err
      Severity: Major
      Found in pkg/node/transfer.go - About 1 hr to fix

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

        func main() {
            // ShortCommit version tag
            verTag := fmt.Sprintf("v%s+%s", RawVersion, ShortCommit)
        
            app := &cli.App{
        Severity: Minor
        Found in cmd/pcp/pcp.go - About 1 hr to fix

          Method PakeProtocol.StartKeyExchange has 12 return statements (exceeds 4 allowed).
          Open

          func (p *PakeProtocol) StartKeyExchange(ctx context.Context, peerID peer.ID) ([]byte, error) {
              s, err := p.node.NewStream(ctx, peerID, ProtocolPake)
              if err != nil {
                  return nil, err
              }
          Severity: Major
          Found in pkg/node/pake.go - About 1 hr to fix

            Method PakeProtocol.StartKeyExchange has 54 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func (p *PakeProtocol) StartKeyExchange(ctx context.Context, peerID peer.ID) ([]byte, error) {
                s, err := p.node.NewStream(ctx, peerID, ProtocolPake)
                if err != nil {
                    return nil, err
                }
            Severity: Minor
            Found in pkg/node/pake.go - About 1 hr to fix

              Method PakeProtocol.onKeyExchange has 11 return statements (exceeds 4 allowed).
              Open

              func (p *PakeProtocol) onKeyExchange(s network.Stream) {
                  defer s.Close()
                  defer p.node.ResetOnShutdown(s)()
              
                  log.Infor("Authenticating peer...")
              Severity: Major
              Found in pkg/node/pake.go - About 1 hr to fix

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

                func onlyPublic(addrs []ma.Multiaddr) []ma.Multiaddr {
                    routable := []ma.Multiaddr{}
                    for _, addr := range addrs {
                        if manet.IsPublicAddr(addr) {
                            routable = append(routable, addr)
                Severity: Minor
                Found in pkg/dht/discoverer.go and 1 other location - About 55 mins to fix
                pkg/mdns/discoverer.go on lines 117..128

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

                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 onlyPrivate(addrs []ma.Multiaddr) []ma.Multiaddr {
                    routable := []ma.Multiaddr{}
                    for _, addr := range addrs {
                        if manet.IsPrivateAddr(addr) {
                            routable = append(routable, addr)
                Severity: Minor
                Found in pkg/mdns/discoverer.go and 1 other location - About 55 mins to fix
                pkg/dht/discoverer.go on lines 79..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 127.

                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 Action has 7 return statements (exceeds 4 allowed).
                Open

                func Action(c *cli.Context) error {
                    // Read config file and fill context with it.
                    c, err := config.FillContext(c)
                    if err != nil {
                        return err
                Severity: Major
                Found in pkg/send/cmd.go - About 45 mins to fix

                  Method Node.authenticateMessage has 7 return statements (exceeds 4 allowed).
                  Open

                  func (n *Node) authenticateMessage(msg p2p.HeaderMessage) (bool, error) {
                      // This will be set to true during unit test runs as the
                      // generated peers from mocknet won't have proper keys.
                      if skipMessageAuth {
                          return true, nil
                  Severity: Major
                  Found in pkg/node/node.go - About 45 mins to fix

                    Function TransferStatus has 6 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                    func TransferStatus(fn string, iteration int, twidth int, p float64, eta time.Duration, bytesPerS int64) string {
                    Severity: Minor
                    Found in internal/format/format.go - About 45 mins to fix

                      Function New has 7 return statements (exceeds 4 allowed).
                      Open

                      func New(c *cli.Context, wrds []string, opts ...libp2p.Option) (*Node, error) {
                          log.Debugln("Initialising local node...")
                      
                          if c.Bool("homebrew") {
                              wrds = words.HomebrewList()
                      Severity: Major
                      Found in pkg/node/node.go - About 45 mins to fix

                        Method Node.Send has 7 return statements (exceeds 4 allowed).
                        Open

                        func (n *Node) Send(s network.Stream, msg p2p.HeaderMessage) error {
                            defer func() {
                                if err := s.CloseWrite(); err != nil {
                                    log.Warningln("Error closing writer part of stream after sending", err)
                                }
                        Severity: Major
                        Found in pkg/node/node.go - About 45 mins to fix

                          Method TransferProtocol.onTransfer has 6 return statements (exceeds 4 allowed).
                          Open

                          func (t *TransferProtocol) onTransfer(s network.Stream) {
                              defer t.th.Done()
                              defer t.node.ResetOnShutdown(s)()
                          
                              // Get PAKE session key for stream decryption
                          Severity: Major
                          Found in pkg/node/transfer.go - About 40 mins to fix

                            Method Node.HandlePeer has 6 return statements (exceeds 4 allowed).
                            Open

                            func (n *Node) HandlePeer(pi peer.AddrInfo) {
                                if n.GetState() != pcpnode.Discovering {
                                    log.Debugln("Received a peer from the discoverer although we're not discovering")
                                    return
                                }
                            Severity: Major
                            Found in pkg/receive/node.go - About 40 mins to fix

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

                              func (n *Node) Read(s network.Stream, buf p2p.HeaderMessage) error {
                                  defer s.CloseRead()
                              
                                  data, err := ioutil.ReadAll(s)
                                  if err != nil {
                              Severity: Major
                              Found in pkg/node/node.go - About 40 mins to fix

                                Method PushProtocol.SendPushRequest has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                Open

                                func (p *PushProtocol) SendPushRequest(ctx context.Context, peerID peer.ID, filename string, size int64, isDir bool) (bool, error) {
                                Severity: Minor
                                Found in pkg/node/push.go - About 35 mins to fix

                                  Method TransferProtocol.Transfer has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring.
                                  Open

                                  func (t *TransferProtocol) Transfer(ctx context.Context, peerID peer.ID, basePath string) error {
                                      // Open a new stream to our peer.
                                      s, err := t.node.NewStream(ctx, peerID, ProtocolTransfer)
                                      if err != nil {
                                          return err
                                  Severity: Minor
                                  Found in pkg/node/transfer.go - About 35 mins 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 (n *Node) StopAdvertising() {
                                      var wg sync.WaitGroup
                                      for _, advertiser := range n.advertisers {
                                          wg.Add(1)
                                          go func(a Advertiser) {
                                  Severity: Minor
                                  Found in pkg/send/node.go and 1 other location - About 35 mins to fix
                                  pkg/receive/node.go on lines 114..124

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

                                  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