-
Notifications
You must be signed in to change notification settings - Fork 199
/
nilConnectionMonitor.go
54 lines (41 loc) · 2.05 KB
/
nilConnectionMonitor.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
package connectionMonitor
import (
"github.com/libp2p/go-libp2p-core/network"
"github.com/multiformats/go-multiaddr"
)
// NilConnectionMonitor does not monitor the connections made by the host
type NilConnectionMonitor struct {
thresholdMinConnectedPeers int
}
// Listen is called when network starts listening on an addr
func (n *NilConnectionMonitor) Listen(network.Network, multiaddr.Multiaddr) {}
// ListenClose is called when network stops listening on an addr
func (n *NilConnectionMonitor) ListenClose(network.Network, multiaddr.Multiaddr) {}
// Connected is called when a connection opened
func (n *NilConnectionMonitor) Connected(network.Network, network.Conn) {}
// Disconnected is called when a connection closed
func (n *NilConnectionMonitor) Disconnected(network.Network, network.Conn) {}
// OpenedStream is called when a stream opened
func (n *NilConnectionMonitor) OpenedStream(network.Network, network.Stream) {}
// ClosedStream is called when a stream closed
func (n *NilConnectionMonitor) ClosedStream(network.Network, network.Stream) {}
// IsConnectedToTheNetwork returns true if the number of connected peer is at least equal with thresholdMinConnectedPeers
func (n *NilConnectionMonitor) IsConnectedToTheNetwork(netw network.Network) bool {
return len(netw.Conns()) >= n.thresholdMinConnectedPeers
}
// SetThresholdMinConnectedPeers sets the minimum connected peers number when the node is considered connected on the network
func (n *NilConnectionMonitor) SetThresholdMinConnectedPeers(thresholdMinConnectedPeers int, _ network.Network) {
n.thresholdMinConnectedPeers = thresholdMinConnectedPeers
}
// ThresholdMinConnectedPeers returns the minimum connected peers number when the node is considered connected on the network
func (n *NilConnectionMonitor) ThresholdMinConnectedPeers() int {
return n.thresholdMinConnectedPeers
}
// Close returns nil
func (n *NilConnectionMonitor) Close() error {
return nil
}
// IsInterfaceNil returns true if there is no value under the interface
func (n *NilConnectionMonitor) IsInterfaceNil() bool {
return n == nil
}