fix staticcheck

This commit is contained in:
Cory Schwartz 2021-04-14 19:40:39 -07:00 committed by Marten Seemann
parent b556f8293d
commit 6cc76d55e5
8 changed files with 12 additions and 21 deletions

View File

@ -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"
)
@ -30,6 +31,6 @@ func init() {
if err != nil {
panic("error in lowTimeoutFilters init: " + err.Error())
}
lowTimeoutFilters.AddDialFilter(f)
lowTimeoutFilters.AddFilter(*f, filter.ActionDeny)
}
}

View File

@ -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

View File

@ -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)
}

View File

@ -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{}{}
})

View File

@ -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())

View File

@ -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"
)
@ -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 {

View File

@ -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])
}
}
@ -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
}
}()

View File

@ -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()
@ -196,6 +194,7 @@ func SubtestSwarm(t *testing.T, SwarmNum int, MsgNum int) {
got[p] = msgCount
count += msgCount
stream.Close()
}
if count != countShouldBe {