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