2004-04-08 04:41:54 +00:00
|
|
|
/*
|
|
|
|
* licensed under BSD license...
|
|
|
|
* (if you know the proper clause for that, add it ...)
|
|
|
|
*/
|
|
|
|
package net.i2p.client.streaming;
|
|
|
|
|
2011-01-05 16:41:41 +00:00
|
|
|
import java.io.IOException;
|
2004-04-08 04:41:54 +00:00
|
|
|
import java.io.InterruptedIOException;
|
2004-04-19 21:45:04 +00:00
|
|
|
import java.net.ConnectException;
|
|
|
|
import java.net.NoRouteToHostException;
|
2011-01-05 16:41:41 +00:00
|
|
|
import java.net.ServerSocket;
|
|
|
|
import java.net.Socket;
|
2004-10-24 23:00:44 +00:00
|
|
|
import java.util.Properties;
|
2004-04-08 04:41:54 +00:00
|
|
|
import java.util.Set;
|
|
|
|
|
2004-06-28 13:18:18 +00:00
|
|
|
import net.i2p.I2PAppContext;
|
2004-04-08 04:41:54 +00:00
|
|
|
import net.i2p.I2PException;
|
|
|
|
import net.i2p.client.I2PSession;
|
2004-05-17 03:38:53 +00:00
|
|
|
import net.i2p.data.Destination;
|
2004-04-08 04:41:54 +00:00
|
|
|
|
2004-06-28 13:18:18 +00:00
|
|
|
|
2004-04-08 04:41:54 +00:00
|
|
|
/**
|
|
|
|
* Centralize the coordination and multiplexing of the local client's streaming.
|
|
|
|
* There should be one I2PSocketManager for each I2PSession, and if an application
|
|
|
|
* is sending and receiving data through the streaming library using an
|
|
|
|
* I2PSocketManager, it should not attempt to call I2PSession's setSessionListener
|
|
|
|
* or receive any messages with its .receiveMessage
|
|
|
|
*
|
|
|
|
*/
|
2004-10-24 01:42:34 +00:00
|
|
|
public interface I2PSocketManager {
|
|
|
|
public I2PSession getSession();
|
2004-05-04 04:44:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* How long should we wait for the client to .accept() a socket before
|
|
|
|
* sending back a NACK/Close?
|
|
|
|
*
|
|
|
|
* @param ms milliseconds to wait, maximum
|
|
|
|
*/
|
2004-10-24 01:42:34 +00:00
|
|
|
public void setAcceptTimeout(long ms);
|
|
|
|
public long getAcceptTimeout();
|
|
|
|
public void setDefaultOptions(I2PSocketOptions options);
|
|
|
|
public I2PSocketOptions getDefaultOptions();
|
|
|
|
public I2PServerSocket getServerSocket();
|
2004-11-16 22:11:11 +00:00
|
|
|
|
|
|
|
public I2PSocketOptions buildOptions();
|
|
|
|
public I2PSocketOptions buildOptions(Properties opts);
|
2004-04-08 04:41:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new connected socket (block until the socket is created)
|
|
|
|
*
|
2004-04-19 21:45:04 +00:00
|
|
|
* @param peer Destination to connect to
|
|
|
|
* @param options I2P socket options to be used for connecting
|
|
|
|
*
|
2008-10-11 10:28:31 +00:00
|
|
|
* @return new connected socket
|
2004-04-19 21:45:04 +00:00
|
|
|
* @throws ConnectException if the peer refuses the connection
|
|
|
|
* @throws NoRouteToHostException if the peer is not found or not reachable
|
2004-04-20 15:38:55 +00:00
|
|
|
* @throws InterruptedIOException if the connection timeouts
|
2004-04-19 21:45:04 +00:00
|
|
|
* @throws I2PException if there is some other I2P-related problem
|
2004-04-08 04:41:54 +00:00
|
|
|
*/
|
refactored packet handling into type specific methods
removed nested synchronization (which had been causing undetected deadlocks)
made sync blocks smaller, though this may have opened holes related to
resent ACK/SYN/CLOSE packets that are delivered in a race. I'm not as
fluent in the ministreaming lib code as i should be (yet), but duck's thread
dumps were showing hundreds of threads waiting on a lock that'll never get
released (since the only way to release it would be to receive another
packet, and no more packets can be received until the lock is released, etc)
also, I2PSession is threadsafe - i can see no reason to synchronize on it
(and it was being synchronized on only part of the time?)
also, refactored the charset encoding stuff and minor log tweaking
i've been testing this for the last hour or so, on eepsites and squid (large
and small files), as well as irc, and there haven't been any glitches. but
it needs more testing before it can be released, obviously.
2004-05-03 03:34:25 +00:00
|
|
|
public I2PSocket connect(Destination peer, I2PSocketOptions options)
|
|
|
|
throws I2PException, ConnectException,
|
2004-10-24 01:42:34 +00:00
|
|
|
NoRouteToHostException, InterruptedIOException;
|
2004-04-10 11:50:11 +00:00
|
|
|
|
2004-04-19 21:45:04 +00:00
|
|
|
/**
|
|
|
|
* Create a new connected socket (block until the socket is created)
|
|
|
|
*
|
|
|
|
* @param peer Destination to connect to
|
|
|
|
*
|
2008-10-11 10:28:31 +00:00
|
|
|
* @return new connected socket
|
2004-04-19 21:45:04 +00:00
|
|
|
* @throws ConnectException if the peer refuses the connection
|
|
|
|
* @throws NoRouteToHostException if the peer is not found or not reachable
|
2004-04-20 15:38:55 +00:00
|
|
|
* @throws InterruptedIOException if the connection timeouts
|
2004-04-19 21:45:04 +00:00
|
|
|
* @throws I2PException if there is some other I2P-related problem
|
|
|
|
*/
|
refactored packet handling into type specific methods
removed nested synchronization (which had been causing undetected deadlocks)
made sync blocks smaller, though this may have opened holes related to
resent ACK/SYN/CLOSE packets that are delivered in a race. I'm not as
fluent in the ministreaming lib code as i should be (yet), but duck's thread
dumps were showing hundreds of threads waiting on a lock that'll never get
released (since the only way to release it would be to receive another
packet, and no more packets can be received until the lock is released, etc)
also, I2PSession is threadsafe - i can see no reason to synchronize on it
(and it was being synchronized on only part of the time?)
also, refactored the charset encoding stuff and minor log tweaking
i've been testing this for the last hour or so, on eepsites and squid (large
and small files), as well as irc, and there haven't been any glitches. but
it needs more testing before it can be released, obviously.
2004-05-03 03:34:25 +00:00
|
|
|
public I2PSocket connect(Destination peer) throws I2PException, ConnectException,
|
2004-10-24 01:42:34 +00:00
|
|
|
NoRouteToHostException, InterruptedIOException;
|
|
|
|
|
2004-04-19 21:45:04 +00:00
|
|
|
/**
|
|
|
|
* Destroy the socket manager, freeing all the associated resources. This
|
|
|
|
* method will block untill all the managed sockets are closed.
|
|
|
|
*
|
|
|
|
*/
|
2004-10-24 01:42:34 +00:00
|
|
|
public void destroySocketManager();
|
2004-04-19 21:45:04 +00:00
|
|
|
|
2004-04-10 11:50:11 +00:00
|
|
|
/**
|
2004-04-08 04:41:54 +00:00
|
|
|
* Retrieve a set of currently connected I2PSockets, either initiated locally or remotely.
|
|
|
|
*
|
2008-10-11 10:28:31 +00:00
|
|
|
* @return a set of currently connected I2PSockets
|
2004-04-08 04:41:54 +00:00
|
|
|
*/
|
2011-01-05 16:41:41 +00:00
|
|
|
public Set<I2PSocket> listSockets();
|
2004-04-10 11:50:11 +00:00
|
|
|
|
2004-04-08 04:41:54 +00:00
|
|
|
/**
|
|
|
|
* Ping the specified peer, returning true if they replied to the ping within
|
|
|
|
* the timeout specified, false otherwise. This call blocks.
|
|
|
|
*
|
2008-10-11 10:28:31 +00:00
|
|
|
* @param peer Destination to ping
|
|
|
|
* @param timeoutMs timeout in ms
|
|
|
|
* @return success or failure
|
2004-04-08 04:41:54 +00:00
|
|
|
*/
|
2004-10-24 01:42:34 +00:00
|
|
|
public boolean ping(Destination peer, long timeoutMs);
|
2004-04-08 04:41:54 +00:00
|
|
|
|
2004-10-24 01:42:34 +00:00
|
|
|
public String getName();
|
|
|
|
public void setName(String name);
|
2004-10-24 23:00:44 +00:00
|
|
|
|
|
|
|
public void init(I2PAppContext context, I2PSession session, Properties opts, String name);
|
2005-01-06 00:17:53 +00:00
|
|
|
|
|
|
|
public void addDisconnectListener(DisconnectListener lsnr);
|
|
|
|
public void removeDisconnectListener(DisconnectListener lsnr);
|
|
|
|
|
|
|
|
public static interface DisconnectListener {
|
|
|
|
public void sessionDisconnected();
|
|
|
|
}
|
2011-01-05 16:41:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
2004-04-16 03:31:13 +00:00
|
|
|
}
|