Skip to content

Commit 14f1aea

Browse files
committed
[FAB-1755] Replace orderer GRPC Server
https://jira.hyperledger.org/browse/FAB-1755 This sets the stage for enabling TLS for the orderer by replacing the direct use of the grpc pacakge for creating a server with the use of the GRPC server from the core/comm package * use comm.GRPCServer in main.go * add TLS config struct to localconfig * add config paramters to orderer.yaml Fixes FAB-1755 Change-Id: Icba2776c1e503021b2873c149949b2b3b0c686fa Signed-off-by: Gari Singh <[email protected]>
1 parent 7e52b66 commit 14f1aea

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

orderer/localconfig/config.go

+11
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,23 @@ type General struct {
4444
MaxWindowSize uint32
4545
ListenAddress string
4646
ListenPort uint16
47+
TLS TLS
4748
GenesisMethod string
4849
GenesisFile string
4950
Profile Profile
5051
LogLevel string
5152
}
5253

54+
//TLS contains config used to configure TLS for the grpc server
55+
type TLS struct {
56+
Enabled bool
57+
ServerKey string
58+
ServerCertificate string
59+
ServerRootCAs []string
60+
ClientAuthEnabled bool
61+
ClientRootCAs []string
62+
}
63+
5364
// Genesis contains config which is used by the provisional bootstrapper
5465
type Genesis struct {
5566
OrdererType string

orderer/main.go

+13-5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"os"
2727

2828
"github.com/hyperledger/fabric/common/flogging"
29+
"github.com/hyperledger/fabric/core/comm"
2930
"github.com/hyperledger/fabric/orderer/common/bootstrap/file"
3031
"github.com/hyperledger/fabric/orderer/common/bootstrap/provisional"
3132
"github.com/hyperledger/fabric/orderer/kafka"
@@ -41,7 +42,6 @@ import (
4142

4243
"github.com/Shopify/sarama"
4344
logging "github.com/op/go-logging"
44-
"google.golang.org/grpc"
4545
)
4646

4747
var logger = logging.MustGetLogger("orderer/main")
@@ -59,14 +59,22 @@ func main() {
5959
}()
6060
}
6161

62-
grpcServer := grpc.NewServer()
63-
6462
lis, err := net.Listen("tcp", fmt.Sprintf("%s:%d", conf.General.ListenAddress, conf.General.ListenPort))
6563
if err != nil {
6664
fmt.Println("Failed to listen:", err)
6765
return
6866
}
6967

68+
//Create GRPC server - return if an error occurs
69+
secureConfig := comm.SecureServerConfig{
70+
UseTLS: conf.General.TLS.Enabled,
71+
}
72+
grpcServer, err := comm.NewGRPCServerFromListener(lis, secureConfig)
73+
if err != nil {
74+
fmt.Println("Failed to return new GRPC server: ", err)
75+
return
76+
}
77+
7078
var lf ordererledger.Factory
7179
switch conf.General.LedgerType {
7280
case "file":
@@ -135,7 +143,7 @@ func main() {
135143
int(conf.General.MaxWindowSize),
136144
)
137145

138-
ab.RegisterAtomicBroadcastServer(grpcServer, server)
146+
ab.RegisterAtomicBroadcastServer(grpcServer.Server(), server)
139147
logger.Infof("Beginning to serve requests")
140-
grpcServer.Serve(lis)
148+
grpcServer.Start()
141149
}

orderer/orderer.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ General:
2727
# Listen port: The port on which to bind to listen
2828
ListenPort: 7050
2929

30+
# TLS: TLS settings for the GRPC server
31+
TLS:
32+
Enabled: false
33+
ServerKey:
34+
ServerCertificate:
35+
ServerRootCAs:
36+
ClientAuthEnabled: false
37+
ClientRootCAs:
38+
39+
3040
# Log Level: The level at which to log. This accepts logging specifications
3141
# per fabric/docs/Setup/logging-control.md
3242
LogLevel: info

0 commit comments

Comments
 (0)