/** * Add the service * @param port > 0 * @return success, false if already registered */ public boolean register(String service, int port) { return register(service, DEFAULT_HOST, port); }
public void run() { for (LifeCycle lc : _jettys) { if (lc.isRunning()) { try { lc.stop(); } catch (Exception e) { changeState(STOPPING, e); } } } if (_context != null) { PortMapper pm = _context.portMapper(); 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); } }
/** * If PROP_PREFER_HTTPS is true or unset, * return https URL unless console is http only. Default https://127.0.0.1:7667/ * If PROP_PREFER_HTTPS is set to false, * return http URL unless console is https only. Default http://127.0.0.1:7657/ * * @since 0.9.33 consolidated from i2ptunnel and desktopgui */ public String getConsoleURL() { return getConsoleURL(I2PAppContext.getGlobalContext().getBooleanPropertyDefaultTrue(PROP_PREFER_HTTPS)); }
/** * @return http URL unless console is https only. Default http://127.0.0.1:7657/ */ private String getHTTPConsoleURL() { String unset = "*unset*"; String httpHost = getActualHost(SVC_CONSOLE, unset); String httpsHost = getActualHost(SVC_HTTPS_CONSOLE, unset); int httpPort = getPort(SVC_CONSOLE, DEFAULT_CONSOLE_PORT); int httpsPort = getPort(SVC_HTTPS_CONSOLE); boolean httpsOnly = httpsPort > 0 && httpHost.equals(unset) && !httpsHost.equals(unset); if (httpsOnly) return "https://" + httpsHost + ':' + httpsPort + '/'; if (httpHost.equals(unset)) httpHost = DEFAULT_HOST; return "http://" + httpHost + ':' + httpPort + '/'; }
public void run() { I2PAppContext.getGlobalContext().portMapper().register(PortMapper.SVC_SAM_UDP, _host, _port); try { run2(); } finally { I2PAppContext.getGlobalContext().portMapper().unregister(PortMapper.SVC_SAM_UDP); } }
/** * Get the registered port for a service * @return -1 if not registered */ public int getPort(String service) { int port = getPort(service, -1); return port; }
StringBuilder out = new StringBuilder(2048); try { boolean hasSusiDNS = ctx.portMapper().isRegistered(PortMapper.SVC_SUSIDNS); boolean hasI2PTunnel = ctx.portMapper().isRegistered(PortMapper.SVC_I2PTUNNEL); if (hasSusiDNS && hasI2PTunnel) { reader = new TranslateReader(ctx, BUNDLE_NAME, new FileInputStream(file)); String url = ctx.portMapper().getConsoleURL(); if (!url.equals("http://127.0.0.1:7657/")) { DataHelper.replace(out, "http://127.0.0.1:7657/", url);
/** * Get the actual host for a service. * Will return "127.0.0.1" if the service was registered without a host. * If the service was registered with the host "0.0.0.0", "::", or "0:0:0:0:0:0:0:0", * it will return a public IP if we have one, * else a local IP if we have one, else def. * If it was not registered with a wildcard address, it will return the registered host. * * @param def default * @return def if not registered * @since 0.9.24 */ public String getActualHost(String service, String def) { InetSocketAddress ia = _dir.get(service); if (ia == null) return def; return convertWildcard(ia.getHostName(), def); }
_overrideProps.putAll(envProps); _shutdownTasks = new ConcurrentHashSet<Runnable>(32); _portMapper = new PortMapper(this); _appManager = isRouterContext() ? null : new ClientAppManagerImpl(this);
if (_mgr != null) _mgr.register(this); I2PAppContext.getGlobalContext().portMapper().register(_useSSL ? PortMapper.SVC_SAM_SSL : PortMapper.SVC_SAM, _listenHost != null ? _listenHost : "127.0.0.1", _listenPort); serverSocket.close(); } catch (IOException e) {} I2PAppContext.getGlobalContext().portMapper().unregister(_useSSL ? PortMapper.SVC_SAM_SSL : PortMapper.SVC_SAM); stopHandlers(); changeState(STOPPED);
/** * Remove the service, * only if it is registered with the supplied port. * * @since 0.9.34 */ public void unregister(String service, int port) { // not synched if (getPort(service) == port) _dir.remove(service); }
String conURL = pm.getConsoleURL(); out.write(("HTTP/1.1 200 OK\r\n"+ "Content-Type: text/html; charset=UTF-8\r\n"+ "<a href=\"" + conURL + "\" title=\"" + _t("Router Console") + "\"><img src=\"http://proxy.i2p/themes/console/images/i2plogo.png\" alt=\"I2P Router Console\" border=\"0\"></a><hr>\n" + "<a href=\"" + conURL + "config\">" + _t("Configuration") + "</a> <a href=\"" + conURL + "help.jsp\">" + _t("Help") + "</a>").getBytes("UTF-8")); if (pm.isRegistered(PortMapper.SVC_SUSIDNS)) out.write((" <a href=\"" + conURL + "susidns/index\">" + _t("Addressbook") + "</a>\n").getBytes("UTF-8")); out.write(("</div>" +
/** * @return https URL unless console is http only. Default http://127.0.0.1:7657/ * @since 0.9.34 */ private String getHTTPSConsoleURL() { String unset = "*unset*"; String httpHost = getActualHost(SVC_CONSOLE, unset); String httpsHost = getActualHost(SVC_HTTPS_CONSOLE, unset); int httpPort = getPort(SVC_CONSOLE); int httpsPort = getPort(SVC_HTTPS_CONSOLE, DEFAULT_HTTPS_CONSOLE_PORT); boolean httpOnly = httpPort > 0 && httpsHost.equals(unset) && !httpHost.equals(unset); if (httpOnly) return "http://" + httpHost + ':' + httpPort + '/'; if (httpsHost.equals(unset)) return "http://" + DEFAULT_HOST + ':' + DEFAULT_CONSOLE_PORT + '/'; return "https://" + httpsHost + ':' + httpsPort + '/'; }
/** * For debugging only * @since 0.9.20 */ public void renderStatusHTML(Writer out) throws IOException { List<String> services = new ArrayList<String>(_dir.keySet()); out.write("<h2 id=\"debug_portmapper\">Port Mapper</h2><table id=\"portmapper\"><tr><th>Service<th>Host<th>Port\n"); Collections.sort(services, Collator.getInstance()); for (String s : services) { InetSocketAddress ia = _dir.get(s); if (ia == null) continue; out.write("<tr><td>" + s + "<td>" + convertWildcard(ia.getHostName(), DEFAULT_HOST) + "<td>" + ia.getPort() + '\n'); } out.write("</table>\n"); } }
@Override public boolean close(boolean forced) { int reg = _context.portMapper().getPort(PortMapper.SVC_HTTPS_PROXY); if (reg == getLocalPort()) _context.portMapper().unregister(PortMapper.SVC_HTTPS_PROXY); return super.close(forced); }
if (_port > 0) { _context.portMapper().register(portMapperService, _socket.getInetAddress().getHostAddress(), _port); if (_port > 0) { _context.portMapper().unregister(portMapperService);
@Override public void startRunning() { super.startRunning(); if (open) _context.portMapper().register(PortMapper.SVC_HTTPS_PROXY, getTunnel().listenHost, getLocalPort()); }
if (sproxyType == SSLEepGet.ProxyType.INTERNAL) { _sproxyHost = "localhost"; _sproxyPort = _context.portMapper().getPort(PortMapper.SVC_HTTP_PROXY, 4444); } else { _sproxyHost = _context.getProperty(PROP_SPROXY_HOST);
Hash h2 = ConvertToHash.getHash(ahelperKey); if (h1 != null && h2 != null) { String conURL = _context.portMapper().getConsoleURL(); out.write(("\n<table class=\"conflict\"><tr><th align=\"center\">" + "<a href=\"" + trustedURL + "\">").getBytes("UTF-8")); out.write(_t("Conflicting address helper destination").getBytes("UTF-8")); out.write(("</a></th></tr>\n").getBytes("UTF-8")); if (_context.portMapper().isRegistered(PortMapper.SVC_IMAGEGEN)) { out.write(("<tr><td align=\"center\">" + "<a href=\"" + trustedURL + "\">" +