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...")
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
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
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{
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
}
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
}
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...")
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)
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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)
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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
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
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 {
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()
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)
}
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
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
}
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 {
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) {
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
- Read upRead up
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) {
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76