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;
}
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;
}
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;
}
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!");
}
}
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;
}
Aggregations