Skip to content

Commit 19c7253

Browse files
Merge pull request #255 from libp2p/feat/fix-staticcheck
fix staticcheck
2 parents b556f82 + 6cc76d5 commit 19c7253

8 files changed

+12
-21
lines changed

p2p/net/swarm/addrs.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package swarm
22

33
import (
4+
filter "github.com/libp2p/go-maddr-filter"
45
ma "github.com/multiformats/go-multiaddr"
56
mamask "github.com/whyrusleeping/multiaddr-filter"
67
)
@@ -30,6 +31,6 @@ func init() {
3031
if err != nil {
3132
panic("error in lowTimeoutFilters init: " + err.Error())
3233
}
33-
lowTimeoutFilters.AddDialFilter(f)
34+
lowTimeoutFilters.AddFilter(*f, filter.ActionDeny)
3435
}
3536
}

p2p/net/swarm/dial_sync.go

-4
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@ package swarm
22

33
import (
44
"context"
5-
"errors"
65
"sync"
76

87
"github.com/libp2p/go-libp2p-core/network"
98
"github.com/libp2p/go-libp2p-core/peer"
109
)
1110

12-
// TODO: change this text when we fix the bug
13-
var errDialCanceled = errors.New("dial was aborted internally, likely due to https://git.io/Je2wW")
14-
1511
// DialWorerFunc is used by DialSync to spawn a new dial worker
1612
type dialWorkerFunc func(context.Context, peer.ID, <-chan dialRequest) error
1713

p2p/net/swarm/dial_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,10 @@ func TestDialBackoffClears(t *testing.T) {
437437
s1.Peerstore().AddAddr(s2.LocalPeer(), s2bad, peerstore.PermanentAddrTTL)
438438

439439
before := time.Now()
440-
if c, err := s1.DialPeer(ctx, s2.LocalPeer()); err == nil {
441-
t.Fatal("dialing to broken addr worked...", err)
440+
c, err := s1.DialPeer(ctx, s2.LocalPeer())
441+
if err == nil {
442442
defer c.Close()
443+
t.Fatal("dialing to broken addr worked...", err)
443444
} else {
444445
t.Log("correctly got error:", err)
445446
}

p2p/net/swarm/peers_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ func TestPeers(t *testing.T) {
3333
// t.Log(s.swarm.Dump())
3434
}
3535

36-
s1GotConn := make(chan struct{}, 0)
37-
s2GotConn := make(chan struct{}, 0)
36+
s1GotConn := make(chan struct{})
37+
s2GotConn := make(chan struct{})
3838
s1.SetConnHandler(func(c network.Conn) {
3939
s1GotConn <- struct{}{}
4040
})

p2p/net/swarm/swarm.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ func (s *Swarm) ClosePeer(p peer.ID) error {
512512
}
513513

514514
var errs []string
515-
for _ = range conns {
515+
for range conns {
516516
err := <-errCh
517517
if err != nil {
518518
errs = append(errs, err.Error())

p2p/net/swarm/swarm_dial.go

+1-7
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import (
1212
"github.com/libp2p/go-libp2p-core/transport"
1313

1414
addrutil "github.com/libp2p/go-addr-util"
15-
lgbl "github.com/libp2p/go-libp2p-loggables"
16-
1715
ma "github.com/multiformats/go-multiaddr"
1816
manet "github.com/multiformats/go-multiaddr/net"
1917
)
@@ -236,20 +234,16 @@ func (s *Swarm) DialPeer(ctx context.Context, p peer.ID) (network.Conn, error) {
236234
// It is gated by the swarm's dial synchronization systems: dialsync and
237235
// dialbackoff.
238236
func (s *Swarm) dialPeer(ctx context.Context, p peer.ID) (*Conn, error) {
239-
log.Debugf("[%s] swarm dialing peer [%s]", s.local, p)
240-
var logdial = lgbl.Dial("swarm", s.LocalPeer(), p, nil, nil)
237+
log.Debugw("dialing peer", "from", s.local, "to", p)
241238
err := p.Validate()
242239
if err != nil {
243240
return nil, err
244241
}
245242

246243
if p == s.local {
247-
log.Event(ctx, "swarmDialSelf", logdial)
248244
return nil, ErrDialToSelf
249245
}
250246

251-
defer log.EventBegin(ctx, "swarmDialAttemptSync", p).Done()
252-
253247
// check if we already have an open (usable) connection first
254248
conn := s.bestAcceptableConnToPeer(ctx, p)
255249
if conn != nil {

p2p/net/swarm/swarm_listen.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func (s *Swarm) Listen(addrs ...ma.Multiaddr) error {
2424

2525
for i, e := range errs {
2626
if e != nil {
27-
log.Warningf("listen on %s failed: %s", addrs[i], errs[i])
27+
log.Warnw("listening failed", "on", addrs[i], "error", errs[i])
2828
}
2929
}
3030

@@ -111,7 +111,7 @@ func (s *Swarm) AddListenAddr(a ma.Multiaddr) error {
111111
// ignore.
112112
return
113113
default:
114-
log.Warningf("add conn %s failed: ", err)
114+
log.Warnw("adding connection failed", "to", a, "error", err)
115115
return
116116
}
117117
}()

p2p/net/swarm/swarm_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,6 @@ func SubtestSwarm(t *testing.T, SwarmNum int, MsgNum int) {
169169
count := 0
170170
countShouldBe := MsgNum * (len(swarms) - 1)
171171
for stream := range streamChan { // one per peer
172-
defer stream.Close()
173-
174172
// get peer on the other side
175173
p := stream.Conn().RemotePeer()
176174

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

197195
got[p] = msgCount
198196
count += msgCount
197+
stream.Close()
199198
}
200199

201200
if count != countShouldBe {

0 commit comments

Comments
 (0)