Search in sources :

Example 16 with ActiveNode

use of com.quorum.tessera.discovery.ActiveNode 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 17 with ActiveNode

use of com.quorum.tessera.discovery.ActiveNode 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)

Example 18 with ActiveNode

use of com.quorum.tessera.discovery.ActiveNode in project tessera by ConsenSys.

the class EnclaveKeySynchroniserImpl method syncKeys.

@Override
public void syncKeys() {
    NodeUri nodeUri = Optional.of(RuntimeContext.getInstance()).map(RuntimeContext::getP2pServerUri).map(NodeUri::create).get();
    List<ActiveNode> activeNodes = networkStore.getActiveNodes().filter(a -> a.getUri().equals(nodeUri)).collect(Collectors.toList());
    if (activeNodes.isEmpty()) {
        return;
    }
    final Set<PublicKey> storedKeys = activeNodes.stream().flatMap(a -> a.getKeys().stream()).collect(Collectors.toSet());
    final Set<PublicKey> keys = enclave.getPublicKeys();
    if (!storedKeys.equals(keys)) {
        final Set<PublicKey> allKeys = Stream.concat(storedKeys.stream(), keys.stream()).collect(Collectors.toUnmodifiableSet());
        activeNodes.forEach(activeNode -> {
            ActiveNode modified = ActiveNode.Builder.from(activeNode).withKeys(allKeys).build();
            networkStore.store(modified);
        });
    }
}
Also used : EnclaveKeySynchroniser(com.quorum.tessera.discovery.EnclaveKeySynchroniser) PublicKey(com.quorum.tessera.encryption.PublicKey) Set(java.util.Set) NodeUri(com.quorum.tessera.discovery.NodeUri) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ActiveNode(com.quorum.tessera.discovery.ActiveNode) NetworkStore(com.quorum.tessera.discovery.NetworkStore) List(java.util.List) Stream(java.util.stream.Stream) RuntimeContext(com.quorum.tessera.context.RuntimeContext) Enclave(com.quorum.tessera.enclave.Enclave) Optional(java.util.Optional) PublicKey(com.quorum.tessera.encryption.PublicKey) NodeUri(com.quorum.tessera.discovery.NodeUri) ActiveNode(com.quorum.tessera.discovery.ActiveNode) RuntimeContext(com.quorum.tessera.context.RuntimeContext)

Aggregations

ActiveNode (com.quorum.tessera.discovery.ActiveNode)18 PublicKey (com.quorum.tessera.encryption.PublicKey)17 Test (org.junit.Test)12 NodeUri (com.quorum.tessera.discovery.NodeUri)11 NodeInfo (com.quorum.tessera.partyinfo.node.NodeInfo)11 RuntimeContext (com.quorum.tessera.context.RuntimeContext)10 Recipient (com.quorum.tessera.partyinfo.node.Recipient)10 URI (java.net.URI)8 NetworkStore (com.quorum.tessera.discovery.NetworkStore)6 Enclave (com.quorum.tessera.enclave.Enclave)6 KeyNotFoundException (com.quorum.tessera.encryption.KeyNotFoundException)6 List (java.util.List)6 Set (java.util.Set)6 Collectors (java.util.stream.Collectors)6 DiscoveryHelper (com.quorum.tessera.discovery.DiscoveryHelper)5 ArrayList (java.util.ArrayList)4 Stream (java.util.stream.Stream)4 Optional (java.util.Optional)3 IntStream (java.util.stream.IntStream)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3