forked from filecoin-project/go-legs
/
trace.go
92 lines (74 loc) · 2.56 KB
/
trace.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
package gossiptopic
import (
logging "github.com/ipfs/go-log/v2"
pubsub "github.com/libp2p/go-libp2p-pubsub"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/protocol"
)
var _ pubsub.RawTracer = (*loggingTracer)(nil)
// loggingTracer is a pubsub.RawTracer that logs the internal operations of the pubsub subsystem
// for debugging purposes with debug log level.
type loggingTracer struct {
log *logging.ZapEventLogger
}
func (l *loggingTracer) AddPeer(p peer.ID, proto protocol.ID) {
l.log.Debugf("Peer added with ID %s and protocol %s", p, proto)
}
func (l *loggingTracer) RemovePeer(p peer.ID) {
l.log.Debugf("Peer removed with ID %s", p)
}
func (l *loggingTracer) Join(topic string) {
l.log.Debugf("Joined topic %s", topic)
}
func (l *loggingTracer) Leave(topic string) {
l.log.Debugf("Left topic %s", topic)
}
func (l *loggingTracer) Graft(p peer.ID, topic string) {
l.log.Debugf("Grafted peer with ID %s to topic %s", p, topic)
}
func (l *loggingTracer) Prune(p peer.ID, topic string) {
l.log.Debugf("Pruned peer with ID %s from topic %s", p, topic)
}
func (l *loggingTracer) ValidateMessage(msg *pubsub.Message) {
l.log.Debugf("Validating message from peer ID %s on topic %s with size %d bytes",
msg.GetFrom(),
msg.GetTopic(),
msg.Size())
}
func (l *loggingTracer) DeliverMessage(msg *pubsub.Message) {
l.log.Debugf("Delivered message from peer ID %s on topic %s with size %d bytes",
msg.GetFrom(),
msg.GetTopic(),
msg.Size())
}
func (l *loggingTracer) RejectMessage(msg *pubsub.Message, reason string) {
l.log.Debugf("Rejected message from peer ID %s on topic %s with size %d bytes: %s",
msg.GetFrom(),
msg.GetTopic(),
msg.Size(),
reason)
}
func (l *loggingTracer) DuplicateMessage(msg *pubsub.Message) {
l.log.Debugf("Dropped duplicate message from peer ID %s on topic %s with size %d bytes",
msg.GetFrom(),
msg.GetTopic(),
msg.Size())
}
func (l *loggingTracer) ThrottlePeer(p peer.ID) {
l.log.Debugf("Throttled peer ID %s", p)
}
func (l *loggingTracer) RecvRPC(rpc *pubsub.RPC) {
l.log.Debugf("Received RPC with size %d bytes", rpc.Size())
}
func (l *loggingTracer) SendRPC(rpc *pubsub.RPC, p peer.ID) {
l.log.Debugf("Sent RPC with size %d bytes to peer ID %s", rpc.Size(), p)
}
func (l *loggingTracer) DropRPC(rpc *pubsub.RPC, p peer.ID) {
l.log.Debugf("Dropped RPC with size %d bytes to peer ID %s", rpc.Size(), p)
}
func (l *loggingTracer) UndeliverableMessage(msg *pubsub.Message) {
l.log.Debugf("Undeliverable message from peer ID %s on topic %s with size %d bytes",
msg.GetFrom(),
msg.GetTopic(),
msg.Size())
}