reverted changes to mstreaming and streaming
This commit is contained in:
@ -30,37 +30,6 @@ public interface I2PServerSocket {
|
||||
*/
|
||||
public I2PSocket accept() throws I2PException, ConnectException, SocketTimeoutException;
|
||||
|
||||
/**
|
||||
* accept(timeout) waits timeout ms for a socket connecting. If a socket is
|
||||
* not available during the timeout, return null. accept(0) behaves like accept()
|
||||
*
|
||||
* @param timeout in ms
|
||||
*
|
||||
* @return a connected I2PSocket, or null
|
||||
*
|
||||
* @throws I2PException if there is a problem with reading a new socket
|
||||
* from the data available (aka the I2PSession closed, etc)
|
||||
* @throws ConnectException if the I2PServerSocket is closed
|
||||
* @throws InterruptedException if thread is interrupted while waiting
|
||||
*/
|
||||
public I2PSocket accept(long timeout) throws I2PException, ConnectException, InterruptedException;
|
||||
|
||||
/**
|
||||
* Wait until there is a socket waiting for acception or the timeout is
|
||||
* reached.
|
||||
*
|
||||
* @param timeoutMs timeout in ms. If ms is 0, wait forever.
|
||||
*
|
||||
* @return true if a socket is available, false if not
|
||||
*
|
||||
* @throws I2PException if there is a problem with reading a new socket
|
||||
* from the data available (aka the I2PSession closed, etc)
|
||||
* @throws ConnectException if the I2PServerSocket is closed
|
||||
* @throws InterruptedException if the thread is interrupted before
|
||||
* completion
|
||||
*/
|
||||
public void waitIncoming(long timeoutMs) throws I2PException, ConnectException, InterruptedException;
|
||||
|
||||
/**
|
||||
* Set Sock Option accept timeout
|
||||
* @param x timeout in ms
|
||||
|
@ -1,7 +1,6 @@
|
||||
package net.i2p.client.streaming;
|
||||
|
||||
import java.net.ConnectException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@ -50,82 +49,6 @@ class I2PServerSocketImpl implements I2PServerSocket {
|
||||
this.mgr = mgr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits until there is a socket waiting for acception or the timeout is
|
||||
* reached.
|
||||
*
|
||||
* @param timeoutMs timeout in ms. A negative value waits forever.
|
||||
*
|
||||
* @throws I2PException if there is a problem with reading a new socket
|
||||
* from the data available (aka the I2PSession closed, etc)
|
||||
* @throws ConnectException if the I2PServerSocket is closed
|
||||
* @throws InterruptedException if thread is interrupted while waiting
|
||||
*/
|
||||
public void waitIncoming(long timeoutMs) throws I2PException, ConnectException, InterruptedException {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("waitIncoming() called, pending: " + pendingSockets.size());
|
||||
|
||||
boolean isTimed = (timeoutMs>0);
|
||||
if (isTimed) {
|
||||
Clock clock = I2PAppContext.getGlobalContext().clock();
|
||||
long now = clock.now();
|
||||
long end = now + timeoutMs;
|
||||
while (pendingSockets.size() <= 0 && now<end) {
|
||||
if (closing) throw new ConnectException("I2PServerSocket closed");
|
||||
synchronized(socketAddedLock) {
|
||||
socketAddedLock.wait(end - now);
|
||||
}
|
||||
now = clock.now();
|
||||
}
|
||||
} else {
|
||||
while (pendingSockets.size() <= 0) {
|
||||
if (closing) throw new ConnectException("I2PServerSocket closed");
|
||||
try {
|
||||
synchronized(socketAddedLock) {
|
||||
socketAddedLock.wait();
|
||||
}
|
||||
} catch (InterruptedException ie) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* accept(timeout) waits timeout ms for a socket connecting. If a socket is
|
||||
* not available during the timeout, return null. accept(0) behaves like accept()
|
||||
*
|
||||
* @param timeout in ms
|
||||
*
|
||||
* @return a connected I2PSocket, or null
|
||||
*
|
||||
* @throws I2PException if there is a problem with reading a new socket
|
||||
* from the data available (aka the I2PSession closed, etc)
|
||||
* @throws ConnectException if the I2PServerSocket is closed
|
||||
* @throws InterruptedException if thread is interrupted while waiting
|
||||
*/
|
||||
public I2PSocket accept(long timeout) throws I2PException, ConnectException, InterruptedException {
|
||||
I2PSocket ret = null;
|
||||
|
||||
if (timeout<=0) {
|
||||
ret = accept();
|
||||
} else {
|
||||
long now = I2PAppContext.getGlobalContext().clock().now();
|
||||
long expiration = timeout + now ;
|
||||
synchronized (pendingSockets) {
|
||||
while (pendingSockets.size() == 0 && expiration>now) {
|
||||
pendingSockets.wait(expiration-now);
|
||||
now = I2PAppContext.getGlobalContext().clock().now();
|
||||
}
|
||||
ret = (I2PSocket)pendingSockets.remove(0);
|
||||
}
|
||||
if (ret != null) {
|
||||
synchronized (socketAcceptedLock) {
|
||||
socketAcceptedLock.notifyAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for the next socket connecting. If a remote user tried to make a
|
||||
* connection and the local application wasn't .accept()ing new connections,
|
||||
@ -145,11 +68,23 @@ class I2PServerSocketImpl implements I2PServerSocket {
|
||||
I2PSocket ret = null;
|
||||
|
||||
while ( (ret == null) && (!closing) ){
|
||||
while (pendingSockets.size() <= 0) {
|
||||
if (closing) throw new ConnectException("I2PServerSocket closed");
|
||||
try {
|
||||
this.waitIncoming(0);
|
||||
ret = accept(1);
|
||||
} catch (InterruptedException e) {
|
||||
throw new I2PException("Thread interrupted") ;
|
||||
synchronized(socketAddedLock) {
|
||||
socketAddedLock.wait();
|
||||
}
|
||||
} catch (InterruptedException ie) {}
|
||||
}
|
||||
synchronized (pendingSockets) {
|
||||
if (pendingSockets.size() > 0) {
|
||||
ret = (I2PSocket)pendingSockets.remove(0);
|
||||
}
|
||||
}
|
||||
if (ret != null) {
|
||||
synchronized (socketAcceptedLock) {
|
||||
socketAcceptedLock.notifyAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -350,6 +350,7 @@ class I2PSocketImpl implements I2PSocket {
|
||||
read = bc.startToByteArray(len);
|
||||
bc.notifyAll();
|
||||
}
|
||||
boolean timedOut = false;
|
||||
|
||||
while ( (read.length == 0) && (!inStreamClosed) ) {
|
||||
synchronized (flagLock) {
|
||||
|
@ -13,6 +13,7 @@ import net.i2p.client.I2PClient;
|
||||
import net.i2p.client.I2PClientFactory;
|
||||
import net.i2p.client.I2PSession;
|
||||
import net.i2p.client.I2PSessionException;
|
||||
import net.i2p.data.Destination;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
|
@ -130,6 +130,7 @@ class I2PSocketManagerImpl implements I2PSocketManager, I2PSessionListener {
|
||||
|
||||
public void messageAvailable(I2PSession session, int msgId, long size) {
|
||||
try {
|
||||
I2PSocketImpl s;
|
||||
byte msg[] = session.receiveMessage(msgId);
|
||||
if (msg.length == 1 && msg[0] == -1) {
|
||||
_log.debug(getName() + ": Ping received");
|
||||
|
@ -28,10 +28,6 @@ public class TestSwarm {
|
||||
private String _conOptions; // unused? used elsewhere?
|
||||
private boolean _dead; // unused? used elsewhere?
|
||||
|
||||
public void antiCompilationWarnings() {
|
||||
_log.debug(""+_conOptions+_dead);
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
if (args.length < 1) {
|
||||
System.err.println("Usage: TestSwarm myDestFile [peerDestFile ]*");
|
||||
@ -135,14 +131,6 @@ public class TestSwarm {
|
||||
_context.statManager().createRateStat("swarm." + _connectionId + ".lifetime", "How long we talk to a peer", "swarm", new long[] { 5*60*1000 });
|
||||
}
|
||||
|
||||
public void antiCompilationWarnings() {
|
||||
_log.debug(""+this._lastReceived+this._lastReceivedOn+this._started);
|
||||
}
|
||||
public void antiCompilationWarnings(long x, long y) {
|
||||
if (false)
|
||||
_log.debug(""+x+y);
|
||||
}
|
||||
|
||||
public Flooder(I2PSocket socket) {
|
||||
_socket = socket;
|
||||
_remoteDestination = socket.getPeerDestination();
|
||||
@ -166,8 +154,6 @@ public class TestSwarm {
|
||||
_context.random().nextBytes(data);
|
||||
long value = 0;
|
||||
long lastSend = _context.clock().now();
|
||||
this.antiCompilationWarnings(value, lastSend);
|
||||
|
||||
if (_socket == null) {
|
||||
try {
|
||||
_socket = _manager.connect(_remoteDestination);
|
||||
|
@ -21,7 +21,6 @@ class ConnectionHandler {
|
||||
private Log _log;
|
||||
private ConnectionManager _manager;
|
||||
private LinkedBlockingQueue<Packet> _synQueue;
|
||||
private Object _synSignal;
|
||||
private boolean _active;
|
||||
private int _acceptTimeout;
|
||||
|
||||
@ -41,7 +40,6 @@ class ConnectionHandler {
|
||||
_log = context.logManager().getLog(ConnectionHandler.class);
|
||||
_manager = mgr;
|
||||
_synQueue = new LinkedBlockingQueue<Packet>(MAX_QUEUE_SIZE);
|
||||
_synSignal= new Object();
|
||||
_active = false;
|
||||
_acceptTimeout = DEFAULT_ACCEPT_TIMEOUT;
|
||||
}
|
||||
@ -81,10 +79,6 @@ class ConnectionHandler {
|
||||
boolean success = _synQueue.offer(packet); // fail immediately if full
|
||||
if (success) {
|
||||
SimpleScheduler.getInstance().addEvent(new TimeoutSyn(packet), _acceptTimeout);
|
||||
// advertise the new syn packet to threads that could be waiting
|
||||
// (by calling waitSyn(long)
|
||||
if (packet.isFlagSet(Packet.FLAG_SYNCHRONIZE))
|
||||
synchronized (this._synSignal) {this._synSignal.notifyAll();}
|
||||
} else {
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("Dropping new SYN request, as the queue is full");
|
||||
@ -93,33 +87,6 @@ class ConnectionHandler {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait until some SYN packet is available
|
||||
* @param ms max amount of time to wait for a connection (if negative or null,
|
||||
* wait indefinitely)
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void waitSyn( long ms ) throws InterruptedException {
|
||||
synchronized (this._synSignal)
|
||||
{
|
||||
long now = this._context.clock().now() ;
|
||||
long expiration = now + ms ;
|
||||
while ( expiration > now || ms<=0 ) {
|
||||
// check if there is a SYN packet in the queue
|
||||
for ( Packet p : this._synQueue ) {
|
||||
if ( p.isFlagSet(Packet.FLAG_SYNCHRONIZE) ) return ;
|
||||
}
|
||||
// wait until a SYN is signaled
|
||||
if ( ms == 0) {
|
||||
this._synSignal.wait();
|
||||
} else {
|
||||
this._synSignal.wait(expiration-now);
|
||||
now = this._context.clock().now();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Receive an incoming connection (built from a received SYN)
|
||||
* Non-SYN packets with a zero SendStreamID may also be queued here so
|
||||
|
@ -1,8 +1,6 @@
|
||||
package net.i2p.client.streaming;
|
||||
|
||||
import java.net.SocketTimeoutException;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.I2PException;
|
||||
|
||||
/**
|
||||
@ -47,43 +45,4 @@ public class I2PServerSocketFull implements I2PServerSocket {
|
||||
public I2PSocketManager getManager() {
|
||||
return _socketManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* accept(timeout) waits timeout ms for a socket connecting. If a socket is
|
||||
* not available during the timeout, return null. accept(0) behaves like accept()
|
||||
*
|
||||
* @param timeout in ms
|
||||
*
|
||||
* @return a connected I2PSocket, or null
|
||||
*
|
||||
* @throws I2PException if there is a problem with reading a new socket
|
||||
* from the data available (aka the I2PSession closed, etc)
|
||||
*/
|
||||
|
||||
public I2PSocket accept(long timeout) throws I2PException {
|
||||
long reset_timeout = this.getSoTimeout();
|
||||
|
||||
try {
|
||||
this.setSoTimeout(timeout);
|
||||
return this.accept();
|
||||
} catch (SocketTimeoutException e) {
|
||||
return null ;
|
||||
} finally {
|
||||
this.setSoTimeout(reset_timeout);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* block until a SYN packet is detected or the timeout is reached. If timeout is 0,
|
||||
* block until a SYN packet is detected.
|
||||
*
|
||||
* @param timeoutMs
|
||||
* @throws InterruptedException
|
||||
* @throws I2PException
|
||||
*/
|
||||
public void waitIncoming(long timeoutMs) throws I2PException, InterruptedException {
|
||||
if (this._socketManager.getConnectionManager().getSession().isClosed())
|
||||
throw new I2PException("Session is closed");
|
||||
this._socketManager.getConnectionManager().getConnectionHandler().waitSyn(timeoutMs);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user