-
Notifications
You must be signed in to change notification settings - Fork 199
/
p2pAntifloodHandlerStub.go
61 lines (49 loc) · 1.87 KB
/
p2pAntifloodHandlerStub.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
package mock
import (
"time"
"github.com/ElrondNetwork/elrond-go/core"
"github.com/ElrondNetwork/elrond-go/p2p"
)
// P2PAntifloodHandlerStub -
type P2PAntifloodHandlerStub struct {
CanProcessMessageCalled func(message p2p.MessageP2P, fromConnectedPeer core.PeerID) error
CanProcessMessagesOnTopicCalled func(peer core.PeerID, topic string, numMessages uint32, totalSize uint64, sequence []byte) error
ApplyConsensusSizeCalled func(size int)
BlacklistPeerCalled func(peer core.PeerID, reason string, duration time.Duration)
}
// ResetForTopic -
func (p2pahs *P2PAntifloodHandlerStub) ResetForTopic(_ string) {
}
// SetMaxMessagesForTopic -
func (p2pahs *P2PAntifloodHandlerStub) SetMaxMessagesForTopic(_ string, _ uint32) {
}
// ApplyConsensusSize -
func (p2pahs *P2PAntifloodHandlerStub) ApplyConsensusSize(size int) {
if p2pahs.ApplyConsensusSizeCalled != nil {
p2pahs.ApplyConsensusSizeCalled(size)
}
}
// CanProcessMessage -
func (p2pahs *P2PAntifloodHandlerStub) CanProcessMessage(message p2p.MessageP2P, fromConnectedPeer core.PeerID) error {
if p2pahs.CanProcessMessageCalled == nil {
return nil
}
return p2pahs.CanProcessMessageCalled(message, fromConnectedPeer)
}
// CanProcessMessagesOnTopic -
func (p2pahs *P2PAntifloodHandlerStub) CanProcessMessagesOnTopic(peer core.PeerID, topic string, numMessages uint32, totalSize uint64, sequence []byte) error {
if p2pahs.CanProcessMessagesOnTopicCalled == nil {
return nil
}
return p2pahs.CanProcessMessagesOnTopicCalled(peer, topic, numMessages, totalSize, sequence)
}
// BlacklistPeer -
func (p2pahs *P2PAntifloodHandlerStub) BlacklistPeer(peer core.PeerID, reason string, duration time.Duration) {
if p2pahs.BlacklistPeerCalled != nil {
p2pahs.BlacklistPeerCalled(peer, reason, duration)
}
}
// IsInterfaceNil -
func (p2pahs *P2PAntifloodHandlerStub) IsInterfaceNil() bool {
return p2pahs == nil
}