forked from I2P_Developers/i2p.i2p
Streaming: Throw I2PSocketException when connection is reset,
display new error page in HTTP client (ticket #643) javadocs
This commit is contained in:
@@ -607,6 +607,8 @@ public abstract class I2PTunnelHTTPClientBase extends I2PTunnelClientBase implem
|
||||
error = usingWWWProxy ? "nolsp" : "nols";
|
||||
} else if (status == MessageStatusMessage.STATUS_SEND_FAILURE_UNSUPPORTED_ENCRYPTION) {
|
||||
error = usingWWWProxy ? "encp" : "enc";
|
||||
} else if (status == I2PSocketException.STATUS_CONNECTION_RESET) {
|
||||
error = usingWWWProxy ? "resetp" : "reset";
|
||||
} else {
|
||||
error = usingWWWProxy ? "dnfp" : "dnf";
|
||||
}
|
||||
@@ -638,7 +640,7 @@ public abstract class I2PTunnelHTTPClientBase extends I2PTunnelClientBase implem
|
||||
|
||||
/**
|
||||
* No jump servers
|
||||
* @param extraMessage extra message
|
||||
* @param extraMessage extra message or null, will be HTML-escaped
|
||||
* @since 0.9.14
|
||||
*/
|
||||
protected void writeErrorMessage(byte[] errMessage, String extraMessage,
|
||||
@@ -649,7 +651,7 @@ public abstract class I2PTunnelHTTPClientBase extends I2PTunnelClientBase implem
|
||||
|
||||
/**
|
||||
* @param jumpServers comma- or space-separated list, or null
|
||||
* @param extraMessage extra message
|
||||
* @param extraMessage extra message or null, will be HTML-escaped
|
||||
* @since 0.9.14
|
||||
*/
|
||||
protected void writeErrorMessage(byte[] errMessage, String extraMessage,
|
||||
@@ -672,7 +674,7 @@ public abstract class I2PTunnelHTTPClientBase extends I2PTunnelClientBase implem
|
||||
out.write((":</b> " + wwwProxy).getBytes());
|
||||
}
|
||||
if (extraMessage != null) {
|
||||
out.write(("<br><br><b>" + extraMessage + "</b>").getBytes());
|
||||
out.write(("<br><br><b>" + DataHelper.escapeHTML(extraMessage) + "</b>").getBytes());
|
||||
}
|
||||
if (jumpServers != null && jumpServers.length() > 0) {
|
||||
boolean first = true;
|
||||
|
@@ -6,8 +6,11 @@ import java.net.SocketTimeoutException;
|
||||
import net.i2p.I2PException;
|
||||
|
||||
/**
|
||||
* Defines how to listen for streaming peer connections
|
||||
*
|
||||
* Streaming server socket returned by {@link I2PSocketManager#getServerSocket()}.
|
||||
* Defines how to listen for streaming peer connections.
|
||||
*<p>
|
||||
* Note that this is not a standard Java {@link java.net.ServerSocket},
|
||||
* if you need one of those, use {@link I2PSocketManager#getStandardServerSocket()} instead.
|
||||
*/
|
||||
public interface I2PServerSocket {
|
||||
/**
|
||||
|
@@ -9,9 +9,10 @@ import java.nio.channels.SelectableChannel;
|
||||
import net.i2p.data.Destination;
|
||||
|
||||
/**
|
||||
* Minimalistic adapter between the socket api and I2PTunnel's way.
|
||||
* Note that this interface is a "subinterface" of the interface
|
||||
* defined in the "official" streaming api.
|
||||
* Streaming socket returned by {@link I2PSocketManager#connect(Destination)}.
|
||||
*<p>
|
||||
* Note that this is not a standard Java {@link java.net.Socket},
|
||||
* if you need one of those, use {@link I2PSocketManager#connectToSocket(Destination)} instead.
|
||||
*/
|
||||
public interface I2PSocket extends Closeable {
|
||||
/**
|
||||
@@ -27,6 +28,12 @@ public interface I2PSocket extends Closeable {
|
||||
/**
|
||||
* As of 0.9.9 will throw an IOE if socket is closed.
|
||||
* Prior to that would return null instead of throwing IOE.
|
||||
*<p>
|
||||
* Note that operations on the returned stream may return an
|
||||
* {@link IOException} whose <i>cause</i> as returned by
|
||||
* {@link IOException#getCause()} is an {@link I2PSocketException}.
|
||||
* If so, the client may retrieve a status code via
|
||||
* {@link I2PSocketException#getStatus()} to provide specific feedback to the user.
|
||||
*
|
||||
* @return an InputStream to read from the socket. Non-null since 0.9.9.
|
||||
* @throws IOException on failure
|
||||
@@ -36,6 +43,12 @@ public interface I2PSocket extends Closeable {
|
||||
/**
|
||||
* As of 0.9.9 will throw an IOE if socket is closed.
|
||||
* Prior to that would return null instead of throwing IOE.
|
||||
*<p>
|
||||
* Note that operations on the returned stream may return an
|
||||
* {@link IOException} whose <i>cause</i> as returned by
|
||||
* {@link IOException#getCause()} is an {@link I2PSocketException}.
|
||||
* If so, the client may retrieve a status code via
|
||||
* {@link I2PSocketException#getStatus()} to provide specific feedback to the user.
|
||||
*
|
||||
* @return an OutputStream to write into the socket. Non-null since 0.9.9.
|
||||
* @throws IOException on failure
|
||||
|
@@ -20,7 +20,18 @@ public class I2PSocketException extends SocketException {
|
||||
private static final String BUNDLE_NAME = "net.i2p.client.streaming.messages";
|
||||
|
||||
/**
|
||||
* Use canned message for this status code
|
||||
* Router and I2CP status codes are 0 - 511. Start ours at 512.
|
||||
* @since 0.9.19
|
||||
*/
|
||||
public static final int STATUS_CONNECTION_RESET = 512;
|
||||
|
||||
/**
|
||||
* Use canned message for this status code.
|
||||
*
|
||||
* Standard codes from the router are 0-255, defined in MessageStatusMessage.
|
||||
* Standard codes from client-side I2CP are 256-511, defined in SendMessageStatusListener.
|
||||
* Standard codes from streaming are 512-767, defined here.
|
||||
*
|
||||
* @param status >= 0 from MessageStatusMessage or SendMessageStatusListener
|
||||
*/
|
||||
public I2PSocketException(int status) {
|
||||
@@ -105,6 +116,9 @@ public class I2PSocketException extends SocketException {
|
||||
case SendMessageStatusListener.STATUS_CANCELLED:
|
||||
return _x("Local destination shutdown");
|
||||
|
||||
case STATUS_CONNECTION_RESET:
|
||||
return _x("Connection was reset");
|
||||
|
||||
case CUSTOM:
|
||||
return super.getMessage();
|
||||
|
||||
|
@@ -12,6 +12,7 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.client.I2PSession;
|
||||
import net.i2p.client.streaming.I2PSocketException;
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.data.Destination;
|
||||
import net.i2p.util.Log;
|
||||
@@ -606,7 +607,7 @@ class Connection {
|
||||
public void resetReceived() {
|
||||
if (!_resetReceived.compareAndSet(false, true))
|
||||
return;
|
||||
IOException ioe = new IOException("Reset received");
|
||||
IOException ioe = new I2PSocketException(I2PSocketException.STATUS_CONNECTION_RESET);
|
||||
_outputStream.streamErrorOccurred(ioe);
|
||||
_inputStream.streamErrorOccurred(ioe);
|
||||
_connectionError = "Connection reset";
|
||||
|
@@ -262,9 +262,12 @@ class ConnectionManager {
|
||||
// Ditto for blacklist / whitelist
|
||||
// This is a tradeoff, because it will keep retransmitting the SYN for a while,
|
||||
// thus more inbound, but let's not spend several KB on the outbound.
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("Dropping RST to " + h);
|
||||
return null;
|
||||
if (!Boolean.valueOf(_context.getProperty("i2p.streaming.sendResetOnBlock"))) {
|
||||
// this is the default. Set property to send reset for debugging.
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("Dropping RST to " + h);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
PacketLocal reply = new PacketLocal(_context, from);
|
||||
|
Reference in New Issue
Block a user