Documentation ¶
Index ¶
- Constants
- Variables
- type CacheEntry
- type FloodSubRouter
- func (fs *FloodSubRouter) AddPeer(peer.ID, protocol.ID)
- func (fs *FloodSubRouter) Attach(p *PubSub)
- func (fs *FloodSubRouter) HandleRPC(rpc *RPC)
- func (fs *FloodSubRouter) Join(topic string)
- func (fs *FloodSubRouter) Leave(topic string)
- func (fs *FloodSubRouter) Protocols() []protocol.ID
- func (fs *FloodSubRouter) Publish(from peer.ID, msg *pb.Message)
- func (fs *FloodSubRouter) RemovePeer(peer.ID)
- type GossipSubRouter
- func (gs *GossipSubRouter) AddPeer(p peer.ID, proto protocol.ID)
- func (gs *GossipSubRouter) Attach(p *PubSub)
- func (gs *GossipSubRouter) HandleRPC(rpc *RPC)
- func (gs *GossipSubRouter) Join(topic string)
- func (gs *GossipSubRouter) Leave(topic string)
- func (gs *GossipSubRouter) Protocols() []protocol.ID
- func (gs *GossipSubRouter) Publish(from peer.ID, msg *pb.Message)
- func (gs *GossipSubRouter) RemovePeer(p peer.ID)
- type Message
- type MessageCache
- type Option
- type PubSub
- func NewFloodSub(ctx context.Context, h host.Host, opts ...Option) (*PubSub, error)
- func NewFloodsubWithProtocols(ctx context.Context, h host.Host, ps []protocol.ID, opts ...Option) (*PubSub, error)
- func NewGossipSub(ctx context.Context, h host.Host, opts ...Option) (*PubSub, error)
- func NewPubSub(ctx context.Context, h host.Host, rt PubSubRouter, opts ...Option) (*PubSub, error)
- func NewRandomSub(ctx context.Context, h host.Host, opts ...Option) (*PubSub, error)
- func (p *PubSub) GetTopics() []string
- func (p *PubSub) ListPeers(topic string) []peer.ID
- func (p *PubSub) Publish(topic string, data []byte) error
- func (p *PubSub) RegisterTopicValidator(topic string, val Validator, opts ...ValidatorOpt) error
- func (p *PubSub) Subscribe(topic string, opts ...SubOpt) (*Subscription, error)
- func (p *PubSub) SubscribeByTopicDescriptor(td *pb.TopicDescriptor, opts ...SubOpt) (*Subscription, error)
- func (p *PubSub) UnregisterTopicValidator(topic string) error
- type PubSubNotif
- func (p *PubSubNotif) ClosedStream(n inet.Network, s inet.Stream)
- func (p *PubSubNotif) Connected(n inet.Network, c inet.Conn)
- func (p *PubSubNotif) Disconnected(n inet.Network, c inet.Conn)
- func (p *PubSubNotif) Listen(n inet.Network, _ ma.Multiaddr)
- func (p *PubSubNotif) ListenClose(n inet.Network, _ ma.Multiaddr)
- func (p *PubSubNotif) OpenedStream(n inet.Network, s inet.Stream)
- type PubSubRouter
- type RPC
- type RandomSubRouter
- func (rs *RandomSubRouter) AddPeer(p peer.ID, proto protocol.ID)
- func (rs *RandomSubRouter) Attach(p *PubSub)
- func (rs *RandomSubRouter) HandleRPC(rpc *RPC)
- func (rs *RandomSubRouter) Join(topic string)
- func (rs *RandomSubRouter) Leave(topic string)
- func (rs *RandomSubRouter) Protocols() []protocol.ID
- func (rs *RandomSubRouter) Publish(from peer.ID, msg *pb.Message)
- func (rs *RandomSubRouter) RemovePeer(p peer.ID)
- type SubOpt
- type Subscription
- type Validator
- type ValidatorOpt
Constants ¶
const (
FloodSubID = protocol.ID("/floodsub/1.0.0")
)
const (
GossipSubID = protocol.ID("/meshsub/1.0.0")
)
const (
RandomSubID = protocol.ID("/randomsub/1.0.0")
)
const SignPrefix = "libp2p-pubsub:"
Variables ¶
var ( // overlay parameters GossipSubD = 6 GossipSubDlo = 4 GossipSubDhi = 12 // gossip parameters GossipSubHistoryLength = 5 GossipSubHistoryGossip = 3 // heartbeat interval GossipSubHeartbeatInitialDelay = 100 * time.Millisecond GossipSubHeartbeatInterval = 1 * time.Second // fanout ttl GossipSubFanoutTTL = 60 * time.Second )
var (
RandomSubD = 6
)
Functions ¶
This section is empty.
Types ¶
type CacheEntry ¶ added in v0.9.21
type CacheEntry struct {
// contains filtered or unexported fields
}
type FloodSubRouter ¶ added in v0.9.10
type FloodSubRouter struct {
// contains filtered or unexported fields
}
func (*FloodSubRouter) AddPeer ¶ added in v0.9.10
func (fs *FloodSubRouter) AddPeer(peer.ID, protocol.ID)
func (*FloodSubRouter) Attach ¶ added in v0.9.10
func (fs *FloodSubRouter) Attach(p *PubSub)
func (*FloodSubRouter) HandleRPC ¶ added in v0.9.10
func (fs *FloodSubRouter) HandleRPC(rpc *RPC)
func (*FloodSubRouter) Join ¶ added in v0.9.21
func (fs *FloodSubRouter) Join(topic string)
func (*FloodSubRouter) Leave ¶ added in v0.9.21
func (fs *FloodSubRouter) Leave(topic string)
func (*FloodSubRouter) Protocols ¶ added in v0.9.10
func (fs *FloodSubRouter) Protocols() []protocol.ID
func (*FloodSubRouter) Publish ¶ added in v0.9.10
func (fs *FloodSubRouter) Publish(from peer.ID, msg *pb.Message)
func (*FloodSubRouter) RemovePeer ¶ added in v0.9.10
func (fs *FloodSubRouter) RemovePeer(peer.ID)
type GossipSubRouter ¶ added in v0.9.21
type GossipSubRouter struct {
// contains filtered or unexported fields
}
GossipSubRouter is a router that implements the gossipsub protocol. For each topic we have joined, we maintain an overlay through which messages flow; this is the mesh map. For each topic we publish to without joining, we maintain a list of peers to use for injecting our messages in the overlay with stable routes; this is the fanout map. Fanout peer lists are expired if we don't publish any messages to their topic for GossipSubFanoutTTL.
func (*GossipSubRouter) AddPeer ¶ added in v0.9.21
func (gs *GossipSubRouter) AddPeer(p peer.ID, proto protocol.ID)
func (*GossipSubRouter) Attach ¶ added in v0.9.21
func (gs *GossipSubRouter) Attach(p *PubSub)
func (*GossipSubRouter) HandleRPC ¶ added in v0.9.21
func (gs *GossipSubRouter) HandleRPC(rpc *RPC)
func (*GossipSubRouter) Join ¶ added in v0.9.21
func (gs *GossipSubRouter) Join(topic string)
func (*GossipSubRouter) Leave ¶ added in v0.9.21
func (gs *GossipSubRouter) Leave(topic string)
func (*GossipSubRouter) Protocols ¶ added in v0.9.21
func (gs *GossipSubRouter) Protocols() []protocol.ID
func (*GossipSubRouter) Publish ¶ added in v0.9.21
func (gs *GossipSubRouter) Publish(from peer.ID, msg *pb.Message)
func (*GossipSubRouter) RemovePeer ¶ added in v0.9.21
func (gs *GossipSubRouter) RemovePeer(p peer.ID)
type MessageCache ¶ added in v0.9.21
type MessageCache struct {
// contains filtered or unexported fields
}
func NewMessageCache ¶ added in v0.9.21
func NewMessageCache(gossip, history int) *MessageCache
func (*MessageCache) Get ¶ added in v0.9.21
func (mc *MessageCache) Get(mid string) (*pb.Message, bool)
func (*MessageCache) GetGossipIDs ¶ added in v0.9.21
func (mc *MessageCache) GetGossipIDs(topic string) []string
func (*MessageCache) Put ¶ added in v0.9.21
func (mc *MessageCache) Put(msg *pb.Message)
func (*MessageCache) Shift ¶ added in v0.9.21
func (mc *MessageCache) Shift()
type Option ¶ added in v0.9.9
func WithMessageSigning ¶ added in v0.10.0
func WithValidateThrottle ¶ added in v0.9.9
type PubSub ¶
type PubSub struct {
// contains filtered or unexported fields
}
func NewFloodSub ¶
NewFloodSub returns a new PubSub object using the FloodSubRouter
func NewFloodsubWithProtocols ¶ added in v0.9.17
func NewFloodsubWithProtocols(ctx context.Context, h host.Host, ps []protocol.ID, opts ...Option) (*PubSub, error)
NewFloodsubWithProtocols returns a new floodsub-enabled PubSub objecting using the protocols specified in ps
func NewGossipSub ¶ added in v0.9.21
NewGossipSub returns a new PubSub object using GossipSubRouter as the router
func NewRandomSub ¶ added in v0.9.36
NewRandomSub returns a new PubSub object using RandomSubRouter as the router
func (*PubSub) RegisterTopicValidator ¶ added in v0.9.9
func (p *PubSub) RegisterTopicValidator(topic string, val Validator, opts ...ValidatorOpt) error
RegisterTopicValidator registers a validator for topic
func (*PubSub) Subscribe ¶
func (p *PubSub) Subscribe(topic string, opts ...SubOpt) (*Subscription, error)
Subscribe returns a new Subscription for the given topic
func (*PubSub) SubscribeByTopicDescriptor ¶ added in v0.8.1
func (p *PubSub) SubscribeByTopicDescriptor(td *pb.TopicDescriptor, opts ...SubOpt) (*Subscription, error)
SubscribeByTopicDescriptor lets you subscribe a topic using a pb.TopicDescriptor
func (*PubSub) UnregisterTopicValidator ¶ added in v0.9.11
UnregisterTopicValidator removes a validator from a topic returns an error if there was no validator registered with the topic
type PubSubNotif ¶ added in v0.4.0
type PubSubNotif PubSub
func (*PubSubNotif) ClosedStream ¶ added in v0.4.0
func (p *PubSubNotif) ClosedStream(n inet.Network, s inet.Stream)
func (*PubSubNotif) Connected ¶ added in v0.4.0
func (p *PubSubNotif) Connected(n inet.Network, c inet.Conn)
func (*PubSubNotif) Disconnected ¶ added in v0.4.0
func (p *PubSubNotif) Disconnected(n inet.Network, c inet.Conn)
func (*PubSubNotif) Listen ¶ added in v0.4.0
func (p *PubSubNotif) Listen(n inet.Network, _ ma.Multiaddr)
func (*PubSubNotif) ListenClose ¶ added in v0.4.0
func (p *PubSubNotif) ListenClose(n inet.Network, _ ma.Multiaddr)
func (*PubSubNotif) OpenedStream ¶ added in v0.4.0
func (p *PubSubNotif) OpenedStream(n inet.Network, s inet.Stream)
type PubSubRouter ¶ added in v0.9.10
type PubSubRouter interface { // Protocols returns the list of protocols supported by the router. Protocols() []protocol.ID // Attach is invoked by the PubSub constructor to attach the router to a // freshly initialized PubSub instance. Attach(*PubSub) // AddPeer notifies the router that a new peer has been connected. AddPeer(peer.ID, protocol.ID) // RemovePeer notifies the router that a peer has been disconnected. RemovePeer(peer.ID) // HandleRPC is invoked to process control messages in the RPC envelope. // It is invoked after subscriptions and payload messages have been processed. HandleRPC(*RPC) // Publish is invoked to forward a new message that has been validated. Publish(peer.ID, *pb.Message) // Join notifies the router that we want to receive and forward messages in a topic. // It is invoked after the subscription announcement. Join(topic string) // Leave notifies the router that we are no longer interested in a topic. // It is invoked after the unsubscription announcement. Leave(topic string) }
PubSubRouter is the message router component of PubSub
type RandomSubRouter ¶ added in v0.9.36
type RandomSubRouter struct {
// contains filtered or unexported fields
}
RandomSubRouter is a router that implements a random propagation strategy. For each message, it selects RandomSubD peers and forwards the message to them.
func (*RandomSubRouter) AddPeer ¶ added in v0.9.36
func (rs *RandomSubRouter) AddPeer(p peer.ID, proto protocol.ID)
func (*RandomSubRouter) Attach ¶ added in v0.9.36
func (rs *RandomSubRouter) Attach(p *PubSub)
func (*RandomSubRouter) HandleRPC ¶ added in v0.9.36
func (rs *RandomSubRouter) HandleRPC(rpc *RPC)
func (*RandomSubRouter) Join ¶ added in v0.9.36
func (rs *RandomSubRouter) Join(topic string)
func (*RandomSubRouter) Leave ¶ added in v0.9.36
func (rs *RandomSubRouter) Leave(topic string)
func (*RandomSubRouter) Protocols ¶ added in v0.9.36
func (rs *RandomSubRouter) Protocols() []protocol.ID
func (*RandomSubRouter) Publish ¶ added in v0.9.36
func (rs *RandomSubRouter) Publish(from peer.ID, msg *pb.Message)
func (*RandomSubRouter) RemovePeer ¶ added in v0.9.36
func (rs *RandomSubRouter) RemovePeer(p peer.ID)
type SubOpt ¶ added in v0.9.9
type SubOpt func(sub *Subscription) error
type Subscription ¶ added in v0.8.1
type Subscription struct {
// contains filtered or unexported fields
}
func (*Subscription) Cancel ¶ added in v0.8.1
func (sub *Subscription) Cancel()
func (*Subscription) Next ¶ added in v0.8.1
func (sub *Subscription) Next(ctx context.Context) (*Message, error)
func (*Subscription) Topic ¶ added in v0.8.1
func (sub *Subscription) Topic() string
type ValidatorOpt ¶ added in v0.9.9
type ValidatorOpt func(addVal *addValReq) error
ValidatorOpt is an option for RegisterTopicValidator
func WithValidatorConcurrency ¶ added in v0.9.9
func WithValidatorConcurrency(n int) ValidatorOpt
WithValidatorConcurrency is an option that sets topic validator throttle
func WithValidatorTimeout ¶ added in v0.9.9
func WithValidatorTimeout(timeout time.Duration) ValidatorOpt
WithValidatorTimeout is an option that sets the topic validator timeout