X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fcore%2FNodeManager.java;h=b9404c738bc417c8364277f589031b0d105512be;hb=f6133c09d874de035fcdcc8926c90324d878ea7b;hp=c67628920316d401276eef13b7dd06c840b897da;hpb=f58c676a286a7cd8d37c3f510e787144a9bff5ad;p=jSite2.git diff --git a/src/net/pterodactylus/jsite/core/NodeManager.java b/src/net/pterodactylus/jsite/core/NodeManager.java index c676289..b9404c7 100644 --- a/src/net/pterodactylus/jsite/core/NodeManager.java +++ b/src/net/pterodactylus/jsite/core/NodeManager.java @@ -40,6 +40,7 @@ import java.util.logging.Logger; import net.pterodactylus.fcp.highlevel.HighLevelClient; import net.pterodactylus.fcp.highlevel.HighLevelClientListener; +import net.pterodactylus.fcp.highlevel.KeyGenerationResult; import net.pterodactylus.util.io.Closer; import net.pterodactylus.util.logging.Logging; @@ -409,6 +410,43 @@ public class NodeManager implements Iterable, PropertyChangeListener, High return nodeClients.get(node); } + /** + * Returns the node for a high-level client. + * + * @param highLevelClient + * The high-level client to get the node for + * @return The node for the high-level client, or null if the + * high-level client is not known + */ + public Node getNode(HighLevelClient highLevelClient) { + return clientNodes.get(highLevelClient); + } + + /** + * Generates a new SSK key pair. + * + * @return An array with the private key at index 0 and the + * public key at index 1 + * @throws IOException + * if an I/O error occurs communicating with the node + * @throws NoNodeException + * if no node is configured + */ + public String[] generateKeyPair() throws IOException, NoNodeException { + if (nodes.isEmpty()) { + throw new NoNodeException("no node configured"); + } + Node node = nodes.get(0); + HighLevelClient highLevelClient = nodeClients.get(node); + try { + KeyGenerationResult keyGenerationResult = highLevelClient.generateKey().getResult(); + return new String[] { keyGenerationResult.getInsertURI(), keyGenerationResult.getRequestURI() }; + } catch (InterruptedException e) { + /* ignore. */ + } + return null; + } + // // PRIVATE METHODS //