Skip to content

Commit c521d3c

Browse files
committed
Fix all golint warnings under gossip
Change-Id: I2954a55cdff9d010cb7853ef4a8530ba2f1963c8 Signed-off-by: Ray Chen <[email protected]>
1 parent 6271740 commit c521d3c

File tree

9 files changed

+41
-36
lines changed

9 files changed

+41
-36
lines changed

gossip/gossip/certstore_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func testCertificateUpdate(t *testing.T, updateFactory func(uint64) comm.Receive
110110
PullInterval: time.Millisecond * 500,
111111
Tag: proto.GossipMessage_EMPTY,
112112
Channel: nil,
113-
Id: "id1",
113+
ID: "id1",
114114
}
115115
sender := &senderMock{}
116116
memberSvc := &membershipSvcMock{}

gossip/gossip/channel/channel.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ func (gc *gossipChannel) createBlockPuller() pull.Mediator {
244244
conf := pull.PullConfig{
245245
MsgType: proto.PullMsgType_BlockMessage,
246246
Channel: []byte(gc.chainID),
247-
Id: gc.GetConf().ID,
247+
ID: gc.GetConf().ID,
248248
PeerCountToSelect: gc.GetConf().PullPeerNum,
249249
PullInterval: gc.GetConf().PullInterval,
250250
Tag: proto.GossipMessage_CHAN_AND_ORG,

gossip/gossip/gossip_impl.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ func (g *gossipServiceImpl) createCertStorePuller() pull.Mediator {
789789
conf := pull.PullConfig{
790790
MsgType: proto.PullMsgType_IdentityMsg,
791791
Channel: []byte(""),
792-
Id: g.conf.SelfEndpoint,
792+
ID: g.conf.SelfEndpoint,
793793
PeerCountToSelect: g.conf.PullPeerNum,
794794
PullInterval: g.conf.PullInterval,
795795
Tag: proto.GossipMessage_EMPTY,

gossip/gossip/msgstore/msgs.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,17 @@ import (
2727
// then the invalidation trigger on 0 was called when 1 was added.
2828
type invalidationTrigger func(message interface{})
2929

30+
// NewMessageStore returns a new MessageStore with the message replacing
31+
// policy and invalidation trigger passed.
3032
func NewMessageStore(pol common.MessageReplacingPolicy, trigger invalidationTrigger) MessageStore {
3133
return &messageStoreImpl{pol: pol, lock: &sync.RWMutex{}, messages: make([]*msg, 0), invTrigger: trigger}
3234
}
3335

3436
// MessageStore adds messages to an internal buffer.
3537
// When a message is received, it might:
3638
// - Be added to the buffer
37-
// - Discarded because of some message already in the buffer (invalidated)
38-
// - Make a message already in the buffer to be discarded (invalidates)
39+
// - Discarded because of some message already in the buffer (invalidated)
40+
// - Make a message already in the buffer to be discarded (invalidates)
3941
// When a message is invalidated, the invalidationTrigger is invoked on that message.
4042
type MessageStore interface {
4143
// add adds a message to the store

gossip/gossip/pull/pullstore.go

+30-26
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/op/go-logging"
3030
)
3131

32+
// Constants go here.
3233
const (
3334
HelloMsgType PullMsgType = iota
3435
DigestMsgType
@@ -40,8 +41,9 @@ const (
4041
type PullMsgType int
4142

4243
// MessageHook defines a function that will run after a certain pull message is received
43-
type MessageHook func(itemIds []string, items []*proto.GossipMessage, msg comm.ReceivedMessage)
44+
type MessageHook func(itemIDs []string, items []*proto.GossipMessage, msg comm.ReceivedMessage)
4445

46+
// Sender sends messages to remote peers
4547
type Sender interface {
4648
// Send sends a message to a list of remote peers
4749
Send(msg *proto.GossipMessage, peers ...*comm.RemotePeer)
@@ -55,7 +57,7 @@ type MembershipService interface {
5557

5658
// PullConfig defines the configuration of the pull mediator
5759
type PullConfig struct {
58-
Id string
60+
ID string
5961
PullInterval time.Duration // Duration between pull invocations
6062
PeerCountToSelect int // Number of peers to initiate pull with
6163
Tag proto.GossipMessage_Tag
@@ -64,7 +66,7 @@ type PullConfig struct {
6466
}
6567

6668
// Mediator is a component wrap a PullEngine and provides the methods
67-
// it needs to perform pull synchronization..
69+
// it needs to perform pull synchronization.
6870
// The specialization of a pull mediator to a certain type of message is
6971
// done by the configuration, a IdentifierExtractor, IdentifierExtractor
7072
// given at construction, and also hooks that can be registered for each
@@ -86,28 +88,29 @@ type Mediator interface {
8688
HandleMessage(msg comm.ReceivedMessage)
8789
}
8890

89-
// pullStoreImpl is an implementation of PullStore
91+
// pullMediatorImpl is an implementation of Mediator
9092
type pullMediatorImpl struct {
93+
sync.RWMutex
94+
Sender
9195
msgType2Hook map[PullMsgType][]MessageHook
9296
idExtractor proto.IdentifierExtractor
9397
msgCons proto.MsgConsumer
9498
config PullConfig
9599
logger *logging.Logger
96-
sync.RWMutex
97-
itemId2msg map[string]*proto.GossipMessage
98-
Sender
99-
memBvc MembershipService
100-
engine *algo.PullEngine
100+
itemID2Msg map[string]*proto.GossipMessage
101+
memBvc MembershipService
102+
engine *algo.PullEngine
101103
}
102104

105+
// NewPullMediator returns a new Mediator
103106
func NewPullMediator(config PullConfig, sndr Sender, memSvc MembershipService, idExtractor proto.IdentifierExtractor, msgCons proto.MsgConsumer) Mediator {
104107
p := &pullMediatorImpl{
105108
msgCons: msgCons,
106109
msgType2Hook: make(map[PullMsgType][]MessageHook),
107110
idExtractor: idExtractor,
108111
config: config,
109-
logger: util.GetLogger(util.LoggingPullModule, config.Id),
110-
itemId2msg: make(map[string]*proto.GossipMessage),
112+
logger: util.GetLogger(util.LoggingPullModule, config.ID),
113+
itemID2Msg: make(map[string]*proto.GossipMessage),
111114
memBvc: memSvc,
112115
Sender: sndr,
113116
}
@@ -128,7 +131,7 @@ func (p *pullMediatorImpl) HandleMessage(m comm.ReceivedMessage) {
128131

129132
p.logger.Debug(msg)
130133

131-
itemIds := []string{}
134+
itemIDs := []string{}
132135
items := []*proto.GossipMessage{}
133136
var pullMsgType PullMsgType
134137

@@ -137,33 +140,33 @@ func (p *pullMediatorImpl) HandleMessage(m comm.ReceivedMessage) {
137140
p.engine.OnHello(helloMsg.Nonce, m)
138141
}
139142
if digest := msg.GetDataDig(); digest != nil {
140-
itemIds = digest.Digests
143+
itemIDs = digest.Digests
141144
pullMsgType = DigestMsgType
142145
p.engine.OnDigest(digest.Digests, digest.Nonce, m)
143146
}
144147
if req := msg.GetDataReq(); req != nil {
145-
itemIds = req.Digests
148+
itemIDs = req.Digests
146149
pullMsgType = RequestMsgType
147150
p.engine.OnReq(req.Digests, req.Nonce, m)
148151
}
149152
if res := msg.GetDataUpdate(); res != nil {
150-
itemIds = make([]string, len(res.Data))
153+
itemIDs = make([]string, len(res.Data))
151154
items = make([]*proto.GossipMessage, len(res.Data))
152155
pullMsgType = ResponseMsgType
153156
for i, pulledMsg := range res.Data {
154157
p.msgCons(pulledMsg)
155-
itemIds[i] = p.idExtractor(pulledMsg)
158+
itemIDs[i] = p.idExtractor(pulledMsg)
156159
items[i] = pulledMsg
157160
p.Lock()
158-
p.itemId2msg[itemIds[i]] = pulledMsg
161+
p.itemID2Msg[itemIDs[i]] = pulledMsg
159162
p.Unlock()
160163
}
161-
p.engine.OnRes(itemIds, res.Nonce)
164+
p.engine.OnRes(itemIDs, res.Nonce)
162165
}
163166

164167
// Invoke hooks for relevant message type
165168
for _, h := range p.hooksByMsgType(pullMsgType) {
166-
h(itemIds, items, m)
169+
h(itemIDs, items, m)
167170
}
168171
}
169172

@@ -183,18 +186,18 @@ func (p *pullMediatorImpl) RegisterMsgHook(pullMsgType PullMsgType, hook Message
183186
func (p *pullMediatorImpl) Add(msg *proto.GossipMessage) {
184187
p.Lock()
185188
defer p.Unlock()
186-
itemId := p.idExtractor(msg)
187-
p.itemId2msg[itemId] = msg
188-
p.engine.Add(itemId)
189+
itemID := p.idExtractor(msg)
190+
p.itemID2Msg[itemID] = msg
191+
p.engine.Add(itemID)
189192
}
190193

191194
// Remove removes a GossipMessage from the store
192195
func (p *pullMediatorImpl) Remove(msg *proto.GossipMessage) {
193196
p.Lock()
194197
defer p.Unlock()
195-
itemId := p.idExtractor(msg)
196-
delete(p.itemId2msg, itemId)
197-
p.engine.Remove(itemId)
198+
itemID := p.idExtractor(msg)
199+
delete(p.itemID2Msg, itemID)
200+
p.engine.Remove(itemID)
198201
}
199202

200203
// SelectPeers returns a slice of peers which the engine will initiate the protocol with
@@ -271,7 +274,7 @@ func (p *pullMediatorImpl) SendRes(items []string, context interface{}, nonce ui
271274
p.RLock()
272275
defer p.RUnlock()
273276
for _, item := range items {
274-
if msg, exists := p.itemId2msg[item]; exists {
277+
if msg, exists := p.itemID2Msg[item]; exists {
275278
items2return = append(items2return, msg)
276279
}
277280
}
@@ -314,6 +317,7 @@ func (p *pullMediatorImpl) hooksByMsgType(msgType PullMsgType) []MessageHook {
314317
return returnedHooks
315318
}
316319

320+
// SelectEndpoints select k peers from peerPool and returns them.
317321
func SelectEndpoints(k int, peerPool []discovery.NetworkMember) []*comm.RemotePeer {
318322
if len(peerPool) < k {
319323
k = len(peerPool)

gossip/gossip/pull/pullstore_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func createPullInstance(endpoint string, peer2PullInst map[string]*pullInstance)
114114
conf := PullConfig{
115115
MsgType: proto.PullMsgType_BlockMessage,
116116
Channel: []byte(""),
117-
Id: endpoint,
117+
ID: endpoint,
118118
PeerCountToSelect: 3,
119119
PullInterval: pullInterval,
120120
Tag: proto.GossipMessage_EMPTY,

gossip/identity/identity.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ type identityMapperImpl struct {
5555
sync.RWMutex
5656
}
5757

58-
// NewIdentityStore method, all we need is a reference to a MessageCryptoService
58+
// NewIdentityMapper method, all we need is a reference to a MessageCryptoService
5959
func NewIdentityMapper(mcs api.MessageCryptoService) Mapper {
6060
return &identityMapperImpl{
6161
mcs: mcs,

gossip/proto/extensions.go

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package proto
1818

1919
import (
2020
"bytes"
21-
2221
"fmt"
2322

2423
"github.com/golang/protobuf/proto"

gossip/state/state_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ var (
4646
logger = gossipUtil.GetLogger(gossipUtil.LoggingStateModule, "")
4747
)
4848

49-
var orgId = []byte("ORG1")
49+
var orgID = []byte("ORG1")
5050
var anchorPeerIdentity = api.PeerIdentityType("identityInOrg1")
5151

5252
type joinChanMsg struct {
@@ -69,7 +69,7 @@ type orgCryptoService struct {
6969
// OrgByPeerIdentity returns the OrgIdentityType
7070
// of a given peer identity
7171
func (*orgCryptoService) OrgByPeerIdentity(identity api.PeerIdentityType) api.OrgIdentityType {
72-
return orgId
72+
return orgID
7373
}
7474

7575
// Verify verifies a JoinChannelMessage, returns nil on success,

0 commit comments

Comments
 (0)