use of bftsmart.reconfiguration.util.HostsConfig in project bftsmart by blockchain-jd-com.
the class ConsensusTest_ method generateHostsConfig.
private HostsConfig generateHostsConfig(int nodeSize) {
try {
String path = ConsensusTest_.class.getResource("/").toURI().getPath();
String dirPath = new File(path).getParentFile().getParentFile().getPath() + File.separator + "config";
FileReader fr = new FileReader(dirPath + File.separator + "hosts.config");
BufferedReader rd = new BufferedReader(fr);
String line = null;
int i = 0;
while (((line = rd.readLine()) != null) && i < nodeSize) {
if (!line.startsWith("#")) {
StringTokenizer str = new StringTokenizer(line, " ");
if (str.countTokens() > 2) {
int id = Integer.valueOf(str.nextToken());
String host = str.nextToken();
int consensusPort = Integer.valueOf(str.nextToken());
i++;
try {
int monitorPort = Integer.valueOf(str.nextToken());
configList.add(new HostsConfig.Config(id, host, consensusPort, monitorPort));
addresses.add(new NodeNetwork(host, consensusPort, monitorPort, false, false));
} catch (Exception e) {
configList.add(id, new HostsConfig.Config(id, host, consensusPort, -1));
addresses.add(new NodeNetwork(host, consensusPort, -1, false, false));
}
}
}
}
fr.close();
rd.close();
} catch (Exception e) {
e.printStackTrace(System.out);
}
return new HostsConfig(configList.toArray(new HostsConfig.Config[configList.size()]));
}
use of bftsmart.reconfiguration.util.HostsConfig in project bftsmart by blockchain-jd-com.
the class ConsensusTest_ method startConsensusNode.
private void startConsensusNode(int i) {
System.out.println("I will restart consensus node " + i);
TestNodeServer nodeServer = new TestNodeServer(i, latestView, systemConfig, new HostsConfig(configList.toArray(new HostsConfig.Config[configList.size()])));
serverNodes[i] = nodeServer;
nodeStartPools.execute(() -> {
nodeServer.startNode(realmName);
});
}
use of bftsmart.reconfiguration.util.HostsConfig in project bftsmart by blockchain-jd-com.
the class MACKeyGeneratorTest 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 jdchain-core by blockchain-jd-com.
the class BftsmartNodeServer method createConfig.
protected void createConfig() {
setting = ((BftsmartServerSettings) serverSettings).getConsensusSettings();
List<HostsConfig.Config> configList = new ArrayList<>();
NodeSettings[] nodeSettingsArray = setting.getNodes();
for (NodeSettings nodeSettings : nodeSettingsArray) {
BftsmartNodeSettings node = (BftsmartNodeSettings) nodeSettings;
if (node.getId() > MAX_SERVER_ID) {
// 节点 ID 不允许超过最大值;
throw new IllegalArgumentException(String.format("The id of node[%s | %s | %s] is large than MAX_SERVER_ID[%s]!", node.getId(), node.getAddress(), node.getNetworkAddress(), MAX_SERVER_ID));
}
LOGGER.info("createConfig node id = {}, port = {}", node.getId(), node.getNetworkAddress().getPort());
configList.add(new HostsConfig.Config(node.getId(), node.getNetworkAddress().getHost(), node.getNetworkAddress().getPort(), -1, node.getNetworkAddress().isSecure(), false));
consensusAddresses.put(node.getId(), new NodeNetwork(node.getNetworkAddress().getHost(), node.getNetworkAddress().getPort(), -1, node.getNetworkAddress().isSecure(), false));
}
// create HostsConfig instance based on consensus realm nodes
hostsConfig = new HostsConfig(configList.toArray(new HostsConfig.Config[configList.size()]));
systemConfig = PropertiesUtils.createProperties(setting.getSystemConfigs());
return;
}
Aggregations