announce

package
v0.0.0-...-6862cae Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2023 License: Apache-2.0, MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrClosed is returned from Next and Direct when the Received is closed.
	ErrClosed = errors.New("closed")
)

Functions

This section is empty.

Types

type AllowPeerFunc

type AllowPeerFunc func(peer.ID) bool

AllowPeerFunc is the signature of a function given to Subscriber that determines whether to allow or reject messages originating from a peer passed into the function. Returning true or false indicates that messages from that peer are allowed rejected, respectively.

type Announce

type Announce struct {
	// Cid is the advertisement content identifier to announce.
	Cid cid.Cid
	// PeerID is the p2p peer ID hosting the announced advertisement.
	PeerID peer.ID
	// Addrs is the network location(s) hosting the announced advertisement.
	Addrs []multiaddr.Multiaddr
}

Announce contains information about the announcement of an index advertisement.

type Option

type Option func(*config) error

func WithAllowPeer

func WithAllowPeer(allowPeer AllowPeerFunc) Option

WithAllowPeer sets the function that determines whether to allow or reject messages from a peer.

func WithFilterIPs

func WithFilterIPs(enable bool) Option

WithFilterIPs sets whether or not IP filtering is enabled. When enabled it removes any private, loopback, or unspecified IP multiaddrs from addresses supplied in announce messages.

func WithResend

func WithResend(enable bool) Option

WithResend determines whether to resend direct announce mesages (those that are not received via pubsub) over pubsub.

func WithTopic

func WithTopic(topic *pubsub.Topic) Option

WithTopic provides an existing pubsub topic.

type Receiver

type Receiver struct {
	// contains filtered or unexported fields
}

Receiver receives announce messages via gossip pubsub and HTTP. Receiver creates a single pubsub subscriber that receives messages from a gossip pubsub topic. Direct messages are received when the Receiver's Direct method is called.

func NewReceiver

func NewReceiver(host host.Host, topicName string, options ...Option) (*Receiver, error)

NewReceiver creates a new Receiver that subscribes to the named pubsub topic and is listening for announce messages.

func (*Receiver) Close

func (r *Receiver) Close() error

Close shuts down the Receiver.

func (*Receiver) Direct

func (r *Receiver) Direct(ctx context.Context, nextCid cid.Cid, peerID peer.ID, addrs []multiaddr.Multiaddr) error

Direct handles a direct announce message, that was not arrived over pubsub. The message is resent over pubsub with the original peerID encoded into the message extra data.

func (*Receiver) Next

func (r *Receiver) Next(ctx context.Context) (Announce, error)

Next waits for and returns the next announce message that has passed filtering checks. Next also returns ErrClosed if the receiver is closed, or the context error if the given context is canceled.

func (*Receiver) SetAllowPeer

func (r *Receiver) SetAllowPeer(allowPeer AllowPeerFunc)

SetAllowPeer configures Subscriber with a function to evaluate whether to allow or reject messages from a peer. Setting nil removes any filtering and allows messages from all peers. Calling SetAllowPeer replaces any previously configured AllowPeerFunc.

func (*Receiver) TopicName

func (r *Receiver) TopicName() string

TopicName returns the name of the topic the Receiver is listening on.

func (*Receiver) UncacheCid

func (r *Receiver) UncacheCid(adCid cid.Cid)

UncacheCid removes a CID from the announce cache.

Directories

Path Synopsis
gen

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL