-
Notifications
You must be signed in to change notification settings - Fork 126
/
metric.go
72 lines (64 loc) · 2.49 KB
/
metric.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
package p2p
import (
"encoding/json"
"sync/atomic"
)
type MetricPool struct {
enabled bool
PeerMessageTypePing uint32 `json:"ping"`
PeerMessageTypeAuthentication uint32 `json:"authentication"`
PeerMessageTypeGraph uint32 `json:"graph"`
PeerMessageTypeSnapshotConfirm uint32 `json:"snapshot-confirm"`
PeerMessageTypeTransactionRequest uint32 `json:"transaction-request"`
PeerMessageTypeTransaction uint32 `json:"transaction"`
PeerMessageTypeSnapshotAnnouncement uint32 `json:"snapshot-announcement"`
PeerMessageTypeSnapshotCommitment uint32 `json:"snapshot-commitment"`
PeerMessageTypeTransactionChallenge uint32 `json:"transaciton-challenge"`
PeerMessageTypeSnapshotResponse uint32 `json:"snapshot-response"`
PeerMessageTypeSnapshotFinalization uint32 `json:"snapshot-finalization"`
PeerMessageTypeCommitments uint32 `json:"commitments"`
PeerMessageTypeFullChallenge uint32 `json:"full-challenge"`
PeerMessageTypeRelay uint32 `json:"relay"`
}
func (mp *MetricPool) handle(msg uint8) {
if !mp.enabled {
return
}
switch msg {
case PeerMessageTypePing:
atomic.AddUint32(&mp.PeerMessageTypePing, 1)
case PeerMessageTypeAuthentication:
atomic.AddUint32(&mp.PeerMessageTypeAuthentication, 1)
case PeerMessageTypeGraph:
atomic.AddUint32(&mp.PeerMessageTypeGraph, 1)
case PeerMessageTypeSnapshotConfirm:
atomic.AddUint32(&mp.PeerMessageTypeSnapshotConfirm, 1)
case PeerMessageTypeTransactionRequest:
atomic.AddUint32(&mp.PeerMessageTypeTransactionRequest, 1)
case PeerMessageTypeTransaction:
atomic.AddUint32(&mp.PeerMessageTypeTransaction, 1)
case PeerMessageTypeSnapshotAnnouncement:
atomic.AddUint32(&mp.PeerMessageTypeSnapshotAnnouncement, 1)
case PeerMessageTypeSnapshotCommitment:
atomic.AddUint32(&mp.PeerMessageTypeSnapshotCommitment, 1)
case PeerMessageTypeTransactionChallenge:
atomic.AddUint32(&mp.PeerMessageTypeTransactionChallenge, 1)
case PeerMessageTypeSnapshotResponse:
atomic.AddUint32(&mp.PeerMessageTypeSnapshotResponse, 1)
case PeerMessageTypeSnapshotFinalization:
atomic.AddUint32(&mp.PeerMessageTypeSnapshotFinalization, 1)
case PeerMessageTypeCommitments:
atomic.AddUint32(&mp.PeerMessageTypeCommitments, 1)
case PeerMessageTypeFullChallenge:
atomic.AddUint32(&mp.PeerMessageTypeFullChallenge, 1)
case PeerMessageTypeRelay:
atomic.AddUint32(&mp.PeerMessageTypeRelay, 1)
}
}
func (mp *MetricPool) String() string {
b, err := json.Marshal(mp)
if err != nil {
panic(err)
}
return string(b)
}