X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fde%2Ftodesbaum%2Fjsite%2Fapplication%2FFreenet7Interface.java;h=ae5c967764d12062cab2e6567dd56a759dda5c62;hb=e2dd2e8bb5771f1ae859b15fab1c4eefa31faf0e;hp=fefb220aa5c0f0744b46e8ccd4740f1777d9b96a;hpb=6f1a8216cfba28add0ef365b46a08d16d4eb87fe;p=jSite.git diff --git a/src/de/todesbaum/jsite/application/Freenet7Interface.java b/src/de/todesbaum/jsite/application/Freenet7Interface.java index fefb220..ae5c967 100644 --- a/src/de/todesbaum/jsite/application/Freenet7Interface.java +++ b/src/de/todesbaum/jsite/application/Freenet7Interface.java @@ -1,5 +1,5 @@ /* - * jSite - + * jSite - * Copyright (C) 2006 David Roden * * This program is free software; you can redistribute it and/or modify @@ -28,55 +28,102 @@ import de.todesbaum.util.freenet.fcp2.Message; import de.todesbaum.util.freenet.fcp2.Node; /** - * @author David Roden <droden@gmail.com> - * @version $Id: Freenet7Interface.java 418 2006-03-29 17:49:16Z bombe $ + * Interface for freenet-related operations. + * + * @author David ‘Bombe’ Roden <bombe@freenetproject.org> */ public class Freenet7Interface { + /** Random number to differentiate several jSites. */ + private static final int number = (int) (Math.random() * Integer.MAX_VALUE); + + /** Counter. */ private static int counter = 0; + /** The node to connect to. */ private Node node; + + /** The connection to the node. */ private Connection connection; + /** + * Sets the hostname of the node. The default port for FCP2 connections ({@link Node#DEFAULT_PORT}) + * is used. + * + * @param hostname + * The hostname of the node + */ public void setNodeAddress(String hostname) { node = new Node(hostname); - connection = new Connection(node, "connection-" + counter++); + connection = new Connection(node, "jSite-" + number + "-connection-" + counter++); } + /** + * Sets the hostname and the port of the node. + * + * @param hostname + * The hostname of the node + * @param port + * The port number of the node + */ public void setNodeAddress(String hostname, int port) { node = new Node(hostname, port); - connection = new Connection(node, "connection-" + counter++); + connection = new Connection(node, "jSite-" + number + "-connection-" + counter++); } - + + /** + * Sets hostname and port from the given node. + * + * @param node + * The node to get the hostname and port from + */ public void setNode(de.todesbaum.jsite.application.Node node) { if (node != null) { this.node = new Node(node.getHostname(), node.getPort()); - connection = new Connection(node, "connection-" + counter++); + connection = new Connection(node, "jSite-" + number + "-connection-" + counter++); } else { this.node = null; connection = null; } } - + + /** + * Removes the current node from the interface. + */ public void removeNode() { node = null; connection = null; } /** - * @return Returns the node. + * Returns the node this interface is connecting to. + * + * @return The node */ public Node getNode() { return node; } /** - * @return Returns the connection. + * Creates a new connection to the current node with the given identifier. + * + * @param identifier + * The identifier of the connection + * @return The connection to the node */ public Connection getConnection(String identifier) { return new Connection(node, identifier); } + /** + * Checks whether the current node is connected. If the node is not + * connected, a connection will be tried. + * + * @return true if the node is connected, false + * otherwise + * @throws IOException + * if an I/O error occurs communicating with the node + */ public boolean isNodePresent() throws IOException { if (!connection.isConnected()) { return connection.connect(); @@ -84,9 +131,18 @@ public class Freenet7Interface { return true; } + /** + * Generates an SSK key pair. + * + * @return An array of strings, the first one being the generated private + * (insert) URI and the second one being the generated public + * (request) URI + * @throws IOException + * if an I/O error occurs communicating with the node + */ public String[] generateKeyPair() throws IOException { if (!isNodePresent()) { - return null; + throw new IOException("Node is offline."); } GenerateSSK generateSSK = new GenerateSSK(); Client client = new Client(connection, generateSSK); @@ -95,6 +151,8 @@ public class Freenet7Interface { } /** + * Checks whether the interface has already been configured with a node. + * * @return true if this interface already has a node set, * false otherwise */