Beispiel #1
0
  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 TRTrackerServerUDP(String _name, int _port, boolean _start_up_ready) {
    super(_name, _start_up_ready);

    port = _port;

    thread_pool = new ThreadPool("TrackerServer:UDP:" + port, THREAD_POOL_SIZE);

    try {
      InetAddress bind_ip = NetworkAdmin.getSingleton().getSingleHomedServiceBindAddress();

      InetSocketAddress address;

      DatagramSocket socket;

      if (bind_ip == null) {

        address = new InetSocketAddress(InetAddress.getByName("127.0.0.1"), port);

        socket = new DatagramSocket(port);

      } else {

        current_bind_ip = bind_ip;

        address = new InetSocketAddress(bind_ip, port);

        socket = new DatagramSocket(address);
      }

      socket.setReuseAddress(true);

      dg_socket = socket;

      final InetSocketAddress f_address = address;

      Thread recv_thread =
          new AEThread("TRTrackerServerUDP:recv.loop") {
            public void runSupport() {
              recvLoop(dg_socket, f_address);
            }
          };

      recv_thread.setDaemon(true);

      recv_thread.start();

      Logger.log(new LogEvent(LOGID, "TRTrackerServerUDP: recv established on port " + port));

    } catch (Throwable e) {

      Logger.log(
          new LogEvent(
              LOGID, "TRTrackerServerUDP: " + "DatagramSocket bind failed on port " + port, e));
    }
  }
