vswarm

package
v0.0.0-...-d4b7e32 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2023 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Overview

package vswarm implements a virtual swarm which is capable of emulating other types of swarms.

Index

Constants

View Source
const (
	DefaultMTU      = 1 << 16
	DefaultQueueLen = 2
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option[A p2p.ComparableAddr] func(*realmConfig[A])

Options are passed to New and NewSecure to configure Realms.

func WithMTU

func WithMTU[A p2p.ComparableAddr](mtu int) Option[A]

WithMTU sets the MTU for all Swarms in the Realm.

func WithQueueLen

func WithQueueLen[A p2p.ComparableAddr](l int) Option[A]

WithQueueLen sets the maximum length of each Node's queue for recieving messages. If l < 1 QueueLen will panic.

func WithTellTransform

func WithTellTransform[A p2p.ComparableAddr](fn func(x *p2p.Message[A]) bool) Option[A]

type Realm

type Realm[A p2p.ComparableAddr] SecureRealm[A, struct{}]

func New

func New[A p2p.ComparableAddr](addrParser p2p.AddrParser[A], opts ...Option[A]) *Realm[A]

func (*Realm[A]) Create

func (r *Realm[A]) Create(a A, opts ...SwarmOption[A]) *Swarm[A]

func (*Realm[A]) Drop

func (r *Realm[A]) Drop(s *Swarm[A])

type SecureRealm

type SecureRealm[A p2p.ComparableAddr, Pub any] struct {
	// contains filtered or unexported fields
}

func NewSecure

func NewSecure[A p2p.ComparableAddr, Pub any](parseAddr p2p.AddrParser[A], opts ...Option[A]) *SecureRealm[A, Pub]

NewSecure creates a new SecureRealm

func (*SecureRealm[A, Pub]) Create

func (r *SecureRealm[A, Pub]) Create(a A, pub Pub, opts ...SwarmOption[A]) *SecureSwarm[A, Pub]

New creates a new SecureSwarm. It returns nil if the address is in use.

func (*SecureRealm[A, Pub]) Drop

func (r *SecureRealm[A, Pub]) Drop(s *SecureSwarm[A, Pub])

func (*SecureRealm[A, Pub]) Len

func (r *SecureRealm[A, Pub]) Len() int

type SecureSwarm

type SecureSwarm[A p2p.ComparableAddr, Pub any] struct {
	// contains filtered or unexported fields
}

func (*SecureSwarm[A, Pub]) Ask

func (s *SecureSwarm[A, Pub]) Ask(ctx context.Context, resp []byte, dst A, v p2p.IOVec) (int, error)

func (*SecureSwarm[A, Pub]) Close

func (s *SecureSwarm[A, Pub]) Close() error

func (*SecureSwarm[A, Pub]) LocalAddr

func (s *SecureSwarm[A, Pub]) LocalAddr() A

func (*SecureSwarm[A, Pub]) LocalAddrs

func (s *SecureSwarm[A, Pub]) LocalAddrs() []A

func (*SecureSwarm[A, Pub]) LookupPublicKey

func (s *SecureSwarm[A, Pub]) LookupPublicKey(ctx context.Context, target A) (Pub, error)

func (*SecureSwarm[A, Pub]) MTU

func (s *SecureSwarm[A, Pub]) MTU() int

func (*SecureSwarm[A, Pub]) ParseAddr

func (s *SecureSwarm[A, Pub]) ParseAddr(x []byte) (A, error)

func (*SecureSwarm[A, Pub]) PublicKey

func (s *SecureSwarm[A, Pub]) PublicKey() Pub

func (*SecureSwarm[A, Pub]) Receive

func (s *SecureSwarm[A, Pub]) Receive(ctx context.Context, fn func(p2p.Message[A])) error

func (*SecureSwarm[A, Pub]) ServeAsk

func (s *SecureSwarm[A, Pub]) ServeAsk(ctx context.Context, fn func(ctx context.Context, resp []byte, req p2p.Message[A]) int) error

func (*SecureSwarm[A, Pub]) Tell

func (s *SecureSwarm[A, Pub]) Tell(ctx context.Context, dst A, v p2p.IOVec) error

type Swarm

type Swarm[A p2p.ComparableAddr] SecureSwarm[A, struct{}]

func (*Swarm[A]) Ask

func (s *Swarm[A]) Ask(ctx context.Context, resp []byte, dst A, v p2p.IOVec) (int, error)

func (*Swarm[A]) Close

func (s *Swarm[A]) Close() error

func (*Swarm[A]) LocalAddr

func (s *Swarm[A]) LocalAddr() A

func (*Swarm[A]) LocalAddrs

func (s *Swarm[A]) LocalAddrs() []A

func (*Swarm[A]) MTU

func (s *Swarm[A]) MTU() int

func (*Swarm[A]) ParseAddr

func (s *Swarm[A]) ParseAddr(x []byte) (A, error)

func (*Swarm[A]) Receive

func (s *Swarm[A]) Receive(ctx context.Context, fn func(p2p.Message[A])) error

func (*Swarm[A]) ServeAsk

func (s *Swarm[A]) ServeAsk(ctx context.Context, fn func(ctx context.Context, resp []byte, req p2p.Message[A]) int) error

func (*Swarm[A]) Tell

func (s *Swarm[A]) Tell(ctx context.Context, dst A, v p2p.IOVec) error

type SwarmOption

type SwarmOption[A p2p.ComparableAddr] func(*swarmConfig)

Jump to

Keyboard shortcuts

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