forked from 0xProject/0x-mesh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
peer_score.go
32 lines (28 loc) · 941 Bytes
/
peer_score.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
package core
import (
peer "github.com/libp2p/go-libp2p-peer"
log "github.com/sirupsen/logrus"
)
type peerScoreEvent uint
const (
psInvalidMessage peerScoreEvent = iota
psValidMessage
psOrderStored
)
func (app *App) handlePeerScoreEvent(id peer.ID, event peerScoreEvent) {
// Note: for some events, we use `SetPeerScore` instead of `AddPeerScore` in
// order to limit the maximum positive score associated with that event.
// Without this, peers could be incentivized to artificially increase their
// score in a way that doesn't benefit the network. (For example, they could
// spam the network with valid messages).
switch event {
case psInvalidMessage:
app.node.AddPeerScore(id, "invalid-message", -5)
case psValidMessage:
app.node.SetPeerScore(id, "valid-message", 5)
case psOrderStored:
app.node.SetPeerScore(id, "order-stored", 10)
default:
log.WithField("event", event).Error("unknown peerScoreEvent")
}
}