relay

package
v1.1.3-0...-78a1a59 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2020 License: MIT Imports: 11 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

View Source
const (
	DefaultPeerToSendRelay = 16
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Events

type Events struct {
	// OnGossipReceived is called whenever new gossip is received from the network. An error may be return to
	// disconnect the sender sending you data; indicating that the gossip received is invalid.
	OnRelayReceived func(sender noise.ID, data []byte) error
}

Events comprise of callbacks that may be hooked against by a user to handle inbound gossip messages/events that occur throughout the lifecycle of this gossip protocol.

type Message

type Message struct {
	From noise.ID
	Code byte

	To   noise.PublicKey
	Data []byte
	// contains filtered or unexported fields
}

func UnmarshalMessage

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

func (Message) Marshal

func (msg Message) Marshal() []byte

func (Message) String

func (m Message) String() string

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.

func WithEvents

func WithEvents(events Events) Option

WithEvents registers a batch of callbacks onto a single gossip protocol instance.

type Protocol

type Protocol struct {
	Logging bool
	// 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.

func New

func New(overlay *kademlia.Protocol, log bool, 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) GetRelayChan

func (p *Protocol) GetRelayChan() chan Message

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

func (p *Protocol) Relay(ctx context.Context, msg Message, changeRandomN bool, Fromid noise.ID)

Jump to

Keyboard shortcuts

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