Beispiel #3
0
  static {
    COConfigurationManager.addListener(
        new COConfigurationListener() {
          public void configurationSaved() {
            readConfig();
          }
        });

    NetworkAdmin.getSingleton()
        .addPropertyChangeListener(
            new NetworkAdminPropertyChangeListener() {
              public void propertyChanged(String property) {
                if (property == NetworkAdmin.PR_DEFAULT_BIND_ADDRESS) {

                  readConfig();
                }
              }
            });

    readConfig();
  }
    protected Searcher(boolean _persistent, boolean _async) throws DeviceManagerException {

      try {
        int last_port = COConfigurationManager.getIntParameter("devices.tivo.net.tcp.port", 0);

        if (last_port > 0) {

          try {
            ServerSocket ss = new ServerSocket(last_port);

            ss.setReuseAddress(true);

            ss.close();

          } catch (Throwable e) {

            last_port = 0;
          }
        }

        twc = plugin_interface.getTracker().createWebContext(last_port, Tracker.PR_HTTP);

        tcp_port = twc.getURLs()[0].getPort();

        COConfigurationManager.setParameter("devices.tivo.net.tcp.port", tcp_port);

        twc.addPageGenerator(
            new TrackerWebPageGenerator() {
              public boolean generate(
                  TrackerWebPageRequest request, TrackerWebPageResponse response)
                  throws IOException {
                String id = (String) request.getHeaders().get("tsn");

                if (id == null) {

                  id = (String) request.getHeaders().get("tivo_tcd_id");
                }

                if (id != null && is_enabled) {

                  persistent = true;

                  DeviceTivo tivo =
                      foundTiVo(request.getClientAddress2().getAddress(), id, null, null);

                  return (tivo.generate(request, response));
                }

                return (false);
              }
            });

        control_socket = new DatagramSocket(null);

        control_socket.setReuseAddress(true);

        try {
          control_socket.setSoTimeout(60 * 1000);

        } catch (Throwable e) {
        }

        InetAddress bind = NetworkAdmin.getSingleton().getSingleHomedServiceBindAddress();

        control_socket.bind(new InetSocketAddress(bind, CONTROL_PORT));

        timer_event =
            SimpleTimer.addPeriodicEvent(
                "Tivo:Beacon",
                60 * 1000,
                new TimerEventPerformer() {
                  public void perform(TimerEvent event) {
                    if (!(manager_destroyed || search_destroyed)) {

                      sendBeacon();
                    }

                    // see if time to auto-shutdown searching

                    if (!persistent) {

                      synchronized (DeviceTivoManager.this) {
                        if (SystemTime.getMonotonousTime() - start >= LIFE_MILLIS) {

                          log("Terminating search, no devices found");

                          current_search = null;

                          destroy();
                        }
                      }
                    }
                  }
                });

        final AESemaphore start_sem = new AESemaphore("TiVo:CtrlListener");

        new AEThread2("TiVo:CtrlListener", true) {
          public void run() {
            start_sem.release();

            long successful_accepts = 0;
            long failed_accepts = 0;

            while (!(manager_destroyed || search_destroyed)) {

              try {
                byte[] buf = new byte[8192];

                DatagramPacket packet = new DatagramPacket(buf, buf.length);

                control_socket.receive(packet);

                successful_accepts++;

                failed_accepts = 0;

                if (receiveBeacon(packet.getAddress(), packet.getData(), packet.getLength())) {

                  persistent = true;
                }

              } catch (SocketTimeoutException e) {

              } catch (Throwable e) {

                if (control_socket != null && !search_destroyed && !manager_destroyed) {

                  failed_accepts++;

                  log("UDP receive on port " + CONTROL_PORT + " failed", e);
                }

                if ((failed_accepts > 100 && successful_accepts == 0) || failed_accepts > 1000) {

                  log("    too many failures, abandoning");

                  break;
                }
              }
            }
          }
        }.start();

        if (_async) {

          new DelayedEvent(
              "search:delay",
              5000,
              new AERunnable() {
                public void runSupport() {
                  sendBeacon();
                }
              });
        } else {

          start_sem.reserve(5000);

          sendBeacon();
        }

        log("Initiated device search");

      } catch (Throwable e) {

        log("Failed to initialise search", e);

        destroy();

        throw (new DeviceManagerException("Creation failed", e));
      }
    }
  public SpeedManagerImpl(AzureusCore _core, SpeedManagerAdapter _adapter) {
    core = _core;
    adapter = _adapter;

    AEDiagnostics.addEvidenceGenerator(this);

    logger = AEDiagnostics.getLogger("SpeedMan");

    ping_mapper = new SpeedManagerPingMapperImpl(this, "Var", LONG_PERIOD_TICKS, true, false);

    if (Constants.isCVSVersion()) {

      SpeedManagerPingMapperImpl pm2 =
          new SpeedManagerPingMapperImpl(this, "Abs", LONG_PERIOD_TICKS, false, false);

      ping_mappers = new SpeedManagerPingMapperImpl[] {pm2, ping_mapper};

    } else {

      ping_mappers = new SpeedManagerPingMapperImpl[] {ping_mapper};
    }

    final File config_dir = new File(SystemProperties.getUserPath(), "net");

    if (!config_dir.exists()) {

      config_dir.mkdirs();
    }

    NetworkAdmin.getSingleton()
        .addAndFirePropertyChangeListener(
            new NetworkAdminPropertyChangeListener() {
              public void propertyChanged(String property) {
                if (property == NetworkAdmin.PR_AS) {

                  NetworkAdminASN net_asn = NetworkAdmin.getSingleton().getCurrentASN();

                  String as = net_asn.getAS();

                  if (as.length() == 0) {

                    as = "default";
                  }

                  File history =
                      new File(config_dir, "pm_" + FileUtil.convertOSSpecificChars(as) + ".dat");

                  ping_mapper.loadHistory(history);

                  asn = net_asn.getASName();

                  if (asn.length() == 0) {

                    asn = "Unknown";
                  }

                  informListeners(SpeedManagerListener.PR_ASN);
                }
              }
            });

    core.addLifecycleListener(
        new AzureusCoreLifecycleAdapter() {
          public void stopping(AzureusCore core) {
            ping_mapper.saveHistory();
          }
        });

    COConfigurationManager.addAndFireParameterListener(
        CONFIG_VERSION,
        new ParameterListener() {
          public void parameterChanged(final String name) {
            dispatcher.dispatch(
                new AERunnable() {
                  public void runSupport() {
                    boolean do_reset = provider_version == -1;

                    int version = COConfigurationManager.getIntParameter(name);

                    if (version != provider_version) {

                      provider_version = version;

                      if (isEnabled()) {

                        setEnabledSupport(false);

                        setEnabledSupport(true);
                      }
                    }

                    if (do_reset) {

                      enableOrAlgChanged();
                    }
                  }
                });
          }
        });

    COConfigurationManager.setParameter(CONFIG_AVAIL, false);

    SimpleTimer.addPeriodicEvent(
        "SpeedManager:timer",
        UPDATE_PERIOD_MILLIS,
        new TimerEventPerformer() {
          private int tick_count;

          public void perform(TimerEvent event) {
            // if enabled the ping stream drives the stats update for the ping mappers
            // When not enabled we do it here instead

            if (!enabled || contacts_array.length == 0) {

              int x =
                  (adapter.getCurrentDataUploadSpeed(SPEED_AVERAGE_PERIOD)
                      + adapter.getCurrentProtocolUploadSpeed(SPEED_AVERAGE_PERIOD));
              int y =
                  (adapter.getCurrentDataDownloadSpeed(SPEED_AVERAGE_PERIOD)
                      + adapter.getCurrentProtocolDownloadSpeed(SPEED_AVERAGE_PERIOD));

              for (int i = 0; i < ping_mappers.length; i++) {

                ping_mappers[i].addSpeed(x, y);
              }
            }

            tick_count++;

            if (tick_count % SAVE_PERIOD_TICKS == 0) {

              ping_mapper.saveHistory();
            }
          }
        });

    emulated_ping_source = false;

    if (emulated_ping_source) {

      Debug.out("Emulated ping source!!!!");

      setSpeedTester(new TestPingSourceRandom(this));
    }
  }
  public Composite configSectionCreate(final Composite parent) {
    GridData gridData;

    Composite cSection = new Composite(parent, SWT.NULL);

    gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL + GridData.VERTICAL_ALIGN_FILL);
    cSection.setLayoutData(gridData);
    GridLayout advanced_layout = new GridLayout();
    cSection.setLayout(advanced_layout);

    int userMode = COConfigurationManager.getIntParameter("User Mode");
    if (userMode < REQUIRED_MODE) {
      Label label = new Label(cSection, SWT.WRAP);
      gridData = new GridData();
      label.setLayoutData(gridData);

      final String[] modeKeys = {
        "ConfigView.section.mode.beginner",
        "ConfigView.section.mode.intermediate",
        "ConfigView.section.mode.advanced"
      };

      String param1, param2;
      if (REQUIRED_MODE < modeKeys.length) param1 = MessageText.getString(modeKeys[REQUIRED_MODE]);
      else param1 = String.valueOf(REQUIRED_MODE);

      if (userMode < modeKeys.length) param2 = MessageText.getString(modeKeys[userMode]);
      else param2 = String.valueOf(userMode);

      label.setText(
          MessageText.getString("ConfigView.notAvailableForMode", new String[] {param1, param2}));

      return cSection;
    }

    new LinkLabel(
        cSection, gridData, CFG_PREFIX + "info.link", MessageText.getString(CFG_PREFIX + "url"));

    ///////////////////////   ADVANCED SOCKET SETTINGS GROUP //////////

    Group gSocket = new Group(cSection, SWT.NULL);
    Messages.setLanguageText(gSocket, CFG_PREFIX + "socket.group");
    gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.FILL_HORIZONTAL);
    gSocket.setLayoutData(gridData);
    GridLayout glayout = new GridLayout();
    glayout.numColumns = 3;
    gSocket.setLayout(glayout);

    // max simultaneous

    Label lmaxout = new Label(gSocket, SWT.NULL);
    Messages.setLanguageText(
        lmaxout, "ConfigView.section.connection.network.max.simultaneous.connect.attempts");
    gridData = new GridData();
    lmaxout.setLayoutData(gridData);

    IntParameter max_connects =
        new IntParameter(gSocket, "network.max.simultaneous.connect.attempts", 1, 100);
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    max_connects.setLayoutData(gridData);

    // // max pending

    Label lmaxpout = new Label(gSocket, SWT.NULL);
    Messages.setLanguageText(
        lmaxpout, "ConfigView.section.connection.network.max.outstanding.connect.attempts");
    gridData = new GridData();
    lmaxpout.setLayoutData(gridData);

    IntParameter max_pending_connects =
        new IntParameter(gSocket, "network.tcp.max.connections.outstanding", 1, 65536);
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    max_pending_connects.setLayoutData(gridData);

    // bind ip

    Label lbind = new Label(gSocket, SWT.NULL);
    Messages.setLanguageText(lbind, "ConfigView.label.bindip");
    gridData = new GridData();
    lbind.setLayoutData(gridData);

    StringParameter bindip = new StringParameter(gSocket, "Bind IP", "", false);
    gridData = new GridData();
    gridData.widthHint = 100;
    gridData.horizontalSpan = 2;
    bindip.setLayoutData(gridData);

    Text lbind2 = new Text(gSocket, SWT.READ_ONLY | SWT.MULTI);
    lbind2.setTabs(8);
    Messages.setLanguageText(
        lbind2,
        "ConfigView.label.bindip.details",
        new String[] {
          "\t"
              + NetworkAdmin.getSingleton()
                  .getNetworkInterfacesAsString()
                  .replaceAll("\\\n", "\n\t")
        });
    gridData = new GridData();
    gridData.horizontalSpan = 3;
    lbind2.setLayoutData(gridData);

    BooleanParameter check_bind =
        new BooleanParameter(gSocket, "Check Bind IP On Start", "network.check.ipbinding");
    gridData = new GridData();
    gridData.horizontalSpan = 3;
    check_bind.setLayoutData(gridData);

    BooleanParameter force_bind =
        new BooleanParameter(gSocket, "Enforce Bind IP", "network.enforce.ipbinding");
    gridData = new GridData();
    gridData.horizontalSpan = 3;
    force_bind.setLayoutData(gridData);

    BooleanParameter bind_icon =
        new BooleanParameter(gSocket, "Show IP Bindings Icon", "network.ipbinding.icon.show");
    gridData = new GridData();
    gridData.horizontalSpan = 3;
    bind_icon.setLayoutData(gridData);

    Label lpbind = new Label(gSocket, SWT.NULL);
    Messages.setLanguageText(lpbind, CFG_PREFIX + "bind_port");
    final IntParameter port_bind = new IntParameter(gSocket, "network.bind.local.port", 0, 65535);
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    port_bind.setLayoutData(gridData);

    Label lmtu = new Label(gSocket, SWT.NULL);
    Messages.setLanguageText(lmtu, CFG_PREFIX + "mtu");
    final IntParameter mtu_size = new IntParameter(gSocket, "network.tcp.mtu.size");
    mtu_size.setMaximumValue(512 * 1024);
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    mtu_size.setLayoutData(gridData);

    // sndbuf

    Label lsend = new Label(gSocket, SWT.NULL);
    Messages.setLanguageText(lsend, CFG_PREFIX + "SO_SNDBUF");
    final IntParameter SO_SNDBUF = new IntParameter(gSocket, "network.tcp.socket.SO_SNDBUF");
    gridData = new GridData();
    SO_SNDBUF.setLayoutData(gridData);

    final Label lsendcurr = new Label(gSocket, SWT.NULL);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalIndent = 10;
    lsendcurr.setLayoutData(gridData);

    // rcvbuf

    Label lreceiv = new Label(gSocket, SWT.NULL);
    Messages.setLanguageText(lreceiv, CFG_PREFIX + "SO_RCVBUF");
    final IntParameter SO_RCVBUF = new IntParameter(gSocket, "network.tcp.socket.SO_RCVBUF");
    gridData = new GridData();
    SO_RCVBUF.setLayoutData(gridData);

    final Label lreccurr = new Label(gSocket, SWT.NULL);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalIndent = 10;
    lreccurr.setLayoutData(gridData);

    final Runnable buff_updater =
        new Runnable() {
          public void run() {
            SocketChannel sc = null;

            int snd_val = 0;
            int rec_val = 0;

            try {
              sc = SocketChannel.open();

              Socket socket = sc.socket();

              if (SO_SNDBUF.getValue() == 0) {

                snd_val = socket.getSendBufferSize();
              }

              if (SO_RCVBUF.getValue() == 0) {

                rec_val = socket.getReceiveBufferSize();
              }
            } catch (Throwable e) {

            } finally {

              try {
                sc.close();

              } catch (Throwable e) {
              }
            }

            if (snd_val == 0) {
              lsendcurr.setText("");
            } else {
              Messages.setLanguageText(
                  lsendcurr, "label.current.equals", new String[] {String.valueOf(snd_val)});
            }

            if (rec_val == 0) {
              lreccurr.setText("");
            } else {
              Messages.setLanguageText(
                  lreccurr, "label.current.equals", new String[] {String.valueOf(rec_val)});
            }
          }
        };

    buff_updater.run();

    ParameterChangeAdapter buff_listener =
        new ParameterChangeAdapter() {
          public void parameterChanged(Parameter p, boolean caused_internally) {
            buff_updater.run();
          }
        };

    SO_RCVBUF.addChangeListener(buff_listener);
    SO_SNDBUF.addChangeListener(buff_listener);

    Label ltos = new Label(gSocket, SWT.NULL);
    Messages.setLanguageText(ltos, CFG_PREFIX + "IPDiffServ");
    final StringParameter IPDiffServ =
        new StringParameter(gSocket, "network.tcp.socket.IPDiffServ");
    gridData = new GridData();
    gridData.widthHint = 100;
    gridData.horizontalSpan = 2;
    IPDiffServ.setLayoutData(gridData);

    // do simple input verification, and registry key setting for TOS field
    IPDiffServ.addChangeListener(
        new ParameterChangeAdapter() {

          final Color obg = IPDiffServ.getControl().getBackground();

          final Color ofg = IPDiffServ.getControl().getForeground();

          public void parameterChanged(Parameter p, boolean caused_internally) {
            String raw = IPDiffServ.getValue();
            int value = -1;

            try {
              value = Integer.decode(raw).intValue();
            } catch (Throwable t) {
            }

            if (value < 0 || value > 255) { // invalid or no value entered
              ConfigurationManager.getInstance().removeParameter("network.tcp.socket.IPDiffServ");

              if (raw != null && raw.length() > 0) { // error state
                IPDiffServ.getControl().setBackground(Colors.red);
                IPDiffServ.getControl().setForeground(Colors.white);
              } else { // no value state
                IPDiffServ.getControl().setBackground(obg);
                IPDiffServ.getControl().setForeground(ofg);
              }

              enableTOSRegistrySetting(false); // disable registry setting if necessary
            } else { // passes test
              IPDiffServ.getControl().setBackground(obg);
              IPDiffServ.getControl().setForeground(ofg);

              enableTOSRegistrySetting(true); // enable registry setting if necessary
            }
          }
        });

    // read select

    Label lreadsel = new Label(gSocket, SWT.NULL);
    Messages.setLanguageText(
        lreadsel,
        CFG_PREFIX + "read_select",
        new String[] {
          String.valueOf(COConfigurationManager.getDefault("network.tcp.read.select.time"))
        });
    final IntParameter read_select =
        new IntParameter(gSocket, "network.tcp.read.select.time", 10, 250);
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    read_select.setLayoutData(gridData);

    Label lreadselmin = new Label(gSocket, SWT.NULL);
    Messages.setLanguageText(
        lreadselmin,
        CFG_PREFIX + "read_select_min",
        new String[] {
          String.valueOf(COConfigurationManager.getDefault("network.tcp.read.select.min.time"))
        });
    final IntParameter read_select_min =
        new IntParameter(gSocket, "network.tcp.read.select.min.time", 0, 100);
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    read_select_min.setLayoutData(gridData);

    // write select

    Label lwritesel = new Label(gSocket, SWT.NULL);
    Messages.setLanguageText(
        lwritesel,
        CFG_PREFIX + "write_select",
        new String[] {
          String.valueOf(COConfigurationManager.getDefault("network.tcp.write.select.time"))
        });
    final IntParameter write_select =
        new IntParameter(gSocket, "network.tcp.write.select.time", 10, 250);
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    write_select.setLayoutData(gridData);

    Label lwriteselmin = new Label(gSocket, SWT.NULL);
    Messages.setLanguageText(
        lwriteselmin,
        CFG_PREFIX + "write_select_min",
        new String[] {
          String.valueOf(COConfigurationManager.getDefault("network.tcp.write.select.min.time"))
        });
    final IntParameter write_select_min =
        new IntParameter(gSocket, "network.tcp.write.select.min.time", 0, 100);
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    write_select_min.setLayoutData(gridData);

    new BooleanParameter(cSection, "IPV6 Enable Support", "network.ipv6.enable.support");

    new BooleanParameter(cSection, "IPV6 Prefer Addresses", "network.ipv6.prefer.addresses");

    if (Constants.isWindowsVistaOrHigher && Constants.isJava7OrHigher) {

      new BooleanParameter(cSection, "IPV4 Prefer Stack", "network.ipv4.prefer.stack");
    }

    //////////////////////////////////////////////////////////////////////////

    return cSection;
  }
  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();
    }
  }
  /**
   * Construct the default version check message.
   *
   * @return message to send
   */
  public static Map constructVersionCheckMessage(String reason) {

    // only send if anonymous-check flag is not set

    boolean send_info = COConfigurationManager.getBooleanParameter("Send Version Info");

    Map message = new HashMap();

    // always send
    message.put("appid", SystemProperties.getApplicationIdentifier());
    message.put("appname", SystemProperties.getApplicationName());
    message.put("version", Constants.AZUREUS_VERSION);

    String sub_ver = Constants.AZUREUS_SUBVER;

    if (sub_ver.length() > 0) {
      message.put("subver", sub_ver);
    }

    if (COConfigurationManager.getBooleanParameter("Beta Programme Enabled")) {

      message.put("beta_prog", "true");
    }

    message.put("ui", COConfigurationManager.getStringParameter("ui", "unknown"));
    message.put("os", Constants.OSName);
    message.put("os_version", System.getProperty("os.version"));
    message.put(
        "os_arch", System.getProperty("os.arch")); // see http://lopica.sourceforge.net/os.html

    boolean using_phe =
        COConfigurationManager.getBooleanParameter("network.transport.encrypted.require");
    message.put("using_phe", using_phe ? new Long(1) : new Long(0));

    // swt stuff
    try {
      Class c = Class.forName("org.eclipse.swt.SWT");

      String swt_platform =
          (String) c.getMethod("getPlatform", new Class[] {}).invoke(null, new Object[] {});
      message.put("swt_platform", swt_platform);

      Integer swt_version =
          (Integer) c.getMethod("getVersion", new Class[] {}).invoke(null, new Object[] {});
      message.put("swt_version", new Long(swt_version.longValue()));

      if (send_info) {
        c = Class.forName("org.gudy.azureus2.ui.swt.mainwindow.MainWindow");
        if (c != null) {
          c.getMethod("addToVersionCheckMessage", new Class[] {Map.class})
              .invoke(null, new Object[] {message});
        }
      }
    } catch (ClassNotFoundException e) {
      /* ignore */
    } catch (NoClassDefFoundError er) {
      /* ignore */
    } catch (InvocationTargetException err) {
      /* ignore */
    } catch (Throwable t) {
      t.printStackTrace();
    }

    int last_send_time = COConfigurationManager.getIntParameter("Send Version Info Last Time", -1);
    int current_send_time = (int) (SystemTime.getCurrentTime() / 1000);
    COConfigurationManager.setParameter("Send Version Info Last Time", current_send_time);

    String id = COConfigurationManager.getStringParameter("ID", null);

    if (id != null && send_info) {
      message.put("id", id);

      try {
        byte[] id2 = CryptoManagerFactory.getSingleton().getSecureID();

        message.put("id2", id2);

      } catch (Throwable e) {
      }

      if (last_send_time != -1 && last_send_time < current_send_time) {
        // time since last
        message.put("tsl", new Long(current_send_time - last_send_time));
      }

      message.put("reason", reason);

      String java_version = System.getProperty("java.version");
      if (java_version == null) {
        java_version = "unknown";
      }
      message.put("java", java_version);

      String java_vendor = System.getProperty("java.vm.vendor");
      if (java_vendor == null) {
        java_vendor = "unknown";
      }
      message.put("javavendor", java_vendor);

      long max_mem = Runtime.getRuntime().maxMemory() / (1024 * 1024);
      message.put("javamx", new Long(max_mem));

      String java_rt_name = System.getProperty("java.runtime.name");
      if (java_rt_name != null) {
        message.put("java_rt_name", java_rt_name);
      }

      String java_rt_version = System.getProperty("java.runtime.version");
      if (java_rt_version != null) {
        message.put("java_rt_version", java_rt_version);
      }

      OverallStats stats = StatsFactory.getStats();

      if (stats != null) {

        // long total_bytes_downloaded 	= stats.getDownloadedBytes();
        // long total_bytes_uploaded		= stats.getUploadedBytes();
        long total_uptime = stats.getTotalUpTime();

        // removed due to complaints about anonymous stats collection
        // message.put( "total_bytes_downloaded", new Long( total_bytes_downloaded ) );
        // message.put( "total_bytes_uploaded", new Long( total_bytes_uploaded ) );
        message.put("total_uptime", new Long(total_uptime));
        // message.put( "dlstats", stats.getDownloadStats());
      }

      try {
        NetworkAdminASN current_asn = NetworkAdmin.getSingleton().getCurrentASN();

        String as = current_asn.getAS();

        message.put("ip_as", current_asn.getAS());

        String asn = current_asn.getASName();

        if (asn.length() > 64) {

          asn = asn.substring(0, 64);
        }

        message.put("ip_asn", asn);

      } catch (Throwable e) {

        Debug.out(e);
      }

      // send locale, so we can determine which languages need attention
      message.put("locale", Locale.getDefault().toString());
      String originalLocale =
          System.getProperty("user.language") + "_" + System.getProperty("user.country");
      String variant = System.getProperty("user.variant");
      if (variant != null && variant.length() > 0) {
        originalLocale += "_" + variant;
      }
      message.put("orig_locale", originalLocale);

      // We may want to reply differently if the user is in Beginner mode vs Advanced
      message.put("user_mode", COConfigurationManager.getIntParameter("User Mode", -1));

      Set<String> features = UtilitiesImpl.getFeaturesInstalled();

      if (features.size() > 0) {

        String str = "";

        for (String f : features) {
          str += (str.length() == 0 ? "" : ",") + f;
        }

        message.put("vzfeatures", str);
      }

      try {
        if (AzureusCoreFactory.isCoreAvailable()) {

          // installed plugin IDs
          PluginInterface[] plugins =
              AzureusCoreFactory.getSingleton().getPluginManager().getPluginInterfaces();

          List pids = new ArrayList();

          List vs_data = new ArrayList();

          for (int i = 0; i < plugins.length; i++) {

            PluginInterface plugin = plugins[i];

            String pid = plugin.getPluginID();

            String info = plugin.getPluginconfig().getPluginStringParameter("plugin.info");

            // filter out built-in and core ones
            if ((info != null && info.length() > 0)
                || (!pid.startsWith("<")
                    && !pid.startsWith("azbp")
                    && !pid.startsWith("azupdater")
                    && !pid.startsWith("azplatform")
                    && !pids.contains(pid))) {

              if (info != null && info.length() > 0) {

                if (info.length() < 256) {

                  pid += ":" + info;

                } else {

                  Debug.out("Plugin '" + pid + "' reported excessive info string '" + info + "'");
                }
              }

              pids.add(pid);
            }

            Map data =
                plugin.getPluginconfig().getPluginMapParameter("plugin.versionserver.data", null);

            if (data != null) {

              Map payload = new HashMap();

              byte[] data_bytes = BEncoder.encode(data);

              if (data_bytes.length > 16 * 1024) {

                Debug.out(
                    "Plugin '"
                        + pid
                        + "' reported excessive version server data (length="
                        + data_bytes.length
                        + ")");

                payload.put("error", "data too long: " + data_bytes.length);

              } else {

                payload.put("data", data_bytes);
              }

              payload.put("id", pid);
              payload.put("version", plugin.getPluginVersion());

              vs_data.add(payload);
            }
          }
          message.put("plugins", pids);

          if (vs_data.size() > 0) {

            message.put("plugin_data", vs_data);
          }
        }
      } catch (Throwable e) {

        Debug.out(e);
      }
    }

    return message;
  }
  protected void preProcessReply(Map reply, final boolean v6) {
    NetworkAdmin admin = NetworkAdmin.getSingleton();

    try {
      byte[] address = (byte[]) reply.get("source_ip_address");

      InetAddress my_ip = InetAddress.getByName(new String(address));

      NetworkAdminASN old_asn = admin.getCurrentASN();

      NetworkAdminASN new_asn = admin.lookupCurrentASN(my_ip);

      if (!new_asn.sameAs(old_asn)) {

        // kick off a secondary version check to communicate the new information

        if (!secondary_check_done) {

          secondary_check_done = true;

          new AEThread("Secondary version check", true) {
            public void runSupport() {
              getVersionCheckInfoSupport(REASON_SECONDARY_CHECK, false, true, v6);
            }
          }.start();
        }
      }
    } catch (Throwable e) {

      Debug.printStackTrace(e);
    }

    Long as_advice = (Long) reply.get("as_advice");

    if (as_advice != null) {

      NetworkAdminASN current_asn = admin.getCurrentASN();

      String asn = current_asn.getASName();

      if (asn != null) {

        long advice = as_advice.longValue();

        if (advice != 0) {

          // require crypto

          String done_asn = COConfigurationManager.getStringParameter("ASN Advice Followed", "");

          if (!done_asn.equals(asn)) {

            COConfigurationManager.setParameter("ASN Advice Followed", asn);

            boolean change = advice == 1 || advice == 2;
            boolean alert = advice == 1 || advice == 3;

            if (!COConfigurationManager.getBooleanParameter(
                "network.transport.encrypted.require")) {

              if (change) {

                COConfigurationManager.setParameter("network.transport.encrypted.require", true);
              }

              if (alert) {

                String msg = MessageText.getString("crypto.alert.as.warning", new String[] {asn});

                Logger.log(new LogAlert(false, LogAlert.AT_WARNING, msg));
              }
            }
          }
        }
      }
    }

    // set ui.toolbar.uiswitcher based on instructions from tracker
    // Really shouldn't be in VersionCheck client, but instead have some
    // listener and have the code elsewhere.  Simply calling
    // getVersionCheckInfo from "code elsewhere" (to get the cached result)
    // caused a deadlock at startup.
    Long lEnabledUISwitcher = (Long) reply.get("ui.toolbar.uiswitcher");
    if (lEnabledUISwitcher != null) {
      COConfigurationManager.setBooleanDefault(
          "ui.toolbar.uiswitcher", lEnabledUISwitcher.longValue() == 1);
    }
  }