2004-04-08 04:48:39 +00:00
|
|
|
package net.i2p.client;
|
2004-04-10 11:39:00 +00:00
|
|
|
|
2004-04-08 04:48:39 +00:00
|
|
|
/*
|
|
|
|
* free (adj.): unencumbered; not under the control of others
|
|
|
|
* Written by jrandom in 2003 and released into the public domain
|
|
|
|
* with no warranty of any kind, either expressed or implied.
|
|
|
|
* It probably won't make your computer catch on fire, or eat
|
|
|
|
* your children, but it might. Use at your own risk.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.BufferedWriter;
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
import java.io.OutputStreamWriter;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Properties;
|
|
|
|
|
2004-05-17 03:38:53 +00:00
|
|
|
import net.i2p.I2PAppContext;
|
2004-04-08 04:48:39 +00:00
|
|
|
import net.i2p.I2PException;
|
|
|
|
import net.i2p.data.DataFormatException;
|
|
|
|
import net.i2p.data.Destination;
|
2004-04-10 11:39:00 +00:00
|
|
|
import net.i2p.util.Clock;
|
2004-04-08 04:48:39 +00:00
|
|
|
import net.i2p.util.I2PThread;
|
|
|
|
import net.i2p.util.Log;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ATalk - anonymous talk, demonstrating a trivial I2P usage scenario.
|
|
|
|
* Run this class with no arguments for a manual.
|
|
|
|
*
|
|
|
|
* @author jrandom
|
|
|
|
*/
|
|
|
|
public class ATalk implements I2PSessionListener, Runnable {
|
|
|
|
/** logging hook - status messages are piped to this */
|
|
|
|
private final static Log _log = new Log(ATalk.class);
|
2008-11-26 15:56:36 +00:00
|
|
|
|
2004-04-08 04:48:39 +00:00
|
|
|
/** platform independent newline */
|
|
|
|
private final static String NL = System.getProperty("line.separator");
|
2008-11-26 15:56:36 +00:00
|
|
|
|
2004-04-08 04:48:39 +00:00
|
|
|
/** the current session */
|
|
|
|
private I2PSession _session;
|
2008-11-26 15:56:36 +00:00
|
|
|
|
2004-04-08 04:48:39 +00:00
|
|
|
/** who am i */
|
|
|
|
private Destination _myDestination;
|
2008-11-26 15:56:36 +00:00
|
|
|
|
2004-04-08 04:48:39 +00:00
|
|
|
/** who are you? */
|
|
|
|
private Destination _peerDestination;
|
2008-11-26 15:56:36 +00:00
|
|
|
|
2004-04-08 04:48:39 +00:00
|
|
|
/** location of my secret key file */
|
|
|
|
private String _myKeyFile;
|
2008-11-26 15:56:36 +00:00
|
|
|
|
2004-04-08 04:48:39 +00:00
|
|
|
/** location of their public key */
|
|
|
|
private String _theirDestinationFile;
|
2008-11-26 15:56:36 +00:00
|
|
|
|
2004-04-08 04:48:39 +00:00
|
|
|
/** where the application reads input from. currently set to standard input */
|
|
|
|
private BufferedReader _in;
|
2008-11-26 15:56:36 +00:00
|
|
|
|
2004-04-08 04:48:39 +00:00
|
|
|
/** where the application sends output to. currently set to standard output */
|
|
|
|
private BufferedWriter _out;
|
2008-11-26 15:56:36 +00:00
|
|
|
|
2004-04-08 04:48:39 +00:00
|
|
|
/** string that messages must begin with to be treated as files */
|
|
|
|
private final static String FILE_COMMAND = ".file: ";
|
2008-11-26 15:56:36 +00:00
|
|
|
|
2004-04-08 04:48:39 +00:00
|
|
|
/** the, erm, manual */
|
2004-04-10 11:39:00 +00:00
|
|
|
private final static String MANUAL = "ATalk: Anonymous Talk, a demo program for the Invisible Internet Project SDK"
|
|
|
|
+ NL
|
|
|
|
+ "To generate a new destination:"
|
|
|
|
+ NL
|
|
|
|
+ "\tATalk [fileToSavePrivateKeyIn] [fileToSavePublicKeyIn]"
|
|
|
|
+ NL
|
|
|
|
+ "To talk to another destination:"
|
|
|
|
+ NL
|
|
|
|
+ "\tATalk [myPrivateKeyFile] [peerPublicKey] [shouldLogToScreen]"
|
|
|
|
+ NL
|
|
|
|
+ "shouldLogToScreen is 'true' or 'false', depending on whether you want log info on the screen"
|
|
|
|
+ NL
|
|
|
|
+ "When talking to another destination, messages are sent after you hit return"
|
|
|
|
+ NL
|
|
|
|
+ "To send a file, send a message saying:"
|
|
|
|
+ NL
|
|
|
|
+ "\t"
|
|
|
|
+ FILE_COMMAND
|
|
|
|
+ "[filenameToSend]"
|
|
|
|
+ NL
|
|
|
|
+ "The peer will then recieve the file and be notified of where it has been saved"
|
|
|
|
+ NL
|
|
|
|
+ "To end the talk session, enter a period on a line by itself and hit return"
|
|
|
|
+ NL;
|
2008-11-26 15:56:36 +00:00
|
|
|
|
2004-04-08 04:48:39 +00:00
|
|
|
public final static String PROP_CONFIG_LOCATION = "configFile";
|
2008-11-26 15:56:36 +00:00
|
|
|
|
2004-04-08 04:48:39 +00:00
|
|
|
private static final SimpleDateFormat _fmt = new SimpleDateFormat("hh:mm:ss.SSS");
|
2004-04-10 11:39:00 +00:00
|
|
|
|
2004-04-08 04:48:39 +00:00
|
|
|
/** Construct the talk engine, but don't connect yet */
|
|
|
|
public ATalk(String myKeyFile, String theirDestFile) {
|
2004-04-10 11:39:00 +00:00
|
|
|
_myKeyFile = myKeyFile;
|
|
|
|
_theirDestinationFile = theirDestFile;
|
2004-04-08 04:48:39 +00:00
|
|
|
}
|
2004-04-10 11:39:00 +00:00
|
|
|
|
2004-04-08 04:48:39 +00:00
|
|
|
/** Actually start up the connection to the I2P network.
|
|
|
|
* Successful connect does not mean the peer is online or reachable.
|
|
|
|
*
|
|
|
|
* @throws IOException if there is a problem reading in the keys from the files specified
|
|
|
|
* @throws DataFormatException if the key files are not in the valid format
|
|
|
|
* @throws I2PSessionException if there is a problem contacting the I2P router
|
|
|
|
*/
|
|
|
|
public void connect() throws IOException, I2PSessionException, DataFormatException {
|
2004-04-10 11:39:00 +00:00
|
|
|
I2PClient client = I2PClientFactory.createClient();
|
|
|
|
File myFile = new File(_myKeyFile);
|
|
|
|
Properties props = new Properties();
|
|
|
|
String configLocation = System.getProperty(PROP_CONFIG_LOCATION, "atalk.config");
|
|
|
|
try {
|
|
|
|
props.load(new FileInputStream(configLocation));
|
|
|
|
} catch (FileNotFoundException fnfe) {
|
|
|
|
_log.warn("Unable to load up the ATalk config file " + configLocation);
|
|
|
|
}
|
|
|
|
// Provide any router or client API configuration here.
|
2008-11-26 15:56:36 +00:00
|
|
|
if (!props.containsKey(I2PClient.PROP_TCP_HOST))
|
|
|
|
props.setProperty(I2PClient.PROP_TCP_HOST, "localhost");
|
|
|
|
if (!props.containsKey(I2PClient.PROP_TCP_PORT))
|
|
|
|
props.setProperty(I2PClient.PROP_TCP_PORT, "7654");
|
2004-04-10 11:39:00 +00:00
|
|
|
if (!props.containsKey(I2PClient.PROP_RELIABILITY))
|
2008-11-26 15:56:36 +00:00
|
|
|
props.setProperty(I2PClient.PROP_RELIABILITY, I2PClient.PROP_RELIABILITY_BEST_EFFORT);
|
2004-04-10 11:39:00 +00:00
|
|
|
_session = client.createSession(new FileInputStream(myFile), props);
|
|
|
|
_session.setSessionListener(this);
|
|
|
|
_session.connect();
|
|
|
|
|
|
|
|
File peerDestFile = new File(_theirDestinationFile);
|
|
|
|
_peerDestination = new Destination();
|
|
|
|
_peerDestination.readBytes(new FileInputStream(peerDestFile));
|
|
|
|
return;
|
2004-04-08 04:48:39 +00:00
|
|
|
}
|
2004-04-10 11:39:00 +00:00
|
|
|
|
2004-04-08 04:48:39 +00:00
|
|
|
/** Actual bulk processing of the application, reading in user input,
|
|
|
|
* sending messages, and displaying results. When this function exits, the
|
|
|
|
* application is complete.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public void run() {
|
2004-04-10 11:39:00 +00:00
|
|
|
try {
|
|
|
|
connect();
|
|
|
|
_in = new BufferedReader(new InputStreamReader(System.in));
|
|
|
|
_out = new BufferedWriter(new OutputStreamWriter(System.out));
|
|
|
|
|
|
|
|
_out.write("Starting up anonymous talk session" + NL);
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
String line = _in.readLine();
|
|
|
|
if ((line == null) || (line.trim().length() <= 0)) continue;
|
|
|
|
if (".".equals(line)) {
|
|
|
|
boolean ok = _session.sendMessage(_peerDestination, ("Peer disconnected at " + now()).getBytes());
|
|
|
|
// ignore ok, we're closing
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (line.startsWith(FILE_COMMAND) && (line.trim().length() > FILE_COMMAND.length())) {
|
|
|
|
try {
|
|
|
|
String file = line.substring(FILE_COMMAND.length());
|
|
|
|
boolean sent = sendFile(file);
|
|
|
|
if (!sent) {
|
|
|
|
_out.write("Failed sending the file: " + file + NL);
|
|
|
|
}
|
|
|
|
} catch (IOException ioe) {
|
|
|
|
_out.write("Error sending the file: " + ioe.getMessage() + NL);
|
|
|
|
_log.error("Error sending the file", ioe);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
boolean ok = _session.sendMessage(_peerDestination, ("[" + now() + "] " + line).getBytes());
|
|
|
|
if (!ok) {
|
|
|
|
_out.write("Failed sending message. Peer disconnected?" + NL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (IOException ioe) {
|
|
|
|
_log.error("Error running", ioe);
|
|
|
|
} catch (I2PSessionException ise) {
|
|
|
|
_log.error("Error communicating", ise);
|
|
|
|
} catch (DataFormatException dfe) {
|
|
|
|
_log.error("Peer destination file is not valid", dfe);
|
|
|
|
} finally {
|
|
|
|
try {
|
|
|
|
_log.debug("Exiting anonymous talk session");
|
|
|
|
if (_out != null) _out.write("Exiting anonymous talk session");
|
|
|
|
} catch (IOException ioe) {
|
|
|
|
// ignored
|
|
|
|
}
|
|
|
|
if (_session != null) {
|
|
|
|
try {
|
|
|
|
_session.destroySession();
|
|
|
|
} catch (I2PSessionException ise) {
|
|
|
|
// ignored
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
Thread.sleep(5000);
|
2004-07-31 01:04:34 +00:00
|
|
|
} catch (InterruptedException ie) { // nop!
|
2004-04-10 11:39:00 +00:00
|
|
|
}
|
|
|
|
}
|
2004-04-08 04:48:39 +00:00
|
|
|
}
|
2004-04-10 11:39:00 +00:00
|
|
|
|
2004-04-08 04:48:39 +00:00
|
|
|
private String now() {
|
2004-04-10 11:39:00 +00:00
|
|
|
Date now = new Date(Clock.getInstance().now());
|
|
|
|
return _fmt.format(now);
|
2004-04-08 04:48:39 +00:00
|
|
|
}
|
2004-04-10 11:39:00 +00:00
|
|
|
|
2004-04-08 04:48:39 +00:00
|
|
|
/** Send the given file to the current peer. This works by sending a message
|
|
|
|
* saying ".file: filename\nbodyOfFile", where filename is the name of the file
|
|
|
|
* (which the recipient will be shown), and the bodyOfFile is the set of raw
|
|
|
|
* bytes in the file.
|
|
|
|
*
|
|
|
|
* @throws IOException if the file could not be found or read
|
|
|
|
* @return false if the file could not be sent to the peer
|
|
|
|
*/
|
|
|
|
private boolean sendFile(String filename) throws IOException, I2PSessionException {
|
2004-04-10 11:39:00 +00:00
|
|
|
_log.debug("Sending file [" + filename + "]");
|
|
|
|
ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
|
|
|
|
baos.write((FILE_COMMAND + filename + "\n").getBytes());
|
|
|
|
FileInputStream fin = new FileInputStream(filename);
|
|
|
|
byte buf[] = new byte[4096];
|
|
|
|
try {
|
|
|
|
while (true) {
|
|
|
|
int len = fin.read(buf);
|
|
|
|
if (len == -1) break;
|
|
|
|
baos.write(buf, 0, len);
|
|
|
|
}
|
|
|
|
} catch (IOException ioe) {
|
|
|
|
_log.debug("Failed reading the file", ioe);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
baos.close();
|
|
|
|
byte val[] = baos.toByteArray();
|
|
|
|
_log.debug("Sending " + filename + " with a full payload of " + val.length);
|
|
|
|
try {
|
|
|
|
boolean rv = _session.sendMessage(_peerDestination, val);
|
|
|
|
_log.debug("Sending " + filename + " complete: rv = " + rv);
|
|
|
|
return rv;
|
|
|
|
} catch (Throwable t) {
|
|
|
|
_log.error("Error sending file", t);
|
|
|
|
return false;
|
|
|
|
}
|
2004-04-08 04:48:39 +00:00
|
|
|
}
|
2004-04-10 11:39:00 +00:00
|
|
|
|
2004-04-08 04:48:39 +00:00
|
|
|
/** I2PSessionListener.messageAvailable requires this method to be called whenever
|
|
|
|
* I2P wants to tell the session that a message is available. ATalk always grabs
|
|
|
|
* the message immediately and either processes it as a "send file" command (passing
|
2004-04-08 09:07:53 +00:00
|
|
|
* it off to handleRecieveFile(..) or simply displays the
|
2004-04-08 04:48:39 +00:00
|
|
|
* message to the user.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public void messageAvailable(I2PSession session, int msgId, long size) {
|
2004-04-10 11:39:00 +00:00
|
|
|
_log.debug("Message available: id = " + msgId + " size = " + size);
|
|
|
|
try {
|
|
|
|
byte msg[] = session.receiveMessage(msgId);
|
|
|
|
// inefficient way to just read the first line of text, but its easy
|
|
|
|
BufferedReader reader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(msg)));
|
|
|
|
String line = reader.readLine();
|
|
|
|
if (line.startsWith(FILE_COMMAND)) {
|
|
|
|
handleRecieveFile(line, msg);
|
|
|
|
} else {
|
|
|
|
// not a file command, so just plop 'er out on the screen
|
|
|
|
_out.write(now() + " --> " + new String(msg));
|
|
|
|
_out.write(NL);
|
|
|
|
_out.flush();
|
|
|
|
}
|
|
|
|
} catch (I2PSessionException ise) {
|
|
|
|
_log.error("Error fetching available message", ise);
|
|
|
|
} catch (IOException ioe) {
|
|
|
|
_log.error("Error writing out the message", ioe);
|
|
|
|
}
|
2004-04-08 04:48:39 +00:00
|
|
|
}
|
2004-04-10 11:39:00 +00:00
|
|
|
|
2004-04-08 04:48:39 +00:00
|
|
|
/** React to a file being sent our way from the peer via {@link #sendFile sendFile}
|
|
|
|
* by saving the file to a temporary location and displaying where, what, and how large
|
|
|
|
* it is.
|
|
|
|
*
|
|
|
|
* @param firstline the first line of the message that, according to the sendFile
|
|
|
|
* implementation, contains the command and the filename that it was stored
|
|
|
|
* at on the peer's computer
|
|
|
|
* @param msg the entire message recieved, including the firstline
|
|
|
|
*/
|
|
|
|
private void handleRecieveFile(String firstline, byte msg[]) throws IOException {
|
2004-04-10 11:39:00 +00:00
|
|
|
_log.debug("handleRecieveFile called");
|
|
|
|
File f = File.createTempFile("recieve", ".dat", new File("."));
|
|
|
|
FileOutputStream fos = new FileOutputStream(f);
|
|
|
|
int lineLen = firstline.getBytes().length + "\n".getBytes().length;
|
|
|
|
int lenToCopy = msg.length - lineLen;
|
|
|
|
byte buf[] = new byte[lenToCopy];
|
|
|
|
System.arraycopy(msg, lineLen, buf, 0, lenToCopy);
|
|
|
|
fos.write(buf);
|
|
|
|
fos.close();
|
|
|
|
String name = firstline.substring(FILE_COMMAND.length());
|
|
|
|
_out.write("Recieved a file called [" + name + "] of size [" + lenToCopy + "] bytes, saved as ["
|
|
|
|
+ f.getAbsolutePath() + "]" + NL);
|
|
|
|
_out.flush();
|
2004-04-08 04:48:39 +00:00
|
|
|
}
|
2004-04-10 11:39:00 +00:00
|
|
|
|
2004-04-08 04:48:39 +00:00
|
|
|
/** driver */
|
|
|
|
public static void main(String args[]) {
|
big ol' update to strip out the singletons, replacing them with
a rooted app context. The core itself has its own I2PAppContext
(see its javadoc for, uh, docs), and the router extends that to
expose the router's singletons. The main point of this is to
make it so that we can run multiple routers in the same JVM, even
to allow different apps in the same JVM to switch singleton
implementations (e.g. run some routers with one set of profile
calculators, and other routers with a different one).
There is still some work to be done regarding the actual boot up
of multiple routers in a JVM, as well as their configuration,
though the plan is to have the RouterContext override the
I2PAppContext's getProperty/getPropertyNames methods to read from
a config file (seperate ones per context) instead of using the
System.getProperty that the base I2PAppContext uses.
Once the multi-router is working, i'll shim in a VMCommSystem
that doesn't depend upon sockets or threads to read/write (and
that uses configurable message send delays / disconnects / etc,
perhaps using data from the routerContext.getProperty to drive it).
I could hold off until the sim is all working, but there's a
truckload of changes in here and I hate dealing with conflicts ;)
Everything works - I've been running 'er for a while and kicked
the tires a bit, but if you see something amiss, please let me
know.
2004-04-24 11:54:35 +00:00
|
|
|
I2PAppContext context = new I2PAppContext();
|
2004-04-10 11:39:00 +00:00
|
|
|
if (args.length == 2) {
|
|
|
|
String myKeyFile = args[0];
|
|
|
|
String myDestinationFile = args[1];
|
|
|
|
boolean success = generateKeys(myKeyFile, myDestinationFile);
|
|
|
|
if (success)
|
|
|
|
_log.debug("Keys generated (private key file: " + myKeyFile + " destination file: " + myDestinationFile
|
|
|
|
+ ")");
|
|
|
|
else
|
|
|
|
_log.debug("Keys generation failed");
|
|
|
|
try {
|
|
|
|
Thread.sleep(5000);
|
2004-07-31 01:04:34 +00:00
|
|
|
} catch (InterruptedException ie) { // nop
|
2004-04-10 11:39:00 +00:00
|
|
|
}
|
|
|
|
} else if (args.length == 3) {
|
|
|
|
_log.debug("Starting chat");
|
|
|
|
String myKeyfile = args[0];
|
|
|
|
String peerDestFile = args[1];
|
|
|
|
String shouldLog = args[2];
|
|
|
|
if (Boolean.TRUE.toString().equalsIgnoreCase(shouldLog))
|
big ol' update to strip out the singletons, replacing them with
a rooted app context. The core itself has its own I2PAppContext
(see its javadoc for, uh, docs), and the router extends that to
expose the router's singletons. The main point of this is to
make it so that we can run multiple routers in the same JVM, even
to allow different apps in the same JVM to switch singleton
implementations (e.g. run some routers with one set of profile
calculators, and other routers with a different one).
There is still some work to be done regarding the actual boot up
of multiple routers in a JVM, as well as their configuration,
though the plan is to have the RouterContext override the
I2PAppContext's getProperty/getPropertyNames methods to read from
a config file (seperate ones per context) instead of using the
System.getProperty that the base I2PAppContext uses.
Once the multi-router is working, i'll shim in a VMCommSystem
that doesn't depend upon sockets or threads to read/write (and
that uses configurable message send delays / disconnects / etc,
perhaps using data from the routerContext.getProperty to drive it).
I could hold off until the sim is all working, but there's a
truckload of changes in here and I hate dealing with conflicts ;)
Everything works - I've been running 'er for a while and kicked
the tires a bit, but if you see something amiss, please let me
know.
2004-04-24 11:54:35 +00:00
|
|
|
context.logManager().setDisplayOnScreen(true);
|
2004-04-10 11:39:00 +00:00
|
|
|
else
|
big ol' update to strip out the singletons, replacing them with
a rooted app context. The core itself has its own I2PAppContext
(see its javadoc for, uh, docs), and the router extends that to
expose the router's singletons. The main point of this is to
make it so that we can run multiple routers in the same JVM, even
to allow different apps in the same JVM to switch singleton
implementations (e.g. run some routers with one set of profile
calculators, and other routers with a different one).
There is still some work to be done regarding the actual boot up
of multiple routers in a JVM, as well as their configuration,
though the plan is to have the RouterContext override the
I2PAppContext's getProperty/getPropertyNames methods to read from
a config file (seperate ones per context) instead of using the
System.getProperty that the base I2PAppContext uses.
Once the multi-router is working, i'll shim in a VMCommSystem
that doesn't depend upon sockets or threads to read/write (and
that uses configurable message send delays / disconnects / etc,
perhaps using data from the routerContext.getProperty to drive it).
I could hold off until the sim is all working, but there's a
truckload of changes in here and I hate dealing with conflicts ;)
Everything works - I've been running 'er for a while and kicked
the tires a bit, but if you see something amiss, please let me
know.
2004-04-24 11:54:35 +00:00
|
|
|
context.logManager().setDisplayOnScreen(false);
|
2004-04-10 11:39:00 +00:00
|
|
|
String logFile = args[2];
|
|
|
|
Thread talkThread = new I2PThread(new ATalk(myKeyfile, peerDestFile));
|
|
|
|
talkThread.start();
|
|
|
|
} else {
|
|
|
|
System.out.println(MANUAL);
|
|
|
|
try {
|
|
|
|
Thread.sleep(5000);
|
2004-07-31 01:04:34 +00:00
|
|
|
} catch (InterruptedException ie) { // nop
|
2004-04-10 11:39:00 +00:00
|
|
|
}
|
|
|
|
System.exit(-1);
|
|
|
|
}
|
2004-04-08 04:48:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Generate a new Destination, saving that destination and the associated
|
|
|
|
* private keys in the privKeyFile, and also saving the destination without
|
|
|
|
* any private keys to destinationFile.
|
|
|
|
*
|
|
|
|
* @param privKeyFile private key file, including the destination and the various
|
|
|
|
* private keys, as defined by {@link I2PClient#createDestination I2PClient.createDestination}
|
|
|
|
* @param destinationFile file in which the Destination is serialized in
|
|
|
|
*/
|
|
|
|
private static boolean generateKeys(String privKeyFile, String destinationFile) {
|
2004-04-10 11:39:00 +00:00
|
|
|
try {
|
|
|
|
Destination d = I2PClientFactory.createClient().createDestination(new FileOutputStream(privKeyFile));
|
|
|
|
FileOutputStream fos = new FileOutputStream(destinationFile);
|
|
|
|
d.writeBytes(fos);
|
|
|
|
fos.flush();
|
|
|
|
fos.close();
|
|
|
|
return true;
|
|
|
|
} catch (IOException ioe) {
|
|
|
|
_log.error("Error generating keys", ioe);
|
|
|
|
} catch (I2PException ipe) {
|
|
|
|
_log.error("Error generating keys", ipe);
|
|
|
|
}
|
|
|
|
return false;
|
2004-04-08 04:48:39 +00:00
|
|
|
}
|
2004-04-10 11:39:00 +00:00
|
|
|
|
2004-04-08 04:48:39 +00:00
|
|
|
/** required by {@link I2PSessionListener I2PSessionListener} to notify of disconnect */
|
2004-04-10 11:39:00 +00:00
|
|
|
public void disconnected(I2PSession session) {
|
|
|
|
_log.debug("Disconnected");
|
|
|
|
}
|
|
|
|
|
2004-04-08 04:48:39 +00:00
|
|
|
/** required by {@link I2PSessionListener I2PSessionListener} to notify of error */
|
2004-04-10 11:39:00 +00:00
|
|
|
public void errorOccurred(I2PSession session, String message, Throwable error) {
|
|
|
|
_log.debug("Error occurred: " + message, error);
|
|
|
|
}
|
|
|
|
|
2004-04-08 04:48:39 +00:00
|
|
|
/** required by {@link I2PSessionListener I2PSessionListener} to notify of abuse */
|
2004-04-10 11:39:00 +00:00
|
|
|
public void reportAbuse(I2PSession session, int severity) {
|
|
|
|
_log.debug("Abuse reported of severity " + severity);
|
|
|
|
}
|
2008-11-26 15:56:36 +00:00
|
|
|
}
|
|
|
|
|