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{} )
var ( // ErrNotFound defines an error that means that an element wasn't found ErrNotFound = errors.New("not found") )
NoFilter returns a noop Filter
var NoFilter = NewFilter(NoPriorities, NoExclusion)
ChannelResponse aggregates responses for a given channel
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) }
Client interacts with the discovery server
type Client struct {
// contains filtered or unexported fields
}
func NewClient(createConnection Dialer, s Signer, signerCacheSize uint) *Client
NewClient creates a new Client instance
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
Dialer connects to the server
type Dialer func() (*grpc.ClientConn, error)
Endorsers defines a set of peers that are sufficient for satisfying some chaincode's endorsement policy
type Endorsers []*Peer
func (endorsers Endorsers) Filter(f ExclusionFilter) Endorsers
Filter filters the endorsers according to the given ExclusionFilter
func (endorsers Endorsers) Shuffle() Endorsers
Shuffle sorts the endorsers in random order
func (endorsers Endorsers) Sort(ps PrioritySelector) Endorsers
Sort sorts the endorsers according to the given PrioritySelector
ExclusionFilter returns true if the given Peer is not to be considered when selecting peers
type ExclusionFilter interface { // Exclude returns whether the given Peer is to be excluded or not Exclude(Peer) bool }
func ExcludeByHost(reject func(host string) bool) ExclusionFilter
ExcludeByHost creates a ExclusionFilter out of the given exclusion predicate
func ExcludeHosts(endpoints ...string) ExclusionFilter
ExcludeHosts returns a ExclusionFilter that excludes the given endpoints
Filter filters and sorts the given endorsers
type Filter interface { Filter(endorsers Endorsers) Endorsers }
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
InvocationChain aggregates ChaincodeCalls
type InvocationChain []*discovery.ChaincodeCall
func (ic InvocationChain) String() string
String returns a string representation of this invocation chain
func (ic InvocationChain) ValidateInvocationChain() error
ValidateInvocationChain validates the InvocationChain's structure
LocalResponse aggregates responses for a channel-less scope
type LocalResponse interface { // Peers returns a response for a local peer membership query, or error if something went wrong Peers() ([]*Peer, error) }
MemoizeSigner signs messages with the same signature if the message was signed recently
type MemoizeSigner struct { sync.RWMutex // contains filtered or unexported fields }
func NewMemoizeSigner(signFunc Signer, maxEntries uint) *MemoizeSigner
NewMemoizeSigner creates a new MemoizeSigner that signs message with the given sign function
func (ms *MemoizeSigner) Sign(msg []byte) ([]byte, error)
Signer signs a message and returns the signature and nil, or nil and error on failure
Peer aggregates identity, membership and channel-scoped information of a certain peer.
type Peer struct { MSPID string AliveMessage *gossip.SignedGossipMessage StateInfoMessage *gossip.SignedGossipMessage Identity []byte }
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 Priority int
PrioritySelector guides the selection of peers via giving peers a relative priority to their selection
type PrioritySelector interface { // Compare compares between 2 peers and returns // their relative scores Compare(Peer, Peer) Priority }
Request aggregates several queries inside it
type Request struct { *discovery.Request // contains filtered or unexported fields }
func NewRequest() *Request
NewRequest creates a new request
func (req *Request) AddConfigQuery() *Request
AddConfigQuery adds to the request a config query
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 (req *Request) AddLocalPeersQuery() *Request
AddLocalPeersQuery adds to the request a local peer query
func (req *Request) AddPeersQuery(invocationChain ...*discovery.ChaincodeCall) *Request
AddPeersQuery adds to the request a peer query
func (req *Request) OfChannel(ch string) *Request
OfChannel sets the next queries added to be in the given channel's context
Response aggregates several responses from the discovery service
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 }
Signer signs a message and returns the signature and nil, or nil and error on failure
type Signer func(msg []byte) ([]byte, error)