Search in sources :

Example 1 with MsgQueueNetworkConfig

use of com.jd.blockchain.consensus.mq.config.MsgQueueNetworkConfig in project jdchain-core by blockchain-jd-com.

the class GatewayQueryServiceHandler method consensusSettingsDecorator.

private ConsensusViewSettings consensusSettingsDecorator(ConsensusViewSettings consensusSettings) {
    if (consensusSettings instanceof BftsmartConsensusViewSettings) {
        // bft-smart单独处理
        BftsmartConsensusViewSettings bftsmartConsensusSettings = (BftsmartConsensusViewSettings) consensusSettings;
        NodeSettings[] nodes = bftsmartConsensusSettings.getNodes();
        BftsmartNodeSettings[] bftsmartNodes = null;
        if (nodes != null && nodes.length > 0) {
            bftsmartNodes = new BftsmartNodeSettings[nodes.length];
            for (int i = 0; i < nodes.length; i++) {
                NodeSettings node = nodes[i];
                if (node instanceof BftsmartNodeSettings) {
                    BftsmartNodeSettings bftsmartNodeSettings = (BftsmartNodeSettings) node;
                    bftsmartNodes[i] = new BftsmartNodeConfig(bftsmartNodeSettings.getPubKey(), bftsmartNodeSettings.getId(), bftsmartNodeSettings.getNetworkAddress());
                }
            }
        }
        return new BftsmartConsensusConfig(bftsmartNodes, bftsmartConsensusSettings.getSystemConfigs(), 0);
    } else if (consensusSettings instanceof RaftConsensusSettings) {
        RaftConsensusSettings raftConsensusSettings = (RaftConsensusSettings) consensusSettings;
        NodeSettings[] nodes = raftConsensusSettings.getNodes();
        RaftNodeSettings[] raftNodeSettings = new RaftNodeSettings[0];
        if (nodes != null && nodes.length > 0) {
            raftNodeSettings = new RaftNodeSettings[nodes.length];
            for (int i = 0; i < nodes.length; i++) {
                NodeSettings node = nodes[i];
                if (node instanceof RaftNodeSettings) {
                    RaftNodeSettings raftNodeSetting = (RaftNodeSettings) node;
                    raftNodeSettings[i] = new RaftNodeConfig(raftNodeSetting.getId(), raftNodeSetting.getAddress(), raftNodeSetting.getPubKey(), raftNodeSetting.getNetworkAddress());
                }
            }
        }
        RaftConsensusConfig raftConsensusConfig = new RaftConsensusConfig();
        RaftConfig raftConfig = new RaftConfig();
        RaftNetworkConfig raftNetworkConfig = new RaftNetworkConfig();
        BeanUtils.copyProperties(raftConsensusSettings, raftConsensusConfig);
        BeanUtils.copyProperties(raftConsensusSettings.getRaftSettings(), raftConfig);
        BeanUtils.copyProperties(raftConsensusSettings.getNetworkSettings(), raftNetworkConfig);
        raftConsensusConfig.setNodeSettingsList(Arrays.asList(raftNodeSettings));
        raftConsensusConfig.setRaftSettings(raftConfig);
        raftConsensusConfig.setNetworkSettings(raftNetworkConfig);
        return raftConsensusConfig;
    } else if (consensusSettings instanceof MsgQueueConsensusSettings) {
        MsgQueueConsensusSettings mqConsensusSettings = (MsgQueueConsensusSettings) consensusSettings;
        MsgQueueConsensusConfig mqConsensusConfig = new MsgQueueConsensusConfig();
        MsgQueueBlockSettings blockSettings = mqConsensusSettings.getBlockSettings();
        MsgQueueBlockConfig mqQueueBlockConfig = new MsgQueueBlockConfig();
        mqQueueBlockConfig.setMaxDelayMilliSecondsPerBlock(blockSettings.getMaxDelayMilliSecondsPerBlock());
        mqQueueBlockConfig.setTxSizePerBlock(blockSettings.getTxSizePerBlock());
        mqConsensusConfig.setBlockSettings(mqQueueBlockConfig);
        MsgQueueNetworkSettings networkSettings = mqConsensusSettings.getNetworkSettings();
        MsgQueueNetworkConfig mqQueueNetworkConfig = new MsgQueueNetworkConfig();
        mqQueueNetworkConfig.setBlockTopic(networkSettings.getBlockTopic());
        mqQueueNetworkConfig.setMsgResultTopic(networkSettings.getMsgResultTopic());
        mqQueueNetworkConfig.setMsgTopic(networkSettings.getMsgTopic());
        mqQueueNetworkConfig.setServer(networkSettings.getServer());
        mqQueueNetworkConfig.setTxTopic(networkSettings.getTxTopic());
        mqQueueNetworkConfig.setTxResultTopic(networkSettings.getTxResultTopic());
        mqConsensusConfig.setNetworkSettings(mqQueueNetworkConfig);
        for (int i = 0; i < mqConsensusSettings.getNodes().length; i++) {
            MsgQueueNodeSettings nodeSettings = (MsgQueueNodeSettings) mqConsensusSettings.getNodes()[i];
            MsgQueueNodeConfig msgQueueNodeConfig = new MsgQueueNodeConfig();
            msgQueueNodeConfig.setAddress(nodeSettings.getAddress());
            msgQueueNodeConfig.setPubKey(nodeSettings.getPubKey());
            msgQueueNodeConfig.setId(nodeSettings.getId());
            mqConsensusConfig.addNodeSettings(msgQueueNodeConfig);
        }
        return mqConsensusConfig;
    }
    return consensusSettings;
}
Also used : BftsmartConsensusViewSettings(com.jd.blockchain.consensus.bftsmart.BftsmartConsensusViewSettings) RaftNetworkConfig(com.jd.blockchain.consensus.raft.config.RaftNetworkConfig) BftsmartNodeSettings(com.jd.blockchain.consensus.bftsmart.BftsmartNodeSettings) MsgQueueBlockSettings(com.jd.blockchain.consensus.mq.settings.MsgQueueBlockSettings) MsgQueueConsensusConfig(com.jd.blockchain.consensus.mq.config.MsgQueueConsensusConfig) MsgQueueBlockConfig(com.jd.blockchain.consensus.mq.config.MsgQueueBlockConfig) RaftConsensusSettings(com.jd.blockchain.consensus.raft.settings.RaftConsensusSettings) RaftConsensusConfig(com.jd.blockchain.consensus.raft.config.RaftConsensusConfig) NodeSettings(com.jd.blockchain.consensus.NodeSettings) RaftNodeSettings(com.jd.blockchain.consensus.raft.settings.RaftNodeSettings) MsgQueueNodeSettings(com.jd.blockchain.consensus.mq.settings.MsgQueueNodeSettings) BftsmartNodeSettings(com.jd.blockchain.consensus.bftsmart.BftsmartNodeSettings) RaftNodeSettings(com.jd.blockchain.consensus.raft.settings.RaftNodeSettings) MsgQueueConsensusSettings(com.jd.blockchain.consensus.mq.settings.MsgQueueConsensusSettings) RaftNodeConfig(com.jd.blockchain.consensus.raft.config.RaftNodeConfig) BftsmartConsensusConfig(com.jd.blockchain.consensus.bftsmart.BftsmartConsensusConfig) MsgQueueNodeConfig(com.jd.blockchain.consensus.mq.config.MsgQueueNodeConfig) MsgQueueNetworkConfig(com.jd.blockchain.consensus.mq.config.MsgQueueNetworkConfig) RaftConfig(com.jd.blockchain.consensus.raft.config.RaftConfig) MsgQueueNodeSettings(com.jd.blockchain.consensus.mq.settings.MsgQueueNodeSettings) BftsmartNodeConfig(com.jd.blockchain.consensus.bftsmart.BftsmartNodeConfig) MsgQueueNetworkSettings(com.jd.blockchain.consensus.mq.settings.MsgQueueNetworkSettings)

