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;
}
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;
}
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();
}
}
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);
}
}
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;
}
Aggregations