Search in sources :

Example 6 with NodeUri

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));
}
Also used : ArrayList(java.util.ArrayList) NodeUri(com.quorum.tessera.discovery.NodeUri) URI(java.net.URI) Test(org.junit.Test)

Example 7 with NodeUri

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);
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) NodeUri(com.quorum.tessera.discovery.NodeUri) ActiveNode(com.quorum.tessera.discovery.ActiveNode) RuntimeContext(com.quorum.tessera.context.RuntimeContext) URI(java.net.URI) Test(org.junit.Test)

Example 8 with NodeUri

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);
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) NodeUri(com.quorum.tessera.discovery.NodeUri) ActiveNode(com.quorum.tessera.discovery.ActiveNode) RuntimeContext(com.quorum.tessera.context.RuntimeContext) URI(java.net.URI) Test(org.junit.Test)

Example 9 with NodeUri

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);
}
Also used : AutoDiscoveryDisabledException(com.quorum.tessera.partyinfo.AutoDiscoveryDisabledException) PublicKey(com.quorum.tessera.encryption.PublicKey) NodeUri(com.quorum.tessera.discovery.NodeUri) ActiveNode(com.quorum.tessera.discovery.ActiveNode)

Example 10 with NodeUri

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;
}
Also used : KeyNotFoundException(com.quorum.tessera.encryption.KeyNotFoundException) PublicKey(com.quorum.tessera.encryption.PublicKey) Logger(org.slf4j.Logger) DiscoveryHelper(com.quorum.tessera.discovery.DiscoveryHelper) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) ApiVersion(com.quorum.tessera.version.ApiVersion) NodeUri(com.quorum.tessera.discovery.NodeUri) Collectors(java.util.stream.Collectors) Recipient(com.quorum.tessera.partyinfo.node.Recipient) ActiveNode(com.quorum.tessera.discovery.ActiveNode) NetworkStore(com.quorum.tessera.discovery.NetworkStore) List(java.util.List) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) RuntimeContext(com.quorum.tessera.context.RuntimeContext) Enclave(com.quorum.tessera.enclave.Enclave) Optional(java.util.Optional) URI(java.net.URI) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) NodeUri(com.quorum.tessera.discovery.NodeUri) Recipient(com.quorum.tessera.partyinfo.node.Recipient) ActiveNode(com.quorum.tessera.discovery.ActiveNode) URI(java.net.URI)

Aggregations

NodeUri (com.quorum.tessera.discovery.NodeUri)14 RuntimeContext (com.quorum.tessera.context.RuntimeContext)7 ActiveNode (com.quorum.tessera.discovery.ActiveNode)7 PublicKey (com.quorum.tessera.encryption.PublicKey)7 URI (java.net.URI)7 Discovery (com.quorum.tessera.discovery.Discovery)4 Test (org.junit.Test)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 NetworkStore (com.quorum.tessera.discovery.NetworkStore)3 Enclave (com.quorum.tessera.enclave.Enclave)3 NodeInfo (com.quorum.tessera.partyinfo.node.NodeInfo)3 List (java.util.List)3 Objects (java.util.Objects)3 Optional (java.util.Optional)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 PartyInfoParser (com.quorum.tessera.p2p.partyinfo.PartyInfoParser)2 PartyStore (com.quorum.tessera.p2p.partyinfo.PartyStore)2 PartyInfo (com.quorum.tessera.partyinfo.model.PartyInfo)2