Search in sources :

Example 1 with BftsmartClientIncomingConfig

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;
}
Also used : BftsmartTopology(com.jd.blockchain.consensus.bftsmart.BftsmartTopology) BftsmartClientIncomingConfig(com.jd.blockchain.consensus.bftsmart.BftsmartClientIncomingConfig) BftsmartSessionCredential(com.jd.blockchain.consensus.bftsmart.BftsmartSessionCredential) BftsmartSessionCredentialConfig(com.jd.blockchain.consensus.bftsmart.client.BftsmartSessionCredentialConfig)

Example 2 with BftsmartClientIncomingConfig

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);
        });
    }
}
Also used : BftsmartMessageService(com.jd.blockchain.consensus.bftsmart.client.BftsmartMessageService) BftsmartConsensusClient(com.jd.blockchain.consensus.bftsmart.client.BftsmartConsensusClient) BftsmartClientIncomingConfig(com.jd.blockchain.consensus.bftsmart.BftsmartClientIncomingConfig) BlockchainKeypair(com.jd.blockchain.ledger.BlockchainKeypair) BftsmartSessionCredentialConfig(com.jd.blockchain.consensus.bftsmart.client.BftsmartSessionCredentialConfig) BftsmartClientConfig(com.jd.blockchain.consensus.bftsmart.client.BftsmartClientConfig)

Aggregations

BftsmartClientIncomingConfig (com.jd.blockchain.consensus.bftsmart.BftsmartClientIncomingConfig)2 BftsmartSessionCredentialConfig (com.jd.blockchain.consensus.bftsmart.client.BftsmartSessionCredentialConfig)2 BftsmartSessionCredential (com.jd.blockchain.consensus.bftsmart.BftsmartSessionCredential)1 BftsmartTopology (com.jd.blockchain.consensus.bftsmart.BftsmartTopology)1 BftsmartClientConfig (com.jd.blockchain.consensus.bftsmart.client.BftsmartClientConfig)1 BftsmartConsensusClient (com.jd.blockchain.consensus.bftsmart.client.BftsmartConsensusClient)1 BftsmartMessageService (com.jd.blockchain.consensus.bftsmart.client.BftsmartMessageService)1 BlockchainKeypair (com.jd.blockchain.ledger.BlockchainKeypair)1