mx

package
v1.0.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2021 License: Apache-2.0, MIT Imports: 10 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

type Clock interface {
	Accuracy() time.Duration
	After(d time.Duration, callback func()) (cancel func())
	Ticker(userExpire time.Duration, callback func()) (cancel func())
}

type ClockController

type ClockController interface {
	Clock
	Advance(time.Time)
}

type FilterFunc

type FilterFunc func(int, host.Host) bool

func SelectIDs

func SelectIDs(ids ...peer.ID) FilterFunc

func SelectIndex

func SelectIndex(i int) FilterFunc

type HostFactory

type HostFactory interface {
	NewHost(ctx context.Context, opt []config.Option) (host.Host, error)
}

type HostSlice

type HostSlice []host.Host

func (HostSlice) Filter

func (hs HostSlice) Filter(f FilterFunc) HostSlice

func (HostSlice) Go

func (hs HostSlice) Go(f func(i int, h host.Host) error) error

func (HostSlice) Len

func (hs HostSlice) Len() int

func (HostSlice) Less

func (hs HostSlice) Less(i, j int) bool

func (HostSlice) Map

func (hs HostSlice) Map(f func(i int, h host.Host) error) (err error)

func (HostSlice) Swap

func (hs HostSlice) Swap(i, j int)

type MapFunc

type MapFunc func(ctx context.Context, sim Simulation, i int, h host.Host) error

type Maybe

type Maybe func(HostSlice) (HostSlice, error)

func (Maybe) Then

func (m Maybe) Then(next Maybe) Maybe

type Op

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

func (Op) Call

func (op Op) Call(ctx context.Context, hs ...host.Host) (HostSlice, error)

func (Op) Must

func (op Op) Must(ctx context.Context, hs ...host.Host) HostSlice

func (Op) Then

func (op Op) Then(call OpFunc) Op

type OpFunc

type OpFunc func(s Simulation) func(ctx context.Context) Maybe

func Announce

func Announce(t netsim.Topology, ns string, opt ...discovery.Option) OpFunc

func Discover

func Discover(t netsim.Topology, ns string, opt ...discovery.Option) OpFunc

func Filter

func Filter(f FilterFunc) OpFunc

func Go

func Go(f MapFunc) OpFunc

func Map

func Map(f MapFunc) OpFunc

func Select

func Select(f SelectFunc) OpFunc

func (OpFunc) Then

func (fn OpFunc) Then(next OpFunc) OpFunc

type Option

type Option func(sim *Simulation)

func WithClock

func WithClock(c ClockController) Option

WithClock sets the simulation clock. If c == nil, a default clock with 10ms accuracy is used.

func WithHostFactory

func WithHostFactory(f HostFactory) Option

WithHostFactory sets the host factory for the simulation. If f == nil, a default factory is used that constructs hosts using an in-process transport.

func WithNamespaceFactory

func WithNamespaceFactory(f func(Clock) netsim.NamespaceProvider) Option

WithNamespaceFactory sets the namespace implementation for the simulation. If ns == nil, a default namespace implementation is used.

type SelectFunc

type SelectFunc func(ctx context.Context, sim Simulation, hs HostSlice) (HostSlice, error)

type Simulation

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

func New

func New(ctx context.Context, opt ...Option) Simulation

func (Simulation) Clock

func (s Simulation) Clock() Clock

func (Simulation) MustHost

func (s Simulation) MustHost(ctx context.Context, opt ...config.Option) host.Host

MustHost returns a host or panics if an error was encountered.

func (Simulation) MustHostSet

func (s Simulation) MustHostSet(ctx context.Context, n int, opt ...config.Option) HostSlice

MustHostSet calls NewHostSet with the supplied parameters and panics if an error is encountered.

func (Simulation) NewDiscovery

func (s Simulation) NewDiscovery(h host.Host, t netsim.Topology) *netsim.DiscoveryService

NewDiscovery returns a discovery.Discovery implementation that supports the Simulation's in-process network.

The topology parameter t can be used to specify an initial connection topology. All peers must use the same instance of t in order to obtain the desired topology.

If t == nil, the topology defaults to netsim.SelectAll.

func (Simulation) NewHost

func (s Simulation) NewHost(ctx context.Context, opt ...config.Option) (host.Host, error)

NewHost assembles and creates a new libp2p host that uses the simulation's network.

The simulation configures hosts to use an in-process network, overriding the following options:

- libp2p.Transport - libp2p.NoTransports - libp2p.ListenAddr - libp2p.ListenAddrStrings - libp2p.NoListenAddrs

Users SHOULD NOT pass any of the above options to NewHost.

func (Simulation) NewHostSet

func (s Simulation) NewHostSet(ctx context.Context, n int, opt ...config.Option) (HostSlice, error)

NewHostSet builds and configures n hosts with identical parameters.

See NewHost.

func (Simulation) Op

func (s Simulation) Op(ops ...OpFunc) Op

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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