|
| 1 | +/* |
| 2 | +Copyright IBM Corp. All Rights Reserved. |
| 3 | +
|
| 4 | +SPDX-License-Identifier: Apache-2.0 |
| 5 | +*/ |
| 6 | + |
| 7 | +package discovery |
| 8 | + |
| 9 | +import ( |
| 10 | + "github.com/hyperledger/fabric/protos/discovery" |
| 11 | + "github.com/hyperledger/fabric/protos/gossip" |
| 12 | + "github.com/pkg/errors" |
| 13 | + "golang.org/x/net/context" |
| 14 | + "google.golang.org/grpc" |
| 15 | +) |
| 16 | + |
| 17 | +var ( |
| 18 | + // ErrNotFound defines an error that means that an element wasn't found |
| 19 | + ErrNotFound = errors.New("not found") |
| 20 | +) |
| 21 | + |
| 22 | +// Signer signs a message and returns the signature and nil, |
| 23 | +// or nil and error on failure |
| 24 | +type Signer func(msg []byte) ([]byte, error) |
| 25 | + |
| 26 | +// Dialer connects to the server |
| 27 | +type Dialer func() (*grpc.ClientConn, error) |
| 28 | + |
| 29 | +// Client defines the client-side API of the discovery service |
| 30 | +type Client interface { |
| 31 | + // Send sends the Request and returns the response, or error on failure |
| 32 | + Send(context.Context, *Request) (Response, error) |
| 33 | +} |
| 34 | + |
| 35 | +// Response aggregates several responses from the discovery service |
| 36 | +type Response interface { |
| 37 | + // ForChannel returns a ChannelResponse in the context of a given channel |
| 38 | + ForChannel(string) ChannelResponse |
| 39 | +} |
| 40 | + |
| 41 | +// ChannelResponse aggregates responses for a given channel |
| 42 | +type ChannelResponse interface { |
| 43 | + // Config returns a response for a config query, or error if something went wrong |
| 44 | + Config() (*discovery.ConfigResult, error) |
| 45 | + |
| 46 | + // Peers returns a response for a peer membership query, or error if something went wrong |
| 47 | + Peers() ([]*Peer, error) |
| 48 | + |
| 49 | + // Endorsers returns the response for an endorser query for a given |
| 50 | + // chaincode in a given channel context, or error if something went wrong. |
| 51 | + // The method returns a random set of endorsers, such that signatures from all of them |
| 52 | + // combined, satisfy the endorsement policy. |
| 53 | + Endorsers(string) (Endorsers, error) |
| 54 | +} |
| 55 | + |
| 56 | +// Endorsers defines a set of peers that are sufficient |
| 57 | +// for satisfying some chaincode's endorsement policy |
| 58 | +type Endorsers []*Peer |
| 59 | + |
| 60 | +// Peer aggregates identity, membership and channel-scoped information |
| 61 | +// of a certain peer. |
| 62 | +type Peer struct { |
| 63 | + MSPID string |
| 64 | + AliveMessage *gossip.SignedGossipMessage |
| 65 | + StateInfoMessage *gossip.SignedGossipMessage |
| 66 | + Identity []byte |
| 67 | +} |
0 commit comments