use of com.jd.blockchain.consensus.bftsmart.BftsmartTopology 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.BftsmartTopology in project jdchain-core by blockchain-jd-com.
the class BftsmartPeerProxyFactory method create.
@Override
public AsynchServiceProxy create() throws Exception {
BftsmartTopology topology = BinarySerializeUtils.deserialize(bftsmartClientSettings.getTopology());
View view = topology.getView();
if (view == null) {
throw new IllegalStateException("No topology view in the bftsmart client settings!");
}
MemoryBasedViewStorage viewStorage = new MemoryBasedViewStorage(view);
TOMConfiguration tomConfiguration = BinarySerializeUtils.deserialize(bftsmartClientSettings.getTomConfig());
// every proxy client has unique id;
int processId = allocateId();
tomConfiguration.setProcessId(processId);
AsynchServiceProxy peerProxy = new AsynchServiceProxy(tomConfiguration, viewStorage, bftsmartClientSettings.getSSLSecurity());
if (LOGGER.isInfoEnabled()) {
// 打印view
int[] processes = view.getProcesses();
NodeNetwork[] addresses = new NodeNetwork[processes.length];
for (int i = 0; i < addresses.length; i++) {
addresses[i] = view.getAddress(processes[i]);
}
LOGGER.info("Creating pooled bftsmart client ... [PooledClientID={}] [ViewID={}] [ViewTopology={}] [Peers={}]", processId, view.getId(), Arrays.toString(processes), Arrays.toString(addresses));
}
return peerProxy;
}
use of com.jd.blockchain.consensus.bftsmart.BftsmartTopology in project jdchain-core by blockchain-jd-com.
the class BftsmartNodeServer method getOuterTopology.
private BftsmartTopology getOuterTopology() {
View currView = this.replica.getReplicaContext().getCurrentView();
int id = currView.getId();
int f = currView.getF();
int[] processes = currView.getProcesses();
NodeNetwork[] addresses = new NodeNetwork[processes.length];
for (int i = 0; i < processes.length; i++) {
int pid = processes[i];
if (serverId == pid) {
addresses[i] = new NodeNetwork(getTomConfig().getHost(pid), getTomConfig().getPort(pid), getTomConfig().getMonitorPort(pid), getTomConfig().isSecure(pid), getTomConfig().isMonitorSecure(pid));
} else {
addresses[i] = currView.getAddress(pid);
}
}
View returnView = new View(id, processes, f, addresses);
this.outerTopology = new BftsmartTopology(returnView);
return outerTopology;
}
Aggregations