Search in sources :

Example 11 with NodeSettings

use of com.jd.blockchain.consensus.NodeSettings in project jdchain-core by blockchain-jd-com.

the class MsgQueueConsensusSettingsBuilder method convertToProperties.

@Override
public Properties convertToProperties(ConsensusViewSettings settings) {
    Properties props = new Properties();
    if (!(settings instanceof MsgQueueConsensusSettings)) {
        throw new IllegalArgumentException("ConsensusSettings data isn't supported! Accept MsgQueueConsensusSettings only!");
    }
    MsgQueueConsensusSettings consensusSettings = (MsgQueueConsensusSettings) settings;
    MsgQueueNetworkSettings networkSettings = consensusSettings.getNetworkSettings();
    if (networkSettings == null || networkSettings.getServer() == null || networkSettings.getServer().length() <= 0) {
        throw new IllegalArgumentException("MsgQueue Consensus server is empty!");
    }
    String server = networkSettings.getServer();
    props.setProperty(MSG_QUEUE_SERVER, server);
    String txTopic = networkSettings.getTxTopic();
    if (txTopic == null || txTopic.length() <= 0) {
        txTopic = DEFAULT_TOPIC_TX;
    }
    props.setProperty(MSG_QUEUE_TOPIC_TX, txTopic);
    String txResultTopic = networkSettings.getTxResultTopic();
    if (txResultTopic == null || txResultTopic.length() <= 0) {
        txResultTopic = DEFAULT_TOPIC_TX_RESULT;
    }
    props.setProperty(MSG_QUEUE_TOPIC_TX_RESULT, txResultTopic);
    String blockTopic = networkSettings.getBlockTopic();
    if (blockTopic == null || blockTopic.length() <= 0) {
        blockTopic = DEFAULT_TOPIC_BLOCK;
    }
    props.setProperty(MSG_QUEUE_TOPIC_BLOCK, blockTopic);
    String msgTopic = networkSettings.getMsgTopic();
    if (msgTopic == null || msgTopic.length() <= 0) {
        msgTopic = DEFAULT_TOPIC_MSG;
    }
    props.setProperty(MSG_QUEUE_TOPIC_MSG, msgTopic);
    String msgResultTopic = networkSettings.getMsgResultTopic();
    if (msgResultTopic == null || msgResultTopic.length() <= 0) {
        msgResultTopic = DEFAULT_TOPIC_MSG_RESULT;
    }
    props.setProperty(MSG_QUEUE_TOPIC_MSG_RESULT, msgResultTopic);
    MsgQueueBlockSettings blockSettings = consensusSettings.getBlockSettings();
    if (blockSettings == null) {
        props.setProperty(MSG_QUEUE_BLOCK_TXSIZE, DEFAULT_TXSIZE + "");
        props.setProperty(MSG_QUEUE_BLOCK_MAXDELAY, DEFAULT_MAXDELAY + "");
    } else {
        int txSize = blockSettings.getTxSizePerBlock();
        long maxDelay = blockSettings.getMaxDelayMilliSecondsPerBlock();
        props.setProperty(MSG_QUEUE_BLOCK_TXSIZE, txSize + "");
        props.setProperty(MSG_QUEUE_BLOCK_MAXDELAY, maxDelay + "");
    }
    NodeSettings[] nodes = consensusSettings.getNodes();
    props.setProperty(SERVER_NUM_KEY, nodes.length + "");
    for (int i = 0; i < nodes.length; i++) {
        props.setProperty(nodeKey(PUBKEY_PATTERN, i), nodes[i].getPubKey().toString());
    }
    return props;
}
Also used : NodeSettings(com.jd.blockchain.consensus.NodeSettings) MsgQueueNodeSettings(com.jd.blockchain.consensus.mq.settings.MsgQueueNodeSettings) MsgQueueConsensusSettings(com.jd.blockchain.consensus.mq.settings.MsgQueueConsensusSettings) MsgQueueBlockSettings(com.jd.blockchain.consensus.mq.settings.MsgQueueBlockSettings) Properties(java.util.Properties) MsgQueueNetworkSettings(com.jd.blockchain.consensus.mq.settings.MsgQueueNetworkSettings)

Example 12 with NodeSettings

use of com.jd.blockchain.consensus.NodeSettings in project jdchain-core by blockchain-jd-com.

the class BftsmartCommunication method getSession.

