static void readConfig() { tracker_ip = COConfigurationManager.getStringParameter("Tracker IP", ""); tracker_ip = UrlUtils.expandIPV6Host(tracker_ip); String override_ips = COConfigurationManager.getStringParameter("Override Ip", ""); StringTokenizer tok = new StringTokenizer(override_ips, ";"); Map new_override_map = new HashMap(); while (tok.hasMoreTokens()) { String ip = tok.nextToken().trim(); if (ip.length() > 0) { new_override_map.put(AENetworkClassifier.categoriseAddress(ip), ip); } } override_map = new_override_map; InetAddress bad = NetworkAdmin.getSingleton().getSingleHomedServiceBindAddress(); if (bad == null || bad.isAnyLocalAddress()) { bind_ip = ""; } else { bind_ip = bad.getHostAddress(); } }
public static String getPublicIPOverride() { String explicit_ips = COConfigurationManager.getStringParameter("Override Ip", ""); if (explicit_ips.length() > 0) { StringTokenizer tok = new StringTokenizer(explicit_ips, ";"); while (tok.hasMoreTokens()) { String this_address = tok.nextToken().trim(); if (this_address.length() > 0) { String cat = AENetworkClassifier.categoriseAddress(this_address); if (cat == AENetworkClassifier.AT_PUBLIC) { return (this_address); } } } } return (null); }
public String getHost() { return (COConfigurationManager.getStringParameter("Tracker IP", "")); }
public static URL[][] getAnnounceURLs() { String tracker_host = COConfigurationManager.getStringParameter("Tracker IP", ""); List urls = new ArrayList(); if (tracker_host.length() > 0) { if (COConfigurationManager.getBooleanParameter("Tracker Port Enable")) { int port = COConfigurationManager.getIntParameter("Tracker Port", TRHost.DEFAULT_PORT); try { List l = new ArrayList(); l.add( new URL( "http://" + UrlUtils.convertIPV6Host(tracker_host) + ":" + port + "/announce")); List ports = stringToPorts(COConfigurationManager.getStringParameter("Tracker Port Backups")); for (int i = 0; i < ports.size(); i++) { l.add( new URL( "http://" + UrlUtils.convertIPV6Host(tracker_host) + ":" + ((Integer) ports.get(i)).intValue() + "/announce")); } urls.add(l); } catch (MalformedURLException e) { Debug.printStackTrace(e); } } if (COConfigurationManager.getBooleanParameter("Tracker Port SSL Enable")) { int port = COConfigurationManager.getIntParameter("Tracker Port SSL", TRHost.DEFAULT_PORT_SSL); try { List l = new ArrayList(); l.add( new URL( "https://" + UrlUtils.convertIPV6Host(tracker_host) + ":" + port + "/announce")); List ports = stringToPorts(COConfigurationManager.getStringParameter("Tracker Port SSL Backups")); for (int i = 0; i < ports.size(); i++) { l.add( new URL( "https://" + UrlUtils.convertIPV6Host(tracker_host) + ":" + ((Integer) ports.get(i)).intValue() + "/announce")); } urls.add(l); } catch (MalformedURLException e) { Debug.printStackTrace(e); } } if (COConfigurationManager.getBooleanParameter("Tracker Port UDP Enable")) { int port = COConfigurationManager.getIntParameter("Tracker Port", TRHost.DEFAULT_PORT); boolean auth = COConfigurationManager.getBooleanParameter("Tracker Password Enable Torrent"); try { List l = new ArrayList(); l.add( new URL( "udp://" + UrlUtils.convertIPV6Host(tracker_host) + ":" + port + "/announce" + (auth ? "?auth" : ""))); urls.add(l); } catch (MalformedURLException e) { Debug.printStackTrace(e); } } } URL[][] res = new URL[urls.size()][]; for (int i = 0; i < urls.size(); i++) { List l = (List) urls.get(i); URL[] u = new URL[l.size()]; l.toArray(u); res[i] = u; } return (res); }
private static String computePortsForURL(boolean force_crypto, boolean allow_incoming) { boolean socks_peer_inform = COConfigurationManager.getBooleanParameter("Proxy.Data.Enable") && COConfigurationManager.getBooleanParameter("Proxy.Data.SOCKS.inform"); // we currently don't support incoming connections when SOCKs proxying allow_incoming &= !COConfigurationManager.getBooleanParameter("Tracker Client No Port Announce"); int tcp_port_num; int udp_port_num; if (allow_incoming) { if (socks_peer_inform) { tcp_port_num = 0; udp_port_num = 0; } else { tcp_port_num = COConfigurationManager.getIntParameter("TCP.Listen.Port"); udp_port_num = COConfigurationManager.getIntParameter("UDP.Listen.Port"); } String portOverride = COConfigurationManager.getStringParameter("TCP.Listen.Port.Override"); if (!portOverride.equals("")) { try { tcp_port_num = Integer.parseInt(portOverride); } catch (Throwable e) { Debug.printStackTrace(e); } } } else { tcp_port_num = 0; udp_port_num = 0; } String port = ""; if (force_crypto) { port += "&requirecrypto=1"; port += "&port=0&cryptoport=" + tcp_port_num; } else { boolean require_crypto = COConfigurationManager.getBooleanParameter("network.transport.encrypted.require"); if (require_crypto) { port += "&requirecrypto=1"; } else { port += "&supportcrypto=1"; } if (require_crypto && (!COConfigurationManager.getBooleanParameter( "network.transport.encrypted.fallback.incoming")) && COConfigurationManager.getBooleanParameter( "network.transport.encrypted.use.crypto.port")) { port += "&port=0&cryptoport=" + tcp_port_num; } else { port += "&port=" + tcp_port_num; } port += "&azudp=" + udp_port_num; // BitComet extension for no incoming connections if (tcp_port_num == 0) { port += "&hide=1"; } if (COConfigurationManager.getBooleanParameter("HTTP.Data.Listen.Port.Enable")) { int http_port = COConfigurationManager.getIntParameter("HTTP.Data.Listen.Port.Override"); if (http_port == 0) { http_port = COConfigurationManager.getIntParameter("HTTP.Data.Listen.Port"); } port += "&azhttp=" + http_port; } } return (port); }
public PasswordAuthentication getAuthentication( String realm, String protocol, String host, int port) { try { this_mon.enter(); String tracker = protocol + "://" + host + ":" + port + "/"; InetAddress bind_ip = NetworkAdmin.getSingleton().getSingleHomedServiceBindAddress(); String self_addr; // System.out.println( "auth req for " + realm + " - " + tracker ); if (bind_ip == null || bind_ip.isAnyLocalAddress()) { self_addr = "127.0.0.1"; } else { self_addr = bind_ip.getHostAddress(); } // when the tracker is connected to internally we don't want to prompt // for the password. Here we return a special user and the password hash // which is picked up in the tracker auth code - search for "<internal>"! // also include the tracker IP as well as for scrapes these can occur on // a raw torrent which hasn't been modified to point to localhost if (host.equals(self_addr) || host.equals(COConfigurationManager.getStringParameter("Tracker IP", ""))) { try { byte[] pw = COConfigurationManager.getByteParameter("Tracker Password", new byte[0]); String str_pw = new String(Base64.encode(pw)); return (new PasswordAuthentication("<internal>", str_pw.toCharArray())); } catch (Throwable e) { Debug.printStackTrace(e); } } String auth_key = realm + ":" + tracker; authCache cache = (authCache) auth_cache.get(auth_key); if (cache != null) { PasswordAuthentication auth = cache.getAuth(); if (auth != null) { return (auth); } } String[] res = getAuthenticationDialog(realm, tracker); if (res == null) { return (null); } else { PasswordAuthentication auth = new PasswordAuthentication(res[0], res[1].toCharArray()); boolean save_pw = res[2].equals("true"); boolean old_entry_existed = auth_cache.put(auth_key, new authCache(auth_key, auth, save_pw)) != null; if (save_pw || old_entry_existed) { saveAuthCache(); } return (auth); } } finally { this_mon.exit(); } }