import net.pterodactylus.fcp.highlevel.HighLevelClient;
import net.pterodactylus.fcp.highlevel.HighLevelClientListener;
+import net.pterodactylus.fcp.highlevel.HighLevelException;
import net.pterodactylus.fcp.highlevel.KeyGenerationResult;
import net.pterodactylus.util.io.Closer;
import net.pterodactylus.util.logging.Logging;
* TODO
*
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
- * @version $Id$
*/
public class NodeManager implements Iterable<Node>, PropertyChangeListener, HighLevelClientListener {
if (nodeClients.containsKey(node)) {
disconnect(node);
}
+ nodes.remove(node);
node.removePropertyChangeListener(this);
fireNodeRemoved(node);
}
* public key at index <code>1</code>
* @throws IOException
* if an I/O error occurs communicating with the node
+ * @throws JSiteException
+ * if there is a problem with the node
*/
- public String[] generateKeyPair() throws IOException {
- if (!nodes.isEmpty()) {
- 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. */
- }
+ public String[] generateKeyPair() throws IOException, JSiteException {
+ 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 (HighLevelException hle1) {
+ throw new BackendException(hle1);
+ } catch (InterruptedException e) {
+ /* ignore. */
}
return null;
}