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));
}
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);
}
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);
}
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;
}
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;
});
}
Aggregations