diff --git a/gossip/comm/comm_impl.go b/gossip/comm/comm_impl.go index 38fab34b8af..436dcb2dd22 100644 --- a/gossip/comm/comm_impl.go +++ b/gossip/comm/comm_impl.go @@ -101,8 +101,8 @@ func NewCommInstanceWithServer(port int, idMapper identity.Mapper, peerIdentity commInst.idMapper.Put(idMapper.GetPKIidOfCert(peerIdentity), peerIdentity) if port > 0 { + commInst.stopWG.Add(1) go func() { - commInst.stopWG.Add(1) defer commInst.stopWG.Done() s.Serve(ll) }() @@ -328,7 +328,6 @@ func (c *commImpl) Accept(acceptor common.MessageAcceptor) <-chan proto.Received select { case msg := <-genericChan: specificChan <- msg.(*ReceivedMessageImpl) - break case s := <-c.exitChan: c.exitChan <- s return diff --git a/gossip/comm/comm_test.go b/gossip/comm/comm_test.go index 0f8f7642c79..25cfaf131a7 100644 --- a/gossip/comm/comm_test.go +++ b/gossip/comm/comm_test.go @@ -112,9 +112,11 @@ func newCommInstance(port int, sec api.MessageCryptoService) (Comm, error) { func handshaker(endpoint string, comm Comm, t *testing.T, sigMutator func([]byte) []byte, pkiIDmutator func([]byte) []byte, mutualTLS bool) <-chan proto.ReceivedMessage { c := &commImpl{} err := generateCertificates("key.pem", "cert.pem") + assert.NoError(t, err, "%v", err) defer os.Remove("cert.pem") defer os.Remove("key.pem") cert, err := tls.LoadX509KeyPair("cert.pem", "key.pem") + assert.NoError(t, err, "%v", err) tlsCfg := &tls.Config{ InsecureSkipVerify: true, } @@ -304,9 +306,11 @@ func TestCloseConn(t *testing.T) { acceptChan := comm1.Accept(acceptAll) err := generateCertificates("key.pem", "cert.pem") + assert.NoError(t, err, "%v", err) defer os.Remove("cert.pem") defer os.Remove("key.pem") cert, err := tls.LoadX509KeyPair("cert.pem", "key.pem") + assert.NoError(t, err, "%v", err) tlsCfg := &tls.Config{ InsecureSkipVerify: true, Certificates: []tls.Certificate{cert}, @@ -383,10 +387,8 @@ func TestParallelSend(t *testing.T) { if c == messages2Send { waiting = false } - break case <-ticker.C: waiting = false - break } } assert.Equal(t, messages2Send, c) @@ -615,10 +617,8 @@ func waitForMessages(t *testing.T, msgChan chan uint64, count int, errMsg string if c == count { waiting = false } - break case <-ticker.C: waiting = false - break } } assert.Equal(t, count, c, errMsg) diff --git a/gossip/comm/conn.go b/gossip/comm/conn.go index b064f59ea35..917e3427d92 100644 --- a/gossip/comm/conn.go +++ b/gossip/comm/conn.go @@ -309,7 +309,6 @@ func (conn *connection) writeToStream() { go m.onErr(err) return } - break case stop := <-conn.stopChan: conn.logger.Debug("Closing writing to stream") conn.stopChan <- stop diff --git a/gossip/comm/crypto.go b/gossip/comm/crypto.go index c85c23e92cb..3b642b2721a 100644 --- a/gossip/comm/crypto.go +++ b/gossip/comm/crypto.go @@ -50,6 +50,9 @@ func generateCertificates(privKeyFile string, certKeyFile string) error { } sn, err := rand.Int(rand.Reader, new(big.Int).Lsh(big.NewInt(1), 128)) + if err != nil { + return err + } template := x509.Certificate{ KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature, SerialNumber: sn, diff --git a/gossip/discovery/discovery_impl.go b/gossip/discovery/discovery_impl.go index 1622adee87f..4a2f2083137 100644 --- a/gossip/discovery/discovery_impl.go +++ b/gossip/discovery/discovery_impl.go @@ -278,7 +278,6 @@ func (d *gossipDiscoveryImpl) handlePresumedDeadPeers() { if d.isAlive(deadPeer) { d.expireDeadMembers([]common.PKIidType{deadPeer}) } - break case s := <-d.toDieChan: d.toDieChan <- s return @@ -304,7 +303,6 @@ func (d *gossipDiscoveryImpl) handleMessages() { return case m := <-in: d.handleMsgFromComm(m) - break } } } @@ -501,7 +499,7 @@ func (d *gossipDiscoveryImpl) handleAliveMessage(m *proto.SignedGossipMessage) { } d.lock.RLock() - lastAliveTS, isAlive := d.aliveLastTS[string(pkiID)] + _, isAlive := d.aliveLastTS[string(pkiID)] lastDeadTS, isDead := d.deadLastTS[string(pkiID)] d.lock.RUnlock() @@ -526,7 +524,7 @@ func (d *gossipDiscoveryImpl) handleAliveMessage(m *proto.SignedGossipMessage) { } d.lock.RLock() - lastAliveTS, isAlive = d.aliveLastTS[string(pkiID)] + lastAliveTS, isAlive := d.aliveLastTS[string(pkiID)] d.lock.RUnlock() if isAlive { diff --git a/gossip/election/adapter_test.go b/gossip/election/adapter_test.go index abbcb958995..2838f9501b9 100644 --- a/gossip/election/adapter_test.go +++ b/gossip/election/adapter_test.go @@ -107,10 +107,9 @@ func TestAdapterImpl_Peers(t *testing.T) { func TestAdapterImpl_Stop(t *testing.T) { _, adapters := createCluster(0, 1, 2, 3, 4, 5) - var ch []<-chan Msg for _, adapter := range adapters { - ch = append(ch, adapter.Accept()) + adapter.Accept() } for _, adapter := range adapters { diff --git a/gossip/gossip/algo/pull_test.go b/gossip/gossip/algo/pull_test.go index fc17c473e5c..b1224b85f61 100644 --- a/gossip/gossip/algo/pull_test.go +++ b/gossip/gossip/algo/pull_test.go @@ -93,7 +93,6 @@ func newPushPullTestInstance(name string, peers map[string]*pullTestInstance) *p return case m := <-inst.msgQueue: inst.handleMessage(m) - break } } }() diff --git a/gossip/gossip/gossip_impl.go b/gossip/gossip/gossip_impl.go index 5aec8a8e9c3..287afe300b8 100644 --- a/gossip/gossip/gossip_impl.go +++ b/gossip/gossip/gossip_impl.go @@ -238,7 +238,6 @@ func (g *gossipServiceImpl) handlePresumedDead() { return case deadEndpoint := <-g.comm.PresumedDead(): g.presumedDead <- deadEndpoint - break } } } @@ -286,7 +285,6 @@ func (g *gossipServiceImpl) acceptMessages(incMsgs <-chan proto.ReceivedMessage) return case msg := <-incMsgs: g.handleMessage(msg) - break } } } @@ -696,7 +694,6 @@ func (g *gossipServiceImpl) Accept(acceptor common.MessageAcceptor, passThrough return } outCh <- m.(*proto.SignedGossipMessage).GossipMessage - break } } }() diff --git a/gossip/state/state.go b/gossip/state/state.go index 70e8802dcae..982257843ee 100644 --- a/gossip/state/state.go +++ b/gossip/state/state.go @@ -305,7 +305,7 @@ func (s *GossipStateProviderImpl) handleStateRequest(msg proto.ReceivedMessage) return } - if batchSize < 0 { + if request.StartSeqNum > request.EndSeqNum { logger.Errorf("Invalid sequence interval [%d...%d], ignoring request...", request.StartSeqNum, request.EndSeqNum) return }