Search in sources :

Example 1 with IntervalPropertyHelper

use of com.quorum.tessera.config.util.IntervalPropertyHelper in project tessera by ConsenSys.

the class ClientFactory method buildFrom.

/**
 * Creates a new client, which may or may not be SSL enabled or a unix socket enabled depending on
 * the configuration.
 *
 * @param config
 * @return
 * @see Client
 */
public Client buildFrom(final ServerConfig config) {
    final ClientBuilder clientBuilder = ClientBuilder.newBuilder();
    final long pollInterval = new IntervalPropertyHelper(config.getProperties()).partyInfoInterval();
    final long timeout = Math.round(Math.ceil(pollInterval * 0.75));
    clientBuilder.connectTimeout(timeout, TimeUnit.MILLISECONDS);
    clientBuilder.readTimeout(timeout, TimeUnit.MILLISECONDS);
    clientBuilder.register(VersionHeaderDecorator.class);
    if (config.isUnixSocket()) {
        Configuration clientConfig = createUnixServerSocketConfig();
        URI unixfile = config.getServerUri();
        return ClientBuilder.newClient(clientConfig).property("unixfile", unixfile);
    } else if (config.isSsl()) {
        final SSLContext sslContext = sslContextFactory.from(config.getServerUri().toString(), config.getSslConfig());
        return clientBuilder.sslContext(sslContext).build();
    } else {
        return clientBuilder.build();
    }
}
Also used : IntervalPropertyHelper(com.quorum.tessera.config.util.IntervalPropertyHelper) Configuration(jakarta.ws.rs.core.Configuration) SSLContext(javax.net.ssl.SSLContext) URI(java.net.URI) ClientBuilder(jakarta.ws.rs.client.ClientBuilder)

Example 2 with IntervalPropertyHelper

use of com.quorum.tessera.config.util.IntervalPropertyHelper in project tessera by ConsenSys.

the class ScheduledServiceFactory method build.

public void build() {
    IntervalPropertyHelper intervalPropertyHelper = new IntervalPropertyHelper(config.getP2PServerConfig().getProperties());
    LOGGER.info("Creating p2p client");
    P2pClient p2pClient = P2pClient.create();
    LOGGER.info("Created p2p client {}", p2pClient);
    if (enableSync) {
        ResendPartyStore resendPartyStore = ResendPartyStore.create();
        TransactionRequester transactionRequester = TransactionRequester.create();
        SyncPoller syncPoller = new SyncPoller(resendPartyStore, transactionRequester, p2pClient);
        ScheduledExecutorService scheduledExecutorService = java.util.concurrent.Executors.newSingleThreadScheduledExecutor();
        tesseraScheduledExecutors.add(new TesseraScheduledExecutor(scheduledExecutorService, syncPoller, intervalPropertyHelper.syncInterval(), 5000L));
    }
    LOGGER.info("Creating EnclaveKeySynchroniser");
    final EnclaveKeySynchroniser enclaveKeySynchroniser = ServiceLoader.load(EnclaveKeySynchroniser.class).stream().map(ServiceLoader.Provider::get).findFirst().get();
    LOGGER.info("Created EnclaveKeySynchroniser {}", enclaveKeySynchroniser);
    tesseraScheduledExecutors.add(new TesseraScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor(), () -> enclaveKeySynchroniser.syncKeys(), intervalPropertyHelper.enclaveKeySyncInterval(), 5000L));
    LOGGER.info("Creating PartyInfoBroadcaster");
    PartyInfoBroadcaster partyInfoPoller = new PartyInfoBroadcaster(p2pClient);
    LOGGER.info("Created PartyInfoBroadcaster {}", partyInfoPoller);
    tesseraScheduledExecutors.add(new TesseraScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor(), partyInfoPoller, intervalPropertyHelper.partyInfoInterval(), 5000L));
    tesseraScheduledExecutors.forEach(TesseraScheduledExecutor::start);
    LOGGER.info("Creating Enclave");
    Enclave enclave = Enclave.create();
    LOGGER.info("Created Enclave {}", enclave);
    serviceContainer = new ServiceContainer(enclave);
    LOGGER.info("Starting Enclave");
    serviceContainer.start();
    LOGGER.info("Started Enclave");
}
Also used : TransactionRequester(com.quorum.tessera.p2p.resend.TransactionRequester) TesseraScheduledExecutor(com.quorum.tessera.threading.TesseraScheduledExecutor) ResendPartyStore(com.quorum.tessera.p2p.resend.ResendPartyStore) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) IntervalPropertyHelper(com.quorum.tessera.config.util.IntervalPropertyHelper) SyncPoller(com.quorum.tessera.p2p.resend.SyncPoller) ServiceContainer(com.quorum.tessera.service.ServiceContainer) P2pClient(com.quorum.tessera.partyinfo.P2pClient) Enclave(com.quorum.tessera.enclave.Enclave) PartyInfoBroadcaster(com.quorum.tessera.p2p.partyinfo.PartyInfoBroadcaster) EnclaveKeySynchroniser(com.quorum.tessera.discovery.EnclaveKeySynchroniser)

