Search in sources :

Example 1 with HostsConfig

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

Example 2 with HostsConfig

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

Example 3 with HostsConfig

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

Example 4 with HostsConfig

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

Example 5 with HostsConfig

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!");
    }
}
Also used : BftsmartNodeSettings(com.jd.blockchain.consensus.bftsmart.BftsmartNodeSettings) HostsConfig(bftsmart.reconfiguration.util.HostsConfig) ArrayList(java.util.ArrayList) HostsConfig(bftsmart.reconfiguration.util.HostsConfig) Properties(java.util.Properties) View(bftsmart.reconfiguration.views.View) Random(java.util.Random) ServiceProxy(bftsmart.tom.ServiceProxy) MemoryBasedViewStorage(bftsmart.reconfiguration.views.MemoryBasedViewStorage) NodeNetwork(bftsmart.reconfiguration.views.NodeNetwork) TOMConfiguration(bftsmart.reconfiguration.util.TOMConfiguration)

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