forked from I2P_Developers/i2p.i2p
Added Simple true/false storage class to the utilities
Added socketSoTimeout CHANGED RetransmissionTimer is now public FIXED SimpleTimer has a way to be stopped, and reap it's children CLEANUP A few javadoc additions, where I could figgure out bits CLEANUP all code that needed to catch the timeout exception for socketSoTimeout
This commit is contained in:
@@ -39,6 +39,7 @@ public class ConnectionManager {
|
||||
private ConnectionOptions _defaultOptions;
|
||||
private volatile int _numWaiting;
|
||||
private Object _connectionLock;
|
||||
private long SoTimeout;
|
||||
|
||||
public ConnectionManager(I2PAppContext context, I2PSession session, int maxConcurrent, ConnectionOptions defaultOptions) {
|
||||
_context = context;
|
||||
@@ -58,6 +59,9 @@ public class ConnectionManager {
|
||||
_maxConcurrentStreams = maxConcurrent;
|
||||
_defaultOptions = defaultOptions;
|
||||
_numWaiting = 0;
|
||||
/** Socket timeout for accept() */
|
||||
SoTimeout = -1;
|
||||
|
||||
_context.statManager().createRateStat("stream.con.lifetimeMessagesSent", "How many messages do we send on a stream?", "Stream", new long[] { 60*60*1000, 24*60*60*1000 });
|
||||
_context.statManager().createRateStat("stream.con.lifetimeMessagesReceived", "How many messages do we receive on a stream?", "Stream", new long[] { 60*60*1000, 24*60*60*1000 });
|
||||
_context.statManager().createRateStat("stream.con.lifetimeBytesSent", "How many bytes do we send on a stream?", "Stream", new long[] { 60*60*1000, 24*60*60*1000 });
|
||||
@@ -90,6 +94,22 @@ public class ConnectionManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the socket accept() timeout.
|
||||
* @param x
|
||||
*/
|
||||
public void MsetSoTimeout(long x) {
|
||||
SoTimeout = x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the socket accept() timeout.
|
||||
* @return
|
||||
*/
|
||||
public long MgetSoTimeout() {
|
||||
return SoTimeout;
|
||||
}
|
||||
|
||||
public void setAllowIncomingConnections(boolean allow) {
|
||||
_connectionHandler.setActive(allow);
|
||||
}
|
||||
|
@@ -1,5 +1,8 @@
|
||||
package net.i2p.client.streaming;
|
||||
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import net.i2p.I2PException;
|
||||
|
||||
/**
|
||||
@@ -13,11 +16,35 @@ public class I2PServerSocketFull implements I2PServerSocket {
|
||||
_socketManager = mgr;
|
||||
}
|
||||
|
||||
public I2PSocket accept() throws I2PException {
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
* @throws net.i2p.I2PException
|
||||
* @throws SocketTimeoutException
|
||||
*/
|
||||
public I2PSocket accept() throws I2PException, SocketTimeoutException {
|
||||
return _socketManager.receiveSocket();
|
||||
}
|
||||
|
||||
public void close() { _socketManager.getConnectionManager().setAllowIncomingConnections(false); }
|
||||
public long getSoTimeout() {
|
||||
return _socketManager.getConnectionManager().MgetSoTimeout();
|
||||
}
|
||||
|
||||
public I2PSocketManager getManager() { return _socketManager; }
|
||||
public void setSoTimeout(long x) {
|
||||
_socketManager.getConnectionManager().MsetSoTimeout(x);
|
||||
}
|
||||
/**
|
||||
* Close the connection.
|
||||
*/
|
||||
public void close() {
|
||||
_socketManager.getConnectionManager().setAllowIncomingConnections(false);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return _socketManager
|
||||
*/
|
||||
public I2PSocketManager getManager() {
|
||||
return _socketManager;
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package net.i2p.client.streaming;
|
||||
|
||||
import java.net.NoRouteToHostException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Properties;
|
||||
@@ -44,6 +45,14 @@ public class I2PSocketManagerFull implements I2PSocketManager {
|
||||
_context = null;
|
||||
_session = null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param session
|
||||
* @param opts
|
||||
* @param name
|
||||
*/
|
||||
public I2PSocketManagerFull(I2PAppContext context, I2PSession session, Properties opts, String name) {
|
||||
this();
|
||||
init(context, session, opts, name);
|
||||
@@ -54,6 +63,11 @@ public class I2PSocketManagerFull implements I2PSocketManager {
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param context
|
||||
* @param session
|
||||
* @param opts
|
||||
* @param name
|
||||
*/
|
||||
public void init(I2PAppContext context, I2PSession session, Properties opts, String name) {
|
||||
_context = context;
|
||||
@@ -96,24 +110,38 @@ public class I2PSocketManagerFull implements I2PSocketManager {
|
||||
return _connectionManager;
|
||||
}
|
||||
|
||||
public I2PSocket receiveSocket() throws I2PException {
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
* @throws net.i2p.I2PException
|
||||
* @throws java.net.SocketTimeoutException
|
||||
*/
|
||||
public I2PSocket receiveSocket() throws I2PException, SocketTimeoutException {
|
||||
verifySession();
|
||||
Connection con = _connectionManager.getConnectionHandler().accept(-1);
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
Connection con = _connectionManager.getConnectionHandler().accept(_connectionManager.MgetSoTimeout());
|
||||
if(_log.shouldLog(Log.DEBUG)) {
|
||||
_log.debug("receiveSocket() called: " + con);
|
||||
}
|
||||
if (con != null) {
|
||||
I2PSocketFull sock = new I2PSocketFull(con);
|
||||
con.setSocket(sock);
|
||||
return sock;
|
||||
} else {
|
||||
if(_connectionManager.MgetSoTimeout() == -1) {
|
||||
return null;
|
||||
}
|
||||
throw new SocketTimeoutException("I2PSocket timed out");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ping the specified peer, returning true if they replied to the ping within
|
||||
* the timeout specified, false otherwise. This call blocks.
|
||||
*
|
||||
*
|
||||
* @param peer
|
||||
* @param timeoutMs
|
||||
* @return
|
||||
*/
|
||||
public boolean ping(Destination peer, long timeoutMs) {
|
||||
return _connectionManager.ping(peer, timeoutMs);
|
||||
|
@@ -5,7 +5,7 @@ import net.i2p.util.SimpleTimer;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class RetransmissionTimer extends SimpleTimer {
|
||||
public class RetransmissionTimer extends SimpleTimer {
|
||||
private static final RetransmissionTimer _instance = new RetransmissionTimer();
|
||||
public static final SimpleTimer getInstance() { return _instance; }
|
||||
protected RetransmissionTimer() { super("StreamingTimer"); }
|
||||
|
Reference in New Issue
Block a user