client

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: Apache-2.0, MIT Imports: 16 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindBatch added in v0.5.2

func FindBatch(ctx context.Context, finder Finder, mhs []multihash.Multihash) (*model.FindResponse, error)

FindBatch is a convenience function to lookup results for multiple multihashes. This works with either the Client or DHashClient. If no results are found then an empty response without error is returned.

Types

type Client added in v0.2.0

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

Client is an http client for the indexer find API

func New added in v0.2.0

func New(baseURL string, options ...Option) (*Client, error)

New creates a new find HTTP client.

func (*Client) Find added in v0.2.0

func (c *Client) Find(ctx context.Context, m multihash.Multihash) (*model.FindResponse, error)

Find looks up content entries by multihash. If no results are found then an empty response without error is returned.

func (*Client) GetProvider added in v0.2.0

func (c *Client) GetProvider(ctx context.Context, providerID peer.ID) (*model.ProviderInfo, error)

func (*Client) GetStats added in v0.2.0

func (c *Client) GetStats(ctx context.Context) (*model.Stats, error)

func (*Client) ListProviders added in v0.2.0

func (c *Client) ListProviders(ctx context.Context) ([]*model.ProviderInfo, error)

type DHStoreAPI added in v0.2.7

type DHStoreAPI interface {
	// FindMultihash does a dh-multihash lookup and returns a
	// model.FindResponse with EncryptedMultihashResults. Returns no data and
	// no error, (nil, nil), if data not found.
	FindMultihash(context.Context, multihash.Multihash) ([]model.EncryptedMultihashResult, error)
	// FindMetadata takes a value-key-hash, does a metadata lookup, and returns
	// encrypted metadata. Returns no data and no error, (nil, nil), if
	// metadata not found
	FindMetadata(context.Context, []byte) ([]byte, error)
}

DHStoreAPI defines multihash and metadata find functions. The default implementation defines functions to do this over HTTP. A replacement implementation that implements the interface can optionally be provided when creating a DHashClient.

type DHashClient added in v0.2.0

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

DHashClient is a client that does double-hashed lookups on a dhstore. By default, it does multihash and metadata lookups over HTTP. If given a DHStoreAPI, it can do the lookups any the underlying implementation defined.

func NewDHashClient added in v0.2.0

func NewDHashClient(options ...Option) (*DHashClient, error)

NewDHashClient instantiates a new client that uses Reader Privacy API for querying data. It requires more roundtrips to fulfill one query however it also protects the user from a passive observer. dhstoreURL specifies the URL of the double hashed store that can respond to find encrypted multihash and find encrypted metadata requests.

func (*DHashClient) Find added in v0.2.0

func (c *DHashClient) Find(ctx context.Context, mh multihash.Multihash) (*model.FindResponse, error)

Find launches FindAsync in a separate go routine and assembles the result into FindResponse as if it was a synchronous invocation. If no results are found then an empty response without error is returned.

func (*DHashClient) FindAsync added in v0.2.0

func (c *DHashClient) FindAsync(ctx context.Context, mh multihash.Multihash, resChan chan<- model.ProviderResult) error

FindAsync implements double hashed lookup workflow. FindAsync returns results on resChan until there are no more results or error. When finished, resChan is closed and the error or nil is returned.

func (*DHashClient) PCache added in v0.2.9

func (c *DHashClient) PCache() *pcache.ProviderCache

type Finder added in v0.5.2

type Finder interface {
	// Find queries for provider content records for a single multihash. If no
	// results are found then an empty response without error is returned.
	Find(context.Context, multihash.Multihash) (*model.FindResponse, error)
}

Finder is the interface implemented by all find clients.

type Option added in v0.2.0

type Option func(*config) error

Option is a function that sets a value in a config.

func WithClient added in v0.2.0

func WithClient(c *http.Client) Option

WithClient allows creation of the http client using an underlying network round tripper / client.

func WithDHStoreAPI added in v0.2.7

func WithDHStoreAPI(dhsAPI DHStoreAPI) Option

WithDHStoreAPI configures an interface to use for doing multihash and metadata lookups with dhstore. If this is not configured, then dhstore lookups are done using the dhstoreURL.

func WithDHStoreURL added in v0.2.2

func WithDHStoreURL(u string) Option

WithDHStoreURL specifies a URL for dhstore (/multihash and /metadata endpoints). If not specified then a WithDHStoreAPI should be used to provide access to dhstore data.

func WithMetadataOnly added in v0.5.3

func WithMetadataOnly(metadataOnly bool) Option

WithMetadataOnly configures lookups to only return metadata and not provider information. This means that is it is not necessary to specify providers URLs, using WithProvidersURL, when provider information is available from a separate location.

func WithPcachePreload added in v0.2.9

func WithPcachePreload(preload bool) Option

WithPcachePreload enables or disabled preloading the cache. Generally this should be enabled, even for short-lived clients needing to look up few providers.

Default is true (enabled). This option is ignored if WithMetadataOnly(true) is specified.

func WithPcacheTTL added in v0.2.8

func WithPcacheTTL(ttl time.Duration) Option

WithPcacheTTL sets the time that provider information remains in the cache after it is not longer available from any of the original sources.

This option is ignored if WithMetadataOnly(true) is specified.

func WithProvidersURL added in v0.2.9

func WithProvidersURL(urls ...string) Option

WithProvidersURL specifies one or more URLs for retrieving provider information (/providers and /providers/<pid> endpoints). Multiple URLs may be given to specify multiple sources of provider information.

This option is ignored if WithMetadataOnly(true) is specified.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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