gossip

package
v0.0.0-...-c9037bb Latest Latest
Warning

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

Go to latest
Published: May 3, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package gossip is a simple implementation of a gossip protocol for noise. It keeps track of a cache of messages sent/received to/from peers to avoid re-gossiping particular messages to specific peers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Message

type Message []byte

Message is a message that is being pushed to nodes.

func UnmarshalMessage

func UnmarshalMessage(data []byte) (Message, error)

UnmarshalMessage deserializes data into a Message. It never throws an error.

func (Message) Marshal

func (m Message) Marshal() []byte

Marshal implements noise.Serializable and serializes Message into a slice of bytes.

type Option

type Option func(protocol *Protocol)

Option is a functional option that may be configured when instantiating a new instance of this gossip protocol.

type Protocol

type Protocol struct {
	eventemitter.EventEmitter
	// contains filtered or unexported fields
}

Protocol implements a simple gossiping protocol that avoids resending messages to peers that it already believes is aware of particular messages that are being gossiped. is aware of particular messages that are being gossiped.

func New

func New(overlay *kademlia.Protocol, opts ...Option) *Protocol

New returns a new instance of a gossip protocol with 32MB of in-memory cache instantiated.

func (*Protocol) Bind

func (p *Protocol) Bind(node *noise.Node) error

Bind registers a single message gossip.Message, and handles them by registering the (*Protocol).Handle Handler.

func (*Protocol) Handle

func (p *Protocol) Handle(ctx noise.HandlerContext) error

Handle implements noise.Protocol and handles gossip.Message messages.

func (*Protocol) Protocol

func (p *Protocol) Protocol() noise.Protocol

Protocol returns a noise.Protocol that may registered to a node via (*noise.Node).Bind.

func (*Protocol) Push

func (p *Protocol) Push(ctx context.Context, data []byte)

Push gossips a single message concurrently to all peers this node is aware of, on the condition that this node believes that the aforementioned peer has not received data before. A context may be provided to cancel Push, as it blocks the current goroutine until the gossiping of a single message is done. Any errors pushing a message to a particular peer is ignored.

Jump to

Keyboard shortcuts

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