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 Roden <droden@gmail.com>
34 public class Freenet7Interface {
36 private static int counter = 0;
39 private Connection connection;
41 public void setNodeAddress(String hostname) {
42 node = new Node(hostname);
43 connection = new Connection(node, "connection-" + counter++);
46 public void setNodeAddress(String hostname, int port) {
47 node = new Node(hostname, port);
48 connection = new Connection(node, "connection-" + counter++);
51 public void setNode(de.todesbaum.jsite.application.Node node) {
53 this.node = new Node(node.getHostname(), node.getPort());
54 connection = new Connection(node, "connection-" + counter++);
61 public void removeNode() {
67 * @return Returns the node.
69 public Node getNode() {
74 * @return Returns the connection.
76 public Connection getConnection(String identifier) {
77 return new Connection(node, identifier);
80 public boolean isNodePresent() throws IOException {
81 if (!connection.isConnected()) {
82 return connection.connect();
87 public String[] generateKeyPair() throws IOException {
88 if (!isNodePresent()) {
91 GenerateSSK generateSSK = new GenerateSSK();
92 Client client = new Client(connection, generateSSK);
93 Message keypairMessage = client.readMessage();
94 return new String[] { keypairMessage.get("InsertURI"), keypairMessage.get("RequestURI") };
98 * @return <code>true</code> if this interface already has a node set,
99 * <code>false</code> otherwise
101 public boolean hasNode() {
102 return (node != null) && (connection != null);