Search in sources :

Example 1 with RaftNetworkSettings

use of com.jd.blockchain.consensus.raft.settings.RaftNetworkSettings in project jdchain-core by blockchain-jd-com.

the class ParticipantManagerService4Raft method createRpcClient.

private CliClientServiceImpl createRpcClient(ParticipantContext context) {
    if (context.getProperty(RPC_CLIENT) != null) {
        return (CliClientServiceImpl) context.getProperty(RPC_CLIENT);
    }
    RaftConsensusSettings consensusSetting = (RaftConsensusSettings) getConsensusSetting(context);
    RaftNetworkSettings networkSettings = consensusSetting.getNetworkSettings();
    SSLSecurity sslSecurity = context.sslSecurity();
    // 启用TLS
    if (sslSecurity != null && sslSecurity.getKeyStore() != null) {
        GmSSLProvider.enableGMSupport(sslSecurity.getProtocol());
        setSystemProperty("bolt.client.ssl.enable", "true");
        setSystemProperty("bolt.client.ssl.keystore", sslSecurity.getTrustStore());
        setSystemProperty("bolt.client.ssl.keystore.password", sslSecurity.getTrustStorePassword());
        setSystemProperty("bolt.client.ssl.keystore.type", sslSecurity.getTrustStoreType() == null ? "JKS" : sslSecurity.getTrustStoreType());
        setSystemProperty("bolt.ssl.protocol", sslSecurity.getProtocol());
        setSystemProperty("bolt.server.ssl.enable", "true");
        setSystemProperty("bolt.server.ssl.keystore", sslSecurity.getKeyStore());
        setSystemProperty("bolt.server.ssl.keyalias", sslSecurity.getKeyAlias());
        setSystemProperty("bolt.server.ssl.keystore.password", sslSecurity.getKeyStorePassword());
        setSystemProperty("bolt.server.ssl.keystore.type", sslSecurity.getKeyStoreType());
        if (sslSecurity.getEnabledProtocols() != null && sslSecurity.getEnabledProtocols().length > 0) {
            setSystemProperty("bolt.ssl.enabled-protocols", String.join(",", sslSecurity.getEnabledProtocols()));
        }
        if (sslSecurity.getCiphers() != null && sslSecurity.getCiphers().length > 0) {
            setSystemProperty("bolt.ssl.ciphers", String.join(",", sslSecurity.getCiphers()));
        }
    }
    CliOptions cliOptions = new CliOptions();
    cliOptions.setRpcConnectTimeoutMs(networkSettings.getRpcConnectTimeoutMs());
    cliOptions.setRpcDefaultTimeout(networkSettings.getRpcDefaultTimeoutMs());
    cliOptions.setRpcInstallSnapshotTimeout(networkSettings.getRpcSnapshotTimeoutMs());
    cliOptions.setTimeoutMs(networkSettings.getRpcRequestTimeoutMs() * 2);
    cliOptions.setMaxRetry(MAX_RETRY_TIMES);
    CliClientServiceImpl clientService = new CliClientServiceImpl();
    clientService.init(cliOptions);
    context.setProperty(RPC_CLIENT, clientService);
    context.setProperty(RPC_QUEST_TIMEOUT_MS, networkSettings.getRpcRequestTimeoutMs() * 2);
    return clientService;
}
Also used : RaftNetworkSettings(com.jd.blockchain.consensus.raft.settings.RaftNetworkSettings) CliClientServiceImpl(com.alipay.sofa.jraft.rpc.impl.cli.CliClientServiceImpl) RaftConsensusSettings(com.jd.blockchain.consensus.raft.settings.RaftConsensusSettings) SSLSecurity(utils.net.SSLSecurity) CliOptions(com.alipay.sofa.jraft.option.CliOptions)

Aggregations

CliOptions (com.alipay.sofa.jraft.option.CliOptions)1 CliClientServiceImpl (com.alipay.sofa.jraft.rpc.impl.cli.CliClientServiceImpl)1 RaftConsensusSettings (com.jd.blockchain.consensus.raft.settings.RaftConsensusSettings)1 RaftNetworkSettings (com.jd.blockchain.consensus.raft.settings.RaftNetworkSettings)1 SSLSecurity (utils.net.SSLSecurity)1