コード例 #1
0
  private Map executeHTTP(Map data_to_send, boolean v6) throws Exception {

    if (v6 && !enable_v6) {

      throw (new Exception("IPv6 is disabled"));
    }

    String host = getHost(v6, HTTP_SERVER_ADDRESS_V6, HTTP_SERVER_ADDRESS_V4);

    if (Logger.isEnabled())
      Logger.log(
          new LogEvent(
              LOGID,
              "VersionCheckClient retrieving "
                  + "version information from "
                  + host
                  + ":"
                  + HTTP_SERVER_PORT
                  + " via HTTP"));

    String url_str =
        "http://"
            + (v6 ? UrlUtils.convertIPV6Host(host) : host)
            + (HTTP_SERVER_PORT == 80 ? "" : (":" + HTTP_SERVER_PORT))
            + "/version?";

    url_str +=
        URLEncoder.encode(new String(BEncoder.encode(data_to_send), "ISO-8859-1"), "ISO-8859-1");

    URL url = new URL(url_str);

    HttpURLConnection url_connection = (HttpURLConnection) url.openConnection();

    url_connection.connect();

    try {
      InputStream is = url_connection.getInputStream();

      Map reply = BDecoder.decode(new BufferedInputStream(is));

      preProcessReply(reply, v6);

      return (reply);

    } finally {

      url_connection.disconnect();
    }
  }
コード例 #2
0
  private String getHTTPGetString(Map content, boolean for_proxy, boolean v6) {
    String host = getHost(v6, HTTP_SERVER_ADDRESS_V6, HTTP_SERVER_ADDRESS_V4);

    String get_str =
        "GET "
            + (for_proxy
                ? ("http://"
                    + (v6 ? UrlUtils.convertIPV6Host(host) : host)
                    + ":"
                    + HTTP_SERVER_PORT)
                : "")
            + "/version?";

    try {
      get_str +=
          URLEncoder.encode(new String(BEncoder.encode(content), "ISO-8859-1"), "ISO-8859-1");

    } catch (Throwable e) {
    }

    get_str += " HTTP/1.1" + "\015\012" + "\015\012";

    return (get_str);
  }
コード例 #3
0
ファイル: TRTrackerUtils.java プロジェクト: aprasa/oldwork
  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);
  }