Skip to content

Commit

Permalink
cleanup: fix vet and staticcheck failures (libp2p#435)
Browse files Browse the repository at this point in the history
* cleanup: fix vet failures and most staticcheck failures

* Fix remaining staticcheck failures

* Give test goroutines chance to exit early when context is canceled
  • Loading branch information
iand authored Jul 22, 2021
1 parent 37ebe34 commit 2efd313
Show file tree
Hide file tree
Showing 12 changed files with 147 additions and 106 deletions.
1 change: 1 addition & 0 deletions discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ func TestGossipSubDiscoveryAfterBootstrap(t *testing.T) {
}
}

//lint:ignore U1000 used only by skipped tests at present
func waitUntilGossipsubMeshCount(ps *PubSub, topic string, count int) {
done := false
doneCh := make(chan bool, 1)
Expand Down
3 changes: 0 additions & 3 deletions gossip_tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ func TestBrokenPromises(t *testing.T) {
peerB := peer.ID("B")
peerC := peer.ID("C")

var msgs []*pb.Message
var mids []string
for i := 0; i < 100; i++ {
m := makeTestMessage(i)
m.From = []byte(peerA)
msgs = append(msgs, m)
mid := DefaultMsgIdFn(m)
mids = append(mids, mid)
}
Expand Down Expand Up @@ -97,5 +95,4 @@ func TestNoBrokenPromises(t *testing.T) {
if brokenPromises != nil {
t.Fatal("expected no broken promises")
}

}
12 changes: 5 additions & 7 deletions gossipsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ func NewGossipSub(ctx context.Context, h host.Host, opts ...Option) (*PubSub, er
outbound: make(map[peer.ID]bool),
connect: make(chan connectInfo, params.MaxPendingConnections),
mcache: NewMessageCache(params.HistoryGossip, params.HistoryLength),
protos: GossipSubDefaultProtocols,
feature: GossipSubDefaultFeatures,
protos: GossipSubDefaultProtocols,
feature: GossipSubDefaultFeatures,
tagTracer: newTagTracer(h.ConnManager()),
params: params,
}
Expand Down Expand Up @@ -668,7 +668,7 @@ func (gs *GossipSubRouter) handleIHave(p peer.ID, ctl *pb.ControlMessage) []*pb.

gs.gossipTracer.AddPromise(p, iwantlst)

return []*pb.ControlIWant{&pb.ControlIWant{MessageIDs: iwantlst}}
return []*pb.ControlIWant{{MessageIDs: iwantlst}}
}

func (gs *GossipSubRouter) handleIWant(p peer.ID, ctl *pb.ControlMessage) []*pb.Message {
Expand Down Expand Up @@ -901,7 +901,6 @@ func (gs *GossipSubRouter) pxConnect(peers []*pb.PeerInfo) {
case gs.connect <- ci:
default:
log.Debugf("ignoring peer connection attempt; too many pending connections")
break
}
}
}
Expand Down Expand Up @@ -1078,7 +1077,7 @@ func (gs *GossipSubRouter) Leave(topic string) {
}

func (gs *GossipSubRouter) sendGraft(p peer.ID, topic string) {
graft := []*pb.ControlGraft{&pb.ControlGraft{TopicID: &topic}}
graft := []*pb.ControlGraft{{TopicID: &topic}}
out := rpcWithControl(nil, nil, nil, graft, nil)
gs.sendRPC(p, out)
}
Expand Down Expand Up @@ -1297,7 +1296,7 @@ func (gs *GossipSubRouter) heartbeatTimer() {
}

func (gs *GossipSubRouter) heartbeat() {
defer log.EventBegin(gs.p.ctx, "heartbeat").Done()
defer log.Infow("heartbeat")

gs.heartbeatTicks++

Expand Down Expand Up @@ -1650,7 +1649,6 @@ func (gs *GossipSubRouter) sendGraftPrune(tograft, toprune map[peer.ID][]string,
out := rpcWithControl(nil, nil, nil, nil, prune)
gs.sendRPC(p, out)
}

}

// emitGossip emits IHAVE gossip advertising items in the message cache window
Expand Down
7 changes: 1 addition & 6 deletions gossipsub_connmgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,9 @@ func TestGossipsubConnTagMessageDeliveries(t *testing.T) {

// sybil squatters to be connected later
sybilHosts := getNetHosts(t, ctx, nSquatter)
squatters := make([]*sybilSquatter, 0, nSquatter)
for _, h := range sybilHosts {
squatter := &sybilSquatter{h: h}
h.SetStreamHandler(GossipSubID_v10, squatter.handleStream)
squatters = append(squatters, squatter)
}

// connect the honest hosts
Expand All @@ -97,14 +95,11 @@ func TestGossipsubConnTagMessageDeliveries(t *testing.T) {

// subscribe everyone to the topic
topic := "test"
var msgs []*Subscription
for _, ps := range psubs {
subch, err := ps.Subscribe(topic)
_, err := ps.Subscribe(topic)
if err != nil {
t.Fatal(err)
}

msgs = append(msgs, subch)
}

// sleep to allow meshes to form
Expand Down
6 changes: 1 addition & 5 deletions gossipsub_feat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ func TestGossipSubCustomProtocols(t *testing.T) {
customsub := protocol.ID("customsub/1.0.0")
protos := []protocol.ID{customsub, FloodSubID}
features := func(feat GossipSubFeature, proto protocol.ID) bool {
if proto == customsub {
return true
}

return false
return proto == customsub
}

ctx, cancel := context.WithCancel(context.Background())
Expand Down
Loading

0 comments on commit 2efd313

Please sign in to comment.