3 * Copyright (C) 2006 David Roden
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 package de.todesbaum.jsite.application;
22 import java.io.IOException;
24 import de.todesbaum.util.freenet.fcp2.Client;
25 import de.todesbaum.util.freenet.fcp2.Connection;
26 import de.todesbaum.util.freenet.fcp2.GenerateSSK;
27 import de.todesbaum.util.freenet.fcp2.Message;
28 import de.todesbaum.util.freenet.fcp2.Node;
31 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
33 public class Freenet7Interface {
35 private static int counter = 0;
38 private Connection connection;
40 public void setNodeAddress(String hostname) {
41 node = new Node(hostname);
42 connection = new Connection(node, "connection-" + counter++);
45 public void setNodeAddress(String hostname, int port) {
46 node = new Node(hostname, port);
47 connection = new Connection(node, "connection-" + counter++);
50 public void setNode(de.todesbaum.jsite.application.Node node) {
52 this.node = new Node(node.getHostname(), node.getPort());
53 connection = new Connection(node, "connection-" + counter++);
60 public void removeNode() {
66 * @return Returns the node.
68 public Node getNode() {
73 * @return Returns the connection.
75 public Connection getConnection(String identifier) {
76 return new Connection(node, identifier);
79 public boolean isNodePresent() throws IOException {
80 if (!connection.isConnected()) {
81 return connection.connect();
86 public String[] generateKeyPair() throws IOException {
87 if (!isNodePresent()) {
90 GenerateSSK generateSSK = new GenerateSSK();
91 Client client = new Client(connection, generateSSK);
92 Message keypairMessage = client.readMessage();
93 return new String[] { keypairMessage.get("InsertURI"), keypairMessage.get("RequestURI") };
97 * @return <code>true</code> if this interface already has a node set,
98 * <code>false</code> otherwise
100 public boolean hasNode() {
101 return (node != null) && (connection != null);