Search in sources :

Example 6 with HostsConfig

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()]));
}
Also used : StringTokenizer(java.util.StringTokenizer) HostsConfig(bftsmart.reconfiguration.util.HostsConfig) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) HostsConfig(bftsmart.reconfiguration.util.HostsConfig) File(java.io.File) NodeNetwork(bftsmart.reconfiguration.views.NodeNetwork)

Example 7 with HostsConfig

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);
    });
}
Also used : HostsConfig(bftsmart.reconfiguration.util.HostsConfig)

Example 8 with HostsConfig

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;
}
Also used : HostsConfig(bftsmart.reconfiguration.util.HostsConfig) Properties(java.util.Properties) TOMConfiguration(bftsmart.reconfiguration.util.TOMConfiguration)

Example 9 with HostsConfig

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;
}
Also used : NodeSettings(com.jd.blockchain.consensus.NodeSettings) BftsmartNodeSettings(com.jd.blockchain.consensus.bftsmart.BftsmartNodeSettings) BftsmartNodeSettings(com.jd.blockchain.consensus.bftsmart.BftsmartNodeSettings) HostsConfig(bftsmart.reconfiguration.util.HostsConfig) ArrayList(java.util.ArrayList) HostsConfig(bftsmart.reconfiguration.util.HostsConfig) NodeNetwork(bftsmart.reconfiguration.views.NodeNetwork)

Aggregations

HostsConfig (bftsmart.reconfiguration.util.HostsConfig)9 TOMConfiguration (bftsmart.reconfiguration.util.TOMConfiguration)5 Properties (java.util.Properties)5 NodeNetwork (bftsmart.reconfiguration.views.NodeNetwork)4 View (bftsmart.reconfiguration.views.View)2 BftsmartNodeSettings (com.jd.blockchain.consensus.bftsmart.BftsmartNodeSettings)2 ArrayList (java.util.ArrayList)2 MemoryBasedViewStorage (bftsmart.reconfiguration.views.MemoryBasedViewStorage)1 ServiceProxy (bftsmart.tom.ServiceProxy)1 NodeSettings (com.jd.blockchain.consensus.NodeSettings)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileReader (java.io.FileReader)1 Random (java.util.Random)1 StringTokenizer (java.util.StringTokenizer)1 CountDownLatch (java.util.concurrent.CountDownLatch)1