mirror of
https://github.com/logos-messaging/go-libp2p-pubsub.git
synced 2026-01-04 05:43:06 +00:00
peer score scaffolding
This commit is contained in:
parent
455a836d7d
commit
7d928697a2
22
gossipsub.go
22
gossipsub.go
@ -71,6 +71,27 @@ func NewGossipSub(ctx context.Context, h host.Host, opts ...Option) (*PubSub, er
|
|||||||
return NewPubSub(ctx, h, rt, opts...)
|
return NewPubSub(ctx, h, rt, opts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithPeerScore is a gossipsub router option that enables peer scoring.
|
||||||
|
func WithPeerScore(params *PeerScoreParams) Option {
|
||||||
|
return func(ps *PubSub) error {
|
||||||
|
gs, ok := ps.rt.(*GossipSubRouter)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("pubsub router is not gossipsub")
|
||||||
|
}
|
||||||
|
|
||||||
|
gs.score = newPeerScore(gs, params)
|
||||||
|
|
||||||
|
// hook the tracer
|
||||||
|
if ps.tracer != nil {
|
||||||
|
ps.tracer.score = gs.score
|
||||||
|
} else {
|
||||||
|
ps.tracer = &pubsubTracer{score: gs.score, pid: ps.host.ID(), msgID: ps.msgID}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// GossipSubRouter is a router that implements the gossipsub protocol.
|
// GossipSubRouter is a router that implements the gossipsub protocol.
|
||||||
// For each topic we have joined, we maintain an overlay through which
|
// For each topic we have joined, we maintain an overlay through which
|
||||||
// messages flow; this is the mesh map.
|
// messages flow; this is the mesh map.
|
||||||
@ -90,6 +111,7 @@ type GossipSubRouter struct {
|
|||||||
connect chan connectInfo // px connection requests
|
connect chan connectInfo // px connection requests
|
||||||
mcache *MessageCache
|
mcache *MessageCache
|
||||||
tracer *pubsubTracer
|
tracer *pubsubTracer
|
||||||
|
score *peerScore
|
||||||
}
|
}
|
||||||
|
|
||||||
type connectInfo struct {
|
type connectInfo struct {
|
||||||
|
|||||||
@ -356,7 +356,11 @@ func WithDiscovery(d discovery.Discovery, opts ...DiscoverOpt) Option {
|
|||||||
// WithEventTracer provides a tracer for the pubsub system
|
// WithEventTracer provides a tracer for the pubsub system
|
||||||
func WithEventTracer(tracer EventTracer) Option {
|
func WithEventTracer(tracer EventTracer) Option {
|
||||||
return func(p *PubSub) error {
|
return func(p *PubSub) error {
|
||||||
p.tracer = &pubsubTracer{tracer: tracer, pid: p.host.ID(), msgID: p.msgID}
|
if tracer != nil {
|
||||||
|
p.tracer.tracer = tracer
|
||||||
|
} else {
|
||||||
|
p.tracer = &pubsubTracer{tracer: tracer, pid: p.host.ID(), msgID: p.msgID}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
61
score.go
Normal file
61
score.go
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
package pubsub
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/libp2p/go-libp2p-core/peer"
|
||||||
|
"github.com/libp2p/go-libp2p-core/protocol"
|
||||||
|
)
|
||||||
|
|
||||||
|
type peerScore struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
type PeerScoreParams struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
type TopicScoreParams struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func newPeerScore(gs *GossipSubRouter, params *PeerScoreParams) *peerScore {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// router interface
|
||||||
|
func (ps *peerScore) Score(p peer.ID, topic string) float64 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// tracer interface
|
||||||
|
func (ps *peerScore) AddPeer(p peer.ID, proto protocol.ID) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ps *peerScore) RemovePeer(p peer.ID) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ps *peerScore) Join(topic string) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ps *peerScore) Leave(topic string) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ps *peerScore) Graft(p peer.ID, topic string) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ps *peerScore) Prune(p peer.ID, topic string) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ps *peerScore) DeliverMessage(msg *Message) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ps *peerScore) RejectMessage(msg *Message, reason string) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ps *peerScore) DuplicateMessage(msg *Message) {
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user