private synchronized NodeSession getSession(String target, boolean created) {
    BftsmartNodeSession session = targetSessions.get(target);
    if (session != null) {
        return session;
    }
    if (created) {
        BftsmartNodeSettings targetNodeSetting = null;
        BftsmartConsensusViewSettings viewSettings = serverSettings.getConsensusSettings();
        NodeSettings[] nodeSettings = viewSettings.getNodes();
        for (NodeSettings ns : nodeSettings) {
            if (ns.getAddress().equals(target)) {
                targetNodeSetting = (BftsmartNodeSettings) ns;
            }
        }
        if (targetNodeSetting == null) {
            return null;
        }
        session = new BftsmartNodeSession(serverSettings.getReplicaSettings().getAddress(), targetNodeSetting.getId(), target);
        targetSessions.put(target, session);
        return session;
    }
    return null;
}
Also used : BftsmartConsensusViewSettings(com.jd.blockchain.consensus.bftsmart.BftsmartConsensusViewSettings) NodeSettings(com.jd.blockchain.consensus.NodeSettings) BftsmartNodeSettings(com.jd.blockchain.consensus.bftsmart.BftsmartNodeSettings) BftsmartNodeSettings(com.jd.blockchain.consensus.bftsmart.BftsmartNodeSettings)

Example 13 with NodeSettings

use of com.jd.blockchain.consensus.NodeSettings 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)

Example 14 with NodeSettings

use of com.jd.blockchain.consensus.NodeSettings in project jdchain-core by blockchain-jd-com.

the class BftsmartNodeServerFactory method setupServer.

@Override
public NodeServer setupServer(ServerSettings serverSettings, MessageHandle messageHandler, StateMachineReplicate stateMachineReplicator, Storage runtimeStorage) {
    BftsmartServerSettings consensusSettings = (BftsmartServerSettings) serverSettings;
    NodeSettings[] currNodeSettings = consensusSettings.getConsensusSettings().getNodes();
    String currRealName = serverSettings.getRealmName();
    // check conflict realm
    if (!hasIntersection(currRealName, currNodeSettings)) {
        Storage nodeRuntimeStorage = runtimeStorage.getStorage("bftsmart");
        BftsmartNodeServer nodeServer = new BftsmartNodeServer(serverSettings, messageHandler, stateMachineReplicator, nodeRuntimeStorage, consensusSettings.getSslSecurity());
        nodeServerMap.put(serverSettings.getRealmName(), currNodeSettings);
        return nodeServer;
    } else {
        throw new IllegalArgumentException("setupServer serverSettings parameters error!");
    }
}
Also used : NodeSettings(com.jd.blockchain.consensus.NodeSettings) BftsmartNodeSettings(com.jd.blockchain.consensus.bftsmart.BftsmartNodeSettings) Storage(utils.io.Storage)

Example 15 with NodeSettings

use of com.jd.blockchain.consensus.NodeSettings in project jdchain-core by blockchain-jd-com.

the class BftsmartNodeServerFactory method getHashcode.

// compute hashcode for consensus nodes
private int getHashcode(NodeSettings[] nodeSettings) {
    int i = 0;
    NetworkAddress[] nodeAddrs = new NetworkAddress[nodeSettings.length];
    for (NodeSettings setting : nodeSettings) {
        nodeAddrs[i++] = ((BftsmartNodeSettings) setting).getNetworkAddress();
    }
    int hashCode = Arrays.hashCode(nodeAddrs);
    return hashCode;
}
Also used : NodeSettings(com.jd.blockchain.consensus.NodeSettings) BftsmartNodeSettings(com.jd.blockchain.consensus.bftsmart.BftsmartNodeSettings) NetworkAddress(utils.net.NetworkAddress)

Aggregations

NodeSettings (com.jd.blockchain.consensus.NodeSettings)17 BftsmartNodeSettings (com.jd.blockchain.consensus.bftsmart.BftsmartNodeSettings)7 RaftNodeSettings (com.jd.blockchain.consensus.raft.settings.RaftNodeSettings)6 MsgQueueConsensusSettings (com.jd.blockchain.consensus.mq.settings.MsgQueueConsensusSettings)4 MsgQueueNodeSettings (com.jd.blockchain.consensus.mq.settings.MsgQueueNodeSettings)4 MsgQueueNodeConfig (com.jd.blockchain.consensus.mq.config.MsgQueueNodeConfig)3 RaftConsensusSettings (com.jd.blockchain.consensus.raft.settings.RaftConsensusSettings)3 PubKey (com.jd.blockchain.crypto.PubKey)3 NetworkAddress (utils.net.NetworkAddress)3 BftsmartConsensusConfig (com.jd.blockchain.consensus.bftsmart.BftsmartConsensusConfig)2 BftsmartConsensusViewSettings (com.jd.blockchain.consensus.bftsmart.BftsmartConsensusViewSettings)2 BftsmartNodeConfig (com.jd.blockchain.consensus.bftsmart.BftsmartNodeConfig)2 MsgQueueConsensusConfig (com.jd.blockchain.consensus.mq.config.MsgQueueConsensusConfig)2 MsgQueueBlockSettings (com.jd.blockchain.consensus.mq.settings.MsgQueueBlockSettings)2 MsgQueueNetworkSettings (com.jd.blockchain.consensus.mq.settings.MsgQueueNetworkSettings)2 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2 HostsConfig (bftsmart.reconfiguration.util.HostsConfig)1 NodeNetwork (bftsmart.reconfiguration.views.NodeNetwork)1 Configuration (com.alipay.sofa.jraft.conf.Configuration)1