use of com.jd.blockchain.consensus.NodeSettings in project jdchain-core by blockchain-jd-com.
the class RaftConsensusSettingsBuilder method convertToProperties.
@Override
public Properties convertToProperties(ConsensusViewSettings settings) {
if (!(settings instanceof RaftConsensusSettings)) {
throw new IllegalStateException("settings should be raft-consensus-settings type");
}
Properties properties = new Properties();
RaftConsensusConfig raftConsensusConfig = new RaftConsensusConfig((RaftConsensusSettings) settings);
PropertiesUtils.mergeFrom(properties, raftConsensusConfig.convert());
for (NodeSettings nodeSettings : raftConsensusConfig.getNodes()) {
PropertiesUtils.mergeFrom(properties, ((RaftNodeConfig) nodeSettings).convert());
}
RaftConfig raftConfig = (RaftConfig) raftConsensusConfig.getRaftSettings();
PropertiesUtils.mergeFrom(properties, raftConfig.convert());
RaftNetworkConfig raftNetworkConfig = (RaftNetworkConfig) raftConsensusConfig.getNetworkSettings();
PropertiesUtils.mergeFrom(properties, raftNetworkConfig.convert());
return properties;
}
use of com.jd.blockchain.consensus.NodeSettings in project jdchain-core by blockchain-jd-com.
the class MsgQueueNodeServerFactory method buildServerSettings.
@Override
public MsgQueueServerSettings buildServerSettings(String realmName, ConsensusViewSettings viewSettings, String nodeAddress, SSLSecurity sslSecurity, Properties properties) {
if (!(viewSettings instanceof MsgQueueConsensusSettings)) {
throw new IllegalArgumentException("ConsensusSettings data isn't supported! Accept MsgQueueConsensusSettings only!");
}
int id = -1;
for (NodeSettings nodeSettings : viewSettings.getNodes()) {
MsgQueueNodeSettings settings = (MsgQueueNodeSettings) nodeSettings;
if (settings.getAddress().equals(nodeAddress)) {
id = settings.getId();
break;
}
}
MsgQueueNodeSettings nodeSettings = new MsgQueueNodeConfig().setAddress(nodeAddress).setId(id);
MsgQueueServerSettings serverSettings = new MsgQueueServerConfig().setRealmName(realmName).setNodeSettings(nodeSettings).setConsensusSettings((MsgQueueConsensusSettings) viewSettings);
return serverSettings;
}
use of com.jd.blockchain.consensus.NodeSettings in project jdchain-core by blockchain-jd-com.
the class RaftNodeServer method init.
private void init(RaftServerSettings raftServerSettings) {
this.selfPeerId = nodeSettingsToPeerId(raftServerSettings.getReplicaSettings());
this.configuration = new Configuration();
for (NodeSettings nodeSettings : raftServerSettings.getConsensusSettings().getNodes()) {
this.configuration.addPeer(nodeSettingsToPeerId(nodeSettings));
}
if (!this.configuration.contains(selfPeerId)) {
this.configuration.addPeer(selfPeerId);
}
this.clientAuthencationService = new RaftClientAuthenticationService(this);
CliOptions cliOptions = new CliOptions();
cliOptions.setRpcConnectTimeoutMs(this.serverSettings.getRaftNetworkSettings().getRpcConnectTimeoutMs());
cliOptions.setRpcDefaultTimeout(this.serverSettings.getRaftNetworkSettings().getRpcDefaultTimeoutMs());
cliOptions.setRpcInstallSnapshotTimeout(this.serverSettings.getRaftNetworkSettings().getRpcSnapshotTimeoutMs());
this.raftClientService = (CliClientServiceImpl) ((CliServiceImpl) RaftServiceFactory.createAndInitCliService(cliOptions)).getCliClientService();
this.rpcClient = this.raftClientService.getRpcClient();
this.nodeOptions = initNodeOptions(raftServerSettings);
this.nodeOptions.setInitialConf(this.configuration);
LedgerRepository ledgerRepository = LedgerManageUtils.getLedgerRepository(this.ledgerHashDigest);
this.messageBus = new MessageBusComponent(raftServerSettings.getRaftSettings().getDisruptorBufferSize());
this.blockSerializer = new SimpleBlockSerializerService();
this.blockProposer = new BlockProposerService(ledgerRepository);
this.blockCommitter = new BlockCommitService(this.realmName, this.messageHandle, ledgerRepository, this.messageBus);
this.blockCommitter.registerCallBack((BlockCommitCallback) blockProposer);
this.blockSyncer = new BlockSyncService(ledgerRepository, this.rpcClient, this.serverSettings.getRaftNetworkSettings().getRpcRequestTimeoutMs());
messageBus.register(BLOCK_CATCH_UP_TOPIC, (Subcriber) this.blockSyncer);
this.stateMachine = new RaftConsensusStateMachine(this.blockCommitter, this.blockSerializer, this.blockSyncer, ledgerRepository);
this.nodeOptions.setFsm(stateMachine);
RaftNodeServerContext.getInstance().init(this);
}
use of com.jd.blockchain.consensus.NodeSettings in project jdchain-core by blockchain-jd-com.
the class ProxyClientTest method peerStart.
public void peerStart(BftsmartNodeServer[] nodeServers) {
BftsmartNodeSettings[] nodesSettings = new BftsmartNodeSettings[nodeNum];
for (int i = 0; i < nodeNum; i++) {
BlockchainKeypair keyPair = BlockchainKeyGenerator.getInstance().generate();
PubKey pubKey = keyPair.getPubKey();
NetworkAddress peerNodeServ = new NetworkAddress("127.0.0.1", peerStartPort + i * 10);
NodeSettings node = new BftsmartNodeConfig(pubKey, i, peerNodeServ);
nodesSettings[i] = (BftsmartNodeSettings) node;
}
BftsmartConsensusConfig consensusConfig = new BftsmartConsensusConfig(nodesSettings, PropertiesUtils.getOrderedValues(bftsmartConf), 0);
for (int j = 0; j < nodeNum; j++) {
BftsmartServerSettingConfig serverSettings = new BftsmartServerSettingConfig();
serverSettings.setReplicaSettings(nodesSettings[j]);
serverSettings.setConsensusSettings(consensusConfig);
BftsmartNodeServer server = new BftsmartNodeServer(serverSettings, null, null, new MemoryStorage("test"));
nodeServers[j] = server;
nodeStartPools.execute(() -> {
server.start();
startPeer.countDown();
});
}
}
use of com.jd.blockchain.consensus.NodeSettings in project jdchain-core by blockchain-jd-com.
the class MsgQueueConsensusSettingsBuilder method updateSettings.
@Override
public ConsensusViewSettings updateSettings(ConsensusViewSettings oldConsensusSettings, Properties newProps) {
String op = newProps.getProperty("participant.op");
int id = Integer.valueOf(newProps.getProperty("participant.id"));
String pubkeyBase58 = newProps.getProperty("system.server." + id + ".pubkey");
PubKey pubkey = Crypto.resolveAsPubKey(Base58Utils.decode(pubkeyBase58));
Bytes address = AddressEncoding.generateAddress(pubkey);
MsgQueueConsensusSettings consensusSettings = (MsgQueueConsensusSettings) oldConsensusSettings;
NodeSettings[] nodes = consensusSettings.getNodes();
List<MsgQueueNodeConfig> mqNodes = new ArrayList<>();
boolean needAdd = true;
for (NodeSettings settings : nodes) {
MsgQueueNodeSettings node = (MsgQueueNodeSettings) settings;
if (node.getPubKey().equals(pubkey)) {
if (op.equals("deactive")) {
needAdd = false;
continue;
}
} else {
MsgQueueNodeConfig nodeConfig = new MsgQueueNodeConfig();
nodeConfig.setAddress(node.getAddress());
nodeConfig.setPubKey(node.getPubKey());
nodeConfig.setId(node.getId());
mqNodes.add(nodeConfig);
}
}
if (needAdd) {
MsgQueueNodeConfig nodeConfig = new MsgQueueNodeConfig();
nodeConfig.setAddress(address.toString());
nodeConfig.setId(id);
nodeConfig.setPubKey(pubkey);
mqNodes.add(nodeConfig);
}
MsgQueueConsensusConfig newSettings = new MsgQueueConsensusConfig();
newSettings.setBlockSettings(consensusSettings.getBlockSettings());
newSettings.setNetworkSettings(consensusSettings.getNetworkSettings());
for (MsgQueueNodeConfig node : mqNodes) {
newSettings.addNodeSettings(node);
}
return newSettings;
}
Aggregations