i2ptunnel: Log correct server host/port on error when there are multiple targets configured

This commit is contained in:
zzz
2023-12-22 11:00:39 -05:00
parent e249449817
commit 6b01b22d00
2 changed files with 19 additions and 2 deletions

View File

@@ -583,6 +583,7 @@ public class I2PTunnelHTTPServer extends I2PTunnelServer {
", start runners: " + (afterHandle-afterSocket) +
"]");
} catch (SocketException ex) {
int port = socket.getLocalPort();
try {
// Send a 503, so the user doesn't get an HTTP Proxy error message
// and blame his router or the network.
@@ -594,7 +595,7 @@ public class I2PTunnelHTTPServer extends I2PTunnelServer {
// Don't complain too early, Jetty may not be ready.
int level = getTunnel().getContext().clock().now() - _startedOn > START_INTERVAL ? Log.ERROR : Log.WARN;
if (_log.shouldLog(level))
_log.log(level, "Error connecting to HTTP server " + remoteHost + ':' + remotePort, ex);
_log.log(level, "Error connecting to HTTP server " + getSocketString(port));
} catch (IOException ex) {
try {
socket.close();

View File

@@ -804,11 +804,12 @@ public class I2PTunnelServer extends I2PTunnelTask implements Runnable {
_log.warn("Took a while to handle the request for " + remoteHost + ':' + remotePort +
" [" + timeToHandle + ", socket create: " + (afterSocket-afterAccept) + "]");
} catch (SocketException ex) {
int port = socket.getLocalPort();
try {
socket.reset();
} catch (IOException ioe) {}
if (_log.shouldLog(Log.ERROR))
_log.error("Error connecting to server " + remoteHost + ':' + remotePort, ex);
_log.error("Error connecting to server " + getSocketString(port));
} catch (IOException ex) {
_log.error("Error while waiting for I2PConnections", ex);
}
@@ -839,6 +840,21 @@ public class I2PTunnelServer extends I2PTunnelTask implements Runnable {
return getSocket(from, host, port, force);
}
/**
* Only for logging, to correctly show where we were trying to get to
* after getSocket() throws a SocketException
*
* @since 0.9.62
*/
protected String getSocketString(int incomingPort) {
if (incomingPort != 0 && !_socketMap.isEmpty()) {
InetSocketAddress isa = _socketMap.get(Integer.valueOf(incomingPort));
if (isa != null)
return isa.toString();
}
return remoteHost.toString() + ':' + remotePort;
}
/**
* Get a regular or SSL socket depending on config.
* The SSL config applies to all hosts/ports.