routinghelpers

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewComposableParallel

func NewComposableParallel(routers []*ParallelRouter) *composableParallel

NewComposableParallel creates a Router that will execute methods from provided Routers in parallel. On all methods, If IgnoreError flag is set, that Router will not stop the entire execution. On all methods, If ExecuteAfter is set, that Router will be executed after the timer. Router specific timeout will start counting AFTER the ExecuteAfter timer.

func NewComposableSequential

func NewComposableSequential(routers []*SequentialRouter) *composableSequential

Types

type Bootstrap

type Bootstrap interface {
	// Bootstrap bootstraps the router.
	Bootstrap(ctx context.Context) error
}

Bootstrap is an interface that should be implemented by any routers wishing to be bootstrapped.

type ComposableRouter

type ComposableRouter interface {
	Routers() []routing.Routing
}

type Compose

type Compose struct {
	ValueStore     routing.ValueStore
	PeerRouting    routing.PeerRouting
	ContentRouting routing.ContentRouting
}

Compose composes the components into a single router. Not specifying a component (leaving it nil) is equivalent to specifying the Null router.

It also implements Bootstrap. All *distinct* components implementing Bootstrap will be bootstrapped in parallel. Identical components will not be bootstrapped twice.

func (*Compose) Bootstrap

func (cr *Compose) Bootstrap(ctx context.Context) (err error)

Bootstrap the router.

func (*Compose) FindPeer

func (cr *Compose) FindPeer(ctx context.Context, p peer.ID) (info peer.AddrInfo, err error)

FindPeer searches for a peer with given ID, returns a peer.AddrInfo with relevant addresses.

func (*Compose) FindProvidersAsync

func (cr *Compose) FindProvidersAsync(ctx context.Context, c cid.Cid, count int) <-chan peer.AddrInfo

FindProvidersAsync searches for peers who are able to provide a given key.

If count > 0, it returns at most count providers. If count == 0, it returns an unbounded number of providers.

func (*Compose) GetPublicKey

func (cr *Compose) GetPublicKey(ctx context.Context, p peer.ID) (ci.PubKey, error)

GetPublicKey returns the public key for the given peer.

func (*Compose) GetValue

func (cr *Compose) GetValue(ctx context.Context, key string, opts ...routing.Option) (value []byte, err error)

GetValue searches for the value corresponding to given Key.

func (*Compose) Provide

func (cr *Compose) Provide(ctx context.Context, c cid.Cid, local bool) (err error)

Provide adds the given cid to the content routing system. If 'true' is passed, it also announces it, otherwise it is just kept in the local accounting of which objects are being provided.

func (*Compose) PutValue

func (cr *Compose) PutValue(ctx context.Context, key string, value []byte, opts ...routing.Option) (err error)

PutValue adds value corresponding to given Key.

func (*Compose) SearchValue

func (cr *Compose) SearchValue(ctx context.Context, key string, opts ...routing.Option) (ch <-chan []byte, err error)

SearchValue searches for the value corresponding to given Key.

type LimitedValueStore

type LimitedValueStore struct {
	routing.ValueStore
	Namespaces []string
}

LimitedValueStore limits the internal value store to the given namespaces.

func (*LimitedValueStore) Bootstrap

func (lvs *LimitedValueStore) Bootstrap(ctx context.Context) error

Bootstrap signals the underlying value store to get into the "bootstrapped" state, if it implements the Bootstrap interface.

func (*LimitedValueStore) Close

func (lvs *LimitedValueStore) Close() error

Close closest the underlying value store if it implements the io.Closer interface.

func (*LimitedValueStore) GetPublicKey

func (lvs *LimitedValueStore) GetPublicKey(ctx context.Context, p peer.ID) (ci.PubKey, error)

GetPublicKey returns the public key for the given peer, if and only if this router supports the /pk namespace. Otherwise, it returns routing.ErrNotFound.

func (*LimitedValueStore) GetValue

