Streaming: Throw I2PSocketException when connection is reset,

display new error page in HTTP client (ticket #643)
javadocs
This commit is contained in:
zzz
2015-03-24 14:33:36 +00:00
parent a975dc4427
commit 9e18c7ea18
10 changed files with 112 additions and 16 deletions

View File

@@ -607,6 +607,8 @@ public abstract class I2PTunnelHTTPClientBase extends I2PTunnelClientBase implem
error = usingWWWProxy ? "nolsp" : "nols"; error = usingWWWProxy ? "nolsp" : "nols";
} else if (status == MessageStatusMessage.STATUS_SEND_FAILURE_UNSUPPORTED_ENCRYPTION) { } else if (status == MessageStatusMessage.STATUS_SEND_FAILURE_UNSUPPORTED_ENCRYPTION) {
error = usingWWWProxy ? "encp" : "enc"; error = usingWWWProxy ? "encp" : "enc";
} else if (status == I2PSocketException.STATUS_CONNECTION_RESET) {
error = usingWWWProxy ? "resetp" : "reset";
} else { } else {
error = usingWWWProxy ? "dnfp" : "dnf"; error = usingWWWProxy ? "dnfp" : "dnf";
} }
@@ -638,7 +640,7 @@ public abstract class I2PTunnelHTTPClientBase extends I2PTunnelClientBase implem
/** /**
* No jump servers * No jump servers
* @param extraMessage extra message * @param extraMessage extra message or null, will be HTML-escaped
* @since 0.9.14 * @since 0.9.14
*/ */
protected void writeErrorMessage(byte[] errMessage, String extraMessage, 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 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 * @since 0.9.14
*/ */
protected void writeErrorMessage(byte[] errMessage, String extraMessage, protected void writeErrorMessage(byte[] errMessage, String extraMessage,
@@ -672,7 +674,7 @@ public abstract class I2PTunnelHTTPClientBase extends I2PTunnelClientBase implem
out.write((":</b> " + wwwProxy).getBytes()); out.write((":</b> " + wwwProxy).getBytes());
} }
if (extraMessage != null) { 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) { if (jumpServers != null && jumpServers.length() > 0) {
boolean first = true; boolean first = true;

View File

@@ -6,8 +6,11 @@ import java.net.SocketTimeoutException;
import net.i2p.I2PException; 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 { public interface I2PServerSocket {
/** /**

View File

@@ -9,9 +9,10 @@ import java.nio.channels.SelectableChannel;
import net.i2p.data.Destination; import net.i2p.data.Destination;
/** /**
* Minimalistic adapter between the socket api and I2PTunnel's way. * Streaming socket returned by {@link I2PSocketManager#connect(Destination)}.
* Note that this interface is a "subinterface" of the interface *<p>
* defined in the "official" streaming api. * 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 { 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. * As of 0.9.9 will throw an IOE if socket is closed.
* Prior to that would return null instead of throwing IOE. * 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. * @return an InputStream to read from the socket. Non-null since 0.9.9.
* @throws IOException on failure * @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. * As of 0.9.9 will throw an IOE if socket is closed.
* Prior to that would return null instead of throwing IOE. * 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. * @return an OutputStream to write into the socket. Non-null since 0.9.9.
* @throws IOException on failure * @throws IOException on failure

View File

@@ -20,7 +20,18 @@ public class I2PSocketException extends SocketException {
private static final String BUNDLE_NAME = "net.i2p.client.streaming.messages"; 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 * @param status >= 0 from MessageStatusMessage or SendMessageStatusListener
*/ */
public I2PSocketException(int status) { public I2PSocketException(int status) {
@@ -105,6 +116,9 @@ public class I2PSocketException extends SocketException {
case SendMessageStatusListener.STATUS_CANCELLED: case SendMessageStatusListener.STATUS_CANCELLED:
return _x("Local destination shutdown"); return _x("Local destination shutdown");
case STATUS_CONNECTION_RESET:
return _x("Connection was reset");
case CUSTOM: case CUSTOM:
return super.getMessage(); return super.getMessage();

View File

@@ -12,6 +12,7 @@ import java.util.concurrent.atomic.AtomicLong;
import net.i2p.I2PAppContext; import net.i2p.I2PAppContext;
import net.i2p.client.I2PSession; import net.i2p.client.I2PSession;
import net.i2p.client.streaming.I2PSocketException;
import net.i2p.data.DataHelper; import net.i2p.data.DataHelper;
import net.i2p.data.Destination; import net.i2p.data.Destination;
import net.i2p.util.Log; import net.i2p.util.Log;
@@ -606,7 +607,7 @@ class Connection {
public void resetReceived() { public void resetReceived() {
if (!_resetReceived.compareAndSet(false, true)) if (!_resetReceived.compareAndSet(false, true))
return; return;
IOException ioe = new IOException("Reset received"); IOException ioe = new I2PSocketException(I2PSocketException.STATUS_CONNECTION_RESET);
_outputStream.streamErrorOccurred(ioe); _outputStream.streamErrorOccurred(ioe);
_inputStream.streamErrorOccurred(ioe); _inputStream.streamErrorOccurred(ioe);
_connectionError = "Connection reset"; _connectionError = "Connection reset";

View File

@@ -262,9 +262,12 @@ class ConnectionManager {
// Ditto for blacklist / whitelist // Ditto for blacklist / whitelist
// This is a tradeoff, because it will keep retransmitting the SYN for a while, // 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. // thus more inbound, but let's not spend several KB on the outbound.
if (_log.shouldLog(Log.INFO)) if (!Boolean.valueOf(_context.getProperty("i2p.streaming.sendResetOnBlock"))) {
_log.info("Dropping RST to " + h); // this is the default. Set property to send reset for debugging.
return null; if (_log.shouldLog(Log.INFO))
_log.info("Dropping RST to " + h);
return null;
}
} }
} }
PacketLocal reply = new PacketLocal(_context, from); PacketLocal reply = new PacketLocal(_context, from);

View File

@@ -1,3 +1,11 @@
2015-03-24 zzz
* Streaming: Throw I2PSocketException when connection is reset,
display new error page in HTTP client (ticket #643)
2015-03-23 zzz
* Javadoc: Add missing package.html files (ticket #1109)
* Summary bar: linkify news headings, remove 'show news' link
2015-03-22 zzz 2015-03-22 zzz
* Console: Better status feedback on manual reseed from URL * Console: Better status feedback on manual reseed from URL
* NetDB: Don't become floodfill w/o ECDSA support * NetDB: Don't become floodfill w/o ECDSA support
@@ -13,7 +21,7 @@
- Finish manual reseed from local file - Finish manual reseed from local file
2015-03-19 zzz 2015-03-19 zzz
* Reseed: * Reseed (ticket #1369):
- Add form to manually reseed from zip or su3 URL - Add form to manually reseed from zip or su3 URL
- Add form to manually reseed from local zip or su3 file - Add form to manually reseed from local zip or su3 file
- Add form to create reseed zip file to share - Add form to create reseed zip file to share

View File

@@ -0,0 +1,26 @@
HTTP/1.1 403 Connection Reset
Content-Type: text/html; charset=UTF-8
Cache-control: no-cache
Connection: close
Proxy-Connection: close
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
<title>_("Connection Reset")</title>
<link rel="shortcut icon" href="http://proxy.i2p/themes/console/images/favicon.ico">
<link href="http://proxy.i2p/themes/console/default/console.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="logo">
<a href="http://127.0.0.1:7657/" title="_("Router Console")"><img src="http://proxy.i2p/themes/console/images/i2plogo.png" alt="_("I2P Router Console")" border="0"></a><hr>
<a href="http://127.0.0.1:7657/config.jsp">_("Configuration")</a> <a href="http://127.0.0.1:7657/help.jsp">_("Help")</a> <a href="http://127.0.0.1:7657/susidns/index">_("Addressbook")</a>
</div>
<div class="warning" id="warning">
<h3>_("Connection Reset")</h3>
<p>
_("The connection to the website was reset while the page was loading.")
_("The website could be temporarily unavailable, too busy, or it has blocked your access.")
_("You may want to {0}retry{1}.", "<a href=\"javascript:window.location.reload()\">", "</a>")</p>
<hr>
<p><b>_("Could not find the following destination:")</b>
</p>

View File

@@ -0,0 +1,26 @@
HTTP/1.1 403 Connection Reset
Content-Type: text/html; charset=UTF-8
Cache-control: no-cache
Connection: close
Proxy-Connection: close
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
<title>_("Connection Reset")</title>
<link rel="shortcut icon" href="http://proxy.i2p/themes/console/images/favicon.ico">
<link href="http://proxy.i2p/themes/console/default/console.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="logo">
<a href="http://127.0.0.1:7657/" title="_("Router Console")"><img src="http://proxy.i2p/themes/console/images/i2plogo.png" alt="_("I2P Router Console")" border="0"></a><hr>
<a href="http://127.0.0.1:7657/config.jsp">_("Configuration")</a> <a href="http://127.0.0.1:7657/help.jsp">_("Help")</a> <a href="http://127.0.0.1:7657/susidns/index">_("Addressbook")</a>
</div>
<div class="warning" id="warning">
<h3>_("Connection Reset")</h3>
<p>
_("The connection to the proxy was reset.")
_("The proxy could be temporarily unavailable, too busy, or it has blocked your access.")
_("You may want to {0}retry{1} as this will randomly reselect an outproxy from the pool you have defined {2}here{3} (if you have more than one configured).", "<a href=\"javascript:parent.window.location.reload()\">", "</a>", "<a href=\"http://127.0.0.1:7657/i2ptunnel/index.jsp\">", "</a>")
_("If you continue to have trouble you may want to edit your outproxy list {0}here{1}.", "<a href=\"http://127.0.0.1:7657/i2ptunnel/edit.jsp?tunnel=0\">", "</a>")
</p>
<hr><p><b>_("Could not find the following destination:")</b></p>

View File

@@ -18,10 +18,10 @@ public class RouterVersion {
/** deprecated */ /** deprecated */
public final static String ID = "Monotone"; public final static String ID = "Monotone";
public final static String VERSION = CoreVersion.VERSION; public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 10; public final static long BUILD = 11;
/** for example "-test" */ /** for example "-test" */
public final static String EXTRA = ""; public final static String EXTRA = "-rc";
public final static String FULL_VERSION = VERSION + "-" + BUILD + EXTRA; public final static String FULL_VERSION = VERSION + "-" + BUILD + EXTRA;
public static void main(String args[]) { public static void main(String args[]) {
System.out.println("I2P Router version: " + FULL_VERSION); System.out.println("I2P Router version: " + FULL_VERSION);