mirror of
https://github.com/logos-messaging/go-libp2p-pubsub.git
synced 2026-01-07 15:23:08 +00:00
peer gater scaffolding
This commit is contained in:
parent
3b92bdc1e9
commit
2bc51e0cf2
@ -347,6 +347,7 @@ type GossipSubRouter struct {
|
|||||||
score *peerScore
|
score *peerScore
|
||||||
gossipTracer *gossipTracer
|
gossipTracer *gossipTracer
|
||||||
tagTracer *tagTracer
|
tagTracer *tagTracer
|
||||||
|
gate *peerGater
|
||||||
|
|
||||||
// whether PX is enabled; this should be enabled in bootstrappers and other well connected/trusted
|
// whether PX is enabled; this should be enabled in bootstrappers and other well connected/trusted
|
||||||
// nodes.
|
// nodes.
|
||||||
@ -515,8 +516,7 @@ func (gs *GossipSubRouter) AcceptFrom(p peer.ID) AcceptStatus {
|
|||||||
return AcceptNone
|
return AcceptNone
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO throttle tracking and reaction
|
return gs.gate.AcceptFrom(p)
|
||||||
return AcceptAll
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gs *GossipSubRouter) HandleRPC(rpc *RPC) {
|
func (gs *GossipSubRouter) HandleRPC(rpc *RPC) {
|
||||||
|
|||||||
60
peer_gater.go
Normal file
60
peer_gater.go
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
package pubsub
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/libp2p/go-libp2p-core/peer"
|
||||||
|
"github.com/libp2p/go-libp2p-core/protocol"
|
||||||
|
)
|
||||||
|
|
||||||
|
type peerGater struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithPeerGater is a gossipsub router option that enables reactive validation queue
|
||||||
|
// management.
|
||||||
|
func WithPeerGater() Option {
|
||||||
|
return func(ps *PubSub) error {
|
||||||
|
gs, ok := ps.rt.(*GossipSubRouter)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("pubsub router is not gossipsub")
|
||||||
|
}
|
||||||
|
|
||||||
|
gs.gate = newPeerGater()
|
||||||
|
|
||||||
|
// hook the tracer
|
||||||
|
if ps.tracer != nil {
|
||||||
|
ps.tracer.internal = append(ps.tracer.internal, gs.gate)
|
||||||
|
} else {
|
||||||
|
ps.tracer = &pubsubTracer{
|
||||||
|
internal: []internalTracer{gs.gate},
|
||||||
|
pid: ps.host.ID(),
|
||||||
|
msgID: ps.msgID,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func newPeerGater() *peerGater {
|
||||||
|
return &peerGater{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pg *peerGater) AcceptFrom(p peer.ID) AcceptStatus {
|
||||||
|
if pg == nil {
|
||||||
|
return AcceptAll
|
||||||
|
}
|
||||||
|
|
||||||
|
return AcceptAll
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pg *peerGater) AddPeer(p peer.ID, proto protocol.ID) {}
|
||||||
|
func (pg *peerGater) RemovePeer(p peer.ID) {}
|
||||||
|
func (pg *peerGater) Join(topic string) {}
|
||||||
|
func (pg *peerGater) Leave(topic string) {}
|
||||||
|
func (pg *peerGater) Graft(p peer.ID, topic string) {}
|
||||||
|
func (pg *peerGater) Prune(p peer.ID, topic string) {}
|
||||||
|
func (pg *peerGater) ValidateMessage(msg *Message) {}
|
||||||
|
func (pg *peerGater) DeliverMessage(msg *Message) {}
|
||||||
|
func (pg *peerGater) RejectMessage(msg *Message, reason string) {}
|
||||||
|
func (pg *peerGater) DuplicateMessage(msg *Message) {}
|
||||||
Loading…
x
Reference in New Issue
Block a user