Skip to content

Commit

Permalink
[FAB-3178] staticcheck errors fix in gossip
Browse files Browse the repository at this point in the history
staticcheck tool found multiple errors in gossip package

Change-Id: Ie6e813ff09a09c495d7c7ac987994a479461f78f
Signed-off-by: Gennady Laventman <gennady@il.ibm.com>
  • Loading branch information
gennadylaventman committed Apr 26, 2017
1 parent c5c60c3 commit 9c1d1bc
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 18 deletions.
3 changes: 1 addition & 2 deletions gossip/comm/comm_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}()
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions gossip/comm/comm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion gossip/comm/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions gossip/comm/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 2 additions & 4 deletions gossip/discovery/discovery_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -304,7 +303,6 @@ func (d *gossipDiscoveryImpl) handleMessages() {
return
case m := <-in:
d.handleMsgFromComm(m)
break
}
}
}
Expand Down Expand Up @@ -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()

Expand All @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions gossip/election/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion gossip/gossip/algo/pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ func newPushPullTestInstance(name string, peers map[string]*pullTestInstance) *p
return
case m := <-inst.msgQueue:
inst.handleMessage(m)
break
}
}
}()
Expand Down
3 changes: 0 additions & 3 deletions gossip/gossip/gossip_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ func (g *gossipServiceImpl) handlePresumedDead() {
return
case deadEndpoint := <-g.comm.PresumedDead():
g.presumedDead <- deadEndpoint
break
}
}
}
Expand Down Expand Up @@ -286,7 +285,6 @@ func (g *gossipServiceImpl) acceptMessages(incMsgs <-chan proto.ReceivedMessage)
return
case msg := <-incMsgs:
g.handleMessage(msg)
break
}
}
}
Expand Down Expand Up @@ -696,7 +694,6 @@ func (g *gossipServiceImpl) Accept(acceptor common.MessageAcceptor, passThrough
return
}
outCh <- m.(*proto.SignedGossipMessage).GossipMessage
break
}
}
}()
Expand Down
2 changes: 1 addition & 1 deletion gossip/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 9c1d1bc

Please sign in to comment.