Skip to content

Commit 1ca3393

Browse files
committed
[FAB-7123] Clean golint warnings
There are few golint warning on gossip module packages, this commit takes care to address them. Change-Id: I13a85ad990f981a0da42446962ac0993383cc8b5 Signed-off-by: Artem Barger <bartem@il.ibm.com>
1 parent a58cf5b commit 1ca3393

File tree

15 files changed

+45
-32
lines changed

15 files changed

+45
-32
lines changed

gossip/comm/crypto.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import (
1717
"math/big"
1818
"os"
1919

20-
"errors"
21-
2220
"github.com/hyperledger/fabric/common/util"
2321
gutil "github.com/hyperledger/fabric/gossip/util"
2422
"golang.org/x/net/context"
@@ -35,6 +33,8 @@ func writeFile(filename string, keyType string, data []byte) error {
3533
return pem.Encode(f, &pem.Block{Type: keyType, Bytes: data})
3634
}
3735

36+
// GenerateCertificatesOrPanic generates a a random pair of public and private keys
37+
// and return TLS certificate
3838
func GenerateCertificatesOrPanic() tls.Certificate {
3939
privKeyFile := fmt.Sprintf("key.%d.priv", gutil.RandomUInt64())
4040
certKeyFile := fmt.Sprintf("cert.%d.pub", gutil.RandomUInt64())
@@ -76,7 +76,7 @@ func GenerateCertificatesOrPanic() tls.Certificate {
7676
panic(err)
7777
}
7878
if len(cert.Certificate) == 0 {
79-
panic(errors.New("Certificate chain is empty"))
79+
panic("Certificate chain is empty")
8080
}
8181
return cert
8282
}

gossip/common/common.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ type PKIidType []byte
2323
// IsNotSameFilter generate filter function which
2424
// provides a predicate to identify whenever current id
2525
// equals to another one.
26-
func (this PKIidType) IsNotSameFilter(that PKIidType) bool {
27-
return !bytes.Equal(this, that)
26+
func (id PKIidType) IsNotSameFilter(that PKIidType) bool {
27+
return !bytes.Equal(id, that)
2828
}
2929

3030
// MessageAcceptor is a predicate that is used to

gossip/gossip/certstore.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ func newCertStore(puller pull.Mediator, idMapper identity.Mapper, selfIdentity a
4444
certStore.logger.Panicf("Failed associating self PKIID to cert: %+v", errors.WithStack(err))
4545
}
4646

47-
selfIdMsg, err := certStore.createIdentityMessage()
47+
selfIDMsg, err := certStore.createIdentityMessage()
4848
if err != nil {
4949
certStore.logger.Panicf("Failed creating self identity message: %+v", errors.WithStack(err))
5050
}
51-
puller.Add(selfIdMsg)
51+
puller.Add(selfIDMsg)
5252
puller.RegisterMsgHook(pull.RequestMsgType, func(_ []string, msgs []*proto.SignedGossipMessage, _ proto.ReceivedMessage) {
5353
for _, msg := range msgs {
5454
pkiID := common.PKIidType(msg.GetPeerIdentity().PkiId)

gossip/gossip/gossip_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,9 @@ func newGossipInstanceWithCustomMCS(portPrefix int, id int, maxMsgCount int, mcs
236236
PublishStateInfoInterval: time.Duration(1) * time.Second,
237237
RequestStateInfoInterval: time.Duration(1) * time.Second,
238238
}
239-
selfId := api.PeerIdentityType(conf.InternalEndpoint)
239+
selfID := api.PeerIdentityType(conf.InternalEndpoint)
240240
g := NewGossipServiceWithServer(conf, &orgCryptoService{}, mcs,
241-
selfId, nil)
241+
selfID, nil)
242242

243243
return g
244244
}
@@ -268,9 +268,9 @@ func newGossipInstanceWithOnlyPull(portPrefix int, id int, maxMsgCount int, boot
268268
}
269269

270270
cryptoService := &naiveCryptoService{}
271-
selfId := api.PeerIdentityType(conf.InternalEndpoint)
271+
selfID := api.PeerIdentityType(conf.InternalEndpoint)
272272
g := NewGossipServiceWithServer(conf, &orgCryptoService{}, cryptoService,
273-
selfId, nil)
273+
selfID, nil)
274274
return g
275275
}
276276

gossip/gossip/orgs_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ func newGossipInstanceWithExternalEndpoint(portPrefix int, id int, mcs *configur
112112
PublishStateInfoInterval: time.Duration(1) * time.Second,
113113
RequestStateInfoInterval: time.Duration(1) * time.Second,
114114
}
115-
selfId := api.PeerIdentityType(conf.InternalEndpoint)
116-
g := NewGossipServiceWithServer(conf, mcs, mcs, selfId,
115+
selfID := api.PeerIdentityType(conf.InternalEndpoint)
116+
g := NewGossipServiceWithServer(conf, mcs, mcs, selfID,
117117
nil)
118118

119119
return g

gossip/privdata/coordinator.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,14 @@ func (d2s dig2sources) keys() []*gossip2.PvtDataDigest {
9999
return res
100100
}
101101

102+
// Fetcher interface which defines API to fetch missing
103+
// private data elements
102104
type Fetcher interface {
103105
fetch(dig2src dig2sources) ([]*gossip2.PvtDataElement, error)
104106
}
105107

108+
// Support encapsulates set of interfaces to
109+
// aggregate required functionality by single struct
106110
type Support struct {
107111
privdata.CollectionStore
108112
txvalidator.Validator
@@ -573,14 +577,14 @@ func (data blockData) forEachTxn(txsFilter txValidationFlags, consumer blockCons
573577
func endorsersFromOrgs(ns string, col string, endorsers []*peer.Endorsement, orgs []string) []*peer.Endorsement {
574578
var res []*peer.Endorsement
575579
for _, e := range endorsers {
576-
sId := &msp.SerializedIdentity{}
577-
err := proto.Unmarshal(e.Endorser, sId)
580+
sID := &msp.SerializedIdentity{}
581+
err := proto.Unmarshal(e.Endorser, sID)
578582
if err != nil {
579583
logger.Warning("Failed unmarshalling endorser:", err)
580584
continue
581585
}
582-
if !util.Contains(sId.Mspid, orgs) {
583-
logger.Debug(sId.Mspid, "isn't among the collection's orgs:", orgs, "for namespace", ns, ",collection", col)
586+
if !util.Contains(sID.Mspid, orgs) {
587+
logger.Debug(sID.Mspid, "isn't among the collection's orgs:", orgs, "for namespace", ns, ",collection", col)
584588
continue
585589
}
586590
res = append(res, e)

gossip/privdata/coordinator_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ func (fc *fetchCall) expectingEndorsers(orgs ...string) *fetchCall {
220220
fc.fetcher.expectedEndorsers = make(map[string]struct{})
221221
}
222222
for _, org := range orgs {
223-
sId := &msp.SerializedIdentity{Mspid: org, IdBytes: []byte(fmt.Sprintf("p0%s", org))}
224-
b, _ := pb.Marshal(sId)
223+
sID := &msp.SerializedIdentity{Mspid: org, IdBytes: []byte(fmt.Sprintf("p0%s", org))}
224+
b, _ := pb.Marshal(sID)
225225
fc.fetcher.expectedEndorsers[string(b)] = struct{}{}
226226
}
227227

gossip/privdata/dataretriever.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Copyright IBM Corp. All Rights Reserved.
33
44
SPDX-License-Identifier: Apache-2.0
55
*/
6+
67
package privdata
78

89
import (
@@ -40,6 +41,8 @@ type dataRetriever struct {
4041
store DataStore
4142
}
4243

44+
// NewDataRetriever constructing function for implementation of the
45+
// StorageDataRetriever interface
4346
func NewDataRetriever(store DataStore) StorageDataRetriever {
4447
return &dataRetriever{store: store}
4548
}

gossip/privdata/pull.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ import (
2727
)
2828

2929
const (
30-
MembershipPollingBackoff = time.Second
30+
membershipPollingBackoff = time.Second
3131
responseWaitTime = time.Second * 5
3232
maxMembershipPollIterations = 5
3333
)
3434

35+
// PrivateDataRetriever interfacce which defines API capable
36+
// of retrieving required private data
3537
type PrivateDataRetriever interface {
3638
// CollectionRWSet returns the bytes of CollectionPvtReadWriteSet for a given txID and collection from the transient store
3739
CollectionRWSet(dig *proto.PvtDataDigest) []util.PrivateRWSet
@@ -67,6 +69,7 @@ type puller struct {
6769
PrivateDataRetriever
6870
}
6971

72+
// NewPuller creates new private data puller
7073
func NewPuller(cs privdata.CollectionStore, g gossip, dataRetriever PrivateDataRetriever, channel string) *puller {
7174
p := &puller{
7275
pubSub: util.NewPubSub(),
@@ -195,7 +198,7 @@ func (p *puller) waitForMembership() []discovery.NetworkMember {
195198
if polIteration == maxMembershipPollIterations {
196199
return nil
197200
}
198-
time.Sleep(MembershipPollingBackoff)
201+
time.Sleep(membershipPollingBackoff)
199202
}
200203
return members
201204
}
@@ -354,10 +357,10 @@ func (dig2f digestToFilterMapping) flattenFilterValues() []filter.RoutingFilter
354357
}
355358

356359
// String returns a string representation of t he digestToFilterMapping
357-
func (dig2Filter digestToFilterMapping) String() string {
360+
func (dig2f digestToFilterMapping) String() string {
358361
var buffer bytes.Buffer
359362
collection2TxID := make(map[string][]string)
360-
for dig := range dig2Filter {
363+
for dig := range dig2f {
361364
collection2TxID[dig.Collection] = append(collection2TxID[dig.Collection], dig.TxId)
362365
}
363366
for col, txIDs := range collection2TxID {

gossip/privdata/pull_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,8 @@ func (g *mockGossip) PeerFilter(channel common.ChainID, messagePredicate api.Sub
152152
args := g.Called(channel, messagePredicate)
153153
if args.Get(1) != nil {
154154
return nil, args.Get(1).(error)
155-
} else {
156-
return args.Get(0).(filter.RoutingFilter), nil
157155
}
156+
return args.Get(0).(filter.RoutingFilter), nil
158157
}
159158
}
160159
return func(member discovery.NetworkMember) bool {

0 commit comments

Comments
 (0)