@Test public void onUpdateNodeSendsNewKey() { String url = knownPeers.iterator().next().asString(); PublicKey key = mock(PublicKey.class); List<Recipient> recipients = List.of(Recipient.of(key,url)); List<ActiveNode> storedNodes = new ArrayList<>(); doAnswer(invocation -> { storedNodes.add(invocation.getArgument(0)); return null; }).when(networkStore).store(any(ActiveNode.class)); NodeInfo nodeInfo = NodeInfo.Builder.create() .withUrl(url) .withRecipients(recipients) .build(); discovery.onUpdate(nodeInfo); assertThat(storedNodes).hasSize(1); ActiveNode savedNode = storedNodes.get(0); assertThat(savedNode.getKeys()).containsExactly(key); assertThat(savedNode.getUri()).isEqualTo(NodeUri.create(url)); verify(networkStore).store(any(ActiveNode.class)); }
@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); }
DisabledAutoDiscovery implements Discovery { @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); } }
DisabledAutoDiscovery implements Discovery { @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); } DisabledAutoDiscovery(NetworkStore networkStore,Set<NodeUri> knownPeers); }
DisabledAutoDiscovery implements Discovery { @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); } DisabledAutoDiscovery(NetworkStore networkStore,Set<NodeUri> knownPeers); @Override void onUpdate(NodeInfo nodeInfo); @Override void onDisconnect(URI nodeUri); }
DisabledAutoDiscovery implements Discovery { @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); } DisabledAutoDiscovery(NetworkStore networkStore,Set<NodeUri> knownPeers); @Override void onUpdate(NodeInfo nodeInfo); @Override void onDisconnect(URI nodeUri);  }