@Test public void onUpdateIgnoresKeysThatAreNotOwnedBySender() { String uri = "http: PublicKey key = mock(PublicKey.class); Recipient recipient = Recipient.of(key,uri); Recipient other = Recipient.of(mock(PublicKey.class),"http: 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)); }
@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); }
AutoDiscovery implements Discovery { @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); } }
AutoDiscovery implements Discovery { @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); } AutoDiscovery(NetworkStore networkStore); }
AutoDiscovery implements Discovery { @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); } AutoDiscovery(NetworkStore networkStore); @Override void onUpdate(final NodeInfo nodeInfo); @Override void onDisconnect(URI nodeUri); }
AutoDiscovery implements Discovery { @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); } AutoDiscovery(NetworkStore networkStore); @Override void onUpdate(final NodeInfo nodeInfo); @Override void onDisconnect(URI nodeUri);  }