Skip to content

Commit 4139f2f

Browse files
use net.JoinHostPort to create endpoint (#318)
Signed-off-by: Dor.Katzelnick <[email protected]>
1 parent 46e09a4 commit 4139f2f

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

config/config.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ func (config *Configuration) ExtractRouterConfig(configBlock *common.Block) *nod
249249
PartyID: config.LocalConfig.NodeLocalConfig.PartyID,
250250
TLSCertificateFile: config.LocalConfig.TLSConfig.Certificate,
251251
TLSPrivateKeyFile: config.LocalConfig.TLSConfig.PrivateKey,
252-
ListenAddress: config.LocalConfig.NodeLocalConfig.GeneralConfig.ListenAddress + ":" + strconv.Itoa(int(config.LocalConfig.NodeLocalConfig.GeneralConfig.ListenPort)),
252+
ListenAddress: net.JoinHostPort(config.LocalConfig.NodeLocalConfig.GeneralConfig.ListenAddress, strconv.Itoa(int(config.LocalConfig.NodeLocalConfig.GeneralConfig.ListenPort))),
253253
ConfigStorePath: config.LocalConfig.NodeLocalConfig.FileStore.Path,
254254
Shards: config.ExtractShards(),
255255
Consenter: config.ExtractConsenterInParty(),
@@ -260,7 +260,7 @@ func (config *Configuration) ExtractRouterConfig(configBlock *common.Block) *nod
260260
RequestMaxBytes: config.SharedConfig.BatchingConfig.RequestMaxBytes,
261261
ClientSignatureVerificationRequired: config.LocalConfig.NodeLocalConfig.GeneralConfig.ClientSignatureVerificationRequired,
262262
Bundle: config.extractBundleFromConfigBlock(configBlock),
263-
MonitoringListenAddress: config.LocalConfig.NodeLocalConfig.GeneralConfig.MonitoringListenAddress + ":" + strconv.Itoa(int(config.LocalConfig.NodeLocalConfig.GeneralConfig.MonitoringListenPort)),
263+
MonitoringListenAddress: net.JoinHostPort(config.LocalConfig.NodeLocalConfig.GeneralConfig.MonitoringListenAddress, strconv.Itoa(int(config.LocalConfig.NodeLocalConfig.GeneralConfig.MonitoringListenPort))),
264264
MetricsLogInterval: config.LocalConfig.NodeLocalConfig.GeneralConfig.MetricsLogInterval,
265265
}
266266
return routerConfig
@@ -279,7 +279,7 @@ func (config *Configuration) ExtractBatcherConfig(configBlock *common.Block) *no
279279
Shards: config.ExtractShards(),
280280
Consenters: config.ExtractConsenters(),
281281
Directory: config.LocalConfig.NodeLocalConfig.FileStore.Path,
282-
ListenAddress: config.LocalConfig.NodeLocalConfig.GeneralConfig.ListenAddress + ":" + strconv.Itoa(int(config.LocalConfig.NodeLocalConfig.GeneralConfig.ListenPort)),
282+
ListenAddress: net.JoinHostPort(config.LocalConfig.NodeLocalConfig.GeneralConfig.ListenAddress, strconv.Itoa(int(config.LocalConfig.NodeLocalConfig.GeneralConfig.ListenPort))),
283283
ConfigStorePath: config.LocalConfig.NodeLocalConfig.FileStore.Path,
284284
PartyId: config.LocalConfig.NodeLocalConfig.PartyID,
285285
ShardId: config.LocalConfig.NodeLocalConfig.BatcherParams.ShardID,
@@ -292,7 +292,7 @@ func (config *Configuration) ExtractBatcherConfig(configBlock *common.Block) *no
292292
RequestMaxBytes: config.SharedConfig.BatchingConfig.RequestMaxBytes,
293293
SubmitTimeout: config.LocalConfig.NodeLocalConfig.BatcherParams.SubmitTimeout,
294294
BatchSequenceGap: types.BatchSequence(config.LocalConfig.NodeLocalConfig.BatcherParams.BatchSequenceGap),
295-
MonitoringListenAddress: config.LocalConfig.NodeLocalConfig.GeneralConfig.MonitoringListenAddress + ":" + strconv.Itoa(int(config.LocalConfig.NodeLocalConfig.GeneralConfig.MonitoringListenPort)),
295+
MonitoringListenAddress: net.JoinHostPort(config.LocalConfig.NodeLocalConfig.GeneralConfig.MonitoringListenAddress, strconv.Itoa(int(config.LocalConfig.NodeLocalConfig.GeneralConfig.MonitoringListenPort))),
296296
MetricsLogInterval: config.LocalConfig.NodeLocalConfig.GeneralConfig.MetricsLogInterval,
297297
ClientSignatureVerificationRequired: config.LocalConfig.NodeLocalConfig.GeneralConfig.ClientSignatureVerificationRequired,
298298
Bundle: config.extractBundleFromConfigBlock(configBlock),
@@ -334,14 +334,14 @@ func (config *Configuration) ExtractConsenterConfig() *nodeconfig.ConsenterNodeC
334334
Consenters: config.ExtractConsenters(),
335335
Router: config.ExtractRouterInParty(),
336336
Directory: config.LocalConfig.NodeLocalConfig.FileStore.Path,
337-
ListenAddress: config.LocalConfig.NodeLocalConfig.GeneralConfig.ListenAddress + ":" + strconv.Itoa(int(config.LocalConfig.NodeLocalConfig.GeneralConfig.ListenPort)),
337+
ListenAddress: net.JoinHostPort(config.LocalConfig.NodeLocalConfig.GeneralConfig.ListenAddress, strconv.Itoa(int(config.LocalConfig.NodeLocalConfig.GeneralConfig.ListenPort))),
338338
PartyId: config.LocalConfig.NodeLocalConfig.PartyID,
339339
TLSPrivateKeyFile: config.LocalConfig.TLSConfig.PrivateKey,
340340
TLSCertificateFile: config.LocalConfig.TLSConfig.Certificate,
341341
SigningPrivateKey: signingPrivateKey,
342342
WALDir: DefaultConsenterNodeConfigParams(config.LocalConfig.NodeLocalConfig.FileStore.Path).WALDir,
343343
BFTConfig: BFTConfig,
344-
MonitoringListenAddress: config.LocalConfig.NodeLocalConfig.GeneralConfig.MonitoringListenAddress + ":" + strconv.Itoa(int(config.LocalConfig.NodeLocalConfig.GeneralConfig.MonitoringListenPort)),
344+
MonitoringListenAddress: net.JoinHostPort(config.LocalConfig.NodeLocalConfig.GeneralConfig.MonitoringListenAddress, strconv.Itoa(int(config.LocalConfig.NodeLocalConfig.GeneralConfig.MonitoringListenPort))),
345345
MetricsLogInterval: config.LocalConfig.NodeLocalConfig.GeneralConfig.MetricsLogInterval,
346346
}
347347
return consenterConfig
@@ -365,7 +365,7 @@ func (config *Configuration) ExtractAssemblerConfig() *nodeconfig.AssemblerNodeC
365365
TLSCertificateFile: config.LocalConfig.TLSConfig.Certificate,
366366
PartyId: config.LocalConfig.NodeLocalConfig.PartyID,
367367
Directory: config.LocalConfig.NodeLocalConfig.FileStore.Path,
368-
ListenAddress: config.LocalConfig.NodeLocalConfig.GeneralConfig.ListenAddress + ":" + strconv.Itoa(int(config.LocalConfig.NodeLocalConfig.GeneralConfig.ListenPort)),
368+
ListenAddress: net.JoinHostPort(config.LocalConfig.NodeLocalConfig.GeneralConfig.ListenAddress, strconv.Itoa(int(config.LocalConfig.NodeLocalConfig.GeneralConfig.ListenPort))),
369369
PrefetchBufferMemoryBytes: config.LocalConfig.NodeLocalConfig.AssemblerParams.PrefetchBufferMemoryBytes,
370370
RestartLedgerScanTimeout: config.LocalConfig.NodeLocalConfig.AssemblerParams.RestartLedgerScanTimeout,
371371
PrefetchEvictionTtl: config.LocalConfig.NodeLocalConfig.AssemblerParams.PrefetchEvictionTtl,
@@ -376,7 +376,7 @@ func (config *Configuration) ExtractAssemblerConfig() *nodeconfig.AssemblerNodeC
376376
Consenter: consenterFromMyParty,
377377
UseTLS: config.LocalConfig.TLSConfig.Enabled,
378378
ClientAuthRequired: config.LocalConfig.TLSConfig.ClientAuthRequired,
379-
MonitoringListenAddress: config.LocalConfig.NodeLocalConfig.GeneralConfig.MonitoringListenAddress + ":" + strconv.Itoa(int(config.LocalConfig.NodeLocalConfig.GeneralConfig.MonitoringListenPort)),
379+
MonitoringListenAddress: net.JoinHostPort(config.LocalConfig.NodeLocalConfig.GeneralConfig.MonitoringListenAddress, strconv.Itoa(int(config.LocalConfig.NodeLocalConfig.GeneralConfig.MonitoringListenPort))),
380380
MetricsLogInterval: config.LocalConfig.NodeLocalConfig.GeneralConfig.MetricsLogInterval,
381381
}
382382
return assemblerConfig
@@ -398,7 +398,7 @@ func (config *Configuration) ExtractShards() []nodeconfig.ShardInfo {
398398

399399
batcher := nodeconfig.BatcherInfo{
400400
PartyID: types.PartyID(party.PartyID),
401-
Endpoint: batcher.Host + ":" + strconv.Itoa(int(batcher.Port)),
401+
Endpoint: net.JoinHostPort(batcher.Host, strconv.Itoa(int(batcher.Port))),
402402
TLSCACerts: tlsCACertsCollection,
403403
PublicKey: pemPublicKey,
404404
TLSCert: batcher.TlsCert,
@@ -436,7 +436,7 @@ func (config *Configuration) ExtractConsenters() []nodeconfig.ConsenterInfo {
436436

437437
consenterInfo := nodeconfig.ConsenterInfo{
438438
PartyID: types.PartyID(party.PartyID),
439-
Endpoint: party.ConsenterConfig.Host + ":" + strconv.Itoa(int(party.ConsenterConfig.Port)),
439+
Endpoint: net.JoinHostPort(party.ConsenterConfig.Host, strconv.Itoa(int(party.ConsenterConfig.Port))),
440440
PublicKey: pemPublicKey,
441441
TLSCACerts: tlsCACertsCollection,
442442
}

config/generate/config_block_gen.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"crypto/rand"
1313
"crypto/x509"
1414
"encoding/pem"
15+
"net"
1516
"os"
1617
"path/filepath"
1718
"strconv"
@@ -55,8 +56,8 @@ func CreateProfile(dir string, sharedConfigYaml *config.SharedConfigYaml, shared
5556
var consenterMapping []*genesisconfig.Consenter
5657
var routerAndAssemblerEndpoints []string
5758
for _, party := range sharedConfigYaml.PartiesConfig {
58-
routerAndAssemblerEndpoints = append(routerAndAssemblerEndpoints, party.RouterConfig.Host+":"+strconv.Itoa(int(party.RouterConfig.Port)))
59-
routerAndAssemblerEndpoints = append(routerAndAssemblerEndpoints, party.AssemblerConfig.Host+":"+strconv.Itoa(int(party.AssemblerConfig.Port)))
59+
routerAndAssemblerEndpoints = append(routerAndAssemblerEndpoints, net.JoinHostPort(party.RouterConfig.Host, strconv.Itoa(int(party.RouterConfig.Port))))
60+
routerAndAssemblerEndpoints = append(routerAndAssemblerEndpoints, net.JoinHostPort(party.AssemblerConfig.Host, strconv.Itoa(int(party.AssemblerConfig.Port))))
6061

6162
consenter := &genesisconfig.Consenter{
6263
ID: uint32(party.PartyID),

0 commit comments

Comments
 (0)