Search in sources :

Example 11 with RuntimeContext

use of com.quorum.tessera.context.RuntimeContext in project tessera by ConsenSys.

the class DiscoveryProvider method provider.

/**
 * @see java.util.ServiceLoader.Provider
 */
public static Discovery provider() {
    final DiscoveryHolder discoveryHolder = DiscoveryHolder.create();
    if (discoveryHolder.get().isPresent()) {
        return discoveryHolder.get().get();
    }
    final NetworkStore networkStore = NetworkStore.getInstance();
    final RuntimeContext runtimeContext = RuntimeContext.getInstance();
    final Discovery discovery;
    if (runtimeContext.isDisablePeerDiscovery()) {
        final Set<NodeUri> knownNodes = runtimeContext.getPeers().stream().map(NodeUri::create).collect(Collectors.toUnmodifiableSet());
        discovery = new DisabledAutoDiscovery(networkStore, knownNodes);
    } else {
        discovery = new AutoDiscovery(networkStore);
    }
    discoveryHolder.set(discovery);
    return discovery;
}
Also used : Discovery(com.quorum.tessera.discovery.Discovery) NetworkStore(com.quorum.tessera.discovery.NetworkStore) NodeUri(com.quorum.tessera.discovery.NodeUri) RuntimeContext(com.quorum.tessera.context.RuntimeContext)

Example 12 with RuntimeContext

use of com.quorum.tessera.context.RuntimeContext in project tessera by ConsenSys.

the class RuntimeContextBuilder method build.

public RuntimeContext build() {
    LOGGER.debug("Building {}", this);
    Objects.requireNonNull(p2pServerUri, "No p2pServerUri provided. ");
    Objects.requireNonNull(keyEncryptor, "No key encryptor provided. ");
    Objects.requireNonNull(p2pClient, "No p2pClient provided. ");
    RuntimeContext instance = new DefaultRuntimeContext(keys, keyEncryptor, alwaysSendTo, peers, p2pClient, remoteKeyValidation, enhancedPrivacy, p2pServerUri, disablePeerDiscovery, useWhiteList, recoveryMode, clientMode == ClientMode.ORION, multiplePrivateStates);
    LOGGER.debug("Built {}", this);
    return instance;
}
Also used : RuntimeContext(com.quorum.tessera.context.RuntimeContext)

Example 13 with RuntimeContext

use of com.quorum.tessera.context.RuntimeContext in project tessera by ConsenSys.

the class PrivacyHelperProviderTest method provider.

@Test
public void provider() {
    try (var mockedRuntimeContext = mockStatic(RuntimeContext.class);
        var mockedEncryptedTransactionDAO = mockStatic(EncryptedTransactionDAO.class)) {
        RuntimeContext runtimeContext = mock(RuntimeContext.class);
        when(runtimeContext.isEnhancedPrivacy()).thenReturn(true);
        mockedRuntimeContext.when(RuntimeContext::getInstance).thenReturn(runtimeContext);
        mockedEncryptedTransactionDAO.when(EncryptedTransactionDAO::create).thenReturn(mock(EncryptedTransactionDAO.class));
        PrivacyHelper privacyHelper = PrivacyHelperProvider.provider();
        assertThat(privacyHelper).isNotNull();
    }
}
Also used : RuntimeContext(com.quorum.tessera.context.RuntimeContext) EncryptedTransactionDAO(com.quorum.tessera.data.EncryptedTransactionDAO) PrivacyHelper(com.quorum.tessera.transaction.PrivacyHelper) Test(org.junit.Test)

Example 14 with RuntimeContext

use of com.quorum.tessera.context.RuntimeContext in project tessera by ConsenSys.

the class PartyStoreTest method loadFromConfigIfEmpty.

@Test
public void loadFromConfigIfEmpty() {
    URI peerUri = URI.create("somepeer");
    try (var runtimeContextMockedStatic = mockStatic(RuntimeContext.class)) {
        RuntimeContext runtimeContext = mock(RuntimeContext.class);
        when(runtimeContext.getPeers()).thenReturn(List.of(URI.create("somepeer")));
        runtimeContextMockedStatic.when(RuntimeContext::getInstance).thenReturn(runtimeContext);
        PartyStore partyStore = PartyStore.getInstance();
        partyStore.loadFromConfigIfEmpty();
        assertThat(partyStore.getParties()).containsExactly(peerUri);
    }
}
Also used : RuntimeContext(com.quorum.tessera.context.RuntimeContext) URI(java.net.URI) Test(org.junit.Test)

Example 15 with RuntimeContext

use of com.quorum.tessera.context.RuntimeContext in project tessera by ConsenSys.

the class PrivacyHelperProvider method provider.

public static PrivacyHelper provider() {
    RuntimeContext runtimeContext = RuntimeContext.getInstance();
    LOGGER.debug("Creating PrivacyHelper");
    boolean privacyEnabled = runtimeContext.isEnhancedPrivacy();
    EncryptedTransactionDAO encryptedTransactionDAO = EncryptedTransactionDAO.create();
    PrivacyHelper privacyHelper = new PrivacyHelperImpl(encryptedTransactionDAO, privacyEnabled);
    LOGGER.debug("Created PrivacyHelper {}", privacyHelper);
    return privacyHelper;
}
Also used : RuntimeContext(com.quorum.tessera.context.RuntimeContext) EncryptedTransactionDAO(com.quorum.tessera.data.EncryptedTransactionDAO) PrivacyHelper(com.quorum.tessera.transaction.PrivacyHelper)

Aggregations

RuntimeContext (com.quorum.tessera.context.RuntimeContext)33 Test (org.junit.Test)20 URI (java.net.URI)14 PublicKey (com.quorum.tessera.encryption.PublicKey)11 ActiveNode (com.quorum.tessera.discovery.ActiveNode)9 NodeUri (com.quorum.tessera.discovery.NodeUri)9 Enclave (com.quorum.tessera.enclave.Enclave)9 Discovery (com.quorum.tessera.discovery.Discovery)6 Set (java.util.Set)6 Stream (java.util.stream.Stream)6 NetworkStore (com.quorum.tessera.discovery.NetworkStore)5 NodeInfo (com.quorum.tessera.partyinfo.node.NodeInfo)5 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 Before (org.junit.Before)5 Response (jakarta.ws.rs.core.Response)4 TransactionManager (com.quorum.tessera.transaction.TransactionManager)3 Client (jakarta.ws.rs.client.Client)3 ConfigKeyPair (com.quorum.tessera.config.keypairs.ConfigKeyPair)2 KeyEncryptor (com.quorum.tessera.config.keys.KeyEncryptor)2