forked from hyperledger/fabric-sdk-go
/
provider.go
163 lines (144 loc) · 5.12 KB
/
provider.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package fab
import (
reqContext "context"
"crypto/tls"
"time"
"github.com/birdycloud/fabric-sdk-go/pkg/common/options"
"github.com/birdycloud/fabric-sdk-go/pkg/common/providers/core"
"github.com/birdycloud/fabric-sdk-go/pkg/common/providers/msp"
commtls "github.com/birdycloud/fabric-sdk-go/pkg/core/config/comm/tls"
"github.com/birdycloud/fabric-sdk-go/pkg/fabsdk/metrics"
"google.golang.org/grpc"
)
// ClientContext contains the client context
type ClientContext interface {
core.Providers
msp.Providers
Providers
msp.SigningIdentity
}
// InfraProvider enables access to fabric objects such as peer and user based on config or
type InfraProvider interface {
CreatePeerFromConfig(peerCfg *NetworkPeer) (Peer, error)
CreateOrdererFromConfig(cfg *OrdererConfig) (Orderer, error)
CommManager() CommManager
Close()
}
// ChaincodeCall contains the ID of the chaincode as well
// as an optional set of private data collections that may be
// accessed by the chaincode.
type ChaincodeCall struct {
ID string
Collections []string
}
// SelectionService selects peers for endorsement and commit events
type SelectionService interface {
// GetEndorsersForChaincode returns a set of peers that should satisfy the endorsement
// policies of all of the given chaincodes.
// A set of options may be provided to the selection service. Note that the type of options
// may vary depending on the specific selection service implementation.
GetEndorsersForChaincode(chaincodes []*ChaincodeCall, opts ...options.Opt) ([]Peer, error)
}
// DiscoveryService is used to discover eligible peers on specific channel
type DiscoveryService interface {
GetPeers() ([]Peer, error)
}
// LocalDiscoveryProvider is used to discover peers in the local MSP
type LocalDiscoveryProvider interface {
CreateLocalDiscoveryService(mspID string) (DiscoveryService, error)
}
// TargetFilter allows for filtering target peers
type TargetFilter interface {
// Accept returns true if peer should be included in the list of target peers
Accept(peer Peer) bool
}
// TargetSorter allows for sorting target peers
type TargetSorter interface {
// Returns the sorted peers
Sort(peers []Peer) []Peer
}
// PrioritySelector determines how likely a peer is to be
// selected over another peer
type PrioritySelector interface {
// A positive return value means peer1 is selected
// A negative return value means the peer2 is selected
// Zero return value means their priorities are the same
Compare(peer1, peer2 Peer) int
}
// CommManager enables network communication.
type CommManager interface {
DialContext(ctx reqContext.Context, target string, opts ...grpc.DialOption) (*grpc.ClientConn, error)
ReleaseConn(conn *grpc.ClientConn)
}
//EndpointConfig contains endpoint network configurations
type EndpointConfig interface {
Timeout(TimeoutType) time.Duration
OrderersConfig() []OrdererConfig
OrdererConfig(nameOrURL string) (*OrdererConfig, bool, bool)
PeersConfig(org string) ([]PeerConfig, bool)
PeerConfig(nameOrURL string) (*PeerConfig, bool)
NetworkConfig() *NetworkConfig
NetworkPeers() []NetworkPeer
ChannelConfig(name string) *ChannelEndpointConfig
ChannelPeers(name string) []ChannelPeer
ChannelOrderers(name string) []OrdererConfig
TLSCACertPool() commtls.CertPool
TLSClientCerts() []tls.Certificate
CryptoConfigPath() string
}
// TimeoutType enumerates the different types of outgoing connections
type TimeoutType int
const (
// PeerConnection connection timeout
PeerConnection TimeoutType = iota
// EventReg connection timeout
EventReg
// Query timeout
Query
// Execute timeout
Execute
// OrdererConnection orderer connection timeout
OrdererConnection
// OrdererResponse orderer response timeout
OrdererResponse
// DiscoveryGreylistExpiry discovery Greylist expiration period
DiscoveryGreylistExpiry
// ConnectionIdle is the timeout for closing idle connections
ConnectionIdle
// CacheSweepInterval is the duration between cache sweeps
CacheSweepInterval
// EventServiceIdle is the timeout for closing the event service connection
EventServiceIdle
// PeerResponse peer response timeout
PeerResponse
// ResMgmt timeout is default overall timeout for all resource management operations
ResMgmt
// ChannelConfigRefresh channel configuration refresh interval
ChannelConfigRefresh
// ChannelMembershipRefresh channel membership refresh interval
ChannelMembershipRefresh
// DiscoveryConnection discovery connection timeout
DiscoveryConnection
// DiscoveryResponse discovery response timeout
DiscoveryResponse
// DiscoveryServiceRefresh discovery service refresh interval
DiscoveryServiceRefresh
// SelectionServiceRefresh selection service refresh interval
SelectionServiceRefresh
)
// Providers represents the SDK configured service providers context.
type Providers interface {
LocalDiscoveryProvider() LocalDiscoveryProvider
ChannelProvider() ChannelProvider
InfraProvider() InfraProvider
EndpointConfig() EndpointConfig
MetricsProvider
}
// MetricsProvider represents a provider of metrics.
type MetricsProvider interface {
GetMetrics() *metrics.ClientMetrics
}