* Streaming:

- Add new real sockets for easier porting of apps.
        See http://zzz.i2p/topics/792 for info.
        Untested.
      - de-SpongeCase
      - Javadoc
This commit is contained in:
zzz
2011-01-05 16:41:41 +00:00
parent 532c9d3fc5
commit 226cb7fdb9
9 changed files with 637 additions and 21 deletions

View File

@@ -4,6 +4,7 @@ package net.i2p.client.streaming;
* Like a StringBuffer, but for bytes. This class is not internally synchronized,
* so care should be taken when using in a multithreaded environment.
*
* @deprecated Only used by deprecated I2PSocketImpl
*/
class ByteCollector {
byte[] contents;
@@ -294,4 +295,4 @@ class ByteCollector {
size = 0;
return bb;
}
}
}

View File

@@ -4,9 +4,12 @@
*/
package net.i2p.client.streaming;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.ConnectException;
import java.net.NoRouteToHostException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Properties;
import java.util.Set;
@@ -84,7 +87,7 @@ public interface I2PSocketManager {
*
* @return a set of currently connected I2PSockets
*/
public Set listSockets();
public Set<I2PSocket> listSockets();
/**
* Ping the specified peer, returning true if they replied to the ping within
@@ -107,4 +110,25 @@ public interface I2PSocketManager {
public static interface DisconnectListener {
public void sessionDisconnected();
}
/**
* Like getServerSocket but returns a real ServerSocket for easier porting of apps.
* @since 0.8.4
*/
public ServerSocket getStandardServerSocket() throws IOException;
/**
* Like connect() but returns a real Socket, and throws only IOE,
* for easier porting of apps.
* @since 0.8.4
*/
public Socket connectToSocket(Destination peer) throws IOException;
/**
* Like connect() but returns a real Socket, and throws only IOE,
* for easier porting of apps.
* @param timeout ms if > 0, forces blocking (disables connectDelay)
* @since 0.8.4
*/
public Socket connectToSocket(Destination peer, int timeout) throws IOException;
}

View File

@@ -10,6 +10,8 @@ import java.io.InterruptedIOException;
import java.io.UnsupportedEncodingException;
import java.net.ConnectException;
import java.net.NoRouteToHostException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -461,6 +463,14 @@ class I2PSocketManagerImpl implements I2PSocketManager, I2PSessionListener {
return _serverSocket;
}
/**
* @throws UnsupportedOperationException
* @since 0.8.4
*/
public ServerSocket getStandardServerSocket() {
throw new UnsupportedOperationException();
}
/**
* Create a new connected socket (block until the socket is created)
*
@@ -601,6 +611,22 @@ class I2PSocketManagerImpl implements I2PSocketManager, I2PSessionListener {
return connect(peer, null);
}
/**
* @throws UnsupportedOperationException
* @since 0.8.4
*/
public Socket connectToSocket(Destination peer) {
throw new UnsupportedOperationException();
}
/**
* @throws UnsupportedOperationException
* @since 0.8.4
*/
public Socket connectToSocket(Destination peer, int timeout) {
throw new UnsupportedOperationException();
}
/**
* Destroy the socket manager, freeing all the associated resources. This
* method will block untill all the managed sockets are closed.
@@ -660,7 +686,7 @@ class I2PSocketManagerImpl implements I2PSocketManager, I2PSessionListener {
* Retrieve a set of currently connected I2PSockets, either initiated locally or remotely.
*
*/
public Set listSockets() {
public Set<I2PSocket> listSockets() {
Set<I2PSocket> sockets = new HashSet<I2PSocket>(8);
synchronized (lock) {
sockets.addAll(_inSockets.values());