announce

package
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: Apache-2.0, MIT Imports: 17 Imported by: 7

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

func Send added in v0.3.0

func Send(ctx context.Context, c cid.Cid, addrs []multiaddr.Multiaddr, senders ...Sender) error

Send sends an advertisement announcement message, containing the specified addresses and extra data, to all senders.

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

Option is a function that sets a value in a config.

func WithAllowPeer

func WithAllowPeer(allowPeer AllowPeerFunc) Option

WithAllowPeer sets the function that determines whether to allow or reject messages from a peer. When not set or nil, allows messages from all peers.

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(p2pHost 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, peerInfo peer.AddrInfo) error

Direct handles a direct announce message, that was not received over pubsub. The message is resent over pubsub with the original peerID encoded into the message extra data. The peerID and addrs are those of the advertisement publisher, since an announce message announces the availability of an advertisement and where to retrieve it from.

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) 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.

type Sender

type Sender interface {
	// Close closes the Sender.
	Close() error
	// Send sends the announce Message.
	Send(context.Context, message.Message) error
}

Sender is the interface for announce sender implementations.

Directories

Path Synopsis
gen

Jump to

Keyboard shortcuts

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