Example 2 with MsgQueueNetworkConfig

use of com.jd.blockchain.consensus.mq.config.MsgQueueNetworkConfig in project jdchain-core by blockchain-jd-com.

the class MsgQueueConsensusSettingsBuilder method createSettings.

@Override
public MsgQueueConsensusSettings createSettings(Properties props, Replica[] participantNodes) {
    MsgQueueNetworkConfig networkConfig = new MsgQueueNetworkConfig();
    Properties resolvingProps = PropertiesUtils.cloneFrom(props);
    String server = PropertiesUtils.getProperty(resolvingProps, MSG_QUEUE_SERVER, true);
    if (server == null || server.length() <= 0) {
        throw new IllegalArgumentException(String.format("Property[%s] is empty!", MSG_QUEUE_SERVER));
    }
    networkConfig.setServer(server).setTxTopic(initProp(resolvingProps, MSG_QUEUE_TOPIC_TX, DEFAULT_TOPIC_TX)).setTxResultTopic(initProp(resolvingProps, MSG_QUEUE_TOPIC_TX_RESULT, DEFAULT_TOPIC_TX_RESULT)).setBlockTopic(initProp(resolvingProps, MSG_QUEUE_TOPIC_BLOCK, DEFAULT_TOPIC_BLOCK)).setMsgTopic(initProp(resolvingProps, MSG_QUEUE_TOPIC_MSG, DEFAULT_TOPIC_MSG)).setMsgResultTopic(initProp(resolvingProps, MSG_QUEUE_TOPIC_MSG_RESULT, DEFAULT_TOPIC_MSG_RESULT));
    MsgQueueBlockConfig blockConfig = new MsgQueueBlockConfig().setTxSizePerBlock(initProp(resolvingProps, MSG_QUEUE_BLOCK_TXSIZE, DEFAULT_TXSIZE)).setMaxDelayMilliSecondsPerBlock(initProp(resolvingProps, MSG_QUEUE_BLOCK_MAXDELAY, DEFAULT_MAXDELAY));
    MsgQueueConsensusConfig consensusConfig = new MsgQueueConsensusConfig().setBlockSettings(blockConfig).setNetworkSettings(networkConfig);
    // load node settings
    int serversNum = PropertiesUtils.getInt(resolvingProps, SERVER_NUM_KEY);
    for (int i = 0; i < serversNum; i++) {
        int id = i;
        String keyOfPubkey = nodeKey(PUBKEY_PATTERN, id);
        String base58PubKey = PropertiesUtils.getRequiredProperty(resolvingProps, keyOfPubkey);
        PubKey pubKey = KeyGenUtils.decodePubKey(base58PubKey);
        // PubKey pubKey = new PubKey(Base58Utils.decode(base58PubKey));
        resolvingProps.remove(keyOfPubkey);
        Bytes address = AddressEncoding.generateAddress(pubKey);
        String networkAddress = address.toBase58();
        MsgQueueNodeConfig nodeConfig = new MsgQueueNodeConfig().setAddress(networkAddress).setPubKey(pubKey).setId(id);
        consensusConfig.addNodeSettings(nodeConfig);
    }
    return consensusConfig;
}
Also used : PubKey(com.jd.blockchain.crypto.PubKey) Bytes(utils.Bytes) MsgQueueConsensusConfig(com.jd.blockchain.consensus.mq.config.MsgQueueConsensusConfig) MsgQueueBlockConfig(com.jd.blockchain.consensus.mq.config.MsgQueueBlockConfig) MsgQueueNodeConfig(com.jd.blockchain.consensus.mq.config.MsgQueueNodeConfig) MsgQueueNetworkConfig(com.jd.blockchain.consensus.mq.config.MsgQueueNetworkConfig) Properties(java.util.Properties)

