Add lotus tracer transport calls

This commit is contained in:
Matija Petrunic 2021-09-10 15:37:38 +02:00
parent c367533a3c
commit d5a4b0637a
2 changed files with 30 additions and 3 deletions

View File

@ -1,11 +1,16 @@
package tracer
import (
"encoding/json"
logging "github.com/ipfs/go-log/v2"
peer "github.com/libp2p/go-libp2p-core/peer"
pubsub "github.com/libp2p/go-libp2p-pubsub"
pubsub_pb "github.com/libp2p/go-libp2p-pubsub/pb"
)
var log = logging.Logger("lotus-tracer")
func newLotusTracer(et pubsub.EventTracer, tt TracerTransport) LotusTracer {
return &lotusTracer{
et: et,
@ -23,6 +28,28 @@ type LotusTracer interface {
Trace(evt *pubsub_pb.TraceEvent)
}
func (lt *lotusTracer) TracePeerScore(scores map[peer.ID]*pubsub.PeerScoreSnapshot) {}
func (lt *lotusTracer) TracePeerScore(scores map[peer.ID]*pubsub.PeerScoreSnapshot) {
jsonEvent, err := json.Marshal(scores)
if err != nil {
log.Errorf("error while marshaling peer score: %s", err)
return
}
func (lt *lotusTracer) Trace(evt *pubsub_pb.TraceEvent) {}
err = lt.tt.Transport(jsonEvent)
if err != nil {
log.Errorf("error while transporting peer scores: %s", err)
}
}
func (lt *lotusTracer) Trace(evt *pubsub_pb.TraceEvent) {
jsonEvent, err := json.Marshal(evt)
if err != nil {
log.Errorf("error while marshaling tracer event: %s", err)
return
}
err = lt.tt.Transport(jsonEvent)
if err != nil {
log.Errorf("error while transporting trace event: %s", err)
}
}

View File

@ -1,5 +1,5 @@
package tracer
type TracerTransport interface {
Transport(jsonEvent []byte)
Transport(jsonEvent []byte) error
}