Example 3 with IntervalPropertyHelper

use of com.quorum.tessera.config.util.IntervalPropertyHelper in project tessera by ConsenSys.

the class RecoveryClientProvider method provider.

public static RecoveryClient provider() {
    final Config config = ConfigFactory.create().getConfig();
    final ServerConfig serverConfig = config.getP2PServerConfig();
    final Map<String, String> properties = serverConfig.getProperties();
    final String waitTime = new IntervalPropertyHelper(properties).resendWaitTime();
    final SSLContextFactory clientSSLContextFactory = ClientSSLContextFactory.create();
    final ClientFactory clientFactory = new ClientFactory(clientSSLContextFactory);
    final Client client = clientFactory.buildFrom(config.getP2PServerConfig());
    client.property("jersey.config.client.readTimeout", waitTime);
    return new RestRecoveryClient(client);
}
Also used : ServerConfig(com.quorum.tessera.config.ServerConfig) IntervalPropertyHelper(com.quorum.tessera.config.util.IntervalPropertyHelper) Config(com.quorum.tessera.config.Config) ServerConfig(com.quorum.tessera.config.ServerConfig) ClientFactory(com.quorum.tessera.jaxrs.client.ClientFactory) ClientSSLContextFactory(com.quorum.tessera.ssl.context.ClientSSLContextFactory) SSLContextFactory(com.quorum.tessera.ssl.context.SSLContextFactory) Client(jakarta.ws.rs.client.Client)

Example 4 with IntervalPropertyHelper

use of com.quorum.tessera.config.util.IntervalPropertyHelper in project tessera by ConsenSys.

the class ResendClientProvider method provider.

public static ResendClient provider() {
    final Config config = ConfigFactory.create().getConfig();
    final ServerConfig serverConfig = config.getP2PServerConfig();
    final Map<String, String> properties = serverConfig.getProperties();
    final String waitTime = new IntervalPropertyHelper(properties).resendWaitTime();
    final SSLContextFactory clientSSLContextFactory = ClientSSLContextFactory.create();
    final ClientFactory clientFactory = new ClientFactory(clientSSLContextFactory);
    final Client client = clientFactory.buildFrom(config.getP2PServerConfig());
    client.property("jersey.config.client.readTimeout", waitTime);
    return new RestResendClient(client);
}
Also used : ServerConfig(com.quorum.tessera.config.ServerConfig) IntervalPropertyHelper(com.quorum.tessera.config.util.IntervalPropertyHelper) Config(com.quorum.tessera.config.Config) ServerConfig(com.quorum.tessera.config.ServerConfig) ClientFactory(com.quorum.tessera.jaxrs.client.ClientFactory) ClientSSLContextFactory(com.quorum.tessera.ssl.context.ClientSSLContextFactory) SSLContextFactory(com.quorum.tessera.ssl.context.SSLContextFactory) Client(jakarta.ws.rs.client.Client)

Aggregations

IntervalPropertyHelper (com.quorum.tessera.config.util.IntervalPropertyHelper)4 Config (com.quorum.tessera.config.Config)2 ServerConfig (com.quorum.tessera.config.ServerConfig)2 ClientFactory (com.quorum.tessera.jaxrs.client.ClientFactory)2 ClientSSLContextFactory (com.quorum.tessera.ssl.context.ClientSSLContextFactory)2 SSLContextFactory (com.quorum.tessera.ssl.context.SSLContextFactory)2 Client (jakarta.ws.rs.client.Client)2 EnclaveKeySynchroniser (com.quorum.tessera.discovery.EnclaveKeySynchroniser)1 Enclave (com.quorum.tessera.enclave.Enclave)1 PartyInfoBroadcaster (com.quorum.tessera.p2p.partyinfo.PartyInfoBroadcaster)1 ResendPartyStore (com.quorum.tessera.p2p.resend.ResendPartyStore)1 SyncPoller (com.quorum.tessera.p2p.resend.SyncPoller)1 TransactionRequester (com.quorum.tessera.p2p.resend.TransactionRequester)1 P2pClient (com.quorum.tessera.partyinfo.P2pClient)1 ServiceContainer (com.quorum.tessera.service.ServiceContainer)1 TesseraScheduledExecutor (com.quorum.tessera.threading.TesseraScheduledExecutor)1 ClientBuilder (jakarta.ws.rs.client.ClientBuilder)1 Configuration (jakarta.ws.rs.core.Configuration)1 URI (java.net.URI)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1