aergoio/aergo

View on GitHub
p2p/v200/v200handshake.go

Summary

Maintainability
C
1 day
Test Coverage
C
77%

Method V200Handshaker.checkRemoteStatus has 8 return statements (exceeds 4 allowed).
Open

func (h *V200Handshaker) checkRemoteStatus(remotePeerStatus *types.Status) error {
    // check if chainID is same or not
    remoteChainID := types.NewChainID()
    err := remoteChainID.Read(remotePeerStatus.ChainID)
    if err != nil {
Severity: Major
Found in p2p/v200/v200handshake.go - About 50 mins to fix

    Method V200Handshaker.receiveRemoteStatus has 6 return statements (exceeds 4 allowed).
    Open

    func (h *V200Handshaker) receiveRemoteStatus(ctx context.Context) (*types.Status, error) {
        // and wait to response status
        data, err := h.msgRW.ReadMsg()
        if err != nil {
            h.sendGoAway("malformed message")
    Severity: Major
    Found in p2p/v200/v200handshake.go - About 40 mins to fix

      Method V200Handshaker.DoForOutbound has 6 return statements (exceeds 4 allowed).
      Open

      func (h *V200Handshaker) DoForOutbound(ctx context.Context) (*p2pcommon.HandshakeResult, error) {
          h.logger.Debug().Stringer(p2putil.LogPeerID, types.LogPeerShort(h.peerID)).Msg("Starting versioned handshake for outbound peer connection")
      
          // find my best block
          bestBlock, err := h.is.GetChainAccessor().GetBestBlock()
      Severity: Major
      Found in p2p/v200/v200handshake.go - About 40 mins to fix

        Method V200Handshaker.DoForInbound has 6 return statements (exceeds 4 allowed).
        Open

        func (h *V200Handshaker) DoForInbound(ctx context.Context) (*p2pcommon.HandshakeResult, error) {
            h.logger.Debug().Stringer(p2putil.LogPeerID, types.LogPeerShort(h.peerID)).Msg("Starting versioned handshake for inbound peer connection")
        
            // inbound: receive, check and send
            remotePeerStatus, err := h.receiveRemoteStatus(ctx)
        Severity: Major
        Found in p2p/v200/v200handshake.go - About 40 mins to fix

          Method V200Handshaker.checkAgent has 5 return statements (exceeds 4 allowed).
          Open

          func (h *V200Handshaker) checkAgent(status *types.Status) error {
              h.logger.Debug().Int("certCnt", len(status.Certificates)).Stringer(p2putil.LogPeerID, types.LogPeerShort(h.remoteMeta.ID)).Msg("checking peer as agent")
          
              // Agent must have at least one block producer
              if len(h.remoteMeta.ProducerIDs) == 0 {
          Severity: Major
          Found in p2p/v200/v200handshake.go - About 35 mins to fix

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

            func (h *V200Handshaker) sendLocalStatus(ctx context.Context, hostStatus *types.Status) error {
                var err error
                container := createMessage(p2pcommon.StatusRequest, p2pcommon.NewMsgID(), hostStatus)
                if container == nil {
                    h.logger.Warn().Stringer(p2putil.LogPeerID, types.LogPeerShort(h.peerID)).Msg("failed to create p2p message")
            Severity: Major
            Found in p2p/v200/v200handshake.go and 1 other location - About 3 hrs to fix
            p2p/v030/v030handshake.go on lines 80..100

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

            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 (h *V200Handshaker) handleGoAway(peerID types.PeerID, data p2pcommon.Message) (*types.Status, error) {
                goAway := &types.GoAwayNotice{}
                if err := p2putil.UnmarshalMessageBody(data.Payload(), goAway); err != nil {
                    h.logger.Warn().Stringer(p2putil.LogPeerID, types.LogPeerShort(peerID)).Err(err).Msg("Remote peer sent goAway but failed to decode internal message")
                    return nil, err
            Severity: Major
            Found in p2p/v200/v200handshake.go and 1 other location - About 1 hr to fix
            p2p/v030/v030handshake.go on lines 219..226

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

            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 data.Subprotocol() != p2pcommon.StatusRequest {
                    if data.Subprotocol() == p2pcommon.GoAway {
                        return h.handleGoAway(h.peerID, data)
                    } else {
                        h.logger.Info().Stringer(p2putil.LogPeerID, types.LogPeerShort(h.peerID)).Str("expected", p2pcommon.StatusRequest.String()).Str("actual", data.Subprotocol().String()).Msg("unexpected message type")
            Severity: Major
            Found in p2p/v200/v200handshake.go and 1 other location - About 1 hr to fix
            p2p/v030/v030handshake.go on lines 116..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 168.

            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 createMessage(protocolID p2pcommon.SubProtocol, msgID p2pcommon.MsgID, msgBody p2pcommon.MessageBody) p2pcommon.Message {
                bytes, err := p2putil.MarshalMessageBody(msgBody)
                if err != nil {
                    return nil
                }
            Severity: Minor
            Found in p2p/v200/v200handshake.go and 1 other location - About 40 mins to fix
            p2p/v030/v030handshake.go on lines 259..267

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

            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 3 locations. Consider refactoring.
            Open

                if rMeta.ID != h.peerID {
                    h.logger.Debug().Str("received_peer_id", rMeta.ID.Pretty()).Stringer(p2putil.LogPeerID, types.LogPeerShort(h.peerID)).Msg("Inconsistent peerID")
                    h.sendGoAway("Inconsistent peerID")
                    return fmt.Errorf("inconsistent peerID")
                }
            Severity: Minor
            Found in p2p/v200/v200handshake.go and 2 other locations - About 35 mins to fix
            p2p/v030/v030handshake.go on lines 177..181
            p2p/v030/v033handshake.go on lines 68..72

            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

            There are no issues that match your filters.

            Category
            Status