use of utils.net.NetworkAddress in project jdchain-core by blockchain-jd-com.
the class QueryManagerInfoRequestProcessor method processRequest.
@Override
protected void processRequest(QueryManagerInfoRequest request, RpcResponseClosure done) throws Exception {
if (manager_info_cache.get() == null) {
synchronized (LOCK) {
if (manager_info_cache.get() == null) {
RaftNodeSettings raftNodeSettings = getNodeServerService().getNodeServer().getServerSettings().getRaftNodeSettings();
NetworkAddress raftNodeNetworkAddress = raftNodeSettings.getNetworkAddress();
ManagerInfoResponse response = new ManagerInfoResponse();
response.setManagerPort(RuntimeConstant.getMonitorPort());
response.setManagerSSLEnabled(RuntimeConstant.isMonitorSecure());
response.setHost(raftNodeNetworkAddress.getHost());
response.setConsensusPort(raftNodeNetworkAddress.getPort());
response.setConsensusSSLEnabled(raftNodeNetworkAddress.isSecure());
manager_info_cache.set(response.toBytes());
}
}
}
done.setResponse(RpcResponse.success(manager_info_cache.get()));
done.run(Status.OK());
}
use of utils.net.NetworkAddress in project jdchain-core by blockchain-jd-com.
the class RaftNodeConfig method init.
public void init(Properties props, int id) {
this.setId(id);
String host = props.getProperty(String.format(SYSTEM_SERVER_D_NETWORK_HOST, id));
int port = Integer.parseInt(props.getProperty(String.format(SYSTEM_SERVER_D_NETWORK_PORT, id)));
boolean secure = Boolean.parseBoolean(props.getProperty(String.format(SYSTEM_SERVER_D_NETWORK_SECURE, id)));
byte[] pubKeyBytes = Base58Utils.decode(props.getProperty(String.format(SYSTEM_SERVER_D_PUBKEY, id)));
PubKey pubKey = Crypto.resolveAsPubKey(pubKeyBytes);
this.setAddress(AddressEncoding.generateAddress(pubKey).toBase58());
this.setPubKey(pubKey);
this.setNetworkAddress(new NetworkAddress(host, port, secure));
}
use of utils.net.NetworkAddress in project jdchain-core by blockchain-jd-com.
the class LedgerAdminDatasetTest method verifyReadonlyState.
/**
* 验证指定账户是否只读;
*
* @param readonlyAccount
*/
private void verifyReadonlyState(LedgerAdminDataSetEditor readonlyAccount) {
ConsensusParticipantData newParti = new ConsensusParticipantData();
newParti.setId((int) readonlyAccount.getParticipantCount());
newParti.setHostAddress(new NetworkAddress("192.168.10." + (10 + newParti.getId()), 10010 + 10 * newParti.getId()));
newParti.setName("Participant[" + newParti.getAddress() + "]");
BlockchainKeypair newKey = BlockchainKeyGenerator.getInstance().generate();
newParti.setPubKey(newKey.getPubKey());
newParti.setParticipantState(ParticipantNodeState.CONSENSUS);
Throwable ex = null;
try {
readonlyAccount.addParticipant(newParti);
} catch (Exception e) {
ex = e;
}
assertNotNull(ex);
ex = null;
try {
LedgerConfiguration newLedgerSetting = new LedgerConfiguration(readonlyAccount.getSettings());
readonlyAccount.setLedgerSetting(newLedgerSetting);
} catch (Exception e) {
ex = e;
}
assertNotNull(ex);
}
use of utils.net.NetworkAddress in project jdchain-core by blockchain-jd-com.
the class LedgerInitOperationTest method test_LedgerInitOperation_ConsensusParticipantData.
@Test
public void test_LedgerInitOperation_ConsensusParticipantData() {
ConsensusParticipantData[] parties = new ConsensusParticipantData[4];
BlockchainKeypair[] keys = new BlockchainKeypair[parties.length];
for (int i = 0; i < parties.length; i++) {
keys[i] = BlockchainKeyGenerator.getInstance().generate();
parties[i] = new ConsensusParticipantData();
// parties[i].setId(i);
parties[i].setAddress(AddressEncoding.generateAddress(keys[i].getPubKey()));
parties[i].setHostAddress(new NetworkAddress("192.168.10." + (10 + i), 10010 + 10 * i));
parties[i].setName("Participant[" + i + "]");
parties[i].setPubKey(keys[i].getPubKey());
parties[i].setParticipantState(ParticipantNodeState.CONSENSUS);
}
ConsensusParticipantData[] parties1 = Arrays.copyOf(parties, 4);
ledgerInitSettingData.setConsensusParticipants(parties1);
ledgerInitSettingData.setIdentityMode(IdentityMode.KEYPAIR);
ledgerInitSettingData.setLedgerDataStructure(LedgerDataStructure.MERKLE_TREE);
LedgerInitOpTemplate template = new LedgerInitOpTemplate(ledgerInitSettingData);
byte[] encode = BinaryProtocol.encode(template, LedgerInitOperation.class);
LedgerInitOperation decode = BinaryProtocol.decode(encode);
for (int i = 0; i < template.getInitSetting().getConsensusParticipants().length; i++) {
assertEquals(template.getInitSetting().getConsensusParticipants()[i].getAddress(), decode.getInitSetting().getConsensusParticipants()[i].getAddress());
assertEquals(template.getInitSetting().getConsensusParticipants()[i].getName(), decode.getInitSetting().getConsensusParticipants()[i].getName());
assertEquals(template.getInitSetting().getConsensusParticipants()[i].getPubKey(), decode.getInitSetting().getConsensusParticipants()[i].getPubKey());
}
assertArrayEquals(template.getInitSetting().getLedgerSeed(), decode.getInitSetting().getLedgerSeed());
assertArrayEquals(template.getInitSetting().getConsensusSettings().toBytes(), decode.getInitSetting().getConsensusSettings().toBytes());
assertEquals(template.getInitSetting().getCryptoSetting().getHashAlgorithm(), decode.getInitSetting().getCryptoSetting().getHashAlgorithm());
assertEquals(template.getInitSetting().getCryptoSetting().getAutoVerifyHash(), decode.getInitSetting().getCryptoSetting().getAutoVerifyHash());
assertEquals(template.getInitSetting().getConsensusProvider(), decode.getInitSetting().getConsensusProvider());
}
use of utils.net.NetworkAddress in project jdchain-core by blockchain-jd-com.
the class LedgerManagerTest method createLedgerInitSetting.
private LedgerInitSetting createLedgerInitSetting() {
CryptoProvider[] supportedProviders = new CryptoProvider[SUPPORTED_PROVIDERS.length];
for (int i = 0; i < SUPPORTED_PROVIDERS.length; i++) {
supportedProviders[i] = Crypto.getProvider(SUPPORTED_PROVIDERS[i]);
}
CryptoConfig defCryptoSetting = new CryptoConfig();
defCryptoSetting.setSupportedProviders(supportedProviders);
defCryptoSetting.setAutoVerifyHash(true);
defCryptoSetting.setHashAlgorithm(ClassicAlgorithm.SHA256);
LedgerInitData initSetting = new LedgerInitData();
initSetting.setLedgerSeed(BytesUtils.toBytes("A Test Ledger seed!", "UTF-8"));
initSetting.setCryptoSetting(defCryptoSetting);
ConsensusParticipantData[] parties = new ConsensusParticipantData[4];
parties[0] = new ConsensusParticipantData();
parties[0].setId(0);
parties[0].setName("John");
AsymmetricKeypair kp0 = signatureFunction.generateKeypair();
parties[0].setPubKey(kp0.getPubKey());
parties[0].setAddress(AddressEncoding.generateAddress(kp0.getPubKey()));
parties[0].setHostAddress(new NetworkAddress("127.0.0.1", 9000));
parties[0].setParticipantState(ParticipantNodeState.CONSENSUS);
parties[1] = new ConsensusParticipantData();
parties[1].setId(1);
parties[1].setName("Mary");
AsymmetricKeypair kp1 = signatureFunction.generateKeypair();
parties[1].setPubKey(kp1.getPubKey());
parties[1].setAddress(AddressEncoding.generateAddress(kp1.getPubKey()));
parties[1].setHostAddress(new NetworkAddress("127.0.0.1", 9010));
parties[1].setParticipantState(ParticipantNodeState.CONSENSUS);
parties[2] = new ConsensusParticipantData();
parties[2].setId(2);
parties[2].setName("Jerry");
AsymmetricKeypair kp2 = signatureFunction.generateKeypair();
parties[2].setPubKey(kp2.getPubKey());
parties[2].setAddress(AddressEncoding.generateAddress(kp2.getPubKey()));
parties[2].setHostAddress(new NetworkAddress("127.0.0.1", 9020));
parties[2].setParticipantState(ParticipantNodeState.CONSENSUS);
parties[3] = new ConsensusParticipantData();
parties[3].setId(3);
parties[3].setName("Tom");
AsymmetricKeypair kp3 = signatureFunction.generateKeypair();
parties[3].setPubKey(kp3.getPubKey());
parties[3].setAddress(AddressEncoding.generateAddress(kp3.getPubKey()));
parties[3].setHostAddress(new NetworkAddress("127.0.0.1", 9030));
parties[3].setParticipantState(ParticipantNodeState.CONSENSUS);
initSetting.setConsensusParticipants(parties);
initSetting.setLedgerDataStructure(LedgerDataStructure.MERKLE_TREE);
initSetting.setIdentityMode(IdentityMode.KEYPAIR);
return initSetting;
}
Aggregations