forked from I2P_Developers/i2p.i2p
Jetty: Register HTTPS eepsite with port mapper (ticket #2159)
This commit is contained in:
@ -34,8 +34,8 @@ import static net.i2p.app.ClientAppState.*;
|
|||||||
import net.i2p.util.I2PAppThread;
|
import net.i2p.util.I2PAppThread;
|
||||||
import net.i2p.util.PortMapper;
|
import net.i2p.util.PortMapper;
|
||||||
|
|
||||||
|
import org.eclipse.jetty.server.AbstractNetworkConnector;
|
||||||
import org.eclipse.jetty.server.Connector;
|
import org.eclipse.jetty.server.Connector;
|
||||||
import org.eclipse.jetty.server.NetworkConnector;
|
|
||||||
import org.eclipse.jetty.server.Server;
|
import org.eclipse.jetty.server.Server;
|
||||||
import org.eclipse.jetty.util.component.LifeCycle;
|
import org.eclipse.jetty.util.component.LifeCycle;
|
||||||
import org.eclipse.jetty.xml.XmlConfiguration;
|
import org.eclipse.jetty.xml.XmlConfiguration;
|
||||||
@ -58,7 +58,7 @@ public class JettyStart implements ClientApp {
|
|||||||
// warning, may be null if called from main
|
// warning, may be null if called from main
|
||||||
private final I2PAppContext _context;
|
private final I2PAppContext _context;
|
||||||
private volatile ClientAppState _state;
|
private volatile ClientAppState _state;
|
||||||
private volatile int _port;
|
private volatile int _port, _sslPort;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All args must be XML file names.
|
* All args must be XML file names.
|
||||||
@ -136,21 +136,34 @@ public class JettyStart implements ClientApp {
|
|||||||
if (!lc.isRunning()) {
|
if (!lc.isRunning()) {
|
||||||
try {
|
try {
|
||||||
lc.start();
|
lc.start();
|
||||||
if (_context != null && _context.portMapper().getPort(PortMapper.SVC_EEPSITE) <= 0) {
|
if (_context != null) {
|
||||||
|
PortMapper pm = _context.portMapper();
|
||||||
if (lc instanceof Server) {
|
if (lc instanceof Server) {
|
||||||
Server server = (Server) lc;
|
Server server = (Server) lc;
|
||||||
Connector[] connectors = server.getConnectors();
|
Connector[] connectors = server.getConnectors();
|
||||||
if (connectors.length > 0) {
|
for (int i = 0; i < connectors.length; i++) {
|
||||||
Connector conn = connectors[0];
|
Connector conn = connectors[i];
|
||||||
if (conn instanceof NetworkConnector) {
|
if (conn instanceof AbstractNetworkConnector) {
|
||||||
NetworkConnector nconn = (NetworkConnector) conn;
|
AbstractNetworkConnector nconn = (AbstractNetworkConnector) conn;
|
||||||
int port = nconn.getPort();
|
int port = nconn.getPort();
|
||||||
if (port > 0) {
|
if (port > 0) {
|
||||||
_port = port;
|
|
||||||
String host = nconn.getHost();
|
String host = nconn.getHost();
|
||||||
if (host.equals("0.0.0.0") || host.equals("::"))
|
if (host.equals("0.0.0.0"))
|
||||||
host = "127.0.0.1";
|
host = "127.0.0.1";
|
||||||
_context.portMapper().register(PortMapper.SVC_EEPSITE, host, port);
|
else if (host.equals("::"))
|
||||||
|
host = "::1";
|
||||||
|
// see ConnectionFactory javadoc, but from testing, it ends with /1.1
|
||||||
|
boolean isSSL = nconn.getConnectionFactory("SSL-http/1.1") != null;
|
||||||
|
String svc;
|
||||||
|
if (isSSL) {
|
||||||
|
_sslPort = port;
|
||||||
|
svc = PortMapper.SVC_HTTPS_EEPSITE;
|
||||||
|
} else {
|
||||||
|
_port = port;
|
||||||
|
svc = PortMapper.SVC_EEPSITE;
|
||||||
|
}
|
||||||
|
if (pm.getPort(svc) <= 0)
|
||||||
|
pm.register(svc, host, port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -194,9 +207,16 @@ public class JettyStart implements ClientApp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_context != null && _port > 0 && _context.portMapper().getPort(PortMapper.SVC_EEPSITE) == _port) {
|
if (_context != null) {
|
||||||
_port = 0;
|
PortMapper pm = _context.portMapper();
|
||||||
_context.portMapper().unregister(PortMapper.SVC_EEPSITE);
|
if (_port > 0 && pm.getPort(PortMapper.SVC_EEPSITE) == _port) {
|
||||||
|
_port = 0;
|
||||||
|
pm.unregister(PortMapper.SVC_EEPSITE);
|
||||||
|
}
|
||||||
|
if (_sslPort > 0 && pm.getPort(PortMapper.SVC_HTTPS_EEPSITE) == _sslPort) {
|
||||||
|
_sslPort = 0;
|
||||||
|
pm.unregister(PortMapper.SVC_HTTPS_EEPSITE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
changeState(STOPPED);
|
changeState(STOPPED);
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,8 @@ public class PortMapper {
|
|||||||
public static final String SVC_HTTP_PROXY = "HTTP";
|
public static final String SVC_HTTP_PROXY = "HTTP";
|
||||||
public static final String SVC_HTTPS_PROXY = "HTTPS";
|
public static final String SVC_HTTPS_PROXY = "HTTPS";
|
||||||
public static final String SVC_EEPSITE = "eepsite";
|
public static final String SVC_EEPSITE = "eepsite";
|
||||||
|
/** @since 0.9.34 */
|
||||||
|
public static final String SVC_HTTPS_EEPSITE = "https_eepsite";
|
||||||
public static final String SVC_IRC = "irc";
|
public static final String SVC_IRC = "irc";
|
||||||
public static final String SVC_SOCKS = "socks";
|
public static final String SVC_SOCKS = "socks";
|
||||||
public static final String SVC_TAHOE = "tahoe-lafs";
|
public static final String SVC_TAHOE = "tahoe-lafs";
|
||||||
|
Reference in New Issue
Block a user