use of com.jd.blockchain.consensus.bftsmart.BftsmartClientIncomingConfig in project jdchain-core by blockchain-jd-com.
the class BftsmartClientAuthencationService method authencateIncoming.
@Override
public BftsmartClientIncomingSettings authencateIncoming(ClientCredential clientCredential) {
if (!verify(clientCredential)) {
return null;
}
BftsmartTopology topology = nodeServer.getTopology();
if (topology == null) {
throw new IllegalStateException("Topology of node[" + nodeServer.getId() + "] still not created !!!");
}
BftsmartClientIncomingConfig clientIncomingSettings = new BftsmartClientIncomingConfig();
clientIncomingSettings.setTopology(BinarySerializeUtils.serialize(topology));
clientIncomingSettings.setTomConfig(BinarySerializeUtils.serialize(nodeServer.getTomConfig()));
clientIncomingSettings.setViewSettings(nodeServer.getConsensusSetting());
clientIncomingSettings.setPubKey(clientCredential.getPubKey());
BftsmartSessionCredential sessionCredential = (BftsmartSessionCredential) clientCredential.getSessionCredential();
// 如果历史会话凭证的客户端ID是小于全局的最小客户端ID,则是无效的客户端ID,对其重新分配;
// 注:忽略历史会话凭证的客户端ID不属于当前节点的分配空间的情形,此种情形是由于该客户端是从其它共识节点重定向过来的,
// 应该继续维持该客户端的 ID 复用;
int clientId = sessionCredential.getClientId();
int clientIdRange = sessionCredential.getClientIdRange();
if (clientIdRange < 1 || clientIdRange > POOL_SIZE_PEER_CLIENT) {
clientIdRange = POOL_SIZE_PEER_CLIENT;
}
if (clientId < GLOBAL_MIN_CLIENT_ID) {
// 重新分配
clientId = allocateClientId(clientIdRange);
}
sessionCredential = new BftsmartSessionCredentialConfig(clientId, clientIdRange, System.currentTimeMillis());
clientIncomingSettings.setSessionCredential(sessionCredential);
return clientIncomingSettings;
}
use of com.jd.blockchain.consensus.bftsmart.BftsmartClientIncomingConfig in project jdchain-core by blockchain-jd-com.
the class ProxyClientTest method proxyClientSend.
public void proxyClientSend(BftsmartNodeServer nodeServer) {
BftsmartClientIncomingConfig clientIncomingConfig = new BftsmartClientIncomingConfig();
BlockchainKeypair keyPair = BlockchainKeyGenerator.getInstance().generate();
clientIncomingConfig.setPubKey(keyPair.getPubKey());
clientIncomingConfig.setSessionCredential(new BftsmartSessionCredentialConfig(0, 10, System.currentTimeMillis()));
clientIncomingConfig.setViewSettings(nodeServer.getConsensusSetting());
clientIncomingConfig.setTomConfig(BinarySerializeUtils.serialize(nodeServer.getTomConfig()));
clientIncomingConfig.setTopology(BinarySerializeUtils.serialize(nodeServer.getTopology()));
BftsmartClientConfig clientSettings = new BftsmartClientConfig(clientIncomingConfig);
BftsmartConsensusClient consensusClient = new BftsmartConsensusClient(clientSettings);
bytes = new byte[1024];
BftsmartMessageService messageService = (BftsmartMessageService) consensusClient.getMessageService();
for (int j = 0; j < number; j++) {
txSendPools.execute(() -> {
random.nextBytes(bytes);
messageService.sendOrdered(bytes);
});
}
}
Aggregations