Skip to content

Commit c8cdbe1

Browse files
author
Brian Buchanan
committed
[FAB-9522] Remove TLSEnabled() from core/comm package
Removed the package scoped function and replaced the references with the underlying viper method. The performance difference between viper and the cached value is negligible. Change-Id: Ib3e644cee74df60572e5159282a11db0e619512d Signed-off-by: Brian Buchanan <bpbuch@gmail.com>
1 parent e8cc36f commit c8cdbe1

File tree

5 files changed

+5
-40
lines changed

5 files changed

+5
-40
lines changed

core/chaincode/shim/chaincode.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ var streamGetter peerStreamGetter
8080
//the non-mock user CC stream establishment func
8181
func userChaincodeStreamGetter(name string) (PeerChaincodeStream, error) {
8282
flag.StringVar(&peerAddress, "peer.address", "", "peer address")
83-
if comm.TLSEnabled() {
83+
if viper.GetBool("peer.tls.enabled") {
8484
keyPath := viper.GetString("tls.client.key.path")
8585
certPath := viper.GetString("tls.client.cert.path")
8686

@@ -254,7 +254,7 @@ func newPeerClientConnection() (*grpc.ClientConn, error) {
254254
ClientInterval: time.Duration(1) * time.Minute,
255255
ClientTimeout: time.Duration(20) * time.Second,
256256
}
257-
if comm.TLSEnabled() {
257+
if viper.GetBool("peer.tls.enabled") {
258258
return comm.NewClientConnectionWithAddress(peerAddress, true, true,
259259
comm.InitTLSForShim(key, cert), kaOpts)
260260
}

core/comm/config.go

-21
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,11 @@ import (
1010
"crypto/tls"
1111
"time"
1212

13-
"github.com/spf13/viper"
1413
"google.golang.org/grpc"
1514
"google.golang.org/grpc/keepalive"
1615
)
1716

1817
var (
19-
// Is the configuration cached?
20-
configurationCached = false
21-
// Is TLS enabled
22-
tlsEnabled bool
2318
// Max send and receive bytes for grpc clients and servers
2419
MaxRecvMsgSize = 100 * 1024 * 1024
2520
MaxSendMsgSize = 100 * 1024 * 1024
@@ -107,22 +102,6 @@ type KeepaliveOptions struct {
107102
ServerMinInterval time.Duration
108103
}
109104

110-
// cacheConfiguration caches common package scoped variables
111-
func cacheConfiguration() {
112-
if !configurationCached {
113-
tlsEnabled = viper.GetBool("peer.tls.enabled")
114-
configurationCached = true
115-
}
116-
}
117-
118-
// TLSEnabled return cached value for "peer.tls.enabled" configuration value
119-
func TLSEnabled() bool {
120-
if !configurationCached {
121-
cacheConfiguration()
122-
}
123-
return tlsEnabled
124-
}
125-
126105
// DefaultKeepaliveOptions returns sane default keepalive settings for gRPC
127106
// servers and clients
128107
func DefaultKeepaliveOptions() *KeepaliveOptions {

core/comm/config_test.go

-14
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,11 @@ package comm
99
import (
1010
"testing"
1111

12-
"github.com/spf13/viper"
1312
"github.com/stretchr/testify/assert"
1413
)
1514

1615
func TestConfig(t *testing.T) {
1716
t.Parallel()
1817
// check the defaults
1918
assert.EqualValues(t, keepaliveOptions, DefaultKeepaliveOptions())
20-
assert.EqualValues(t, false, TLSEnabled())
21-
assert.EqualValues(t, true, configurationCached)
22-
23-
// reset cache
24-
configurationCached = false
25-
viper.Set("peer.tls.enabled", true)
26-
assert.EqualValues(t, true, TLSEnabled())
27-
// check that value is cached
28-
viper.Set("peer.tls.enabled", false)
29-
assert.NotEqual(t, false, TLSEnabled())
30-
// reset tls
31-
configurationCached = false
32-
viper.Set("peer.tls.enabled", false)
3319
}

core/deliverservice/deliveryclient.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ func (d *deliverServiceImpl) Stop() {
215215

216216
func (d *deliverServiceImpl) newClient(chainID string, ledgerInfoProvider blocksprovider.LedgerInfo) *broadcastClient {
217217
requester := &blocksRequester{
218-
tls: comm.TLSEnabled(),
218+
tls: viper.GetBool("peer.tls.enabled"),
219219
chainID: chainID,
220220
}
221221
broadcastSetup := func(bd blocksprovider.BlocksDeliverer) error {
@@ -253,7 +253,7 @@ func DefaultConnectionFactory(channelID string) func(endpoint string) (*grpc.Cli
253253
}
254254
dialOpts = append(dialOpts, comm.ClientKeepaliveOptions(kaOpts)...)
255255

256-
if comm.TLSEnabled() {
256+
if viper.GetBool("peer.tls.enabled") {
257257
creds, err := comm.GetCredentialSupport().GetDeliverServiceCredentials(channelID)
258258
if err != nil {
259259
return nil, fmt.Errorf("Failed obtaining credentials for channel %s: %v", channelID, err)

peer/node/start.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ func serve(args []string) error {
280280
}
281281
dialOpts = append(dialOpts, comm.ClientKeepaliveOptions(kaOpts)...)
282282

283-
if comm.TLSEnabled() {
283+
if viper.GetBool("peer.tls.enabled") {
284284
dialOpts = append(dialOpts, grpc.WithTransportCredentials(comm.GetCredentialSupport().GetPeerCredentials()))
285285
} else {
286286
dialOpts = append(dialOpts, grpc.WithInsecure())

0 commit comments

Comments
 (0)