From 856ab6683072172f5e1730431c5f8c597bdae3e5 Mon Sep 17 00:00:00 2001 From: shaozhuguang Date: Thu, 14 May 2020 15:43:10 +0800 Subject: [PATCH] modify bftsmart return topology --- .../bftsmart/service/BftsmartNodeServer.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) 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 de86c890..faf61155 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 @@ -1,12 +1,14 @@ package com.jd.blockchain.consensus.bftsmart.service; import java.io.ByteArrayOutputStream; +import java.net.InetSocketAddress; import java.util.*; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import bftsmart.consensus.app.BatchAppResultImpl; +import bftsmart.reconfiguration.views.View; import bftsmart.tom.*; import com.jd.blockchain.binaryproto.BinaryProtocol; import com.jd.blockchain.consensus.service.*; @@ -55,9 +57,10 @@ public class BftsmartNodeServer extends DefaultRecoverable implements NodeServer private BftsmartConsensusManageService manageService; - private volatile BftsmartTopology topology; + private volatile BftsmartTopology outerTopology; + private volatile BftsmartConsensusSettings setting; private TOMConfiguration tomConfig; @@ -190,6 +193,9 @@ public class BftsmartNodeServer extends DefaultRecoverable implements NodeServer } public BftsmartTopology getTopology() { + if (outerTopology != null) { + return outerTopology; + } return topology; } @@ -512,6 +518,7 @@ public class BftsmartNodeServer extends DefaultRecoverable implements NodeServer LOGGER.debug("Start replica...[ID=" + getId() + "]"); this.replica = new ServiceReplica(tomConfig, this, this); this.topology = new BftsmartTopology(replica.getReplicaContext().getCurrentView()); + initOutTopology(); status = Status.RUNNING; // createProxyClient(); LOGGER.debug( @@ -551,6 +558,24 @@ public class BftsmartNodeServer extends DefaultRecoverable implements NodeServer } } + private void initOutTopology() { + View currView = this.topology.getView(); + int id = currView.getId(); + int f = currView.getF(); + int[] processes = currView.getProcesses(); + InetSocketAddress[] addresses = new InetSocketAddress[processes.length]; + for (int i = 0; i < processes.length; i++) { + int pid = processes[i]; + if (id == pid) { + addresses[i] = new InetSocketAddress(this.outerTomConfig.getHost(id), this.outerTomConfig.getPort(id)); + } else { + addresses[i] = currView.getAddress(pid); + } + } + View returnView = new View(id, processes, f, addresses); + this.outerTopology = new BftsmartTopology(returnView); + } + enum Status { STARTING,