discovery

package
v1.4.10 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// PrioritiesByHeight selects peers by descending height
	PrioritiesByHeight = &byHeight{}
	// NoExclusion accepts all peers and rejects no peers
	NoExclusion = selectionFunc(noExclusion)
	// NoPriorities is indifferent to how it selects peers
	NoPriorities = &noPriorities{}
)
View Source
var (
	// ErrNotFound defines an error that means that an element wasn't found
	ErrNotFound = errors.New("not found")
)

NoFilter returns a noop Filter

Functions

This section is empty.

Types

type ChannelResponse

type ChannelResponse interface {
	// Config returns a response for a config query, or error if something went wrong
	Config() (*discovery.ConfigResult, error)

	// Peers returns a response for a peer membership query, or error if something went wrong
	Peers(invocationChain ...*discovery.ChaincodeCall) ([]*Peer, error)

	// Endorsers returns the response for an endorser query for a given
	// chaincode in a given channel context, or error if something went wrong.
	// The method returns a random set of endorsers, such that signatures from all of them
	// combined, satisfy the endorsement policy.
	// The selection is based on the given selection hints:
	// Filter: Filters and sorts the endorsers
	// The given InvocationChain specifies the chaincode calls (along with collections)
	// that the client passed during the construction of the request
	Endorsers(invocationChain InvocationChain, f Filter) (Endorsers, error)
}

ChannelResponse aggregates responses for a given channel

type Client

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

Client interacts with the discovery server

func NewClient

func NewClient(createConnection Dialer, s Signer, signerCacheSize uint) *Client

NewClient creates a new Client instance

func (*Client) Send

func (c *Client) Send(ctx context.Context, req *Request, auth *discovery.AuthInfo) (Response, error)

Send sends the request and returns the response, or error on failure

type Dialer

type Dialer func() (*grpc.ClientConn, error)

Dialer connects to the server

type Endorsers

type Endorsers []*Peer

Endorsers defines a set of peers that are sufficient for satisfying some chaincode's endorsement policy

func (Endorsers) Filter

func (endorsers Endorsers) Filter(f ExclusionFilter) Endorsers

Filter filters the endorsers according to the given ExclusionFilter

func (Endorsers) Shuffle

func (endorsers Endorsers) Shuffle() Endorsers

Shuffle sorts the endorsers in random order

func (Endorsers) Sort

func (endorsers Endorsers) Sort(ps PrioritySelector) Endorsers

Sort sorts the endorsers according to the given PrioritySelector

type ExclusionFilter

type ExclusionFilter interface {
	// Exclude returns whether the given Peer is to be excluded or not
	Exclude(Peer) bool
}

ExclusionFilter returns true if the given Peer is not to be considered when selecting peers

func ExcludeByHost

func ExcludeByHost(reject func(host string) bool) ExclusionFilter

ExcludeByHost creates a ExclusionFilter out of the given exclusion predicate

func ExcludeHosts

func ExcludeHosts(endpoints ...string) ExclusionFilter

ExcludeHosts returns a ExclusionFilter that excludes the given endpoints

type Filter added in v1.3.0

type Filter interface {
	Filter(endorsers Endorsers) Endorsers
}

Filter filters and sorts the given endorsers

func NewFilter added in v1.3.0

func NewFilter(ps PrioritySelector, ef ExclusionFilter) Filter

NewFilter returns an endorser filter that uses the given exclusion filter and priority selector to filter and sort the endorsers

type InvocationChain

type InvocationChain []*discovery.ChaincodeCall

InvocationChain aggregates ChaincodeCalls

func (InvocationChain) String

func (ic InvocationChain) String() string

String returns a string representation of this invocation chain

func (InvocationChain) ValidateInvocationChain

func (ic InvocationChain) ValidateInvocationChain() error

ValidateInvocationChain validates the InvocationChain's structure

type LocalResponse

type LocalResponse interface {
	// Peers returns a response for a local peer membership query, or error if something went wrong
	Peers() ([]*Peer, error)
}

LocalResponse aggregates responses for a channel-less scope

type MemoizeSigner added in v1.3.0

type MemoizeSigner struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

MemoizeSigner signs messages with the same signature if the message was signed recently

func NewMemoizeSigner added in v1.3.0

func NewMemoizeSigner(signFunc Signer, maxEntries uint) *MemoizeSigner

NewMemoizeSigner creates a new MemoizeSigner that signs message with the given sign function

func (*MemoizeSigner) Sign added in v1.3.0

func (ms *MemoizeSigner) Sign(msg []byte) ([]byte, error)

Signer signs a message and returns the signature and nil, or nil and error on failure

type Peer

type Peer struct {
	MSPID            string
	AliveMessage     *gossip.SignedGossipMessage
	StateInfoMessage *gossip.SignedGossipMessage
	Identity         []byte
}

Peer aggregates identity, membership and channel-scoped information of a certain peer.

type Priority

type Priority int

Priority defines how likely a peer is to be selected over another peer. Positive priority means the left peer is selected Negative priority means the right peer is selected Zero priority means their priorities are the same

type PrioritySelector

type PrioritySelector interface {
	// Compare compares between 2 peers and returns
	// their relative scores
	Compare(Peer, Peer) Priority
}

PrioritySelector guides the selection of peers via giving peers a relative priority to their selection

type Request

type Request struct {
	*discovery.Request
	// contains filtered or unexported fields
}

Request aggregates several queries inside it

func NewRequest

func NewRequest() *Request

NewRequest creates a new request

func (*Request) AddConfigQuery

func (req *Request) AddConfigQuery() *Request

AddConfigQuery adds to the request a config query

func (*Request) AddEndorsersQuery

func (req *Request) AddEndorsersQuery(interests ...*discovery.ChaincodeInterest) (*Request, error)

AddEndorsersQuery adds to the request a query for given chaincodes interests are the chaincode interests that the client wants to query for. All interests for a given channel should be supplied in an aggregated slice

func (*Request) AddLocalPeersQuery

func (req *Request) AddLocalPeersQuery() *Request

AddLocalPeersQuery adds to the request a local peer query

func (*Request) AddPeersQuery

func (req *Request) AddPeersQuery(invocationChain ...*discovery.ChaincodeCall) *Request

AddPeersQuery adds to the request a peer query

func (*Request) OfChannel

func (req *Request) OfChannel(ch string) *Request

OfChannel sets the next queries added to be in the given channel's context

type Response

type Response interface {
	// ForChannel returns a ChannelResponse in the context of a given channel
	ForChannel(string) ChannelResponse

	// ForLocal returns a LocalResponse in the context of no channel
	ForLocal() LocalResponse
}

Response aggregates several responses from the discovery service

type Signer

type Signer func(msg []byte) ([]byte, error)

Signer signs a message and returns the signature and nil, or nil and error on failure

Jump to

Keyboard shortcuts

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