Aggregations

MsgQueueBlockConfig (com.jd.blockchain.consensus.mq.config.MsgQueueBlockConfig)2 MsgQueueConsensusConfig (com.jd.blockchain.consensus.mq.config.MsgQueueConsensusConfig)2 MsgQueueNetworkConfig (com.jd.blockchain.consensus.mq.config.MsgQueueNetworkConfig)2 MsgQueueNodeConfig (com.jd.blockchain.consensus.mq.config.MsgQueueNodeConfig)2 NodeSettings (com.jd.blockchain.consensus.NodeSettings)1 BftsmartConsensusConfig (com.jd.blockchain.consensus.bftsmart.BftsmartConsensusConfig)1 BftsmartConsensusViewSettings (com.jd.blockchain.consensus.bftsmart.BftsmartConsensusViewSettings)1 BftsmartNodeConfig (com.jd.blockchain.consensus.bftsmart.BftsmartNodeConfig)1 BftsmartNodeSettings (com.jd.blockchain.consensus.bftsmart.BftsmartNodeSettings)1 MsgQueueBlockSettings (com.jd.blockchain.consensus.mq.settings.MsgQueueBlockSettings)1 MsgQueueConsensusSettings (com.jd.blockchain.consensus.mq.settings.MsgQueueConsensusSettings)1 MsgQueueNetworkSettings (com.jd.blockchain.consensus.mq.settings.MsgQueueNetworkSettings)1 MsgQueueNodeSettings (com.jd.blockchain.consensus.mq.settings.MsgQueueNodeSettings)1 RaftConfig (com.jd.blockchain.consensus.raft.config.RaftConfig)1 RaftConsensusConfig (com.jd.blockchain.consensus.raft.config.RaftConsensusConfig)1 RaftNetworkConfig (com.jd.blockchain.consensus.raft.config.RaftNetworkConfig)1 RaftNodeConfig (com.jd.blockchain.consensus.raft.config.RaftNodeConfig)1 RaftConsensusSettings (com.jd.blockchain.consensus.raft.settings.RaftConsensusSettings)1 RaftNodeSettings (com.jd.blockchain.consensus.raft.settings.RaftNodeSettings)1 PubKey (com.jd.blockchain.crypto.PubKey)1