Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

fix staticcheck #255

Merged
merged 1 commit into from
Apr 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion addrs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package swarm

import (
filter "github.com/libp2p/go-maddr-filter"
ma "github.com/multiformats/go-multiaddr"
mamask "github.com/whyrusleeping/multiaddr-filter"
)
Expand Down Expand Up @@ -30,6 +31,6 @@ func init() {
if err != nil {
panic("error in lowTimeoutFilters init: " + err.Error())
}
lowTimeoutFilters.AddDialFilter(f)
lowTimeoutFilters.AddFilter(*f, filter.ActionDeny)
}
}
4 changes: 0 additions & 4 deletions dial_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@ package swarm

import (
"context"
"errors"
"sync"

"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
)

// TODO: change this text when we fix the bug
var errDialCanceled = errors.New("dial was aborted internally, likely due to https://git.io/Je2wW")

// DialWorerFunc is used by DialSync to spawn a new dial worker
type dialWorkerFunc func(context.Context, peer.ID, <-chan dialRequest) error

Expand Down
5 changes: 3 additions & 2 deletions dial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,10 @@ func TestDialBackoffClears(t *testing.T) {
s1.Peerstore().AddAddr(s2.LocalPeer(), s2bad, peerstore.PermanentAddrTTL)

before := time.Now()
if c, err := s1.DialPeer(ctx, s2.LocalPeer()); err == nil {
t.Fatal("dialing to broken addr worked...", err)
c, err := s1.DialPeer(ctx, s2.LocalPeer())
if err == nil {
defer c.Close()
t.Fatal("dialing to broken addr worked...", err)
} else {
t.Log("correctly got error:", err)
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/libp2p/go-libp2p-testing v0.4.0
github.com/libp2p/go-libp2p-transport-upgrader v0.4.2
github.com/libp2p/go-libp2p-yamux v0.5.0
github.com/libp2p/go-maddr-filter v0.1.0
github.com/libp2p/go-stream-muxer-multistream v0.3.0
github.com/libp2p/go-tcp-transport v0.2.0
github.com/multiformats/go-multiaddr v0.3.1
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ github.com/libp2p/go-libp2p-transport-upgrader v0.4.2/go.mod h1:NR8ne1VwfreD5VIW
github.com/libp2p/go-libp2p-yamux v0.5.0 h1:ZzmUhbQE+X7NuYUT2naxN31JyebZfRmpZVhKtRP13ys=
github.com/libp2p/go-libp2p-yamux v0.5.0/go.mod h1:AyR8k5EzyM2QN9Bbdg6X1SkVVuqLwTGf0L4DFq9g6po=
github.com/libp2p/go-maddr-filter v0.0.5/go.mod h1:Jk+36PMfIqCJhAnaASRH83bdAvfDRp/w6ENFaC9bG+M=
github.com/libp2p/go-maddr-filter v0.1.0 h1:4ACqZKw8AqiuJfwFGq1CYDFugfXTOos+qQ3DETkhtCE=
github.com/libp2p/go-maddr-filter v0.1.0/go.mod h1:VzZhTXkMucEGGEOSKddrwGiOv0tUhgnKqNEmIAz/bPU=
github.com/libp2p/go-mplex v0.1.0/go.mod h1:SXgmdki2kwCUlCCbfGLEgHjC4pFqhTp0ZoV6aiKgxDU=
github.com/libp2p/go-mplex v0.1.2/go.mod h1:Xgz2RDCi3co0LeZfgjm4OgUF15+sVR8SRcu3SFXI1lk=
Expand Down
4 changes: 2 additions & 2 deletions peers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ func TestPeers(t *testing.T) {
// t.Log(s.swarm.Dump())
}

s1GotConn := make(chan struct{}, 0)
s2GotConn := make(chan struct{}, 0)
s1GotConn := make(chan struct{})
s2GotConn := make(chan struct{})
s1.SetConnHandler(func(c network.Conn) {
s1GotConn <- struct{}{}
})
Expand Down
2 changes: 1 addition & 1 deletion swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ func (s *Swarm) ClosePeer(p peer.ID) error {
}

var errs []string
for _ = range conns {
for range conns {
err := <-errCh
if err != nil {
errs = append(errs, err.Error())
Expand Down
8 changes: 1 addition & 7 deletions swarm_dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (
"github.com/libp2p/go-libp2p-core/transport"

addrutil "github.com/libp2p/go-addr-util"
lgbl "github.com/libp2p/go-libp2p-loggables"

ma "github.com/multiformats/go-multiaddr"
manet "github.com/multiformats/go-multiaddr/net"
)
Expand Down Expand Up @@ -236,20 +234,16 @@ func (s *Swarm) DialPeer(ctx context.Context, p peer.ID) (network.Conn, error) {
// It is gated by the swarm's dial synchronization systems: dialsync and
// dialbackoff.
func (s *Swarm) dialPeer(ctx context.Context, p peer.ID) (*Conn, error) {
log.Debugf("[%s] swarm dialing peer [%s]", s.local, p)
var logdial = lgbl.Dial("swarm", s.LocalPeer(), p, nil, nil)
log.Debugw("dialing peer", "from", s.local, "to", p)
err := p.Validate()
if err != nil {
return nil, err
}

if p == s.local {
log.Event(ctx, "swarmDialSelf", logdial)
return nil, ErrDialToSelf
}

defer log.EventBegin(ctx, "swarmDialAttemptSync", p).Done()

// check if we already have an open (usable) connection first
conn := s.bestAcceptableConnToPeer(ctx, p)
if conn != nil {
Expand Down
4 changes: 2 additions & 2 deletions swarm_listen.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (s *Swarm) Listen(addrs ...ma.Multiaddr) error {

for i, e := range errs {
if e != nil {
log.Warningf("listen on %s failed: %s", addrs[i], errs[i])
log.Warnw("listening failed", "on", addrs[i], "error", errs[i])
}
}

Expand Down Expand Up @@ -111,7 +111,7 @@ func (s *Swarm) AddListenAddr(a ma.Multiaddr) error {
// ignore.
return
default:
log.Warningf("add conn %s failed: ", err)
log.Warnw("adding connection failed", "to", a, "error", err)
return
}
}()
Expand Down
3 changes: 1 addition & 2 deletions swarm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,6 @@ func SubtestSwarm(t *testing.T, SwarmNum int, MsgNum int) {
count := 0
countShouldBe := MsgNum * (len(swarms) - 1)
for stream := range streamChan { // one per peer
defer stream.Close()

// get peer on the other side
p := stream.Conn().RemotePeer()

Expand All @@ -196,6 +194,7 @@ func SubtestSwarm(t *testing.T, SwarmNum int, MsgNum int) {

got[p] = msgCount
count += msgCount
stream.Close()
}

if count != countShouldBe {
Expand Down