@@ -31,14 +31,14 @@ import (
31
31
32
32
// Constants go here.
33
33
const (
34
- HelloMsgType PullMsgType = iota
34
+ HelloMsgType MsgType = iota
35
35
DigestMsgType
36
36
RequestMsgType
37
37
ResponseMsgType
38
38
)
39
39
40
- // PullMsgType defines the type of a message that is sent to the PullStore
41
- type PullMsgType int
40
+ // MsgType defines the type of a message that is sent to the PullStore
41
+ type MsgType int
42
42
43
43
// MessageHook defines a function that will run after a certain pull message is received
44
44
type MessageHook func (itemIDs []string , items []* proto.SignedGossipMessage , msg proto.ReceivedMessage )
@@ -55,6 +55,16 @@ type MembershipService interface {
55
55
GetMembership () []discovery.NetworkMember
56
56
}
57
57
58
+ // Config defines the configuration of the pull mediator
59
+ type Config struct {
60
+ ID string
61
+ PullInterval time.Duration // Duration between pull invocations
62
+ PeerCountToSelect int // Number of peers to initiate pull with
63
+ Tag proto.GossipMessage_Tag
64
+ Channel common.ChainID
65
+ MsgType proto.PullMsgType
66
+ }
67
+
58
68
// DigestFilter filters digests to be sent to a remote peer, that
59
69
// sent a hello with the following message
60
70
type DigestFilter func (helloMsg proto.ReceivedMessage ) func (digestItem string ) bool
@@ -68,16 +78,6 @@ func (df DigestFilter) byContext() algo.DigestFilter {
68
78
}
69
79
}
70
80
71
- // PullConfig defines the configuration of the pull mediator
72
- type PullConfig struct {
73
- ID string
74
- PullInterval time.Duration // Duration between pull invocations
75
- PeerCountToSelect int // Number of peers to initiate pull with
76
- Tag proto.GossipMessage_Tag
77
- Channel common.ChainID
78
- MsgType proto.PullMsgType
79
- }
80
-
81
81
// PullAdapter defines methods of the pullStore to interact
82
82
// with various modules of gossip
83
83
type PullAdapter struct {
@@ -99,7 +99,7 @@ type Mediator interface {
99
99
Stop ()
100
100
101
101
// RegisterMsgHook registers a message hook to a specific type of pull message
102
- RegisterMsgHook (PullMsgType , MessageHook )
102
+ RegisterMsgHook (MsgType , MessageHook )
103
103
104
104
// Add adds a GossipMessage to the Mediator
105
105
Add (* proto.SignedGossipMessage )
@@ -115,18 +115,18 @@ type Mediator interface {
115
115
type pullMediatorImpl struct {
116
116
sync.RWMutex
117
117
Sender
118
- msgType2Hook map [PullMsgType ][]MessageHook
118
+ msgType2Hook map [MsgType ][]MessageHook
119
119
idExtractor proto.IdentifierExtractor
120
120
msgCons proto.MsgConsumer
121
- config PullConfig
121
+ config Config
122
122
logger * logging.Logger
123
123
itemID2Msg map [string ]* proto.SignedGossipMessage
124
124
memBvc MembershipService
125
125
engine * algo.PullEngine
126
126
}
127
127
128
128
// NewPullMediator returns a new Mediator
129
- func NewPullMediator (config PullConfig , adapter PullAdapter ) Mediator {
129
+ func NewPullMediator (config Config , adapter PullAdapter ) Mediator {
130
130
digFilter := adapter .DigFilter
131
131
132
132
acceptAllFilter := func (_ proto.ReceivedMessage ) func (string ) bool {
@@ -141,7 +141,7 @@ func NewPullMediator(config PullConfig, adapter PullAdapter) Mediator {
141
141
142
142
p := & pullMediatorImpl {
143
143
msgCons : adapter .MsgCons ,
144
- msgType2Hook : make (map [PullMsgType ][]MessageHook ),
144
+ msgType2Hook : make (map [MsgType ][]MessageHook ),
145
145
idExtractor : adapter .IdExtractor ,
146
146
config : config ,
147
147
logger : util .GetLogger (util .LoggingPullModule , config .ID ),
@@ -169,7 +169,7 @@ func (p *pullMediatorImpl) HandleMessage(m proto.ReceivedMessage) {
169
169
170
170
itemIDs := []string {}
171
171
items := []* proto.SignedGossipMessage {}
172
- var pullMsgType PullMsgType
172
+ var pullMsgType MsgType
173
173
174
174
if helloMsg := msg .GetHello (); helloMsg != nil {
175
175
pullMsgType = HelloMsgType
@@ -216,7 +216,7 @@ func (p *pullMediatorImpl) Stop() {
216
216
}
217
217
218
218
// RegisterMsgHook registers a message hook to a specific type of pull message
219
- func (p * pullMediatorImpl ) RegisterMsgHook (pullMsgType PullMsgType , hook MessageHook ) {
219
+ func (p * pullMediatorImpl ) RegisterMsgHook (pullMsgType MsgType , hook MessageHook ) {
220
220
p .Lock ()
221
221
defer p .Unlock ()
222
222
p .msgType2Hook [pullMsgType ] = append (p .msgType2Hook [pullMsgType ], hook )
@@ -348,7 +348,7 @@ func (p *pullMediatorImpl) peersWithEndpoints(endpoints ...string) []*comm.Remot
348
348
return peers
349
349
}
350
350
351
- func (p * pullMediatorImpl ) hooksByMsgType (msgType PullMsgType ) []MessageHook {
351
+ func (p * pullMediatorImpl ) hooksByMsgType (msgType MsgType ) []MessageHook {
352
352
p .RLock ()
353
353
defer p .RUnlock ()
354
354
returnedHooks := []MessageHook {}
0 commit comments