use of bftsmart.reconfiguration.util.HostsConfig in project bftsmart by blockchain-jd-com.
the class ConsensusTest_ method initNode.
private void initNode(int nodeSize) {
CountDownLatch servers = new CountDownLatch(nodeSize);
serverNodes = new TestNodeServer[nodeSize];
// start nodeSize node servers
for (int i = 0; i < nodeSize; i++) {
serverNodes[i] = new TestNodeServer(i, latestView, systemConfig, new HostsConfig(configList.toArray(new HostsConfig.Config[configList.size()])));
TestNodeServer node = serverNodes[i];
nodeStartPools.execute(() -> {
node.startNode(realmName);
servers.countDown();
});
}
try {
servers.await();
Thread.sleep(40000);
} catch (Exception e) {
e.printStackTrace();
}
}
use of bftsmart.reconfiguration.util.HostsConfig in project bftsmart by blockchain-jd-com.
the class SystemMessageCodecTest method generateConfig.
private static ReplicaConfiguration generateConfig(int id, int[] viewProcessIds) {
HostsConfig hosts = new HostsConfig();
hosts.add(0, "localhost", 10010, 10012);
hosts.add(1, "localhost", 10020, 10022);
hosts.add(2, "localhost", 10030, 10032);
hosts.add(3, "localhost", 10040, 10042);
TOMConfiguration conf = new TOMConfiguration(0, new Properties(), hosts);
return conf;
}
use of bftsmart.reconfiguration.util.HostsConfig in project bftsmart by blockchain-jd-com.
the class CommunicationtTestMocker method mockDefaultConfiguration.
public static ReplicaConfiguration mockDefaultConfiguration(int currentId, int[] processIds, int[] ports) {
HostsConfig hosts = new HostsConfig();
for (int i = 0; i < processIds.length; i++) {
int port = ports == null ? 0 : ports[i];
hosts.add(processIds[i], "localhost", port, 0);
}
TOMConfiguration conf = new TOMConfiguration(currentId, new Properties(), hosts);
conf = Mockito.spy(conf);
when(conf.getProcessId()).thenReturn(currentId);
when(conf.getInQueueSize()).thenReturn(100000);
when(conf.getOutQueueSize()).thenReturn(100000);
return conf;
// ReplicaConfiguration conf = mockConfiguration(currentId, processIds);
//
// when(conf.getServerToServerPort(anyInt())).thenAnswer(new Answer<Integer>() {
// @Override
// public Integer answer(InvocationOnMock invocation) throws Throwable {
// int id = invocation.getArgument(0);
// for (int i = 0; i < processIds.length; i++) {
// if (processIds[i] == id) {
// return ports[i];
// }
// }
// throw new IllegalArgumentException(
// "The id[" + id + "] is out of range[" + Arrays.toString(processIds) + "]!");
// }
// });
// return conf;
}
use of bftsmart.reconfiguration.util.HostsConfig in project jdchain-core by blockchain-jd-com.
the class BftsmartNodeServer method initConfig.
protected void initConfig(int id, Properties systemsConfig, HostsConfig hostConfig) {
HostsConfig outerHostConfig = BinarySerializeUtils.deserialize(BinarySerializeUtils.serialize(hostConfig));
Properties sysConfClone = (Properties) systemsConfig.clone();
int port = hostConfig.getPort(id);
boolean isSecure = hostConfig.isSecure(id);
// hostConfig.add(id, DEFAULT_BINDING_HOST, port);
// if peer-startup.sh set up the -DhostIp=xxx, then get it;
String preHostPort = System.getProperty("hostPort");
if (!StringUtils.isEmpty(preHostPort)) {
port = NumberUtils.parseNumber(preHostPort, Integer.class);
LOGGER.info("###peer-startup.sh###,set up the -DhostPort=" + port);
}
int monitorPort = RuntimeConstant.getMonitorPort();
boolean monitorSecure = RuntimeConstant.isMonitorSecure();
String preHostIp = System.getProperty("hostIp");
if (!StringUtils.isEmpty(preHostIp)) {
hostConfig.add(id, preHostIp, port, monitorPort, isSecure, monitorSecure);
LOGGER.info("###peer-startup.sh###,set up the -DhostIp=" + preHostIp);
LOGGER.info("###peer-startup.sh###,isSecure=" + isSecure);
}
// 调整视图中的本节点端口号
consensusAddresses.get(id).setMonitorPort(monitorPort);
consensusAddresses.get(id).setMonitorSecure(monitorSecure);
this.tomConfig = new TOMConfiguration(id, systemsConfig, hostConfig, outerHostConfig);
Collection<NodeNetwork> nodeNetworks = consensusAddresses.values();
NodeNetwork[] nodeNetworksArray = new NodeNetwork[nodeNetworks.size()];
// 保证处理器ID与共识端口一致性
int[] init_view = new int[consensusAddresses.size()];
int i = 0;
for (int proid : consensusAddresses.keySet()) {
init_view[i++] = proid;
}
this.latestView = new View(setting.getViewId(), init_view, tomConfig.getF(), nodeNetworks.toArray(nodeNetworksArray));
LOGGER.info("[initConfig] latestview = {}", this.latestView);
this.outerTomConfig = new TOMConfiguration(id, sysConfClone, outerHostConfig);
}
use of bftsmart.reconfiguration.util.HostsConfig in project jdchain-core by blockchain-jd-com.
the class ParticipantManagerService4Bft method createPeerProxy.
private ServiceProxy createPeerProxy(Properties systemConfig, int viewId, List<NodeSettings> origConsensusNodes, SSLSecurity security) {
HostsConfig hostsConfig;
List<HostsConfig.Config> configList = new ArrayList<>();
List<NodeNetwork> nodeAddresses = new ArrayList<>();
try {
int[] origConsensusProcesses = new int[origConsensusNodes.size()];
for (int i = 0; i < origConsensusNodes.size(); i++) {
BftsmartNodeSettings node = (BftsmartNodeSettings) origConsensusNodes.get(i);
origConsensusProcesses[i] = node.getId();
configList.add(new HostsConfig.Config(node.getId(), node.getNetworkAddress().getHost(), node.getNetworkAddress().getPort(), -1, node.getNetworkAddress().isSecure(), false));
nodeAddresses.add(new NodeNetwork(node.getNetworkAddress().getHost(), node.getNetworkAddress().getPort(), -1, node.getNetworkAddress().isSecure(), false));
}
// 构建共识的代理客户端需要的主机配置和系统参数配置结构
hostsConfig = new HostsConfig(configList.toArray(new HostsConfig.Config[configList.size()]));
Properties tempSystemConfig = (Properties) systemConfig.clone();
// 构建tom 配置
TOMConfiguration tomConfig = new TOMConfiguration(-(new Random().nextInt(Integer.MAX_VALUE - 2) - 1), tempSystemConfig, hostsConfig);
View view = new View(viewId, origConsensusProcesses, tomConfig.getF(), nodeAddresses.toArray(new NodeNetwork[nodeAddresses.size()]));
LOGGER.info("ManagementController start updateView operation!, current view : {}", view.toString());
// 构建共识的代理客户端,连接目标共识节点,并递交交易进行共识过程
return new ServiceProxy(tomConfig, new MemoryBasedViewStorage(view), null, null, security);
} catch (Exception e) {
throw new CreateProxyClientException("create proxy client exception!");
}
}
Aggregations