forked from I2P_Developers/i2p.i2p
* Streaming:
- Hook I2CP ports through to I2PSocket - Javadocs, init cleanups, final
This commit is contained in:
@@ -70,6 +70,21 @@ public interface I2PSocket {
|
||||
public boolean isClosed();
|
||||
|
||||
public void setSocketErrorListener(SocketErrorListener lsnr);
|
||||
|
||||
/**
|
||||
* The remote port.
|
||||
* @return Default I2PSession.PORT_UNSPECIFIED (0) or PORT_ANY (0)
|
||||
* @since 0.8.9
|
||||
*/
|
||||
public int getPort();
|
||||
|
||||
/**
|
||||
* The local port.
|
||||
* @return Default I2PSession.PORT_UNSPECIFIED (0) or PORT_ANY (0)
|
||||
* @since 0.8.9
|
||||
*/
|
||||
public int getLocalPort();
|
||||
|
||||
/**
|
||||
* Allow notification of underlying errors communicating across I2P without
|
||||
* waiting for any sort of cleanup process. For example, if some data could
|
||||
|
@@ -7,6 +7,7 @@ import java.io.OutputStream;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.I2PException;
|
||||
import net.i2p.client.I2PSession;
|
||||
import net.i2p.client.I2PSessionException;
|
||||
import net.i2p.data.Destination;
|
||||
import net.i2p.util.Clock;
|
||||
@@ -301,6 +302,24 @@ class I2PSocketImpl implements I2PSocket {
|
||||
public long getCreatedOn() { return _createdOn; }
|
||||
public long getClosedOn() { return _closedOn; }
|
||||
|
||||
/**
|
||||
* The remote port.
|
||||
* @return 0 always
|
||||
* @since 0.8.9
|
||||
*/
|
||||
public int getPort() {
|
||||
return I2PSession.PORT_UNSPECIFIED;
|
||||
}
|
||||
|
||||
/**
|
||||
* The local port.
|
||||
* @return 0 always
|
||||
* @since 0.8.9
|
||||
*/
|
||||
public int getLocalPort() {
|
||||
return I2PSession.PORT_UNSPECIFIED;
|
||||
}
|
||||
|
||||
|
||||
private String getPrefix() { return "[" + _socketId + "]: "; }
|
||||
|
||||
@@ -671,7 +690,7 @@ class I2PSocketImpl implements I2PSocket {
|
||||
return sent;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() { return "" + hashCode(); }
|
||||
}
|
||||
|
@@ -90,7 +90,7 @@ public class I2PSocketManagerFactory {
|
||||
* Create a socket manager using the destination loaded from the given private key
|
||||
* stream and connected to the default I2CP host and port.
|
||||
*
|
||||
* @param myPrivateKeyStream private key stream
|
||||
* @param myPrivateKeyStream private key stream, format is specified in {@link net.i2p.data.PrivateKeyFile PrivateKeyFile}
|
||||
* @return the newly created socket manager, or null if there were errors
|
||||
*/
|
||||
public static I2PSocketManager createManager(InputStream myPrivateKeyStream) {
|
||||
@@ -101,7 +101,7 @@ public class I2PSocketManagerFactory {
|
||||
* Create a socket manager using the destination loaded from the given private key
|
||||
* stream and connected to the default I2CP host and port.
|
||||
*
|
||||
* @param myPrivateKeyStream private key stream
|
||||
* @param myPrivateKeyStream private key stream, format is specified in {@link net.i2p.data.PrivateKeyFile PrivateKeyFile}
|
||||
* @param opts I2CP options
|
||||
* @return the newly created socket manager, or null if there were errors
|
||||
*/
|
||||
@@ -114,7 +114,7 @@ public class I2PSocketManagerFactory {
|
||||
* stream and connected to the I2CP router on the specified machine on the given
|
||||
* port
|
||||
*
|
||||
* @param myPrivateKeyStream private key stream
|
||||
* @param myPrivateKeyStream private key stream, format is specified in {@link net.i2p.data.PrivateKeyFile PrivateKeyFile}
|
||||
* @param i2cpHost I2CP host
|
||||
* @param i2cpPort I2CP port
|
||||
* @param opts I2CP options
|
||||
|
@@ -2,7 +2,7 @@ package net.i2p.client.streaming;
|
||||
|
||||
/**
|
||||
* Define the configuration for streaming and verifying data on the socket.
|
||||
*
|
||||
* Use I2PSocketManager.buildOptions() to get one of these.
|
||||
*/
|
||||
public interface I2PSocketOptions {
|
||||
/** How much data will we accept that hasn't been written out yet. */
|
||||
@@ -81,4 +81,32 @@ public interface I2PSocketOptions {
|
||||
* @param ms wait time to block on the output stream while waiting for the data to flush.
|
||||
*/
|
||||
public void setWriteTimeout(long ms);
|
||||
|
||||
/**
|
||||
* The remote port.
|
||||
* @return Default I2PSession.PORT_UNSPECIFIED (0) or PORT_ANY (0)
|
||||
* @since 0.8.9
|
||||
*/
|
||||
public int getPort();
|
||||
|
||||
/**
|
||||
* The remote port.
|
||||
* @param port 0 - 65535
|
||||
* @since 0.8.9
|
||||
*/
|
||||
public void setPort(int port);
|
||||
|
||||
/**
|
||||
* The local port.
|
||||
* @return Default I2PSession.PORT_UNSPECIFIED (0) or PORT_ANY (0)
|
||||
* @since 0.8.9
|
||||
*/
|
||||
public int getLocalPort();
|
||||
|
||||
/**
|
||||
* The local port.
|
||||
* @param port 0 - 65535
|
||||
* @since 0.8.9
|
||||
*/
|
||||
public void setLocalPort(int port);
|
||||
}
|
||||
|
@@ -4,22 +4,32 @@ import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Define the configuration for streaming and verifying data on the socket.
|
||||
*
|
||||
* Use I2PSocketManager.buildOptions() to get one of these.
|
||||
*/
|
||||
class I2PSocketOptionsImpl implements I2PSocketOptions {
|
||||
private long _connectTimeout;
|
||||
private long _readTimeout;
|
||||
private long _writeTimeout;
|
||||
private int _maxBufferSize;
|
||||
private int _localPort;
|
||||
private int _remotePort;
|
||||
|
||||
public static final int DEFAULT_BUFFER_SIZE = 1024*64;
|
||||
public static final int DEFAULT_WRITE_TIMEOUT = -1;
|
||||
public static final int DEFAULT_CONNECT_TIMEOUT = 60*1000;
|
||||
|
||||
/**
|
||||
* Sets max buffer size, connect timeout, read timeout, and write timeout
|
||||
* from System properties. Does not set local port or remote port.
|
||||
*/
|
||||
public I2PSocketOptionsImpl() {
|
||||
this(System.getProperties());
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes from System properties then copies over all options.
|
||||
* @param opts may be null
|
||||
*/
|
||||
public I2PSocketOptionsImpl(I2PSocketOptions opts) {
|
||||
this(System.getProperties());
|
||||
if (opts != null) {
|
||||
@@ -27,13 +37,25 @@ class I2PSocketOptionsImpl implements I2PSocketOptions {
|
||||
_readTimeout = opts.getReadTimeout();
|
||||
_writeTimeout = opts.getWriteTimeout();
|
||||
_maxBufferSize = opts.getMaxBufferSize();
|
||||
_localPort = opts.getLocalPort();
|
||||
_remotePort = opts.getPort();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets max buffer size, connect timeout, read timeout, and write timeout
|
||||
* from properties. Does not set local port or remote port.
|
||||
* @param opts may be null
|
||||
*/
|
||||
public I2PSocketOptionsImpl(Properties opts) {
|
||||
init(opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets max buffer size, connect timeout, read timeout, and write timeout
|
||||
* from properties. Does not set local port or remote port.
|
||||
* @param opts may be null
|
||||
*/
|
||||
public void setProperties(Properties opts) {
|
||||
if (opts == null) return;
|
||||
if (opts.containsKey(PROP_BUFFER_SIZE))
|
||||
@@ -46,6 +68,10 @@ class I2PSocketOptionsImpl implements I2PSocketOptions {
|
||||
_writeTimeout = getInt(opts, PROP_WRITE_TIMEOUT, DEFAULT_WRITE_TIMEOUT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets max buffer size, connect timeout, read timeout, and write timeout
|
||||
* from properties. Does not set local port or remote port.
|
||||
*/
|
||||
protected void init(Properties opts) {
|
||||
_maxBufferSize = getInt(opts, PROP_BUFFER_SIZE, DEFAULT_BUFFER_SIZE);
|
||||
_connectTimeout = getInt(opts, PROP_CONNECT_TIMEOUT, DEFAULT_CONNECT_TIMEOUT);
|
||||
@@ -144,4 +170,40 @@ class I2PSocketOptionsImpl implements I2PSocketOptions {
|
||||
public void setWriteTimeout(long ms) {
|
||||
_writeTimeout = ms;
|
||||
}
|
||||
|
||||
/**
|
||||
* The remote port.
|
||||
* @return Default I2PSession.PORT_UNSPECIFIED (0) or PORT_ANY (0)
|
||||
* @since 0.8.9
|
||||
*/
|
||||
public int getPort() {
|
||||
return _remotePort;
|
||||
}
|
||||
|
||||
/**
|
||||
* The remote port.
|
||||
* @param port 0 - 65535
|
||||
* @since 0.8.9
|
||||
*/
|
||||
public void setPort(int port) {
|
||||
_remotePort = port;
|
||||
}
|
||||
|
||||
/**
|
||||
* The local port.
|
||||
* @return Default I2PSession.PORT_UNSPECIFIED (0) or PORT_ANY (0)
|
||||
* @since 0.8.9
|
||||
*/
|
||||
public int getLocalPort() {
|
||||
return _localPort;
|
||||
}
|
||||
|
||||
/**
|
||||
* The local port.
|
||||
* @param port 0 - 65535
|
||||
* @since 0.8.9
|
||||
*/
|
||||
public void setLocalPort(int port) {
|
||||
_localPort = port;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user