routinghelpers

package
v0.0.0-...-8b9b725 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2019 License: MIT, MIT Imports: 13 Imported by: 4

README

go-libp2p-routing-helpers

standard-readme compliant GoDoc Coverage Status Build Status

A collection of helper types for composing different types of routers.

Documenation

See https://godoc.org/github.com/libp2p/go-libp2p-routing-helpers.

Contribute

Feel free to join in. All welcome. Open an issue!

This repository falls under the IPFS Code of Conduct.

Want to hack on IPFS?

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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

Bootstrap the router.

func (*Compose) FindPeer

func (cr *Compose) FindPeer(ctx context.Context, p peer.ID) (pstore.PeerInfo, error)

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

func (*Compose) FindProvidersAsync

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

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

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 ...ropts.Option) ([]byte, 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) 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 ...ropts.Option) error

PutValue adds value corresponding to given Key.

func (*Compose) SearchValue

func (cr *Compose) SearchValue(ctx context.Context, key string, opts ...ropts.Option) (<-chan []byte, 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

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.

func (*LimitedValueStore) GetValue

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

GetValue returns routing.ErrNotFound if key isn't supported

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 ...ropts.Option) error

PutValue returns ErrNotSupported

func (*LimitedValueStore) SearchValue

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

SearchValue returns empty channel if key isn't supported or calls SearchValue on the underlying ValueStore

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

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

FindPeer always returns ErrNotFound

func (Null) FindProvidersAsync

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

FindProvidersAsync always returns a closed channel

func (Null) GetValue

func (nr Null) GetValue(context.Context, string, ...ropts.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, ...ropts.Option) error

PutValue always returns ErrNotSupported

func (Null) SearchValue

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

SearchValue always returns ErrNotFound

type Parallel

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

Parallel operates on the slice of routers in parallel.

func (Parallel) Bootstrap

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

func (Parallel) FindPeer

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

func (Parallel) FindProvidersAsync

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

func (Parallel) GetPublicKey

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

func (Parallel) GetValue

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

func (Parallel) Provide

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

func (Parallel) PutValue

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

func (Parallel) SearchValue

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

type Tiered

type Tiered struct {
	Routers   []routing.IpfsRouting
	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

func (Tiered) FindPeer

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

func (Tiered) FindProvidersAsync

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

func (Tiered) GetPublicKey

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

func (Tiered) GetValue

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

func (Tiered) Provide

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

func (Tiered) PutValue

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

func (Tiered) SearchValue

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

Jump to

Keyboard shortcuts

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