Skip to content
This repository has been archived by the owner on Nov 13, 2017. It is now read-only.

Commit

Permalink
Update to I2P 0.9.11
Browse files Browse the repository at this point in the history
  • Loading branch information
oakes committed Feb 26, 2014
1 parent a2da9c1 commit 677a2bb
Show file tree
Hide file tree
Showing 173 changed files with 2,254 additions and 1,805 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
*/
public abstract class AcceptingChannel extends SelectableChannel {

abstract I2PSocket accept() throws I2PException, ConnectException;
protected abstract I2PSocket accept() throws I2PException, ConnectException;

protected final I2PSocketManager _socketManager;

AcceptingChannel(I2PSocketManager manager) {
protected AcceptingChannel(I2PSocketManager manager) {
this._socketManager = manager;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.net.MalformedURLException;
import java.net.UnknownHostException;
import java.net.URL;
import java.util.Locale;
import java.util.Properties;

import net.i2p.I2PAppContext;
Expand Down Expand Up @@ -193,13 +194,17 @@ protected String getRequest() throws IOException {
buf.append("Accept-Encoding: \r\n" +
"Cache-control: no-cache\r\n" +
"Pragma: no-cache\r\n" +
"User-Agent: " + USER_AGENT + "\r\n" +
"Connection: close\r\n");
boolean uaOverridden = false;
if (_extraHeaders != null) {
for (String hdr : _extraHeaders) {
if (hdr.toLowerCase(Locale.US).startsWith("user-agent: "))
uaOverridden = true;
buf.append(hdr).append("\r\n");
}
}
if(!uaOverridden)
buf.append("User-Agent: " + USER_AGENT + "\r\n");
buf.append("\r\n");
return buf.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;

Expand All @@ -26,7 +25,7 @@
public class I2PSocketManagerFactory {

public static final String PROP_MANAGER = "i2p.streaming.manager";
public static final String DEFAULT_MANAGER = "net.i2p.client.streaming.I2PSocketManagerFull";
public static final String DEFAULT_MANAGER = "net.i2p.client.streaming.impl.I2PSocketManagerFull";

/**
* Create a socket manager using a brand new destination connected to the
Expand Down Expand Up @@ -202,7 +201,7 @@ private static I2PSocketManager createManager(InputStream myPrivateKeyStream, St
if (opts == null)
opts = new Properties();
Properties syscopy = (Properties) System.getProperties().clone();
for (Map.Entry e : syscopy.entrySet()) {
for (Map.Entry<Object, Object> e : syscopy.entrySet()) {
String name = (String) e.getKey();
if (!opts.containsKey(name))
opts.setProperty(name, (String) e.getValue());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
package net.i2p.client.streaming;

import net.i2p.I2PException;
package net.i2p.client.streaming.impl;

import java.net.SocketTimeoutException;
import java.net.ConnectException;
Expand All @@ -12,6 +10,12 @@
import java.nio.channels.spi.AbstractSelectionKey;
import java.nio.channels.spi.SelectorProvider;

import net.i2p.I2PException;
import net.i2p.client.streaming.AcceptingChannel;
import net.i2p.client.streaming.I2PServerSocket;
import net.i2p.client.streaming.I2PSocket;
import net.i2p.client.streaming.I2PSocketManager;

/**
* As this does not (yet) extend ServerSocketChannel it cannot be returned by StandardServerSocket.getChannel(),
* until we implement an I2P SocketAddress class.
Expand All @@ -29,7 +33,7 @@ class AcceptingChannelImpl extends AcceptingChannel {
private volatile I2PSocket next;
private final I2PServerSocket socket;

I2PSocket accept() throws I2PException, ConnectException {
protected I2PSocket accept() throws I2PException, ConnectException {
I2PSocket sock;
try {
sock = socket.accept();
Expand All @@ -43,7 +47,7 @@ I2PSocket accept() throws I2PException, ConnectException {
}
}

AcceptingChannelImpl(I2PSocketManager manager) {
protected AcceptingChannelImpl(I2PSocketManager manager) {
super(manager);
// this cheats and just sets the manager timeout low in order to repeatedly poll it.
// that means we can "only" accept one new connection every 100 milliseconds.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.i2p.client.streaming;
package net.i2p.client.streaming.impl;

import java.util.concurrent.atomic.AtomicInteger;

Expand Down Expand Up @@ -30,7 +30,7 @@ class ConnThrottler {
_totalMax = totalMax;
this.counter = new ObjectCounter<Hash>();
_currentTotal = new AtomicInteger();
// shorten the initial period by a random amount,mpleScheduler.getInstance().addPeriodicEvent(new Cleaner(),
// shorten the initial period by a random amount
// to prevent correlation across destinations
// and identification of router startup time
SimpleScheduler.getInstance().addPeriodicEvent(new Cleaner(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.i2p.client.streaming;
package net.i2p.client.streaming.impl;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -15,7 +15,6 @@
import net.i2p.data.DataHelper;
import net.i2p.data.Destination;
import net.i2p.util.Log;
import net.i2p.util.SimpleScheduler;
import net.i2p.util.SimpleTimer;
import net.i2p.util.SimpleTimer2;

Expand Down Expand Up @@ -125,7 +124,7 @@ public Connection(I2PAppContext ctx, ConnectionManager manager, SchedulerChooser
// FIXME pass through a passive flush delay setting as the 4th arg
_outputStream = new MessageOutputStream(_context, timer, _receiver, (opts == null ? Packet.MAX_PAYLOAD_SIZE : opts.getMaxMessageSize()));
_timer = timer;
_outboundPackets = new TreeMap();
_outboundPackets = new TreeMap<Long, PacketLocal>();
if (opts != null) {
_localPort = opts.getLocalPort();
_remotePort = opts.getPort();
Expand Down Expand Up @@ -469,7 +468,7 @@ public List<PacketLocal> ackPackets(long ackThrough, long nacks[]) {
}
if (!nacked) { // aka ACKed
if (acked == null)
acked = new ArrayList(8);
acked = new ArrayList<PacketLocal>(8);
PacketLocal ackedPacket = e.getValue();
ackedPacket.ackReceived();
acked.add(ackedPacket);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.i2p.client.streaming;
package net.i2p.client.streaming.impl;

import net.i2p.I2PAppContext;
import net.i2p.data.ByteArray;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package net.i2p.client.streaming;
package net.i2p.client.streaming.impl;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

import net.i2p.I2PAppContext;
import net.i2p.data.Destination;
import net.i2p.util.Log;
import net.i2p.util.SimpleScheduler;
import net.i2p.util.SimpleTimer;

/**
Expand All @@ -22,7 +21,7 @@ class ConnectionHandler {
private final Log _log;
private final ConnectionManager _manager;
private final LinkedBlockingQueue<Packet> _synQueue;
private boolean _active;
private volatile boolean _active;
private int _acceptTimeout;

/** max time after receiveNewSyn() and before the matched accept() */
Expand Down Expand Up @@ -231,7 +230,8 @@ private void sendReset(Packet packet) {
}

private class TimeoutSyn implements SimpleTimer.TimedEvent {
private Packet _synPacket;
private final Packet _synPacket;

public TimeoutSyn(Packet packet) {
_synPacket = packet;
}
Expand All @@ -240,12 +240,15 @@ public void timeReached() {
boolean removed = _synQueue.remove(_synPacket);

if (removed) {
if (_synPacket.isFlagSet(Packet.FLAG_SYNCHRONIZE))
if (_synPacket.isFlagSet(Packet.FLAG_SYNCHRONIZE)) {
if (_log.shouldLog(Log.WARN))
_log.warn("Expired on the SYN queue: " + _synPacket);
// timeout - send RST
sendReset(_synPacket);
else
} else {
// non-syn packet got stranded on the syn queue, send it to the con
reReceivePacket(_synPacket);
}
} else {
// handled. noop
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.i2p.client.streaming;
package net.i2p.client.streaming.impl;

import java.util.HashSet;
import java.util.Iterator;
Expand Down Expand Up @@ -593,8 +593,9 @@ public boolean ping(Destination peer, long timeoutMs, boolean blocking, PingNoti
Long id = Long.valueOf(_context.random().nextLong(Packet.MAX_STREAM_ID-1)+1);
PacketLocal packet = new PacketLocal(_context, peer);
packet.setSendStreamId(id.longValue());
packet.setFlag(Packet.FLAG_ECHO);
packet.setFlag(Packet.FLAG_SIGNATURE_INCLUDED);
packet.setFlag(Packet.FLAG_ECHO |
Packet.FLAG_NO_ACK |
Packet.FLAG_SIGNATURE_INCLUDED);
packet.setOptionalFrom(_session.getMyDestination());
//if ( (keyToUse != null) && (tagsToSend != null) ) {
// packet.setKeyUsed(keyToUse);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package net.i2p.client.streaming;
package net.i2p.client.streaming.impl;

import net.i2p.client.streaming.I2PSocketOptions;

import java.util.Collections;
import java.util.HashSet;
Expand Down Expand Up @@ -767,13 +769,13 @@ private void initLists(Properties opts) {
// but avoid concurrent modification just in case
Set<Hash> accessList, blackList;
if (accessListEnabled)
accessList = new HashSet();
accessList = new HashSet<Hash>();
else
accessList = Collections.EMPTY_SET;
accessList = Collections.emptySet();
if (blackListEnabled)
blackList = new HashSet();
blackList = new HashSet<Hash>();
else
blackList = Collections.EMPTY_SET;
blackList = Collections.emptySet();
if (accessListEnabled || blackListEnabled) {
String hashes = opts.getProperty(PROP_ACCESS_LIST);
if (hashes == null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.i2p.client.streaming;
package net.i2p.client.streaming.impl;

import java.util.List;

Expand All @@ -7,7 +7,6 @@
import net.i2p.data.DataHelper;
import net.i2p.data.Destination;
import net.i2p.util.Log;
import net.i2p.util.SimpleScheduler;
import net.i2p.util.SimpleTimer;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package net.i2p.client.streaming;
package net.i2p.client.streaming.impl;

import java.net.SocketTimeoutException;

import net.i2p.I2PException;
import net.i2p.client.streaming.AcceptingChannel;
import net.i2p.client.streaming.I2PServerSocket;
import net.i2p.client.streaming.I2PSocket;
import net.i2p.client.streaming.I2PSocketManager;

/**
* Bridge to allow accepting new connections
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.i2p.client.streaming;
package net.i2p.client.streaming.impl;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -8,6 +8,8 @@

import net.i2p.I2PAppContext;
import net.i2p.client.I2PSession;
import net.i2p.client.streaming.I2PSocket;
import net.i2p.client.streaming.I2PSocketOptions;
import net.i2p.data.Destination;
import net.i2p.util.Log;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.i2p.client.streaming;
package net.i2p.client.streaming.impl;

import java.io.IOException;
import java.net.NoRouteToHostException;
Expand All @@ -15,10 +15,13 @@
import net.i2p.I2PException;
import net.i2p.client.I2PSession;
import net.i2p.client.I2PSessionException;
import net.i2p.client.streaming.I2PServerSocket;
import net.i2p.client.streaming.I2PSocket;
import net.i2p.client.streaming.I2PSocketManager;
import net.i2p.client.streaming.I2PSocketOptions;
import net.i2p.data.Destination;
import net.i2p.util.Log;


/**
* Centralize the coordination and multiplexing of the local client's streaming.
* There should be one I2PSocketManager for each I2PSession, and if an application
Expand Down Expand Up @@ -302,8 +305,9 @@ private Socket connectToSocket(Destination peer, I2PSocketOptions options) throw
I2PSocket sock = connect(peer, options);
return new StandardSocket(sock);
} catch (I2PException i2pe) {
// fixme in 1.6 change to cause
throw new IOException(i2pe.toString());
IOException ioe = new IOException("connect fail");
ioe.initCause(i2pe);
throw ioe;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package net.i2p.client.streaming;
package net.i2p.client.streaming.impl;

import java.util.Properties;

import net.i2p.client.streaming.I2PSocketOptions;

/**
* Define the configuration for streaming and verifying data on the socket.
* Use I2PSocketManager.buildOptions() to get one of these.
Expand Down Expand Up @@ -93,7 +95,7 @@ protected static int getInt(Properties opts, String name, int defaultVal) {
}
}

protected static double getDouble(Properties opts, String name, double defaultVal) {
public static double getDouble(Properties opts, String name, double defaultVal) {
if (opts == null) return defaultVal;
String val = opts.getProperty(name);
if (val == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.i2p.client.streaming;
package net.i2p.client.streaming.impl;

import java.io.IOException;
import java.io.InterruptedIOException;
Expand All @@ -14,6 +14,8 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import net.i2p.client.streaming.I2PSocket;

/**
* As this does not (yet) extend SocketChannel it cannot be returned by StandardSocket.getChannel(),
* until we implement an I2P SocketAddress class.
Expand Down
Loading

0 comments on commit 677a2bb

Please sign in to comment.