use of com.quorum.tessera.discovery.NodeUri in project tessera by ConsenSys.
the class AutoDiscoveryTest method onDisconnect.
@Test
public void onDisconnect() {
URI uri = URI.create("http://onDisconnect.com");
List<NodeUri> results = new ArrayList<>();
doAnswer(invocation -> {
results.add(invocation.getArgument(0));
return null;
}).when(networkStore).remove(any(NodeUri.class));
discovery.onDisconnect(uri);
assertThat(results).containsExactly(NodeUri.create(uri));
verify(networkStore).remove(any(NodeUri.class));
}
use of com.quorum.tessera.discovery.NodeUri in project tessera by ConsenSys.
the class EnclaveKeySynchroniserTest method syncWithChanges.
@Test
public void syncWithChanges() {
URI uri = URI.create("http://somedomain.com/");
when(runtimeContext.getP2pServerUri()).thenReturn(uri);
NodeUri nodeUri = NodeUri.create(uri);
Set<PublicKey> newKeys = Set.of(mock(PublicKey.class));
ActiveNode activeNode = mock(ActiveNode.class);
when(activeNode.getUri()).thenReturn(nodeUri);
when(activeNode.getKeys()).thenReturn(newKeys);
when(networkStore.getActiveNodes()).thenReturn(Stream.of(activeNode));
when(enclave.getPublicKeys()).thenReturn(Set.of(mock(PublicKey.class)));
enclaveKeySynchroniser.syncKeys();
verify(runtimeContext).getP2pServerUri();
verify(networkStore).getActiveNodes();
verify(enclave).getPublicKeys();
verify(networkStore).store(any(ActiveNode.class));
mockedStaticRuntimeContext.verify(RuntimeContext::getInstance);
}
use of com.quorum.tessera.discovery.NodeUri in project tessera by ConsenSys.
the class EnclaveKeySynchroniserTest method syncKeysNoChanges.
@Test
public void syncKeysNoChanges() {
URI uri = URI.create("http://somedomain.com/");
when(runtimeContext.getP2pServerUri()).thenReturn(uri);
NodeUri nodeUri = NodeUri.create(uri);
Set<PublicKey> keys = Set.of(mock(PublicKey.class));
ActiveNode activeNode = mock(ActiveNode.class);
when(activeNode.getKeys()).thenReturn(keys);
when(activeNode.getUri()).thenReturn(nodeUri);
when(networkStore.getActiveNodes()).thenReturn(Stream.of(activeNode));
when(enclave.getPublicKeys()).thenReturn(keys);
enclaveKeySynchroniser.syncKeys();
verify(runtimeContext).getP2pServerUri();
verify(networkStore).getActiveNodes();
verify(enclave).getPublicKeys();
mockedStaticRuntimeContext.verify(RuntimeContext::getInstance);
}
use of com.quorum.tessera.discovery.NodeUri in project tessera by ConsenSys.
the class DisabledAutoDiscovery method onUpdate.
@Override
public void onUpdate(NodeInfo nodeInfo) {
if (!knownPeers.contains(NodeUri.create(nodeInfo.getUrl()))) {
throw new AutoDiscoveryDisabledException(String.format("%s is not a known peer", nodeInfo.getUrl()));
}
final NodeUri callerNodeUri = NodeUri.create(nodeInfo.getUrl());
final Set<PublicKey> keys = nodeInfo.getRecipients().stream().filter(r -> NodeUri.create(r.getUrl()).equals(callerNodeUri)).map(Recipient::getKey).collect(Collectors.toSet());
final ActiveNode activeNode = ActiveNode.Builder.create().withUri(callerNodeUri).withSupportedVersions(nodeInfo.supportedApiVersions()).withKeys(keys).build();
networkStore.store(activeNode);
}
use of com.quorum.tessera.discovery.NodeUri in project tessera by ConsenSys.
the class DiscoveryHelperImpl method buildCurrent.
@Override
public NodeInfo buildCurrent() {
final URI uri = RuntimeContext.getInstance().getP2pServerUri();
final NodeUri nodeUri = NodeUri.create(uri);
final List<ActiveNode> activeNodes = networkStore.getActiveNodes().collect(Collectors.toList());
Set<Recipient> recipients = activeNodes.stream().filter(a -> !a.getKeys().isEmpty()).flatMap(a -> a.getKeys().stream().map(k -> Recipient.of(k, a.getUri().asString()))).collect(Collectors.toSet());
NodeInfo nodeInfo = NodeInfo.Builder.create().withRecipients(recipients).withUrl(nodeUri.asString()).withSupportedApiVersions(ApiVersion.versions()).build();
LOGGER.debug("Built nodeinfo {}", nodeInfo);
return nodeInfo;
}
Aggregations