client

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2018 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyLibrarianAddresses indicates that the librarian addresses is empty.
	ErrEmptyLibrarianAddresses = errors.New("empty librarian addresses")

	// ErrClientMissingFromSet indicates when a client ID is expected to be in a set but isn't.
	ErrClientMissingFromSet = errors.New("client missing from set")

	// ErrNoNewClients indicates when Next() cannot return a new LibrarianClient because no
	// new clients were available.
	ErrNoNewClients = errors.New("no new LibrarianClients are available")
)
View Source
var (
	// ErrGetMissingValue denotes when a Get request expects to receive a value response but
	// doesn't and instead receives a ClosestPeers response.
	ErrGetMissingValue = errors.New("Get response expected to have value but it is missing")
)
View Source
var ErrUnexpectedRequestID = errors.New("response contains unexpected RequestID")

ErrUnexpectedRequestID indicates when the RequestID in a response is different than that in the request.

Functions

func FromSignatureContext

func FromSignatureContext(ctx context.Context) (string, string, error)

FromSignatureContext extracts the signed JSON web token from the context.

func NewExpBackoff

func NewExpBackoff(timeout time.Duration) *cbackoff.ExponentialBackOff

NewExpBackoff creates a new exponential backoff retrier with default parameters.

func NewFindRequest

func NewFindRequest(peerID, orgID ecid.ID, key id.ID, nPeers uint) *api.FindRequest

NewFindRequest creates a FindRequest object.

func NewGetRequest

func NewGetRequest(peerID, orgID ecid.ID, key id.ID) *api.GetRequest

NewGetRequest creates a GetRequest object.

func NewIncomingSignatureContext

func NewIncomingSignatureContext(
	ctx context.Context, signedJWT, orgSignedJWT string,
) context.Context

NewIncomingSignatureContext creates a new context with the signed JSON web token (JWT) string in the incoming metadata field. This function should only be used for testing.

func NewIntroduceRequest

func NewIntroduceRequest(
	peerID, orgID ecid.ID, apiSelf *api.PeerAddress, nPeers uint,
) *api.IntroduceRequest

NewIntroduceRequest creates an IntroduceRequest object.

func NewPutRequest

func NewPutRequest(peerID, orgID ecid.ID, key id.ID, value *api.Document) *api.PutRequest

NewPutRequest creates a PutRequest object.

func NewRequestMetadata

func NewRequestMetadata(peerID, orgID ecid.ID) *api.RequestMetadata

NewRequestMetadata creates a RequestMetadata object from the peer ID and a random request ID.

func NewRetryFinder

func NewRetryFinder(inner api.Finder, timeout time.Duration) api.Finder

NewRetryFinder creates a new api.Finder with exponential backoff retries.

func NewRetryGetter

func NewRetryGetter(cb GetterBalancer, valueOnly bool, timeout time.Duration) api.Getter

NewRetryGetter wraps a client balancer with an exponential backoff, returning an api.Getter. Each backoff attempt samples a (possibly) different api.Getter to use for the query.

func NewRetryPutter

func NewRetryPutter(cb PutterBalancer, timeout time.Duration) api.Putter

NewRetryPutter wraps a client balancer with an exponential backoff, returning an api.Putter.

func NewRetryStorer

func NewRetryStorer(inner api.Storer, timeout time.Duration) api.Storer

NewRetryStorer creates a new api.Storer with exponential backoff retries.

func NewRetryVerifier

func NewRetryVerifier(inner api.Verifier, timeout time.Duration) api.Verifier

NewRetryVerifier creates a new api.Finder with exponential backoff retries.

func NewSignatureContext

func NewSignatureContext(ctx context.Context, signedJWT, orgSignedJWT string) context.Context

NewSignatureContext creates a new context with the signed JSON web token (JWT) string.

func NewSignedContext

func NewSignedContext(signer, orgSigner Signer, request proto.Message) (context.Context, error)

NewSignedContext creates a new context with a request signature.

func NewSignedTimeoutContext

func NewSignedTimeoutContext(
	signer, orgSigner Signer, request proto.Message, timeout time.Duration,
) (
	context.Context, context.CancelFunc, error)

NewSignedTimeoutContext creates a new context with a timeout and request signature.

func NewStoreRequest

func NewStoreRequest(peerID, orgID ecid.ID, key id.ID, value *api.Document) *api.StoreRequest

NewStoreRequest creates a StoreRequest object.

func NewSubscribeRequest

func NewSubscribeRequest(
	peerID, orgID ecid.ID, subscription *api.Subscription,
) *api.SubscribeRequest

NewSubscribeRequest creates a SubscribeRequest object.

func NewVerifyRequest

func NewVerifyRequest(
	peerID, orgID ecid.ID, key id.ID, macKey []byte, nPeers uint,
) *api.VerifyRequest

NewVerifyRequest creates a VerifyRequest object.

Types

type Balancer

type Balancer interface {
	// Next selects the next LibrarianClient.
	Next() (api.LibrarianClient, error)

	// CloseAll closes all LibrarianClient connections.
	CloseAll() error
}

Balancer load balances between a collection of LibrarianClients.

func NewUniformBalancer

func NewUniformBalancer(libAddrs []*net.TCPAddr, clients Pool, rng *rand.Rand) (Balancer, error)

