-
Notifications
You must be signed in to change notification settings - Fork 202
/
interface.go
122 lines (107 loc) · 4.34 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package heartbeat
import (
"io"
"time"
"github.com/ElrondNetwork/elrond-go-core/core"
"github.com/ElrondNetwork/elrond-go-core/data"
"github.com/ElrondNetwork/elrond-go-crypto"
"github.com/ElrondNetwork/elrond-go/common"
heartbeatData "github.com/ElrondNetwork/elrond-go/heartbeat/data"
"github.com/ElrondNetwork/elrond-go/p2p"
"github.com/ElrondNetwork/elrond-go/state"
)
// P2PMessenger defines a subset of the p2p.Messenger interface
type P2PMessenger interface {
io.Closer
Bootstrap() error
Broadcast(topic string, buff []byte)
BroadcastOnChannel(channel string, topic string, buff []byte)
BroadcastOnChannelBlocking(channel string, topic string, buff []byte) error
CreateTopic(name string, createChannelForTopic bool) error
HasTopic(name string) bool
RegisterMessageProcessor(topic string, identifier string, handler p2p.MessageProcessor) error
PeerAddresses(pid core.PeerID) []string
IsConnectedToTheNetwork() bool
ID() core.PeerID
IsInterfaceNil() bool
}
// MessageHandler defines what a message processor for heartbeat should do
type MessageHandler interface {
CreateHeartbeatFromP2PMessage(message p2p.MessageP2P) (*heartbeatData.Heartbeat, error)
IsInterfaceNil() bool
}
// EligibleListProvider defines what an eligible list provider should do
type EligibleListProvider interface {
GetAllEligibleValidatorsPublicKeys(epoch uint32) (map[uint32][][]byte, error)
GetAllWaitingValidatorsPublicKeys(epoch uint32) (map[uint32][][]byte, error)
IsInterfaceNil() bool
}
//Timer defines an interface for tracking time
type Timer interface {
Now() time.Time
IsInterfaceNil() bool
}
// HeartbeatStorageHandler defines what a heartbeat's storer should do
type HeartbeatStorageHandler interface {
LoadGenesisTime() (time.Time, error)
UpdateGenesisTime(genesisTime time.Time) error
LoadHeartBeatDTO(pubKey string) (*heartbeatData.HeartbeatDTO, error)
SavePubkeyData(pubkey []byte, heartbeat *heartbeatData.HeartbeatDTO) error
LoadKeys() ([][]byte, error)
SaveKeys(peersSlice [][]byte) error
IsInterfaceNil() bool
}
// NetworkShardingCollector defines the updating methods used by the network sharding component
// The interface assures that the collected data will be used by the p2p network sharding components
type NetworkShardingCollector interface {
UpdatePeerIDInfo(pid core.PeerID, pk []byte, shardID uint32)
UpdatePeerIdSubType(pid core.PeerID, peerSubType core.P2PPeerSubType)
IsInterfaceNil() bool
}
// P2PAntifloodHandler defines the behavior of a component able to signal that the system is too busy (or flooded) processing
// p2p messages
type P2PAntifloodHandler interface {
CanProcessMessage(message p2p.MessageP2P, fromConnectedPeer core.PeerID) error
CanProcessMessagesOnTopic(peer core.PeerID, topic string, numMessages uint32, totalSize uint64, sequence []byte) error
BlacklistPeer(peer core.PeerID, reason string, duration time.Duration)
IsInterfaceNil() bool
}
// PeerTypeProviderHandler defines what a component which computes the type of a peer should do
type PeerTypeProviderHandler interface {
ComputeForPubKey(pubKey []byte) (common.PeerType, uint32, error)
GetAllPeerTypeInfos() []*state.PeerTypeInfo
IsInterfaceNil() bool
}
// HardforkTrigger defines the behavior of a hardfork trigger
type HardforkTrigger interface {
TriggerReceived(payload []byte, data []byte, pkBytes []byte) (bool, error)
RecordedTriggerMessage() ([]byte, bool)
NotifyTriggerReceived() <-chan struct{}
CreateData() []byte
IsInterfaceNil() bool
}
// PeerBlackListHandler can determine if a certain peer ID is or not blacklisted
type PeerBlackListHandler interface {
Add(pid core.PeerID) error
Has(pid core.PeerID) bool
Sweep()
IsInterfaceNil() bool
}
// ValidatorStatisticsProcessor is the interface for consensus participation statistics
type ValidatorStatisticsProcessor interface {
RootHash() ([]byte, error)
GetValidatorInfoForRootHash(rootHash []byte) (map[uint32][]*state.ValidatorInfo, error)
IsInterfaceNil() bool
}
// CurrentBlockProvider can provide the current block that the node was able to commit
type CurrentBlockProvider interface {
GetCurrentBlockHeader() data.HeaderHandler
IsInterfaceNil() bool
}
// NodeRedundancyHandler defines the interface responsible for the redundancy management of the node
type NodeRedundancyHandler interface {
IsRedundancyNode() bool
IsMainMachineActive() bool
ObserverPrivateKey() crypto.PrivateKey
IsInterfaceNil() bool
}