use of com.quorum.tessera.discovery.ActiveNode in project tessera by ConsenSys.
the class DiscoveryHelperTest method buildAllNodeInfos.
@Test
public void buildAllNodeInfos() {
when(runtimeContext.getP2pServerUri()).thenReturn(URI.create("http://own.com"));
final ActiveNode node1 = ActiveNode.Builder.create().withUri(NodeUri.create("http://node1.com")).withKeys(List.of(PublicKey.from("key1".getBytes()))).withSupportedVersions(List.of("v1")).build();
final ActiveNode node2 = ActiveNode.Builder.create().withUri(NodeUri.create("http://node2.com")).withKeys(List.of(PublicKey.from("key2".getBytes()))).withSupportedVersions(List.of("v2")).build();
when(networkStore.getActiveNodes()).thenReturn(Stream.of(node1, node2));
final Set<NodeInfo> nodeInfos = discoveryHelper.buildRemoteNodeInfos();
assertThat(nodeInfos).hasSize(2);
Set<ActiveNode> activeNodes = nodeInfos.stream().map(nodeInfo -> ActiveNode.Builder.create().withUri(NodeUri.create(nodeInfo.getUrl())).withKeys(nodeInfo.getRecipients().stream().map(Recipient::getKey).collect(Collectors.toSet())).withSupportedVersions(nodeInfo.supportedApiVersions()).build()).collect(Collectors.toSet());
assertThat(activeNodes).containsExactlyInAnyOrder(node1, node2);
verify(networkStore).getActiveNodes();
verify(runtimeContext).getP2pServerUri();
mockedRuntimeContext.verify(RuntimeContext::getInstance);
}
use of com.quorum.tessera.discovery.ActiveNode in project tessera by ConsenSys.
the class AutoDiscovery method onUpdate.
@Override
public void onUpdate(final NodeInfo nodeInfo) {
LOGGER.debug("Processing node info {}", nodeInfo);
final NodeUri callerNodeUri = NodeUri.create(nodeInfo.getUrl());
LOGGER.debug("Update node {}", callerNodeUri);
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).withKeys(keys).withSupportedVersions(nodeInfo.supportedApiVersions()).build();
networkStore.store(activeNode);
}
use of com.quorum.tessera.discovery.ActiveNode in project tessera by ConsenSys.
the class DiscoveryHelperImpl method onCreate.
@Override
public void onCreate() {
RuntimeContext runtimeContext = RuntimeContext.getInstance();
final NodeUri nodeUri = Optional.of(runtimeContext).map(RuntimeContext::getP2pServerUri).map(NodeUri::create).get();
ActiveNode thisNode = ActiveNode.Builder.create().withUri(nodeUri).withKeys(enclave.getPublicKeys()).withSupportedVersions(ApiVersion.versions()).build();
networkStore.store(thisNode);
}
use of com.quorum.tessera.discovery.ActiveNode in project tessera by ConsenSys.
the class DiscoveryHelperImpl method buildRemoteNodeInfo.
@Override
public NodeInfo buildRemoteNodeInfo(PublicKey recipientKey) {
final ActiveNode activeNode = networkStore.getActiveNodes().filter(node -> node.getKeys().contains(recipientKey)).findAny().orElseThrow(() -> new KeyNotFoundException("Recipient not found for key: " + recipientKey.encodeToBase64()));
final String nodeUrl = activeNode.getUri().asString();
final Set<Recipient> recipients = activeNode.getKeys().stream().map(k -> Recipient.of(k, nodeUrl)).collect(Collectors.toSet());
final NodeInfo nodeInfo = NodeInfo.Builder.create().withUrl(nodeUrl).withRecipients(recipients).withSupportedApiVersions(activeNode.getSupportedVersions()).build();
return nodeInfo;
}
use of com.quorum.tessera.discovery.ActiveNode in project tessera by ConsenSys.
the class AutoDiscoveryTest method onUpdateIgnoresKeysThatAreNotOwnedBySender.
@Test
public void onUpdateIgnoresKeysThatAreNotOwnedBySender() {
String uri = "http://mynode.com";
PublicKey key = mock(PublicKey.class);
Recipient recipient = Recipient.of(key, uri);
Recipient other = Recipient.of(mock(PublicKey.class), "http://othernode.com");
List<Recipient> recipients = List.of(recipient, other);
NodeInfo nodeInfo = NodeInfo.Builder.create().withUrl(uri).withRecipients(recipients).withSupportedApiVersions(List.of("Two", "Fifty")).build();
List<ActiveNode> storedNodes = new ArrayList<>();
doAnswer(invocation -> {
storedNodes.add(invocation.getArgument(0));
return null;
}).when(networkStore).store(any(ActiveNode.class));
discovery.onUpdate(nodeInfo);
assertThat(storedNodes).hasSize(1);
ActiveNode result = storedNodes.iterator().next();
assertThat(result.getUri()).isEqualTo(NodeUri.create(uri));
assertThat(result.getKeys()).containsExactly(key);
assertThat(result.getSupportedVersions()).containsExactlyInAnyOrder("Two", "Fifty");
verify(networkStore).store(any(ActiveNode.class));
}
Aggregations