Search in sources :

Example 1 with NodeUri

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

the class DisabledAutoDiscoveryTest 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 2 with NodeUri

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

Example 3 with NodeUri

use of com.quorum.tessera.discovery.NodeUri 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);
}
Also used : NodeUri(com.quorum.tessera.discovery.NodeUri) ActiveNode(com.quorum.tessera.discovery.ActiveNode) RuntimeContext(com.quorum.tessera.context.RuntimeContext)

Example 4 with NodeUri

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

the class DiscoveryProvider method provider.

/**
 * @see java.util.ServiceLoader.Provider
 */
public static Discovery provider() {
    final DiscoveryHolder discoveryHolder = DiscoveryHolder.create();
    if (discoveryHolder.get().isPresent()) {
        return discoveryHolder.get().get();
    }
    final NetworkStore networkStore = NetworkStore.getInstance();
    final RuntimeContext runtimeContext = RuntimeContext.getInstance();
    final Discovery discovery;
    if (runtimeContext.isDisablePeerDiscovery()) {
        final Set<NodeUri> knownNodes = runtimeContext.getPeers().stream().map(NodeUri::create).collect(Collectors.toUnmodifiableSet());
        discovery = new DisabledAutoDiscovery(networkStore, knownNodes);
    } else {
        discovery = new AutoDiscovery(networkStore);
    }
    discoveryHolder.set(discovery);
    return discovery;
}
Also used : Discovery(com.quorum.tessera.discovery.Discovery) NetworkStore(com.quorum.tessera.discovery.NetworkStore) NodeUri(com.quorum.tessera.discovery.NodeUri) RuntimeContext(com.quorum.tessera.context.RuntimeContext)

Example 5 with NodeUri

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

the class PartyInfoBroadcaster method pollSingleParty.

/**
 * Sends a request for node information to a single target
 *
 * @param url the target URL to call
 * @param encodedPartyInfo the encoded current party information
 */
protected void pollSingleParty(final String url, final byte[] encodedPartyInfo) {
    final NodeUri nodeUri = NodeUri.create(url);
    CompletableFuture.runAsync(() -> {
        LOGGER.debug("Sending party info to {}", nodeUri.asString());
        p2pClient.sendPartyInfo(url, encodedPartyInfo);
        LOGGER.debug("Sent party info to {}", nodeUri.asString());
    }, executor).exceptionally(ex -> {
        Throwable cause = Optional.of(ex).map(Throwable::getCause).orElse(ex);
        LOGGER.warn("Failed to connect to node {}, due to {}", url, cause.getMessage());
        LOGGER.debug("Send failure exception", cause);
        if (ProcessingException.class.isInstance(cause)) {
            discovery.onDisconnect(URI.create(url));
            partyStore.remove(URI.create(url));
        }
        return null;
    });
}
Also used : NodeUri(com.quorum.tessera.discovery.NodeUri)

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