neteng

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2022 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

package neteng provides a template for implementing Networks Network implements a mesh256.Network in terms of a Router

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DeliverFunc

type DeliverFunc = func(src inet256.Addr, data []byte)

DeliverFunc is the type of functions used to deliver data to the application

type InfoFunc

type InfoFunc = func(inet256.Addr, inet256.PublicKey)

InfoFunc is the type of functions used to deliver information about peers

type Network

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

func New

func New(params mesh256.NetworkParams, router Router, hbPeriod time.Duration) *Network

func (*Network) Bootstrap

func (n *Network) Bootstrap(ctx context.Context) error

func (*Network) Close

func (n *Network) Close() error

func (*Network) FindAddr

func (n *Network) FindAddr(ctx context.Context, prefix []byte, nbits int) (inet256.Addr, error)

func (*Network) LocalAddr

func (n *Network) LocalAddr() inet256.Addr

func (*Network) LookupPublicKey

func (n *Network) LookupPublicKey(ctx context.Context, target inet256.Addr) (inet256.PublicKey, error)

func (*Network) MTU

func (n *Network) MTU(ctx context.Context, target inet256.Addr) int

func (*Network) PublicKey

func (n *Network) PublicKey() inet256.PublicKey

func (*Network) Receive

func (n *Network) Receive(ctx context.Context, fn func(p2p.Message[inet256.Addr])) error

func (*Network) Tell

func (n *Network) Tell(ctx context.Context, dst inet256.Addr, data p2p.IOVec) error

type PublicKeyFunc

type PublicKeyFunc = func(inet256.Addr) inet256.PublicKey

PublicKeyFunc is the type of functinos used to get the public key for an ID

type Router

type Router interface {
	// Reset is called to clear the state of the router
	Reset(privateKey inet256.PrivateKey, peers mesh256.PeerSet, getPublicKey PublicKeyFunc, now time.Time)
	// HandleAbove handles a message from the application
	HandleAbove(to inet256.Addr, data p2p.IOVec, send SendFunc) bool
	// HandleBelow handles a message from the network.
	HandleBelow(from inet256.Addr, data []byte, send SendFunc, deliver DeliverFunc, info InfoFunc)
	// Heartbeat is called periodically with the current time.
	Heartbeat(now time.Time, send SendFunc)

	// FindAddr looks up an address
	FindAddr(send SendFunc, info InfoFunc, prefix []byte, nbits int)
	// LookupPublicKey looks up a public key
	LookupPublicKey(send SendFunc, info InfoFunc, target inet256.Addr)
}

Router contains logic for routing messages throughout the network Routers do not maintain any backgroud goroutines or allocate any additional resources If all references to a router are lost, resources MUST not leak.

type SendFunc

type SendFunc = func(dst inet256.Addr, data p2p.IOVec)

SendFunc is the type of functions used to send data to peers

Jump to

Keyboard shortcuts

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