-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.go
101 lines (87 loc) · 3.14 KB
/
interface.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
package libp2p
import (
"context"
"github.com/bhagyaraj1208117/andes-abc-1/core"
"github.com/bhagyaraj1208117/andes-communication-go/p2p"
pubsub "github.com/libp2p/go-libp2p-pubsub"
"github.com/libp2p/go-libp2p/core/crypto"
"github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/peer"
)
// ConnectionMonitor defines the behavior of a connection monitor
type ConnectionMonitor interface {
network.Notifiee
IsConnectedToTheNetwork(netw network.Network) bool
SetThresholdMinConnectedPeers(thresholdMinConnectedPeers int, netw network.Network)
ThresholdMinConnectedPeers() int
SetPeerDenialEvaluator(handler p2p.PeerDenialEvaluator) error
PeerDenialEvaluator() p2p.PeerDenialEvaluator
Close() error
IsInterfaceNil() bool
}
// PeerDiscovererWithSharder extends the PeerDiscoverer with the possibility to set the sharder
type PeerDiscovererWithSharder interface {
p2p.PeerDiscoverer
SetSharder(sharder p2p.Sharder) error
}
type p2pSigner interface {
Sign(payload []byte) ([]byte, error)
Verify(payload []byte, pid core.PeerID, signature []byte) error
SignUsingPrivateKey(skBytes []byte, payload []byte) ([]byte, error)
}
// SendableData represents the struct used in data throttler implementation
type SendableData struct {
Buff []byte
Topic string
Sk crypto.PrivKey
ID peer.ID
}
// ChannelLoadBalancer defines what a load balancer that uses chans should do
type ChannelLoadBalancer interface {
AddChannel(channel string) error
RemoveChannel(channel string) error
GetChannelOrDefault(channel string) chan *SendableData
CollectOneElementFromChannels() *SendableData
Close() error
IsInterfaceNil() bool
}
// PubSub interface defines what a publish/subscribe system should do
type PubSub interface {
Join(topic string, opts ...pubsub.TopicOpt) (*pubsub.Topic, error)
ListPeers(topic string) []peer.ID
RegisterTopicValidator(topic string, val interface{}, opts ...pubsub.ValidatorOpt) error
UnregisterTopicValidator(topic string) error
GetTopics() []string
}
// TopicProcessor interface defines what a topic processor can do
type TopicProcessor interface {
AddTopicProcessor(identifier string, processor p2p.MessageProcessor) error
RemoveTopicProcessor(identifier string) error
GetList() ([]string, []p2p.MessageProcessor)
IsInterfaceNil() bool
}
// PubSubSubscription interface defines what a pubSub subscription can do
type PubSubSubscription interface {
Topic() string
Next(ctx context.Context) (*pubsub.Message, error)
Cancel()
}
// PubSubTopic interface defines what a pubSub topic can do
type PubSubTopic interface {
Subscribe(opts ...pubsub.SubOpt) (*pubsub.Subscription, error)
Publish(ctx context.Context, data []byte, opts ...pubsub.PubOpt) error
Close() error
}
// PeersOnChannel interface defines what a component able to handle peers on a channel should do
type PeersOnChannel interface {
ConnectedPeersOnChannel(topic string) []core.PeerID
Close() error
IsInterfaceNil() bool
}
// ConnectionsMetric is an extension of the libp2p network notifiee able to track connections metrics
type ConnectionsMetric interface {
network.Notifiee
ResetNumConnections() uint32
ResetNumDisconnections() uint32
IsInterfaceNil() bool
}