2021-06-16 20:19:45 +00:00
|
|
|
package pubsub
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2022-11-04 13:57:20 +00:00
|
|
|
"github.com/libp2p/go-libp2p/core/peer"
|
|
|
|
"github.com/libp2p/go-libp2p/core/protocol"
|
2021-06-16 20:19:45 +00:00
|
|
|
|
2021-10-19 13:43:41 +00:00
|
|
|
pb "github.com/libp2p/go-libp2p-pubsub/pb"
|
2021-06-16 20:19:45 +00:00
|
|
|
)
|
|
|
|
|
2021-10-19 13:43:41 +00:00
|
|
|
// EventTracer is a generic event tracer interface.
|
|
|
|
// This is a high level tracing interface which delivers tracing events, as defined by the protobuf
|
|
|
|
// schema in pb/trace.proto.
|
2021-06-16 20:19:45 +00:00
|
|
|
type EventTracer interface {
|
|
|
|
Trace(evt *pb.TraceEvent)
|
|
|
|
}
|
|
|
|
|
2021-10-19 13:43:41 +00:00
|
|
|
// RawTracer is a low level tracing interface that allows an application to trace the internal
|
|
|
|
// operation of the pubsub subsystem.
|
|
|
|
//
|
|
|
|
// Note that the tracers are invoked synchronously, which means that application tracers must
|
|
|
|
// take care to not block or modify arguments.
|
|
|
|
//
|
|
|
|
// Warning: this interface is not fixed, we may be adding new methods as necessitated by the system
|
|
|
|
// in the future.
|
|
|
|
type RawTracer interface {
|
|
|
|
// AddPeer is invoked when a new peer is added.
|
2021-06-16 20:19:45 +00:00
|
|
|
AddPeer(p peer.ID, proto protocol.ID)
|
2021-10-19 13:43:41 +00:00
|
|
|
// RemovePeer is invoked when a peer is removed.
|
2021-06-16 20:19:45 +00:00
|
|
|
RemovePeer(p peer.ID)
|
2021-10-19 13:43:41 +00:00
|
|
|
// Join is invoked when a new topic is joined
|
2021-06-16 20:19:45 +00:00
|
|
|
Join(topic string)
|
2021-10-19 13:43:41 +00:00
|
|
|
// Leave is invoked when a topic is abandoned
|
2021-06-16 20:19:45 +00:00
|
|
|
Leave(topic string)
|
2021-10-19 13:43:41 +00:00
|
|
|
// Graft is invoked when a new peer is grafted on the mesh (gossipsub)
|
2021-06-16 20:19:45 +00:00
|
|
|
Graft(p peer.ID, topic string)
|
2021-10-19 13:43:41 +00:00
|
|
|
// Prune is invoked when a peer is pruned from the message (gossipsub)
|
2021-06-16 20:19:45 +00:00
|
|
|
Prune(p peer.ID, topic string)
|
2021-10-19 13:43:41 +00:00
|
|
|
// ValidateMessage is invoked when a message first enters the validation pipeline.
|
2021-06-16 20:19:45 +00:00
|
|
|
ValidateMessage(msg *Message)
|
2021-10-19 13:43:41 +00:00
|
|
|
// DeliverMessage is invoked when a message is delivered
|
2021-06-16 20:19:45 +00:00
|
|
|
DeliverMessage(msg *Message)
|
2021-10-19 13:43:41 +00:00
|
|
|
// RejectMessage is invoked when a message is Rejected or Ignored.
|
|
|
|
// The reason argument can be one of the named strings Reject*.
|
2021-06-16 20:19:45 +00:00
|
|
|
RejectMessage(msg *Message, reason string)
|
2021-10-19 13:43:41 +00:00
|
|
|
// DuplicateMessage is invoked when a duplicate message is dropped.
|
2021-06-16 20:19:45 +00:00
|
|
|
DuplicateMessage(msg *Message)
|
2021-10-19 13:43:41 +00:00
|
|
|
// ThrottlePeer is invoked when a peer is throttled by the peer gater.
|
2021-06-16 20:19:45 +00:00
|
|
|
ThrottlePeer(p peer.ID)
|
2021-10-19 13:43:41 +00:00
|
|
|
// RecvRPC is invoked when an incoming RPC is received.
|
|
|
|
RecvRPC(rpc *RPC)
|
|
|
|
// SendRPC is invoked when a RPC is sent.
|
|
|
|
SendRPC(rpc *RPC, p peer.ID)
|
|
|
|
// DropRPC is invoked when an outbound RPC is dropped, typically because of a queue full.
|
|
|
|
DropRPC(rpc *RPC, p peer.ID)
|
|
|
|
// UndeliverableMessage is invoked when the consumer of Subscribe is not reading messages fast enough and
|
|
|
|
// the pressure release mechanism trigger, dropping messages.
|
|
|
|
UndeliverableMessage(msg *Message)
|
2021-06-16 20:19:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// pubsub tracer details
|
|
|
|
type pubsubTracer struct {
|
2021-10-19 13:43:41 +00:00
|
|
|
tracer EventTracer
|
|
|
|
raw []RawTracer
|
|
|
|
pid peer.ID
|
2022-08-19 16:34:07 +00:00
|
|
|
idGen *msgIDGenerator
|
2021-06-16 20:19:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *pubsubTracer) PublishMessage(msg *Message) {
|
|
|
|
if t == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if t.tracer == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
now := time.Now().UnixNano()
|
|
|
|
evt := &pb.TraceEvent{
|
|
|
|
Type: pb.TraceEvent_PUBLISH_MESSAGE.Enum(),
|
|
|
|
PeerID: []byte(t.pid),
|
|
|
|
Timestamp: &now,
|
|
|
|
PublishMessage: &pb.TraceEvent_PublishMessage{
|
2022-08-19 16:34:07 +00:00
|
|
|
MessageID: []byte(t.idGen.ID(msg)),
|
2021-06-16 20:19:45 +00:00
|
|
|
Topic: msg.Message.Topic,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
t.tracer.Trace(evt)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *pubsubTracer) ValidateMessage(msg *Message) {
|
|
|
|
if t == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if msg.ReceivedFrom != t.pid {
|
2021-10-19 13:43:41 +00:00
|
|
|
for _, tr := range t.raw {
|
2021-06-16 20:19:45 +00:00
|
|
|
tr.ValidateMessage(msg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *pubsubTracer) RejectMessage(msg *Message, reason string) {
|
|
|
|
if t == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if msg.ReceivedFrom != t.pid {
|
2021-10-19 13:43:41 +00:00
|
|
|
for _, tr := range t.raw {
|
2021-06-16 20:19:45 +00:00
|
|
|
tr.RejectMessage(msg, reason)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if t.tracer == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
now := time.Now().UnixNano()
|
|
|
|
evt := &pb.TraceEvent{
|
|
|
|
Type: pb.TraceEvent_REJECT_MESSAGE.Enum(),
|
|
|
|
PeerID: []byte(t.pid),
|
|
|
|
Timestamp: &now,
|
|
|
|
RejectMessage: &pb.TraceEvent_RejectMessage{
|
2022-08-19 16:34:07 +00:00
|
|
|
MessageID: []byte(t.idGen.ID(msg)),
|
2021-06-16 20:19:45 +00:00
|
|
|
ReceivedFrom: []byte(msg.ReceivedFrom),
|
|
|
|
Reason: &reason,
|
|
|
|
Topic: msg.Topic,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
t.tracer.Trace(evt)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *pubsubTracer) DuplicateMessage(msg *Message) {
|
|
|
|
if t == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if msg.ReceivedFrom != t.pid {
|
2021-10-19 13:43:41 +00:00
|
|
|
for _, tr := range t.raw {
|
2021-06-16 20:19:45 +00:00
|
|
|
tr.DuplicateMessage(msg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if t.tracer == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
now := time.Now().UnixNano()
|
|
|
|
evt := &pb.TraceEvent{
|
|
|
|
Type: pb.TraceEvent_DUPLICATE_MESSAGE.Enum(),
|
|
|
|
PeerID: []byte(t.pid),
|
|
|
|
Timestamp: &now,
|
|
|
|
DuplicateMessage: &pb.TraceEvent_DuplicateMessage{
|
2022-08-19 16:34:07 +00:00
|
|
|
MessageID: []byte(t.idGen.ID(msg)),
|
2021-06-16 20:19:45 +00:00
|
|
|
ReceivedFrom: []byte(msg.ReceivedFrom),
|
|
|
|
Topic: msg.Topic,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
t.tracer.Trace(evt)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *pubsubTracer) DeliverMessage(msg *Message) {
|
|
|
|
if t == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if msg.ReceivedFrom != t.pid {
|
2021-10-19 13:43:41 +00:00
|
|
|
for _, tr := range t.raw {
|
2021-06-16 20:19:45 +00:00
|
|
|
tr.DeliverMessage(msg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if t.tracer == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
now := time.Now().UnixNano()
|
|
|
|
evt := &pb.TraceEvent{
|
|
|
|
Type: pb.TraceEvent_DELIVER_MESSAGE.Enum(),
|
|
|
|
PeerID: []byte(t.pid),
|
|
|
|
Timestamp: &now,
|
|
|
|
DeliverMessage: &pb.TraceEvent_DeliverMessage{
|
2022-08-19 16:34:07 +00:00
|
|
|
MessageID: []byte(t.idGen.ID(msg)),
|
2021-06-16 20:19:45 +00:00
|
|
|
Topic: msg.Topic,
|
|
|
|
ReceivedFrom: []byte(msg.ReceivedFrom),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
t.tracer.Trace(evt)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *pubsubTracer) AddPeer(p peer.ID, proto protocol.ID) {
|
|
|
|
if t == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-10-19 13:43:41 +00:00
|
|
|
for _, tr := range t.raw {
|
2021-06-16 20:19:45 +00:00
|
|
|
tr.AddPeer(p, proto)
|
|
|
|
}
|
|
|
|
|
|
|
|
if t.tracer == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
protoStr := string(proto)
|
|
|
|
now := time.Now().UnixNano()
|
|
|
|
evt := &pb.TraceEvent{
|
|
|
|
Type: pb.TraceEvent_ADD_PEER.Enum(),
|
|
|
|
PeerID: []byte(t.pid),
|
|
|
|
Timestamp: &now,
|
|
|
|
AddPeer: &pb.TraceEvent_AddPeer{
|
|
|
|
PeerID: []byte(p),
|
|
|
|
Proto: &protoStr,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
t.tracer.Trace(evt)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *pubsubTracer) RemovePeer(p peer.ID) {
|
|
|
|
if t == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-10-19 13:43:41 +00:00
|
|
|
for _, tr := range t.raw {
|
2021-06-16 20:19:45 +00:00
|
|
|
tr.RemovePeer(p)
|
|
|
|
}
|
|
|
|
|
|
|
|
if t.tracer == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
now := time.Now().UnixNano()
|
|
|
|
evt := &pb.TraceEvent{
|
|
|
|
Type: pb.TraceEvent_REMOVE_PEER.Enum(),
|
|
|
|
PeerID: []byte(t.pid),
|
|
|
|
Timestamp: &now,
|
|
|
|
RemovePeer: &pb.TraceEvent_RemovePeer{
|
|
|
|
PeerID: []byte(p),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
t.tracer.Trace(evt)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *pubsubTracer) RecvRPC(rpc *RPC) {
|
|
|
|
if t == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-10-19 13:43:41 +00:00
|
|
|
for _, tr := range t.raw {
|
|
|
|
tr.RecvRPC(rpc)
|
|
|
|
}
|
|
|
|
|
2021-06-16 20:19:45 +00:00
|
|
|
if t.tracer == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
now := time.Now().UnixNano()
|
|
|
|
evt := &pb.TraceEvent{
|
|
|
|
Type: pb.TraceEvent_RECV_RPC.Enum(),
|
|
|
|
PeerID: []byte(t.pid),
|
|
|
|
Timestamp: &now,
|
|
|
|
RecvRPC: &pb.TraceEvent_RecvRPC{
|
|
|
|
ReceivedFrom: []byte(rpc.from),
|
|
|
|
Meta: t.traceRPCMeta(rpc),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
t.tracer.Trace(evt)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *pubsubTracer) SendRPC(rpc *RPC, p peer.ID) {
|
|
|
|
if t == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-10-19 13:43:41 +00:00
|
|
|
for _, tr := range t.raw {
|
|
|
|
tr.SendRPC(rpc, p)
|
|
|
|
}
|
|
|
|
|
2021-06-16 20:19:45 +00:00
|
|
|
if t.tracer == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
now := time.Now().UnixNano()
|
|
|
|
evt := &pb.TraceEvent{
|
|
|
|
Type: pb.TraceEvent_SEND_RPC.Enum(),
|
|
|
|
PeerID: []byte(t.pid),
|
|
|
|
Timestamp: &now,
|
|
|
|
SendRPC: &pb.TraceEvent_SendRPC{
|
|
|
|
SendTo: []byte(p),
|
|
|
|
Meta: t.traceRPCMeta(rpc),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
t.tracer.Trace(evt)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *pubsubTracer) DropRPC(rpc *RPC, p peer.ID) {
|
|
|
|
if t == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-10-19 13:43:41 +00:00
|
|
|
for _, tr := range t.raw {
|
|
|
|
tr.DropRPC(rpc, p)
|
|
|
|
}
|
|
|
|
|
2021-06-16 20:19:45 +00:00
|
|
|
if t.tracer == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
now := time.Now().UnixNano()
|
|
|
|
evt := &pb.TraceEvent{
|
|
|
|
Type: pb.TraceEvent_DROP_RPC.Enum(),
|
|
|
|
PeerID: []byte(t.pid),
|
|
|
|
Timestamp: &now,
|
|
|
|
DropRPC: &pb.TraceEvent_DropRPC{
|
|
|
|
SendTo: []byte(p),
|
|
|
|
Meta: t.traceRPCMeta(rpc),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
t.tracer.Trace(evt)
|
|
|
|
}
|
|
|
|
|
2021-10-19 13:43:41 +00:00
|
|
|
func (t *pubsubTracer) UndeliverableMessage(msg *Message) {
|
|
|
|
if t == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tr := range t.raw {
|
|
|
|
tr.UndeliverableMessage(msg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-16 20:19:45 +00:00
|
|
|
func (t *pubsubTracer) traceRPCMeta(rpc *RPC) *pb.TraceEvent_RPCMeta {
|
|
|
|
rpcMeta := new(pb.TraceEvent_RPCMeta)
|
|
|
|
|
|
|
|
var msgs []*pb.TraceEvent_MessageMeta
|
|
|
|
for _, m := range rpc.Publish {
|
|
|
|
msgs = append(msgs, &pb.TraceEvent_MessageMeta{
|
2022-08-19 16:34:07 +00:00
|
|
|
MessageID: []byte(t.idGen.RawID(m)),
|
2021-06-16 20:19:45 +00:00
|
|
|
Topic: m.Topic,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
rpcMeta.Messages = msgs
|
|
|
|
|
|
|
|
var subs []*pb.TraceEvent_SubMeta
|
|
|
|
for _, sub := range rpc.Subscriptions {
|
|
|
|
subs = append(subs, &pb.TraceEvent_SubMeta{
|
|
|
|
Subscribe: sub.Subscribe,
|
|
|
|
Topic: sub.Topicid,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
rpcMeta.Subscription = subs
|
|
|
|
|
|
|
|
if rpc.Control != nil {
|
|
|
|
var ihave []*pb.TraceEvent_ControlIHaveMeta
|
|
|
|
for _, ctl := range rpc.Control.Ihave {
|
|
|
|
var mids [][]byte
|
|
|
|
for _, mid := range ctl.MessageIDs {
|
|
|
|
mids = append(mids, []byte(mid))
|
|
|
|
}
|
|
|
|
ihave = append(ihave, &pb.TraceEvent_ControlIHaveMeta{
|
|
|
|
Topic: ctl.TopicID,
|
|
|
|
MessageIDs: mids,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
var iwant []*pb.TraceEvent_ControlIWantMeta
|
|
|
|
for _, ctl := range rpc.Control.Iwant {
|
|
|
|
var mids [][]byte
|
|
|
|
for _, mid := range ctl.MessageIDs {
|
|
|
|
mids = append(mids, []byte(mid))
|
|
|
|
}
|
|
|
|
iwant = append(iwant, &pb.TraceEvent_ControlIWantMeta{
|
|
|
|
MessageIDs: mids,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
var graft []*pb.TraceEvent_ControlGraftMeta
|
|
|
|
for _, ctl := range rpc.Control.Graft {
|
|
|
|
graft = append(graft, &pb.TraceEvent_ControlGraftMeta{
|
|
|
|
Topic: ctl.TopicID,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
var prune []*pb.TraceEvent_ControlPruneMeta
|
|
|
|
for _, ctl := range rpc.Control.Prune {
|
|
|
|
peers := make([][]byte, 0, len(ctl.Peers))
|
|
|
|
for _, pi := range ctl.Peers {
|
|
|
|
peers = append(peers, pi.PeerID)
|
|
|
|
}
|
|
|
|
prune = append(prune, &pb.TraceEvent_ControlPruneMeta{
|
|
|
|
Topic: ctl.TopicID,
|
|
|
|
Peers: peers,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
rpcMeta.Control = &pb.TraceEvent_ControlMeta{
|
|
|
|
Ihave: ihave,
|
|
|
|
Iwant: iwant,
|
|
|
|
Graft: graft,
|
|
|
|
Prune: prune,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rpcMeta
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *pubsubTracer) Join(topic string) {
|
|
|
|
if t == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-10-19 13:43:41 +00:00
|
|
|
for _, tr := range t.raw {
|
2021-06-16 20:19:45 +00:00
|
|
|
tr.Join(topic)
|
|
|
|
}
|
|
|
|
|
|
|
|
if t.tracer == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
now := time.Now().UnixNano()
|
|
|
|
evt := &pb.TraceEvent{
|
|
|
|
Type: pb.TraceEvent_JOIN.Enum(),
|
|
|
|
PeerID: []byte(t.pid),
|
|
|
|
Timestamp: &now,
|
|
|
|
Join: &pb.TraceEvent_Join{
|
|
|
|
Topic: &topic,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
t.tracer.Trace(evt)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *pubsubTracer) Leave(topic string) {
|
|
|
|
if t == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-10-19 13:43:41 +00:00
|
|
|
for _, tr := range t.raw {
|
2021-06-16 20:19:45 +00:00
|
|
|
tr.Leave(topic)
|
|
|
|
}
|
|
|
|
|
|
|
|
if t.tracer == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
now := time.Now().UnixNano()
|
|
|
|
evt := &pb.TraceEvent{
|
|
|
|
Type: pb.TraceEvent_LEAVE.Enum(),
|
|
|
|
PeerID: []byte(t.pid),
|
|
|
|
Timestamp: &now,
|
|
|
|
Leave: &pb.TraceEvent_Leave{
|
|
|
|
Topic: &topic,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
t.tracer.Trace(evt)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *pubsubTracer) Graft(p peer.ID, topic string) {
|
|
|
|
if t == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-10-19 13:43:41 +00:00
|
|
|
for _, tr := range t.raw {
|
2021-06-16 20:19:45 +00:00
|
|
|
tr.Graft(p, topic)
|
|
|
|
}
|
|
|
|
|
|
|
|
if t.tracer == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
now := time.Now().UnixNano()
|
|
|
|
evt := &pb.TraceEvent{
|
|
|
|
Type: pb.TraceEvent_GRAFT.Enum(),
|
|
|
|
PeerID: []byte(t.pid),
|
|
|
|
Timestamp: &now,
|
|
|
|
Graft: &pb.TraceEvent_Graft{
|
|
|
|
PeerID: []byte(p),
|
|
|
|
Topic: &topic,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
t.tracer.Trace(evt)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *pubsubTracer) Prune(p peer.ID, topic string) {
|
|
|
|
if t == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-10-19 13:43:41 +00:00
|
|
|
for _, tr := range t.raw {
|
2021-06-16 20:19:45 +00:00
|
|
|
tr.Prune(p, topic)
|
|
|
|
}
|
|
|
|
|
|
|
|
if t.tracer == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
now := time.Now().UnixNano()
|
|
|
|
evt := &pb.TraceEvent{
|
|
|
|
Type: pb.TraceEvent_PRUNE.Enum(),
|
|
|
|
PeerID: []byte(t.pid),
|
|
|
|
Timestamp: &now,
|
|
|
|
Prune: &pb.TraceEvent_Prune{
|
|
|
|
PeerID: []byte(p),
|
|
|
|
Topic: &topic,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
t.tracer.Trace(evt)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *pubsubTracer) ThrottlePeer(p peer.ID) {
|
|
|
|
if t == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-10-19 13:43:41 +00:00
|
|
|
for _, tr := range t.raw {
|
2021-06-16 20:19:45 +00:00
|
|
|
tr.ThrottlePeer(p)
|
|
|
|
}
|
|
|
|
}
|