func (lvs *LimitedValueStore) GetValue(ctx context.Context, key string, opts ...routing.Option) ([]byte, error)

GetValue retrieves the given key from the underlying value store if the namespace is supported. Otherwise, it returns routing.ErrNotFound.

func (*LimitedValueStore) KeySupported

func (lvs *LimitedValueStore) KeySupported(key string) bool

KeySupported returns true if the passed key is supported by this value store.

func (*LimitedValueStore) PutValue

func (lvs *LimitedValueStore) PutValue(ctx context.Context, key string, value []byte, opts ...routing.Option) error

PutValue puts the given key in the underlying value store if the namespace is supported. Otherwise, it returns routing.ErrNotSupported.

func (*LimitedValueStore) SearchValue

func (lvs *LimitedValueStore) SearchValue(ctx context.Context, key string, opts ...routing.Option) (<-chan []byte, error)

SearchValue searches the underlying value store for the given key if the namespace is supported, returning results in monotonically increasing "freshness". Otherwise, it returns an empty, closed channel to indicate that the value wasn't found.

type Null

type Null struct{}

Null is a router that doesn't do anything.

func (Null) Bootstrap

func (nr Null) Bootstrap(context.Context) error

Bootstrap always succeeds instantly

func (Null) Close

func (nr Null) Close() error

Close always succeeds instantly

func (Null) FindPeer

func (nr Null) FindPeer(context.Context, peer.ID) (peer.AddrInfo, error)

FindPeer always returns ErrNotFound

func (Null) FindProvidersAsync

func (nr Null) FindProvidersAsync(context.Context, cid.Cid, int) <-chan peer.AddrInfo

FindProvidersAsync always returns a closed channel

func (Null) GetValue

func (nr Null) GetValue(context.Context, string, ...routing.Option) ([]byte, error)

GetValue always returns ErrNotFound

func (Null) Provide

func (nr Null) Provide(context.Context, cid.Cid, bool) error

Provide always returns ErrNotSupported

func (Null) PutValue

func (nr Null) PutValue(context.Context, string, []byte, ...routing.Option) error

PutValue always returns ErrNotSupported

func (Null) SearchValue

func (nr Null) SearchValue(ctx context.Context, key string, opts ...routing.Option) (<-chan []byte, error)

SearchValue always returns ErrNotFound

type Parallel

type Parallel struct {
	Routers   []routing.Routing
	Validator record.Validator
}

Parallel operates on the slice of routers in parallel.

func (Parallel) Bootstrap

func (r Parallel) Bootstrap(ctx context.Context) error

Bootstrap signals all the sub-routers to bootstrap.

func (Parallel) Close

func (r Parallel) Close() error

Close closes all sub-routers that implement the io.Closer interface.

func (Parallel) FindPeer

func (r Parallel) FindPeer(ctx context.Context, p peer.ID) (peer.AddrInfo, error)

FindPeer finds the given peer in all sub-routers in parallel, returning the first result.

func (Parallel) FindProvidersAsync

func (r Parallel) FindProvidersAsync(ctx context.Context, c cid.Cid, count int) <-chan peer.AddrInfo

FindProvidersAsync searches all sub-routers in parallel for peers who are able to provide a given key.

If count > 0, it returns at most count providers. If count == 0, it returns an unbounded number of providers.

func (Parallel) GetPublicKey

func (r Parallel) GetPublicKey(ctx context.Context, p peer.ID) (ci.PubKey, error)

GetPublicKey retrieves the public key from all sub-routers in parallel, returning the first result.

func (Parallel) GetValue

func (r Parallel) GetValue(ctx context.Context, key string, opts ...routing.Option) ([]byte, error)

GetValue searches all sub-routers for the given key, returning the result from the first sub-router to complete the query.

func (Parallel) Provide

func (r Parallel) Provide(ctx context.Context, c cid.Cid, local bool) error

