Skip to content

Commit

Permalink
Merge "[FAB-7123] Clean golint warnings"
Browse files Browse the repository at this point in the history
  • Loading branch information
mastersingh24 authored and Gerrit Code Review committed Nov 29, 2017
2 parents c04ae69 + 1ca3393 commit 92be90e
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 32 deletions.
6 changes: 3 additions & 3 deletions gossip/comm/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import (
"math/big"
"os"

"errors"

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

// GenerateCertificatesOrPanic generates a a random pair of public and private keys
// and return TLS certificate
func GenerateCertificatesOrPanic() tls.Certificate {
privKeyFile := fmt.Sprintf("key.%d.priv", gutil.RandomUInt64())
certKeyFile := fmt.Sprintf("cert.%d.pub", gutil.RandomUInt64())
Expand Down Expand Up @@ -76,7 +76,7 @@ func GenerateCertificatesOrPanic() tls.Certificate {
panic(err)
}
if len(cert.Certificate) == 0 {
panic(errors.New("Certificate chain is empty"))
panic("Certificate chain is empty")
}
return cert
}
Expand Down
4 changes: 2 additions & 2 deletions gossip/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ type PKIidType []byte
// IsNotSameFilter generate filter function which
// provides a predicate to identify whenever current id
// equals to another one.
func (this PKIidType) IsNotSameFilter(that PKIidType) bool {
return !bytes.Equal(this, that)
func (id PKIidType) IsNotSameFilter(that PKIidType) bool {
return !bytes.Equal(id, that)
}

// MessageAcceptor is a predicate that is used to
Expand Down
4 changes: 2 additions & 2 deletions gossip/gossip/certstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ func newCertStore(puller pull.Mediator, idMapper identity.Mapper, selfIdentity a
certStore.logger.Panicf("Failed associating self PKIID to cert: %+v", errors.WithStack(err))
}

selfIdMsg, err := certStore.createIdentityMessage()
selfIDMsg, err := certStore.createIdentityMessage()
if err != nil {
certStore.logger.Panicf("Failed creating self identity message: %+v", errors.WithStack(err))
}
puller.Add(selfIdMsg)
puller.Add(selfIDMsg)
puller.RegisterMsgHook(pull.RequestMsgType, func(_ []string, msgs []*proto.SignedGossipMessage, _ proto.ReceivedMessage) {
for _, msg := range msgs {
pkiID := common.PKIidType(msg.GetPeerIdentity().PkiId)
Expand Down
8 changes: 4 additions & 4 deletions gossip/gossip/gossip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,9 @@ func newGossipInstanceWithCustomMCS(portPrefix int, id int, maxMsgCount int, mcs
PublishStateInfoInterval: time.Duration(1) * time.Second,
RequestStateInfoInterval: time.Duration(1) * time.Second,
}
selfId := api.PeerIdentityType(conf.InternalEndpoint)
selfID := api.PeerIdentityType(conf.InternalEndpoint)
g := NewGossipServiceWithServer(conf, &orgCryptoService{}, mcs,
selfId, nil)
selfID, nil)

return g
}
Expand Down Expand Up @@ -268,9 +268,9 @@ func newGossipInstanceWithOnlyPull(portPrefix int, id int, maxMsgCount int, boot
}

cryptoService := &naiveCryptoService{}
selfId := api.PeerIdentityType(conf.InternalEndpoint)
selfID := api.PeerIdentityType(conf.InternalEndpoint)
g := NewGossipServiceWithServer(conf, &orgCryptoService{}, cryptoService,
selfId, nil)
selfID, nil)
return g
}

Expand Down
4 changes: 2 additions & 2 deletions gossip/gossip/orgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ func newGossipInstanceWithExternalEndpoint(portPrefix int, id int, mcs *configur
PublishStateInfoInterval: time.Duration(1) * time.Second,
RequestStateInfoInterval: time.Duration(1) * time.Second,
}
selfId := api.PeerIdentityType(conf.InternalEndpoint)
g := NewGossipServiceWithServer(conf, mcs, mcs, selfId,
selfID := api.PeerIdentityType(conf.InternalEndpoint)
g := NewGossipServiceWithServer(conf, mcs, mcs, selfID,
nil)

return g
Expand Down
12 changes: 8 additions & 4 deletions gossip/privdata/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,14 @@ func (d2s dig2sources) keys() []*gossip2.PvtDataDigest {
return res
}

// Fetcher interface which defines API to fetch missing
// private data elements
type Fetcher interface {
fetch(dig2src dig2sources) ([]*gossip2.PvtDataElement, error)
}

// Support encapsulates set of interfaces to
// aggregate required functionality by single struct
type Support struct {
privdata.CollectionStore
txvalidator.Validator
Expand Down Expand Up @@ -571,14 +575,14 @@ func (data blockData) forEachTxn(txsFilter txValidationFlags, consumer blockCons
func endorsersFromOrgs(ns string, col string, endorsers []*peer.Endorsement, orgs []string) []*peer.Endorsement {
var res []*peer.Endorsement
for _, e := range endorsers {
sId := &msp.SerializedIdentity{}
err := proto.Unmarshal(e.Endorser, sId)
sID := &msp.SerializedIdentity{}
err := proto.Unmarshal(e.Endorser, sID)
if err != nil {
logger.Warning("Failed unmarshalling endorser:", err)
continue
}
if !util.Contains(sId.Mspid, orgs) {
logger.Debug(sId.Mspid, "isn't among the collection's orgs:", orgs, "for namespace", ns, ",collection", col)
if !util.Contains(sID.Mspid, orgs) {
logger.Debug(sID.Mspid, "isn't among the collection's orgs:", orgs, "for namespace", ns, ",collection", col)
continue
}
res = append(res, e)
Expand Down
4 changes: 2 additions & 2 deletions gossip/privdata/coordinator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ func (fc *fetchCall) expectingEndorsers(orgs ...string) *fetchCall {
fc.fetcher.expectedEndorsers = make(map[string]struct{})
}
for _, org := range orgs {
sId := &msp.SerializedIdentity{Mspid: org, IdBytes: []byte(fmt.Sprintf("p0%s", org))}
b, _ := pb.Marshal(sId)
sID := &msp.SerializedIdentity{Mspid: org, IdBytes: []byte(fmt.Sprintf("p0%s", org))}
b, _ := pb.Marshal(sID)
fc.fetcher.expectedEndorsers[string(b)] = struct{}{}
}

Expand Down
3 changes: 3 additions & 0 deletions gossip/privdata/dataretriever.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package privdata

import (
Expand Down Expand Up @@ -40,6 +41,8 @@ type dataRetriever struct {
store DataStore
}

// NewDataRetriever constructing function for implementation of the
// StorageDataRetriever interface
func NewDataRetriever(store DataStore) StorageDataRetriever {
return &dataRetriever{store: store}
}
Expand Down
11 changes: 7 additions & 4 deletions gossip/privdata/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ import (
)

const (
MembershipPollingBackoff = time.Second
membershipPollingBackoff = time.Second
responseWaitTime = time.Second * 5
maxMembershipPollIterations = 5
)

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

// NewPuller creates new private data puller
func NewPuller(cs privdata.CollectionStore, g gossip, dataRetriever PrivateDataRetriever, channel string) *puller {
p := &puller{
pubSub: util.NewPubSub(),
Expand Down Expand Up @@ -195,7 +198,7 @@ func (p *puller) waitForMembership() []discovery.NetworkMember {
if polIteration == maxMembershipPollIterations {
return nil
}
time.Sleep(MembershipPollingBackoff)
time.Sleep(membershipPollingBackoff)
}
return members
}
Expand Down Expand Up @@ -354,10 +357,10 @@ func (dig2f digestToFilterMapping) flattenFilterValues() []filter.RoutingFilter
}

// String returns a string representation of t he digestToFilterMapping
func (dig2Filter digestToFilterMapping) String() string {
func (dig2f digestToFilterMapping) String() string {
var buffer bytes.Buffer
collection2TxID := make(map[string][]string)
for dig := range dig2Filter {
for dig := range dig2f {
collection2TxID[dig.Collection] = append(collection2TxID[dig.Collection], dig.TxId)
}
for col, txIDs := range collection2TxID {
Expand Down
3 changes: 1 addition & 2 deletions gossip/privdata/pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,8 @@ func (g *mockGossip) PeerFilter(channel common.ChainID, messagePredicate api.Sub
args := g.Called(channel, messagePredicate)
if args.Get(1) != nil {
return nil, args.Get(1).(error)
} else {
return args.Get(0).(filter.RoutingFilter), nil
}
return args.Get(0).(filter.RoutingFilter), nil
}
}
return func(member discovery.NetworkMember) bool {
Expand Down
4 changes: 2 additions & 2 deletions gossip/privdata/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ func (bf *blockFactory) AddTxnWithEndorsement(txID string, nsName string, hash [
}

if org != "" {
sId := &msp.SerializedIdentity{Mspid: org, IdBytes: []byte(fmt.Sprintf("p0%s", org))}
b, _ := proto.Marshal(sId)
sID := &msp.SerializedIdentity{Mspid: org, IdBytes: []byte(fmt.Sprintf("p0%s", org))}
b, _ := proto.Marshal(sID)
ccPayload.Action.Endorsements = []*peer.Endorsement{
{
Endorser: b,
Expand Down
4 changes: 4 additions & 0 deletions gossip/service/gossip_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,17 @@ func (g *gossipServiceImpl) NewConfigEventer() ConfigProcessor {
return newConfigEventer(g)
}

// Support aggregates functionality of several
// interfaces required by gossip service
type Support struct {
Validator txvalidator.Validator
Committer committer.Committer
Store privdata2.TransientStore
Cs privdata.CollectionStore
}

// DataStoreSupport aggregates interfaces capable
// of handling either incoming blocks or private data
type DataStoreSupport struct {
committer.Committer
privdata2.TransientStore
Expand Down
4 changes: 2 additions & 2 deletions gossip/service/gossip_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,11 +652,11 @@ func newGossipInstance(portPrefix int, id int, maxMsgCount int, boot ...int) Gos
PublishStateInfoInterval: time.Duration(1) * time.Second,
RequestStateInfoInterval: time.Duration(1) * time.Second,
}
selfId := api.PeerIdentityType(conf.InternalEndpoint)
selfID := api.PeerIdentityType(conf.InternalEndpoint)
cryptoService := &naiveCryptoService{}

gossip := gossip.NewGossipServiceWithServer(conf, &orgCryptoService{}, cryptoService,
selfId, nil)
selfID, nil)

gossipService := &gossipServiceImpl{
mcs: cryptoService,
Expand Down
2 changes: 1 addition & 1 deletion gossip/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func init() {
logger = util.GetLogger(util.LoggingStateModule, "")
}

// NewGossipCoordinatedStateProvider creates state provider with coordinator instance
// NewGossipStateProvider creates state provider with coordinator instance
// to orchestrate arrival of private rwsets and blocks before committing them into the ledger.
func NewGossipStateProvider(chainID string, services *ServicesMediator, ledger ledgerResources) GossipStateProvider {

Expand Down
4 changes: 2 additions & 2 deletions gossip/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,7 @@ func TestTransferOfPrivateRWSet(t *testing.T) {

coord1.On("LedgerHeight", mock.Anything).Return(uint64(5), nil)

var data map[uint64]*testData = map[uint64]*testData{
var data = map[uint64]*testData{
uint64(2): {
block: &pcomm.Block{
Header: &pcomm.BlockHeader{
Expand Down Expand Up @@ -1422,7 +1422,7 @@ func (t testPeer) Comm() chan proto.ReceivedMessage {
return t.commChannel
}

var peers map[string]testPeer = map[string]testPeer{
var peers = map[string]testPeer{
"peer1": {
id: "peer1",
gossipChannel: make(chan *proto.GossipMessage),
Expand Down

0 comments on commit 92be90e

Please sign in to comment.