-
Notifications
You must be signed in to change notification settings - Fork 0
/
connectionsHandlerStub.go
169 lines (148 loc) · 4.74 KB
/
connectionsHandlerStub.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
158
159
160
161
162
163
164
165
166
167
168
169
package testscommon
import (
"time"
"github.com/bhagyaraj1208117/andes-abc-1/core"
"github.com/bhagyaraj1208117/andes-communication-go/p2p"
)
// ConnectionsHandlerStub -
type ConnectionsHandlerStub struct {
BootstrapCalled func() error
PeersCalled func() []core.PeerID
AddressesCalled func() []string
ConnectToPeerCalled func(address string) error
IsConnectedCalled func(peerID core.PeerID) bool
ConnectedPeersCalled func() []core.PeerID
ConnectedAddressesCalled func() []string
PeerAddressesCalled func(pid core.PeerID) []string
ConnectedPeersOnTopicCalled func(topic string) []core.PeerID
SetPeerShardResolverCalled func(peerShardResolver p2p.PeerShardResolver) error
GetConnectedPeersInfoCalled func() *p2p.ConnectedPeersInfo
WaitForConnectionsCalled func(maxWaitingTime time.Duration, minNumOfPeers uint32)
IsConnectedToTheNetworkCalled func() bool
ThresholdMinConnectedPeersCalled func() int
SetThresholdMinConnectedPeersCalled func(minConnectedPeers int) error
SetPeerDenialEvaluatorCalled func(handler p2p.PeerDenialEvaluator) error
CloseCalled func() error
}
// Bootstrap -
func (stub *ConnectionsHandlerStub) Bootstrap() error {
if stub.BootstrapCalled != nil {
return stub.BootstrapCalled()
}
return nil
}
// Peers -
func (stub *ConnectionsHandlerStub) Peers() []core.PeerID {
if stub.PeersCalled != nil {
return stub.PeersCalled()
}
return nil
}
// Addresses -
func (stub *ConnectionsHandlerStub) Addresses() []string {
if stub.AddressesCalled != nil {
return stub.AddressesCalled()
}
return nil
}
// ConnectToPeer -
func (stub *ConnectionsHandlerStub) ConnectToPeer(address string) error {
if stub.ConnectToPeerCalled != nil {
return stub.ConnectToPeerCalled(address)
}
return nil
}
// IsConnected -
func (stub *ConnectionsHandlerStub) IsConnected(peerID core.PeerID) bool {
if stub.IsConnectedCalled != nil {
return stub.IsConnectedCalled(peerID)
}
return false
}
// ConnectedPeers -
func (stub *ConnectionsHandlerStub) ConnectedPeers() []core.PeerID {
if stub.ConnectedPeersCalled != nil {
return stub.ConnectedPeersCalled()
}
return nil
}
// ConnectedAddresses -
func (stub *ConnectionsHandlerStub) ConnectedAddresses() []string {
if stub.ConnectedAddressesCalled != nil {
return stub.ConnectedAddressesCalled()
}
return nil
}
// PeerAddresses -
func (stub *ConnectionsHandlerStub) PeerAddresses(pid core.PeerID) []string {
if stub.PeerAddressesCalled != nil {
return stub.PeerAddressesCalled(pid)
}
return nil
}
// ConnectedPeersOnTopic -
func (stub *ConnectionsHandlerStub) ConnectedPeersOnTopic(topic string) []core.PeerID {
if stub.ConnectedPeersOnTopicCalled != nil {
return stub.ConnectedPeersOnTopicCalled(topic)
}
return nil
}
// SetPeerShardResolver -
func (stub *ConnectionsHandlerStub) SetPeerShardResolver(peerShardResolver p2p.PeerShardResolver) error {
if stub.SetPeerShardResolverCalled != nil {
return stub.SetPeerShardResolverCalled(peerShardResolver)
}
return nil
}
// GetConnectedPeersInfo -
func (stub *ConnectionsHandlerStub) GetConnectedPeersInfo() *p2p.ConnectedPeersInfo {
if stub.GetConnectedPeersInfoCalled != nil {
return stub.GetConnectedPeersInfoCalled()
}
return nil
}
// WaitForConnections -
func (stub *ConnectionsHandlerStub) WaitForConnections(maxWaitingTime time.Duration, minNumOfPeers uint32) {
if stub.WaitForConnectionsCalled != nil {
stub.WaitForConnectionsCalled(maxWaitingTime, minNumOfPeers)
}
}
// IsConnectedToTheNetwork -
func (stub *ConnectionsHandlerStub) IsConnectedToTheNetwork() bool {
if stub.IsConnectedToTheNetworkCalled != nil {
return stub.IsConnectedToTheNetworkCalled()
}
return false
}
// ThresholdMinConnectedPeers -
func (stub *ConnectionsHandlerStub) ThresholdMinConnectedPeers() int {
if stub.ThresholdMinConnectedPeersCalled != nil {
return stub.ThresholdMinConnectedPeersCalled()
}
return 0
}
// SetThresholdMinConnectedPeers -
func (stub *ConnectionsHandlerStub) SetThresholdMinConnectedPeers(minConnectedPeers int) error {
if stub.SetThresholdMinConnectedPeersCalled != nil {
return stub.SetThresholdMinConnectedPeersCalled(minConnectedPeers)
}
return nil
}
// SetPeerDenialEvaluator -
func (stub *ConnectionsHandlerStub) SetPeerDenialEvaluator(handler p2p.PeerDenialEvaluator) error {
if stub.SetPeerDenialEvaluatorCalled != nil {
return stub.SetPeerDenialEvaluatorCalled(handler)
}
return nil
}
// Close -
func (stub *ConnectionsHandlerStub) Close() error {
if stub.CloseCalled != nil {
return stub.CloseCalled()
}
return nil
}
// IsInterfaceNil -
func (stub *ConnectionsHandlerStub) IsInterfaceNil() bool {
return stub == nil
}