Provide announces that this peer provides the content in question to all sub-routers in parallel. Provide returns success as long as a single sub-router succeeds, but still waits for all sub-routers to finish before returning.

If count > 0, it returns at most count providers. If count == 0, it returns an unbounded number of providers.

func (Parallel) PutValue

func (r Parallel) PutValue(ctx context.Context, key string, value []byte, opts ...routing.Option) error

PutValue puts the given key to all sub-routers in parallel. It succeeds as long as putting to at least one sub-router succeeds, but it waits for all puts to terminate.

func (Parallel) SearchValue

func (r Parallel) SearchValue(ctx context.Context, key string, opts ...routing.Option) (<-chan []byte, error)

SearchValue searches all sub-routers for the given key in parallel, returning results in monotonically increasing "freshness" from all sub-routers.

type ParallelRouter

type ParallelRouter struct {
	Timeout      time.Duration
	Router       routing.Routing
	ExecuteAfter time.Duration
	// DoNotWaitForSearchValue is experimental while we wait for a better solution.
	DoNotWaitForSearchValue bool
	IgnoreError             bool
}

type ProvideManyRouter

type ProvideManyRouter interface {
	ProvideMany(ctx context.Context, keys []multihash.Multihash) error
}

type ReadyAbleRouter

type ReadyAbleRouter interface {
	Ready() bool
}

type SequentialRouter

type SequentialRouter struct {
	Timeout     time.Duration
	IgnoreError bool
	Router      routing.Routing
}

type Tiered

type Tiered struct {
	Routers   []routing.Routing
	Validator record.Validator
}

Tiered is like the Parallel except that GetValue and FindPeer are called in series.

func (Tiered) Bootstrap

func (r Tiered) Bootstrap(ctx context.Context) error

Bootstrap signals all the sub-routers to bootstrap.

func (Tiered) Close

func (r Tiered) Close() error

Close closes all sub-routers that implement the io.Closer interface.

func (Tiered) FindPeer

func (r Tiered) FindPeer(ctx context.Context, p peer.ID) (peer.AddrInfo, error)

FindPeer sequentially searches for given peer using each sub-router, returning the first result.

func (Tiered) FindProvidersAsync

func (r Tiered) FindProvidersAsync(ctx context.Context, c cid.Cid, count int) <-chan peer.AddrInfo

FindProvidersAsync searches all sub-routers in parallel for peers who are able to provide a given key.

If count > 0, it returns at most count providers. If count == 0, it returns an unbounded number of providers.

func (Tiered) GetPublicKey

func (r Tiered) GetPublicKey(ctx context.Context, p peer.ID) (ci.PubKey, error)

GetPublicKey sequentially searches each sub-router for the the public key, returning the first result.

func (Tiered) GetValue

func (r Tiered) GetValue(ctx context.Context, key string, opts ...routing.Option) ([]byte, error)

GetValue sequentially searches each sub-router for the given key, returning the value from the first sub-router to complete the query.

func (Tiered) Provide

func (r Tiered) Provide(ctx context.Context, c cid.Cid, local bool) error

Provide announces that this peer provides the content in question to all sub-routers in parallel. Provide returns success as long as a single sub-router succeeds, but still waits for all sub-routers to finish before returning.

func (Tiered) PutValue

func (r Tiered) PutValue(ctx context.Context, key string, value []byte, opts ...routing.Option) error

PutValue puts the given key to all sub-routers in parallel. It succeeds as long as putting to at least one sub-router succeeds, but it waits for all puts to terminate.

func (Tiered) SearchValue

func (r Tiered) SearchValue(ctx context.Context, key string, opts ...routing.Option) (<-chan []byte, error)

SearchValue searches all sub-routers for the given key in parallel, returning results in monotonically increasing "freshness" from all sub-routers.

Directories

Path Synopsis
tracing provides high level method tracing for the [routing.Routing] API.
tracing provides high level method tracing for the [routing.Routing] API.

Jump to

Keyboard shortcuts

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