From 18efe924dd7e2ef25dce46bd83c5d4e58f221b08 Mon Sep 17 00:00:00 2001 From: zhaoguangwei Date: Wed, 13 May 2020 20:19:10 +0800 Subject: [PATCH] use the outerTomConfig for gateway's auth; --- .../bftsmart/service/BftsmartNodeServer.java | 22 ++++++++++--------- .../tools/initializer/LedgerInitCommand.java | 10 +++++---- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartNodeServer.java b/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartNodeServer.java index 18fb7be0..de86c890 100644 --- a/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartNodeServer.java +++ b/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartNodeServer.java @@ -13,6 +13,8 @@ import com.jd.blockchain.consensus.service.*; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.ledger.*; import com.jd.blockchain.transaction.TxResponseMessage; +import com.jd.blockchain.utils.ConsoleUtils; +import com.jd.blockchain.utils.StringUtils; import com.jd.blockchain.utils.serialize.binary.BinarySerializeUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -60,7 +62,7 @@ public class BftsmartNodeServer extends DefaultRecoverable implements NodeServer private TOMConfiguration tomConfig; -// private TOMConfiguration outerTomConfig; + private TOMConfiguration outerTomConfig; private HostsConfig hostsConfig; private Properties systemConfig; @@ -130,26 +132,26 @@ public class BftsmartNodeServer extends DefaultRecoverable implements NodeServer } protected void initConfig(int id, Properties systemsConfig, HostsConfig hostConfig) { -// byte[] serialHostConf = BinarySerializeUtils.serialize(hostConfig); -// Properties sysConfClone = (Properties)systemsConfig.clone(); + byte[] serialHostConf = BinarySerializeUtils.serialize(hostConfig); + Properties sysConfClone = (Properties)systemsConfig.clone(); int port = hostConfig.getPort(id); // hostConfig.add(id, DEFAULT_BINDING_HOST, port); //if ledger-init.sh set up the -DhostIp=xxx, then get it; String preHostPort = System.getProperty("hostPort"); - if(preHostPort != null && preHostPort.length()>0){ + if(!StringUtils.isEmpty(preHostPort)){ port = NumberUtils.parseNumber(preHostPort, Integer.class); - System.out.println("###peer-startup.sh###,set up the -DhostPort="+port); + ConsoleUtils.info("###peer-startup.sh###,set up the -DhostPort="+port); } String preHostIp = System.getProperty("hostIp"); - if(preHostIp != null && preHostIp.length()>0){ + if(!StringUtils.isEmpty(preHostIp)){ hostConfig.add(id, preHostIp, port); - System.out.println("###peer-startup.sh###,set up the -DhostIp="+preHostIp); + ConsoleUtils.info("###peer-startup.sh###,set up the -DhostIp="+preHostIp); } this.tomConfig = new TOMConfiguration(id, systemsConfig, hostConfig); -// this.outerTomConfig = new TOMConfiguration(id, systemsConfig, hostConfig); + this.outerTomConfig = new TOMConfiguration(id, sysConfClone, BinarySerializeUtils.deserialize(serialHostConf)); } @Override @@ -168,7 +170,7 @@ public class BftsmartNodeServer extends DefaultRecoverable implements NodeServer } public TOMConfiguration getTomConfig() { - return tomConfig; + return outerTomConfig; } public int getId() { @@ -180,7 +182,7 @@ public class BftsmartNodeServer extends DefaultRecoverable implements NodeServer throw new IllegalArgumentException("ReplicaID is negative!"); } this.tomConfig.setProcessId(id); -// this.outerTomConfig.setProcessId(id); + this.outerTomConfig.setProcessId(id); } public BftsmartConsensusSettings getConsensusSetting() { diff --git a/source/tools/tools-initializer/src/main/java/com/jd/blockchain/tools/initializer/LedgerInitCommand.java b/source/tools/tools-initializer/src/main/java/com/jd/blockchain/tools/initializer/LedgerInitCommand.java index 71bfac65..bf51610d 100644 --- a/source/tools/tools-initializer/src/main/java/com/jd/blockchain/tools/initializer/LedgerInitCommand.java +++ b/source/tools/tools-initializer/src/main/java/com/jd/blockchain/tools/initializer/LedgerInitCommand.java @@ -2,6 +2,8 @@ package com.jd.blockchain.tools.initializer; import java.io.File; +import com.jd.blockchain.utils.ConsoleUtils; +import com.jd.blockchain.utils.StringUtils; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -209,15 +211,15 @@ public class LedgerInitCommand { //for dockers binding the 0.0.0.0; //if ledger-init.sh set up the -DhostPort=xxx -DhostIp=xxx, then get it; String preHostPort = System.getProperty("hostPort"); - if(preHostPort != null && preHostPort.length()>0){ + if(!StringUtils.isEmpty(preHostPort)){ int port = NumberUtils.parseNumber(preHostPort, Integer.class); serverAddress.setPort(port); - System.out.println("###ledger-init.sh###,set up the -DhostPort="+port); + ConsoleUtils.info("###ledger-init.sh###,set up the -DhostPort="+port); } String preHostIp = System.getProperty("hostIp"); - if(preHostIp != null && preHostIp.length()>0){ + if(!StringUtils.isEmpty(preHostIp)){ serverAddress.setHost(preHostIp); - System.out.println("###ledger-init.sh###,set up the -DhostIp="+preHostIp); + ConsoleUtils.info("###ledger-init.sh###,set up the -DhostIp="+preHostIp); } String argServerAddress = String.format("--server.address=%s", serverAddress.getHost());