NewUniformBalancer creates a new Balancer that selects the next client uniformly at random.

type Claims

type Claims struct {
	// Hash is the base-64-url encoded string of the hash of the message being signed
	Hash string `json:"hash"`
}

Claims holds the claims associated with a message signature.

func NewSignatureClaims

func NewSignatureClaims(hash [sha256.Size]byte) *Claims

NewSignatureClaims creates a new SignatureClaims instance with the given message hash.

func (*Claims) Valid

func (c *Claims) Valid() error

Valid returns whether the claim is valid or invalid via an error.

type FinderCreator

type FinderCreator interface {
	// Create creates an api.Finder from the api.Connector.
	Create(address string) (api.Finder, error)
}

FinderCreator creates api.Finders.

func NewFinderCreator

func NewFinderCreator(clients Pool) FinderCreator

NewFinderCreator creates a new FinderCreator.

type GetterBalancer

type GetterBalancer interface {
	// Next selects the next Getter.
	Next() (api.Getter, error)
}

GetterBalancer load balances between a collection of Getters.

func NewUniformGetterBalancer

func NewUniformGetterBalancer(inner Balancer) GetterBalancer

NewUniformGetterBalancer creates a GetterBalancer using an internal Balancer.

type IntroducerCreator

type IntroducerCreator interface {
	// Create creates an api.Introducer from the api.Connector.
	Create(address string) (api.Introducer, error)
}

IntroducerCreator creates api.Introducers.

func NewIntroducerCreator

func NewIntroducerCreator(clients Pool) IntroducerCreator

NewIntroducerCreator creates a new IntroducerCreator.

type Pool added in v0.3.0

type Pool interface {
	// Get the connection to the given address.
	Get(address string) (api.LibrarianClient, error)

	// CloseAll closes all active connections. Not further Get() calls may be made after this call.
	CloseAll() error
}

Pool maintains a pool of librarian clients.

func NewDefaultLRUPool added in v0.3.0

func NewDefaultLRUPool() (Pool, error)

NewDefaultLRUPool creates a new LRU pool with the default number of max connections.

func NewLRUPool added in v0.3.0

func NewLRUPool(maxConns int) (Pool, error)

NewLRUPool creates a new LRU Pool with the given number of max connections.

type PutterBalancer

type PutterBalancer interface {
	// Next selects the next Putter.
	Next() (api.Putter, error)
}

PutterBalancer laod balances between a collection of Putters.

func NewUniformPutterBalancer

func NewUniformPutterBalancer(inner Balancer) PutterBalancer

NewUniformPutterBalancer creates a PutterBalancer using an internal Balancer.

type SetBalancer

type SetBalancer interface {
	// AddNext selects the next LibrarianClient, adds it to the set, and returns it along with
	// its peer address string.
	AddNext() (api.LibrarianClient, string, error)

	// Remove removes the librarian from the set.
	Remove(address string) error
}

SetBalancer load balances between librarian clients, ensuring that a new librarian is always returned.

func NewSetBalancer added in v0.4.0

func NewSetBalancer(libAddrs []*net.TCPAddr, clients Pool, rng *rand.Rand) (SetBalancer, error)

NewSetBalancer creates a new SetBalancer that selects the next client from the remaining clients in the available set.

type Signer

type Signer interface {
	// Sign returns the signature (in the form of an encoded json web token) on the message.
	Sign(m proto.Message) (string, error)
}

Signer can sign a message.

func NewECDSASigner added in v0.5.0

func NewECDSASigner(key *ecdsa.PrivateKey) Signer

NewECDSASigner returns a new Signer instance using the given private key.

func NewEmptySigner added in v0.5.0

func NewEmptySigner() Signer

NewEmptySigner returns a Signer than returns an empty string signature instead of actually signing the message.

type StorerCreator

type StorerCreator interface {
	// Create creates an api.Storer from the api.Connector.
	Create(address string) (api.Storer, error)
}

StorerCreator creates api.Storers.

func NewStorerCreator

func NewStorerCreator(clients Pool) StorerCreator

NewStorerCreator creates a new StorerCreator.

type TestErrSigner

type TestErrSigner struct{}

TestErrSigner implements the signature.Signer interface but always returns an error.

func (*TestErrSigner) Sign

func (s *TestErrSigner) Sign(m proto.Message) (string, error)

Sign returns an error.

type TestNoOpSigner

type TestNoOpSigner struct{}

TestNoOpSigner implements the signature.Signer interface but just returns a dummy token.

func (*TestNoOpSigner) Sign

func (s *TestNoOpSigner) Sign(m proto.Message) (string, error)

Sign returns a dummy token.

type Verifier

type Verifier interface {
	// Verify verifies that the encoded token is well formed and has been signed by the peer.
	Verify(encToken string, fromPubKey *ecdsa.PublicKey, m proto.Message) error
}

Verifier verifies the signature on a message.

func NewVerifier

func NewVerifier() Verifier

NewVerifier creates a new Verifier instance.

type VerifierCreator

type VerifierCreator interface {
	// Create creates an api.Verifier from the api.Connector.
	Create(address string) (api.Verifier, error)
}

VerifierCreator creates api.Verifiers.

func NewVerifierCreator

func NewVerifierCreator(clients Pool) VerifierCreator

NewVerifierCreator creates a new FinderCreator.

Jump to

Keyboard shortcuts

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