...

Package discovery

import "github.com/hyperledger/fabric/discovery/client"
Overview
Index

Overview ▾

Index ▾

Package files

api.go client.go selection.go signer.go

Variables

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)

type ChannelResponse

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

type Client

Client interacts with the discovery server

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

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

Dialer connects to the server

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

type Endorsers

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

type Endorsers []*Peer

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

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

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

Filter filters and sorts the given endorsers

type Filter interface {
    Filter(endorsers Endorsers) Endorsers
}

func NewFilter

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

InvocationChain aggregates ChaincodeCalls

type InvocationChain []*discovery.ChaincodeCall

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

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

type MemoizeSigner

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

func NewMemoizeSigner(signFunc Signer, maxEntries uint) *MemoizeSigner

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

func (*MemoizeSigner) Sign

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

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
}

type Priority

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

type PrioritySelector

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
}

type Request

Request aggregates several queries inside it

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

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

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
}

type Signer

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

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