Browse Source

add bftsmart return topology print

tags/1.1.5
shaozhuguang 5 years ago
parent
commit
9c99ec6d2c
2 changed files with 36 additions and 12 deletions
  1. +13
    -0
      source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/client/BftsmartPeerProxyFactory.java
  2. +23
    -12
      source/peer/src/main/java/com/jd/blockchain/peer/web/ManagementController.java

+ 13
- 0
source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/client/BftsmartPeerProxyFactory.java View File

@@ -2,6 +2,7 @@ package com.jd.blockchain.consensus.bftsmart.client;


import bftsmart.reconfiguration.util.TOMConfiguration; import bftsmart.reconfiguration.util.TOMConfiguration;
import bftsmart.reconfiguration.views.MemoryBasedViewStorage; import bftsmart.reconfiguration.views.MemoryBasedViewStorage;
import bftsmart.reconfiguration.views.View;
import bftsmart.tom.AsynchServiceProxy; import bftsmart.tom.AsynchServiceProxy;
import com.jd.blockchain.consensus.bftsmart.BftsmartConsensusConfig; import com.jd.blockchain.consensus.bftsmart.BftsmartConsensusConfig;
import com.jd.blockchain.consensus.bftsmart.BftsmartTopology; import com.jd.blockchain.consensus.bftsmart.BftsmartTopology;
@@ -11,6 +12,7 @@ import org.apache.commons.pool2.BasePooledObjectFactory;
import org.apache.commons.pool2.PooledObject; import org.apache.commons.pool2.PooledObject;
import org.apache.commons.pool2.impl.DefaultPooledObject; import org.apache.commons.pool2.impl.DefaultPooledObject;


import java.net.InetSocketAddress;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;


public class BftsmartPeerProxyFactory extends BasePooledObjectFactory<AsynchServiceProxy> { public class BftsmartPeerProxyFactory extends BasePooledObjectFactory<AsynchServiceProxy> {
@@ -31,6 +33,17 @@ public class BftsmartPeerProxyFactory extends BasePooledObjectFactory<AsynchServ


BftsmartTopology topology = BinarySerializeUtils.deserialize(bftsmartClientSettings.getTopology()); BftsmartTopology topology = BinarySerializeUtils.deserialize(bftsmartClientSettings.getTopology());


View view = topology.getView();
if (view != null) {
// 打印view
int[] processes = view.getProcesses();
for (int process : processes) {
InetSocketAddress address = view.getAddress(process);
System.out.printf("read topology id = %s, address = %s \r\n",
process, address);
}
}

MemoryBasedViewStorage viewStorage = new MemoryBasedViewStorage(topology.getView()); MemoryBasedViewStorage viewStorage = new MemoryBasedViewStorage(topology.getView());
TOMConfiguration tomConfiguration = BinarySerializeUtils.deserialize(bftsmartClientSettings.getTomConfig()); TOMConfiguration tomConfiguration = BinarySerializeUtils.deserialize(bftsmartClientSettings.getTomConfig());




+ 23
- 12
source/peer/src/main/java/com/jd/blockchain/peer/web/ManagementController.java View File

@@ -1,12 +1,18 @@
package com.jd.blockchain.peer.web; package com.jd.blockchain.peer.web;


import java.net.InetSocketAddress;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;


import bftsmart.reconfiguration.util.TOMConfiguration;
import bftsmart.reconfiguration.views.View;
import com.jd.blockchain.consensus.bftsmart.BftsmartClientIncomingSettings;
import com.jd.blockchain.consensus.bftsmart.BftsmartTopology;
import com.jd.blockchain.ledger.*; import com.jd.blockchain.ledger.*;
import com.jd.blockchain.utils.net.NetworkAddress; import com.jd.blockchain.utils.net.NetworkAddress;
import com.jd.blockchain.utils.serialize.binary.BinarySerializeUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -171,21 +177,26 @@ public class ManagementController implements LedgerBindingConfigAware, PeerManag
clientIncomingSettings = peer.getManageService().authClientIncoming(authId); clientIncomingSettings = peer.getManageService().authClientIncoming(authId);


//add for test the gateway connect to peer0; 20200514; //add for test the gateway connect to peer0; 20200514;
ConsensusSettings consensusSettings = clientIncomingSettings.getConsensusSettings();
if (consensusSettings instanceof BftsmartConsensusSettings) {
BftsmartConsensusSettings settings = (BftsmartConsensusSettings) consensusSettings;
NodeSettings[] nodeSettings = settings.getNodes();
if (nodeSettings != null) {
for (NodeSettings ns : nodeSettings) {
if (ns instanceof BftsmartNodeSettings) {
BftsmartNodeSettings bftNs = (BftsmartNodeSettings) ns;
NetworkAddress address = bftNs.getNetworkAddress();
System.out.printf("PartiNode id = %s, host = %s, port = %s \r\n", bftNs.getId(), address.getHost(), address.getPort());
}
if (clientIncomingSettings instanceof BftsmartClientIncomingSettings) {
BftsmartClientIncomingSettings bftsmartClientIncomingSettings = (BftsmartClientIncomingSettings) clientIncomingSettings;
byte[] topologyBytes = bftsmartClientIncomingSettings.getTopology();
byte[] tomConfigBytes = bftsmartClientIncomingSettings.getTomConfig();
BftsmartTopology topology = BinarySerializeUtils.deserialize(topologyBytes);
TOMConfiguration tomConfig = BinarySerializeUtils.deserialize(tomConfigBytes);
View view = topology.getView();
if (view != null) {
// 打印view
int[] processes = view.getProcesses();
for (int process : processes) {
InetSocketAddress address = view.getAddress(process);
System.out.printf("topology id = %s, address = %s \r\n",
process, address);

System.out.printf("tomConfig id = %s, host = %s, port = %s \r\n",
process, tomConfig.getHost(process), tomConfig.getPort(process));
} }
} }
} }

break; break;
} catch (Exception e) { } catch (Exception e) {
throw new AuthenticationServiceException(e.getMessage(), e); throw new AuthenticationServiceException(e.getMessage(), e);


Loading…
Cancel
Save