Browse Source

modify bftsmart return topology

tags/1.1.5
shaozhuguang 5 years ago
parent
commit
856ab66830
1 changed files with 26 additions and 1 deletions
  1. +26
    -1
      source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartNodeServer.java

+ 26
- 1
source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartNodeServer.java View File

@@ -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,


Loading…
Cancel
Save