-
Notifications
You must be signed in to change notification settings - Fork 199
/
messengerStub.go
157 lines (129 loc) · 4.7 KB
/
messengerStub.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package mock
import (
"github.com/ElrondNetwork/elrond-go-core/core"
"github.com/ElrondNetwork/elrond-go/p2p"
)
// MessengerStub -
type MessengerStub struct {
ConnectedPeersOnTopicCalled func(topic string) []core.PeerID
ConnectedFullHistoryPeersOnTopicCalled func(topic string) []core.PeerID
CloseCalled func() error
IDCalled func() core.PeerID
PeersCalled func() []core.PeerID
AddressesCalled func() []string
ConnectToPeerCalled func(address string) error
TrimConnectionsCalled func()
IsConnectedCalled func(peerID core.PeerID) bool
ConnectedPeersCalled func() []core.PeerID
CreateTopicCalled func(name string, createChannelForTopic bool) error
HasTopicCalled func(name string) bool
HasTopicValidatorCalled func(name string) bool
BroadcastOnChannelCalled func(channel string, topic string, buff []byte)
BroadcastCalled func(topic string, buff []byte)
RegisterMessageProcessorCalled func(topic string, identifier string, handler p2p.MessageProcessor) error
UnregisterMessageProcessorCalled func(topic string, identifier string) error
SendToConnectedPeerCalled func(topic string, buff []byte, peerID core.PeerID) error
OutgoingChannelLoadBalancerCalled func() p2p.ChannelLoadBalancer
BootstrapCalled func() error
}
// ConnectedPeersOnTopic -
func (ms *MessengerStub) ConnectedPeersOnTopic(topic string) []core.PeerID {
if ms.ConnectedPeersOnTopicCalled != nil {
return ms.ConnectedPeersOnTopicCalled(topic)
}
return make([]core.PeerID, 0)
}
// ConnectedFullHistoryPeersOnTopic -
func (ms *MessengerStub) ConnectedFullHistoryPeersOnTopic(topic string) []core.PeerID {
if ms.ConnectedFullHistoryPeersOnTopicCalled != nil {
return ms.ConnectedFullHistoryPeersOnTopicCalled(topic)
}
return make([]core.PeerID, 0)
}
// RegisterMessageProcessor -
func (ms *MessengerStub) RegisterMessageProcessor(topic string, identifier string, handler p2p.MessageProcessor) error {
return ms.RegisterMessageProcessorCalled(topic, identifier, handler)
}
// UnregisterMessageProcessor -
func (ms *MessengerStub) UnregisterMessageProcessor(topic string, identifier string) error {
return ms.UnregisterMessageProcessorCalled(topic, identifier)
}
// Broadcast -
func (ms *MessengerStub) Broadcast(topic string, buff []byte) {
ms.BroadcastCalled(topic, buff)
}
// OutgoingChannelLoadBalancer -
func (ms *MessengerStub) OutgoingChannelLoadBalancer() p2p.ChannelLoadBalancer {
return ms.OutgoingChannelLoadBalancerCalled()
}
// Close -
func (ms *MessengerStub) Close() error {
return ms.CloseCalled()
}
// ID -
func (ms *MessengerStub) ID() core.PeerID {
if ms.IDCalled != nil {
return ms.IDCalled()
}
return ""
}
// Peers -
func (ms *MessengerStub) Peers() []core.PeerID {
return ms.PeersCalled()
}
// Addresses -
func (ms *MessengerStub) Addresses() []string {
return ms.AddressesCalled()
}
// ConnectToPeer -
func (ms *MessengerStub) ConnectToPeer(address string) error {
return ms.ConnectToPeerCalled(address)
}
// TrimConnections -
func (ms *MessengerStub) TrimConnections() {
ms.TrimConnectionsCalled()
}
// IsConnected -
func (ms *MessengerStub) IsConnected(peerID core.PeerID) bool {
return ms.IsConnectedCalled(peerID)
}
// ConnectedPeers -
func (ms *MessengerStub) ConnectedPeers() []core.PeerID {
return ms.ConnectedPeersCalled()
}
// CreateTopic -
func (ms *MessengerStub) CreateTopic(name string, createChannelForTopic bool) error {
return ms.CreateTopicCalled(name, createChannelForTopic)
}
// HasTopic -
func (ms *MessengerStub) HasTopic(name string) bool {
return ms.HasTopicCalled(name)
}
// HasTopicValidator -
func (ms *MessengerStub) HasTopicValidator(name string) bool {
return ms.HasTopicValidatorCalled(name)
}
// BroadcastOnChannel -
func (ms *MessengerStub) BroadcastOnChannel(channel string, topic string, buff []byte) {
ms.BroadcastOnChannelCalled(channel, topic, buff)
}
// SendToConnectedPeer -
func (ms *MessengerStub) SendToConnectedPeer(topic string, buff []byte, peerID core.PeerID) error {
return ms.SendToConnectedPeerCalled(topic, buff, peerID)
}
// Bootstrap -
func (ms *MessengerStub) Bootstrap() error {
return ms.BootstrapCalled()
}
// UnregisterAllMessageProcessors -
func (ms *MessengerStub) UnregisterAllMessageProcessors() error {
return nil
}
// UnjoinAllTopics -
func (ms *MessengerStub) UnjoinAllTopics() error {
return nil
}
// IsInterfaceNil returns true if there is no value under the interface
func (ms *MessengerStub) IsInterfaceNil() bool {
return ms == nil
}