@@ -50,7 +50,7 @@ import (
50
50
"github.com/hyperledger/fabric/protos/utils"
51
51
"go.uber.org/zap/zapcore"
52
52
"google.golang.org/grpc"
53
- "gopkg.in/alecthomas/kingpin.v2"
53
+ kingpin "gopkg.in/alecthomas/kingpin.v2"
54
54
)
55
55
56
56
var logger = flogging .MustGetLogger ("orderer.common.server" )
@@ -97,14 +97,14 @@ func Start(cmd string, conf *localconfig.TopLevel) {
97
97
lf , _ := createLedgerFactory (conf )
98
98
99
99
clusterDialer := & cluster.PredicateDialer {}
100
- clusterConfig := initializeClusterConfig (conf )
101
- clusterDialer .SetConfig (clusterConfig )
100
+ clusterClientConfig := initializeClusterClientConfig (conf )
101
+ clusterDialer .SetConfig (clusterClientConfig )
102
102
103
103
// Only clusters that are equipped with a recent config block can replicate.
104
104
if clusterType && conf .General .GenesisMethod == "file" {
105
105
r := & replicationInitiator {
106
106
logger : logger ,
107
- secOpts : clusterConfig .SecOpts ,
107
+ secOpts : clusterClientConfig .SecOpts ,
108
108
bootstrapBlock : bootstrapBlock ,
109
109
conf : conf ,
110
110
lf : & ledgerFactory {lf },
@@ -129,25 +129,49 @@ func Start(cmd string, conf *localconfig.TopLevel) {
129
129
ClientRootCAs : serverConfig .SecOpts .ClientRootCAs ,
130
130
}
131
131
132
+ clusterServerConfig := serverConfig
133
+ clusterGRPCServer := grpcServer
134
+ if clusterType {
135
+ clusterServerConfig , clusterGRPCServer = configureClusterListener (conf , serverConfig , grpcServer , ioutil .ReadFile )
136
+ }
137
+
138
+ var servers = []* comm.GRPCServer {grpcServer }
139
+ // If we have a separate gRPC server for the cluster, we need to update its TLS
140
+ // CA certificate pool too.
141
+ if clusterGRPCServer != grpcServer {
142
+ servers = append (servers , clusterGRPCServer )
143
+ }
144
+
132
145
tlsCallback := func (bundle * channelconfig.Bundle ) {
133
146
// only need to do this if mutual TLS is required or if the orderer node is part of a cluster
134
147
if grpcServer .MutualTLSRequired () || clusterType {
135
148
logger .Debug ("Executing callback to update root CAs" )
136
- updateTrustedRoots (grpcServer , caSupport , bundle )
149
+ updateTrustedRoots (caSupport , bundle , servers ... )
137
150
if clusterType {
138
- updateClusterDialer (caSupport , clusterDialer , clusterConfig .SecOpts .ServerRootCAs )
151
+ updateClusterDialer (caSupport , clusterDialer , clusterClientConfig .SecOpts .ServerRootCAs )
139
152
}
140
153
}
141
154
}
142
155
143
- manager := initializeMultichannelRegistrar (bootstrapBlock , clusterDialer , serverConfig , grpcServer , conf , signer , metricsProvider , lf , tlsCallback )
156
+ manager := initializeMultichannelRegistrar (bootstrapBlock , clusterDialer , clusterServerConfig , clusterGRPCServer , conf , signer , metricsProvider , lf , tlsCallback )
144
157
mutualTLS := serverConfig .SecOpts .UseTLS && serverConfig .SecOpts .RequireClientCert
145
158
server := NewServer (manager , metricsProvider , & conf .Debug , conf .General .Authentication .TimeWindow , mutualTLS )
146
159
147
160
logger .Infof ("Starting %s" , metadata .GetVersionInfo ())
148
161
go handleSignals (addPlatformSignals (map [os.Signal ]func (){
149
- syscall .SIGTERM : func () { grpcServer .Stop () },
162
+ syscall .SIGTERM : func () {
163
+ grpcServer .Stop ()
164
+ if clusterGRPCServer != grpcServer {
165
+ clusterGRPCServer .Stop ()
166
+ }
167
+ },
150
168
}))
169
+
170
+ if clusterGRPCServer != grpcServer {
171
+ logger .Info ("Starting cluster listener on" , clusterGRPCServer .Address ())
172
+ go clusterGRPCServer .Start ()
173
+ }
174
+
151
175
initializeProfilingService (conf )
152
176
ab .RegisterAtomicBroadcastServer (grpcServer .Server (), server )
153
177
logger .Info ("Beginning to serve requests" )
@@ -190,7 +214,75 @@ func handleSignals(handlers map[os.Signal]func()) {
190
214
}
191
215
}
192
216
193
- func initializeClusterConfig (conf * localconfig.TopLevel ) comm.ClientConfig {
217
+ type loadPEMFunc func (string ) ([]byte , error )
218
+
219
+ // configureClusterListener gets a ServerConfig and a GRPCServer, and:
220
+ // 1) If the TopLevel configuration states that the cluster configuration for the cluster gRPC service is missing, returns them back.
221
+ // 2) Else, returns a new ServerConfig and a new gRPC server (with its own TLS listener on a different port).
222
+ func configureClusterListener (conf * localconfig.TopLevel , generalConf comm.ServerConfig , generalSrv * comm.GRPCServer , loadPEM loadPEMFunc ) (comm.ServerConfig , * comm.GRPCServer ) {
223
+ clusterConf := conf .General .Cluster
224
+ // If listen address is not configured, or the TLS certificate isn't configured,
225
+ // it means we use the general listener of the node.
226
+ if clusterConf .ListenPort == 0 && clusterConf .ServerCertificate == "" && clusterConf .ListenAddress == "" && clusterConf .ServerPrivateKey == "" {
227
+ logger .Info ("Cluster listener is not configured, defaulting to use the general listener on port" , conf .General .ListenPort )
228
+ return generalConf , generalSrv
229
+ }
230
+
231
+ // Else, one of the above is defined, so all 4 properties should be defined.
232
+ if clusterConf .ListenPort == 0 || clusterConf .ServerCertificate == "" || clusterConf .ListenAddress == "" || clusterConf .ServerPrivateKey == "" {
233
+ logger .Panic ("Options: General.Cluster.ListenPort, General.Cluster.ListenAddress, General.Cluster.ServerCertificate," +
234
+ " General.Cluster.ServerPrivateKey, should be defined altogether." )
235
+ }
236
+
237
+ cert , err := loadPEM (clusterConf .ServerCertificate )
238
+ if err != nil {
239
+ logger .Panicf ("Failed to load cluster server certificate from '%s' (%s)" , clusterConf .ServerCertificate , err )
240
+ }
241
+
242
+ key , err := loadPEM (clusterConf .ServerPrivateKey )
243
+ if err != nil {
244
+ logger .Panicf ("Failed to load cluster server key from '%s' (%s)" , clusterConf .ServerPrivateKey , err )
245
+ }
246
+
247
+ port := fmt .Sprintf ("%d" , clusterConf .ListenPort )
248
+ bindAddr := net .JoinHostPort (clusterConf .ListenAddress , port )
249
+
250
+ var clientRootCAs [][]byte
251
+ for _ , serverRoot := range conf .General .Cluster .RootCAs {
252
+ rootCACert , err := loadPEM (serverRoot )
253
+ if err != nil {
254
+ logger .Panicf ("Failed to load CA cert file '%s' (%s)" ,
255
+ err , serverRoot )
256
+ }
257
+ clientRootCAs = append (clientRootCAs , rootCACert )
258
+ }
259
+
260
+ serverConf := comm.ServerConfig {
261
+ StreamInterceptors : generalConf .StreamInterceptors ,
262
+ UnaryInterceptors : generalConf .UnaryInterceptors ,
263
+ ConnectionTimeout : generalConf .ConnectionTimeout ,
264
+ MetricsProvider : generalConf .MetricsProvider ,
265
+ Logger : generalConf .Logger ,
266
+ KaOpts : generalConf .KaOpts ,
267
+ SecOpts : & comm.SecureOptions {
268
+ CipherSuites : comm .DefaultTLSCipherSuites ,
269
+ ClientRootCAs : clientRootCAs ,
270
+ RequireClientCert : true ,
271
+ Certificate : cert ,
272
+ UseTLS : true ,
273
+ Key : key ,
274
+ },
275
+ }
276
+
277
+ srv , err := comm .NewGRPCServer (bindAddr , serverConf )
278
+ if err != nil {
279
+ logger .Panicf ("Failed creating gRPC server on %s:%d due to %v" , clusterConf .ListenAddress , clusterConf .ListenPort , err )
280
+ }
281
+
282
+ return serverConf , srv
283
+ }
284
+
285
+ func initializeClusterClientConfig (conf * localconfig.TopLevel ) comm.ClientConfig {
194
286
cc := comm.ClientConfig {
195
287
AsyncConnect : true ,
196
288
KaOpts : comm .DefaultKeepaliveOptions ,
@@ -455,8 +547,7 @@ func newOperationsSystem(ops localconfig.Operations, metrics localconfig.Metrics
455
547
})
456
548
}
457
549
458
- func updateTrustedRoots (srv * comm.GRPCServer , rootCASupport * comm.CASupport ,
459
- cm channelconfig.Resources ) {
550
+ func updateTrustedRoots (rootCASupport * comm.CASupport , cm channelconfig.Resources , servers ... * comm.GRPCServer ) {
460
551
rootCASupport .Lock ()
461
552
defer rootCASupport .Unlock ()
462
553
@@ -541,12 +632,14 @@ func updateTrustedRoots(srv *comm.GRPCServer, rootCASupport *comm.CASupport,
541
632
}
542
633
543
634
// now update the client roots for the gRPC server
544
- err = srv .SetClientRootCAs (trustedRoots )
545
- if err != nil {
546
- msg := "Failed to update trusted roots for orderer from latest config " +
547
- "block. This orderer may not be able to communicate " +
548
- "with members of channel %s (%s)"
549
- logger .Warningf (msg , cm .ConfigtxValidator ().ChainID (), err )
635
+ for _ , srv := range servers {
636
+ err = srv .SetClientRootCAs (trustedRoots )
637
+ if err != nil {
638
+ msg := "Failed to update trusted roots for orderer from latest config " +
639
+ "block. This orderer may not be able to communicate " +
640
+ "with members of channel %s (%s)"
641
+ logger .Warningf (msg , cm .ConfigtxValidator ().ChainID (), err )
642
+ }
550
643
}
551
644
}
552
645
0 commit comments