Versions in this module Expand all Collapse all v1 v1.3.1 Dec 26, 2023 v1.3.0 Dec 23, 2022 v1.1.4 Mar 29, 2024 v1.1.3 Sep 5, 2022 v1.1.2 May 17, 2022 v1.1.1 Apr 19, 2022 Changes in this version type PubSub + func (p *PubSub) GetWhitelistSize() int v1.1.0 Mar 15, 2022 v1.0.0 Aug 26, 2021 v0 v0.0.3 Aug 26, 2021 Changes in this version + const DefaultDecayInterval + const DefaultDecayToZero + const DefaultMaxMessageSize + const FloodSubID + const FloodSubTopicSearchSize + const GossipSubID_v10 + const GossipSubID_v11 + const LaxNoSign + const LaxSign + const RandomSubID + const RemoteTracerProtoID + const SignPrefix + const StrictNoSign + const StrictSign + const ValidationAccept + const ValidationIgnore + const ValidationReject + var DiscoveryPollInitialDelay = 0 * time.Millisecond + var DiscoveryPollInterval = 1 * time.Second + var ErrSubscriptionCancelled = errors.New("subscription cancelled") + var ErrTopicClosed = errors.New("this Topic is closed, try opening a new one") + var GossipSubConnTagBumpMessageDelivery = 1 + var GossipSubConnTagDecayAmount = 1 + var GossipSubConnTagDecayInterval = 10 * time.Minute + var GossipSubConnTagMessageDeliveryCap = 15 + var GossipSubConnectionTimeout = 30 * time.Second + var GossipSubConnectors = 8 + var GossipSubD = 6 + var GossipSubDhi = 12 + var GossipSubDirectConnectInitialDelay = time.Second + var GossipSubDirectConnectTicks uint64 = 300 + var GossipSubDlazy = 6 + var GossipSubDlo = 5 + var GossipSubDout = 2 + var GossipSubDscore = 4 + var GossipSubFanoutTTL = 60 * time.Second + var GossipSubGossipFactor = 0.25 + var GossipSubGossipRetransmission = 3 + var GossipSubGraftFloodThreshold = 10 * time.Second + var GossipSubHeartbeatInitialDelay = 100 * time.Millisecond + var GossipSubHeartbeatInterval = 1 * time.Second + var GossipSubHistoryGossip = 3 + var GossipSubHistoryLength = 5 + var GossipSubIWantFollowupTime = 3 * time.Second + var GossipSubMaxIHaveLength = 5000 + var GossipSubMaxIHaveMessages = 10 + var GossipSubMaxPendingConnections = 128 + var GossipSubOpportunisticGraftPeers = 2 + var GossipSubOpportunisticGraftTicks uint64 = 60 + var GossipSubPruneBackoff = time.Minute + var GossipSubPrunePeers = 16 + var MinTraceBatchSize = 16 + var RandomSubD = 6 + var TimeCacheDuration = 120 * time.Second + var TraceBufferSize = 1 << 16 + func DefaultMsgIdFn(pmsg *pb.Message) string + func ScoreParameterDecay(decay time.Duration) float64 + func ScoreParameterDecayWithBase(decay time.Duration, base time.Duration, decayToZero float64) float64 + type BackoffConnectorFactory func(host host.Host) (*discimpl.BackoffConnector, error) + type Blacklist interface + Add func(peer.ID) bool + Contains func(peer.ID) bool + func NewMapBlacklist() Blacklist + func NewTimeCachedBlacklist(expiry time.Duration) (Blacklist, error) + type CacheEntry struct + type DiscoverOpt func(*discoverOptions) error + func WithDiscoverConnector(connFactory BackoffConnectorFactory) DiscoverOpt + func WithDiscoveryOpts(opts ...discovery.Option) DiscoverOpt + type EventTracer interface + Trace func(evt *pb.TraceEvent) + type EventType int + const PeerJoin + const PeerLeave + type ExtendedPeerScoreInspectFn = func(map[peer.ID]*PeerScoreSnapshot) + type FloodSubRouter struct + func (fs *FloodSubRouter) AcceptFrom(peer.ID) bool + func (fs *FloodSubRouter) AddPeer(p peer.ID, proto protocol.ID) + func (fs *FloodSubRouter) Attach(p *PubSub) + func (fs *FloodSubRouter) EnoughPeers(topic string, suggested int) bool + 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(msg *Message) + func (fs *FloodSubRouter) RemovePeer(p peer.ID) + type GossipSubRouter struct + D int + Dhi int + Dlazy int + Dlo int + Dout int + Dscore int + func (gs *GossipSubRouter) AcceptFrom(p peer.ID) bool + func (gs *GossipSubRouter) AddPeer(p peer.ID, proto protocol.ID) + func (gs *GossipSubRouter) Attach(p *PubSub) + func (gs *GossipSubRouter) EnoughPeers(topic string, suggested int) bool + 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(msg *Message) + func (gs *GossipSubRouter) RemovePeer(p peer.ID) + type JSONTracer struct + func NewJSONTracer(file string) (*JSONTracer, error) + func OpenJSONTracer(file string, flags int, perm os.FileMode) (*JSONTracer, error) + func (t *JSONTracer) Close() + func (t *JSONTracer) Trace(evt *pb.TraceEvent) + type MapBlacklist map[peer.ID]struct + func (b MapBlacklist) Add(p peer.ID) bool + func (b MapBlacklist) Contains(p peer.ID) bool + type MapWhitelist struct + func (b *MapWhitelist) Add(p peer.ID) bool + func (b *MapWhitelist) Contains(p peer.ID) bool + func (b *MapWhitelist) Remove(p peer.ID) bool + func (b *MapWhitelist) Size() int + type Message struct + ReceivedFrom peer.ID + ValidatorData interface{} + func (m *Message) GetFrom() peer.ID + type MessageCache struct + func NewMessageCache(gossip, history int) *MessageCache + func (mc *MessageCache) Get(mid string) (*pb.Message, bool) + func (mc *MessageCache) GetForPeer(mid string, p peer.ID) (*pb.Message, int, bool) + func (mc *MessageCache) GetGossipIDs(topic string) []string + func (mc *MessageCache) Put(msg *pb.Message) + func (mc *MessageCache) SetMsgIdFn(msgID MsgIdFunction) + func (mc *MessageCache) Shift() + type MessageSignaturePolicy uint8 + type MsgIdFunction func(pmsg *pb.Message) string + type Option func(*PubSub) error + func WithBlacklist(b Blacklist) Option + func WithDirectConnectTicks(t uint64) Option + func WithDirectPeers(pis []peer.AddrInfo) Option + func WithDiscovery(d discovery.Discovery, opts ...DiscoverOpt) Option + func WithEventTracer(tracer EventTracer) Option + func WithFloodPublish(floodPublish bool) Option + func WithMaxMessageSize(maxMessageSize int) Option + func WithMessageAuthor(author peer.ID) Option + func WithMessageIdFn(fn MsgIdFunction) Option + func WithMessageSignaturePolicy(policy MessageSignaturePolicy) Option + func WithMessageSigning(enabled bool) Option + func WithNoAuthor() Option + func WithPeerExchange(doPX bool) Option + func WithPeerOutboundQueueSize(size int) Option + func WithPeerScore(params *PeerScoreParams, thresholds *PeerScoreThresholds) Option + func WithPeerScoreInspect(inspect interface{}, period time.Duration) Option + func WithStrictSignatureVerification(required bool) Option + func WithUid(uid string) Option + func WithValidateQueueSize(n int) Option + func WithValidateThrottle(n int) Option + func WithValidateWorkers(n int) Option + func WithWhitelist(w Whitelist) Option + type PBTracer struct + func NewPBTracer(file string) (*PBTracer, error) + func OpenPBTracer(file string, flags int, perm os.FileMode) (*PBTracer, error) + func (t *PBTracer) Close() + func (t *PBTracer) Trace(evt *pb.TraceEvent) + type PeerEvent struct + Peer peer.ID + Type EventType + type PeerScoreInspectFn = func(map[peer.ID]float64) + type PeerScoreParams struct + AppSpecificScore func(p peer.ID) float64 + AppSpecificWeight float64 + BehaviourPenaltyDecay float64 + BehaviourPenaltyThreshold float64 + BehaviourPenaltyWeight float64 + DecayInterval time.Duration + DecayToZero float64 + IPColocationFactorThreshold int + IPColocationFactorWeight float64 + IPColocationFactorWhitelist map[string]struct{} + RetainScore time.Duration + TopicScoreCap float64 + Topics map[string]*TopicScoreParams + type PeerScoreSnapshot struct + AppSpecificScore float64 + BehaviourPenalty float64 + IPColocationFactor float64 + Score float64 + Topics map[string]*TopicScoreSnapshot + type PeerScoreThresholds struct + AcceptPXThreshold float64 + GossipThreshold float64 + GraylistThreshold float64 + OpportunisticGraftThreshold float64 + PublishThreshold float64 + type PubOpt func(pub *PublishOptions) error + func WithReadiness(ready RouterReady) PubOpt + type PubSub struct + 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, size int, opts ...Option) (*PubSub, error) + func (p *PubSub) AddWhitelistPeer(pid peer.ID) + func (p *PubSub) BlacklistPeer(pid peer.ID) + func (p *PubSub) GetTopics() []string + func (p *PubSub) Join(topic string, opts ...TopicOpt) (*Topic, error) + func (p *PubSub) ListPeers(topic string) []peer.ID + func (p *PubSub) Publish(topic string, data []byte, opts ...PubOpt) error + func (p *PubSub) RegisterTopicValidator(topic string, val interface{}, opts ...ValidatorOpt) error + func (p *PubSub) RemoveWhitelistPeer(pid peer.ID) + func (p *PubSub) Subscribe(topic string, opts ...SubOpt) (*Subscription, error) + func (p *PubSub) SubscribeByTopicDescriptor(td *pb.TopicDescriptor, opts ...SubOpt) (*Subscription, error) + func (p *PubSub) TryToReloadPeer(pid peer.ID) + func (p *PubSub) UnregisterTopicValidator(topic string) error + type PubSubNotif PubSub + func (p *PubSubNotif) ClosedStream(n network.Network, s network.Stream) + func (p *PubSubNotif) Connected(n network.Network, c network.Conn) + func (p *PubSubNotif) Disconnected(n network.Network, c network.Conn) + func (p *PubSubNotif) Listen(n network.Network, _ ma.Multiaddr) + func (p *PubSubNotif) ListenClose(n network.Network, _ ma.Multiaddr) + func (p *PubSubNotif) OpenedStream(n network.Network, s network.Stream) + type PubSubRouter interface + AcceptFrom func(peer.ID) bool + AddPeer func(peer.ID, protocol.ID) + Attach func(*PubSub) + EnoughPeers func(topic string, suggested int) bool + HandleRPC func(*RPC) + Join func(topic string) + Leave func(topic string) + Protocols func() []protocol.ID + Publish func(*Message) + RemovePeer func(peer.ID) + type PublishOptions struct + type RPC struct + type RandomSubRouter struct + func (rs *RandomSubRouter) AcceptFrom(peer.ID) bool + func (rs *RandomSubRouter) AddPeer(p peer.ID, proto protocol.ID) + func (rs *RandomSubRouter) Attach(p *PubSub) + func (rs *RandomSubRouter) EnoughPeers(topic string, suggested int) bool + 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(msg *Message) + func (rs *RandomSubRouter) RemovePeer(p peer.ID) + type RelayCancelFunc func() + type RemoteTracer struct + func NewRemoteTracer(ctx context.Context, host host.Host, pi peer.AddrInfo) (*RemoteTracer, error) + func (t *RemoteTracer) Close() + func (t *RemoteTracer) Trace(evt *pb.TraceEvent) + type RouterReady func(rt PubSubRouter, topic string) (bool, error) + func MinTopicSize(size int) RouterReady + type SubOpt func(sub *Subscription) error + type Subscription struct + func (sub *Subscription) Cancel() + func (sub *Subscription) Next(ctx context.Context) (*Message, error) + func (sub *Subscription) Topic() string + type TimeCachedBlacklist struct + func (b *TimeCachedBlacklist) Add(p peer.ID) bool + func (b *TimeCachedBlacklist) Contains(p peer.ID) bool + type Topic struct + func (t *Topic) Close() error + func (t *Topic) EventHandler(opts ...TopicEventHandlerOpt) (*TopicEventHandler, error) + func (t *Topic) ListPeers() []peer.ID + func (t *Topic) Publish(ctx context.Context, data []byte, opts ...PubOpt) error + func (t *Topic) Relay() (RelayCancelFunc, error) + func (t *Topic) String() string + func (t *Topic) Subscribe(opts ...SubOpt) (*Subscription, error) + type TopicEventHandler struct + func (t *TopicEventHandler) Cancel() + func (t *TopicEventHandler) NextPeerEvent(ctx context.Context) (PeerEvent, error) + type TopicEventHandlerOpt func(t *TopicEventHandler) error + type TopicOpt func(t *Topic) error + type TopicOptions struct + type TopicScoreParams struct + FirstMessageDeliveriesCap float64 + FirstMessageDeliveriesDecay float64 + FirstMessageDeliveriesWeight float64 + InvalidMessageDeliveriesDecay float64 + InvalidMessageDeliveriesWeight float64 + MeshFailurePenaltyDecay float64 + MeshFailurePenaltyWeight float64 + MeshMessageDeliveriesActivation time.Duration + MeshMessageDeliveriesCap float64 + MeshMessageDeliveriesDecay float64 + MeshMessageDeliveriesThreshold float64 + MeshMessageDeliveriesWeight float64 + MeshMessageDeliveriesWindow time.Duration + TimeInMeshCap float64 + TimeInMeshQuantum time.Duration + TimeInMeshWeight float64 + TopicWeight float64 + type TopicScoreSnapshot struct + FirstMessageDeliveries float64 + InvalidMessageDeliveries float64 + MeshMessageDeliveries float64 + TimeInMesh time.Duration + type ValidationResult int + type Validator func(context.Context, peer.ID, *Message) bool + type ValidatorEx func(context.Context, peer.ID, *Message) ValidationResult + type ValidatorOpt func(addVal *addValReq) error + func WithValidatorConcurrency(n int) ValidatorOpt + func WithValidatorInline(inline bool) ValidatorOpt + func WithValidatorTimeout(timeout time.Duration) ValidatorOpt + type Whitelist interface + Add func(peer.ID) bool + Contains func(peer.ID) bool + Remove func(peer.ID) bool + Size func() int + func NewMapWhitelist() Whitelist