propagate from branch 'i2p.i2p' (head 2072db743073a703da2f4be9707e7edd696c2925)

to branch 'i2p.i2p.zzz.test' (head cc952c7db4822bb6c49c8e6fb6df02a62c6cbe63)
This commit is contained in:
zzz
2011-07-15 22:27:31 +00:00
45 changed files with 1814 additions and 579 deletions

View File

@ -44,7 +44,9 @@ public interface I2PClient {
* using the specified options to both connect to the router, to instruct
* the router how to handle the new session, and to configure the end to end
* encryption.
* @param destKeyStream location from which to read the Destination, PrivateKey, and SigningPrivateKey from
*
* @param destKeyStream location from which to read the Destination, PrivateKey, and SigningPrivateKey from,
* format is specified in {@link net.i2p.data.PrivateKeyFile PrivateKeyFile}
* @param options set of options to configure the router with, if null will use System properties
* @return new session allowing a Destination to recieve all of its messages and send messages to any other Destination.
*/
@ -52,8 +54,10 @@ public interface I2PClient {
/** Create a new destination with the default certificate creation properties and store
* it, along with the private encryption and signing keys at the specified location
*
* @param destKeyStream create a new destination and write out the object to the given stream,
* formatted as Destination, PrivateKey, and SigningPrivateKey
* format is specified in {@link net.i2p.data.PrivateKeyFile PrivateKeyFile}
* @return new destination
*/
public Destination createDestination(OutputStream destKeyStream) throws I2PException, IOException;
@ -61,7 +65,8 @@ public interface I2PClient {
/** Create a new destination with the given certificate and store it, along with the private
* encryption and signing keys at the specified location
*
* @param destKeyStream location to write out the destination, PrivateKey, and SigningPrivateKey
* @param destKeyStream location to write out the destination, PrivateKey, and SigningPrivateKey,
* format is specified in {@link net.i2p.data.PrivateKeyFile PrivateKeyFile}
* @param cert certificate to tie to the destination
* @return newly created destination
*/

View File

@ -30,8 +30,12 @@ import net.i2p.data.SigningPublicKey;
* @author jrandom
*/
class I2PClientImpl implements I2PClient {
/**
* Create the destination with a null payload
*
* @param destKeyStream location to write out the destination, PrivateKey, and SigningPrivateKey,
* format is specified in {@link net.i2p.data.PrivateKeyFile PrivateKeyFile}
*/
public Destination createDestination(OutputStream destKeyStream) throws I2PException, IOException {
Certificate cert = new Certificate();
@ -44,6 +48,8 @@ class I2PClientImpl implements I2PClient {
* Create the destination with the given payload and write it out along with
* the PrivateKey and SigningPrivateKey to the destKeyStream
*
* @param destKeyStream location to write out the destination, PrivateKey, and SigningPrivateKey,
* format is specified in {@link net.i2p.data.PrivateKeyFile PrivateKeyFile}
*/
public Destination createDestination(OutputStream destKeyStream, Certificate cert) throws I2PException, IOException {
Destination d = new Destination();
@ -67,13 +73,20 @@ class I2PClientImpl implements I2PClient {
/**
* Create a new session (though do not connect it yet)
*
* @param destKeyStream location from which to read the Destination, PrivateKey, and SigningPrivateKey from,
* format is specified in {@link net.i2p.data.PrivateKeyFile PrivateKeyFile}
* @param options set of options to configure the router with, if null will use System properties
*/
public I2PSession createSession(InputStream destKeyStream, Properties options) throws I2PSessionException {
return createSession(I2PAppContext.getGlobalContext(), destKeyStream, options);
}
/**
* Create a new session (though do not connect it yet)
*
* @param destKeyStream location from which to read the Destination, PrivateKey, and SigningPrivateKey from,
* format is specified in {@link net.i2p.data.PrivateKeyFile PrivateKeyFile}
* @param options set of options to configure the router with, if null will use System properties
*/
public I2PSession createSession(I2PAppContext context, InputStream destKeyStream, Properties options) throws I2PSessionException {

View File

@ -217,11 +217,34 @@ public interface I2PSession {
*/
public int[] bandwidthLimits() throws I2PSessionException;
/** See I2PSessionMuxedImpl for details */
/**
* Listen on specified protocol and port.
*
* An existing listener with the same proto and port is replaced.
* Only the listener with the best match is called back for each message.
*
* @param proto 1-254 or PROTO_ANY (0) for all; recommended:
* I2PSession.PROTO_STREAMING
* I2PSession.PROTO_DATAGRAM
* 255 disallowed
* @param port 1-65535 or PORT_ANY (0) for all
* @since 0.7.1
*/
public void addSessionListener(I2PSessionListener lsnr, int proto, int port);
/** See I2PSessionMuxedImpl for details */
/**
* Listen on specified protocol and port, and receive notification
* of proto, fromPort, and toPort for every message.
* @param proto 1-254 or PROTO_ANY (0) for all; 255 disallowed
* @param port 1-65535 or PORT_ANY (0) for all
* @since 0.7.1
*/
public void addMuxedSessionListener(I2PSessionMuxedListener l, int proto, int port);
/** See I2PSessionMuxedImpl for details */
/**
* removes the specified listener (only)
* @since 0.7.1
*/
public void removeListener(int proto, int port);
public static final int PORT_ANY = 0;

View File

@ -16,13 +16,14 @@ import net.i2p.util.Log;
* depending on whether they want to hear about the
* protocol, from port, and to port for every received message.
*
* This only calls one listener, not all that apply.
* messageAvailable() only calls one listener, not all that apply.
* The others call all listeners.
*
* @author zzz
*/
public class I2PSessionDemultiplexer implements I2PSessionMuxedListener {
private Log _log;
private Map<Integer, I2PSessionMuxedListener> _listeners;
private final Log _log;
private final Map<Integer, I2PSessionMuxedListener> _listeners;
public I2PSessionDemultiplexer(I2PAppContext ctx) {
_log = ctx.logManager().getLog(I2PSessionDemultiplexer.class);

View File

@ -159,6 +159,8 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa
* Create a new session, reading the Destination, PrivateKey, and SigningPrivateKey
* from the destKeyStream, and using the specified options to connect to the router
*
* @param destKeyStream stream containing the private key data,
* format is specified in {@link net.i2p.data.PrivateKeyFile PrivateKeyFile}
* @param options set of options to configure the router with, if null will use System properties
* @throws I2PSessionException if there is a problem loading the private keys or
*/

View File

@ -49,6 +49,8 @@ class I2PSessionImpl2 extends I2PSessionImpl {
* Create a new session, reading the Destination, PrivateKey, and SigningPrivateKey
* from the destKeyStream, and using the specified options to connect to the router
*
* @param destKeyStream stream containing the private key data,
* format is specified in {@link net.i2p.data.PrivateKeyFile PrivateKeyFile}
* @param options set of options to configure the router with, if null will use System properties
* @throws I2PSessionException if there is a problem loading the private keys or
*/

View File

@ -65,9 +65,12 @@ import net.i2p.util.SimpleScheduler;
* @author zzz
*/
class I2PSessionMuxedImpl extends I2PSessionImpl2 implements I2PSession {
private I2PSessionDemultiplexer _demultiplexer;
private final I2PSessionDemultiplexer _demultiplexer;
/*
* @param destKeyStream stream containing the private key data,
* format is specified in {@link net.i2p.data.PrivateKeyFile PrivateKeyFile}
* @param options set of options to configure the router with, if null will use System properties
*/
public I2PSessionMuxedImpl(I2PAppContext ctx, InputStream destKeyStream, Properties options) throws I2PSessionException {
@ -92,11 +95,11 @@ class I2PSessionMuxedImpl extends I2PSessionImpl2 implements I2PSession {
* An existing listener with the same proto and port is replaced.
* Only the listener with the best match is called back for each message.
*
* @param proto 1-254 or PROTO_ANY for all; recommended:
* @param proto 1-254 or PROTO_ANY (0) for all; recommended:
* I2PSession.PROTO_STREAMING
* I2PSession.PROTO_DATAGRAM
* 255 disallowed
* @param port 1-65535 or PORT_ANY for all
* @param port 1-65535 or PORT_ANY (0) for all
*/
@Override
public void addSessionListener(I2PSessionListener lsnr, int proto, int port) {
@ -106,8 +109,8 @@ class I2PSessionMuxedImpl extends I2PSessionImpl2 implements I2PSession {
/**
* Listen on specified protocol and port, and receive notification
* of proto, fromPort, and toPort for every message.
* @param proto 1-254 or 0 for all; 255 disallowed
* @param port 1-65535 or 0 for all
* @param proto 1-254 or PROTO_ANY (0) for all; 255 disallowed
* @param port 1-65535 or PORT_ANY (0) for all
*/
@Override
public void addMuxedSessionListener(I2PSessionMuxedListener l, int proto, int port) {

View File

@ -9,13 +9,13 @@ package net.i2p.util;
*
*/
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.ListIterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
/**
* An implementation of the EventDispatcher interface. Since Java
@ -34,11 +34,9 @@ import java.util.Set;
*/
public class EventDispatcherImpl implements EventDispatcher {
//private final static Log _log = new Log(EventDispatcherImpl.class);
private boolean _ignore = false;
private final HashMap _events = new HashMap(4);
private final ArrayList _attached = new ArrayList();
private final Map<String, Object> _events = new ConcurrentHashMap(4);
private final List<EventDispatcher> _attached = new CopyOnWriteArrayList();
public EventDispatcher getEventDispatcher() {
return this;
@ -46,23 +44,12 @@ public class EventDispatcherImpl implements EventDispatcher {
public void attachEventDispatcher(EventDispatcher ev) {
if (ev == null) return;
synchronized (_attached) {
//_log.debug(this.hashCode() + ": attaching EventDispatcher " + ev.hashCode());
_attached.add(ev);
}
_attached.add(ev);
}
public void detachEventDispatcher(EventDispatcher ev) {
if (ev == null) return;
synchronized (_attached) {
ListIterator it = _attached.listIterator();
while (it.hasNext()) {
if (((EventDispatcher) it.next()) == ev) {
it.remove();
break;
}
}
}
_attached.remove(ev);
}
public void notifyEvent(String eventName, Object args) {
@ -70,50 +57,28 @@ public class EventDispatcherImpl implements EventDispatcher {
if (args == null) {
args = "[null value]";
}
//_log.debug(this.hashCode() + ": got notification [" + eventName + "] = [" + args + "]");
_events.put(eventName, args);
synchronized (_events) {
_events.put(eventName, args);
_events.notifyAll();
synchronized (_attached) {
Iterator it = _attached.iterator();
EventDispatcher e;
while (it.hasNext()) {
e = (EventDispatcher) it.next();
//_log.debug(this.hashCode() + ": notifying attached EventDispatcher " + e.hashCode() + ": ["
// + eventName + "] = [" + args + "]");
e.notifyEvent(eventName, args);
}
}
}
for (EventDispatcher e : _attached) {
e.notifyEvent(eventName, args);
}
}
public Object getEventValue(String name) {
if (_ignore) return null;
Object val;
synchronized (_events) {
val = _events.get(name);
}
return val;
return _events.get(name);
}
public Set getEvents() {
public Set<String> getEvents() {
if (_ignore) return Collections.EMPTY_SET;
Set set;
synchronized (_events) {
set = new HashSet(_events.keySet());
}
return set;
return new HashSet(_events.keySet());
}
public void ignoreEvents() {
_ignore = true;
synchronized (_events) {
_events.clear();
}
_events.clear();
}
public void unIgnoreEvents() {
@ -122,22 +87,15 @@ public class EventDispatcherImpl implements EventDispatcher {
public Object waitEventValue(String name) {
if (_ignore) return null;
Object val;
//_log.debug(this.hashCode() + ": waiting for [" + name + "]");
do {
synchronized (_events) {
if (_events.containsKey(name)) {
val = _events.get(name);
break;
}
Object val = _events.get(name);
if (val != null)
return val;
try {
_events.wait(1 * 1000);
} catch (InterruptedException e) { // nop
}
_events.wait(5 * 1000);
} catch (InterruptedException e) {}
}
} while (true);
return val;
}
}