public void addParameterListener(String parameter, ParameterListener new_listener) {
    if (parameter == null || new_listener == null) {

      return;
    }

    synchronized (parameterListenerz) {
      ParameterListener[] listeners = parameterListenerz.get(parameter);

      if (listeners == null) {

        parameterListenerz.put(parameter, new ParameterListener[] {new_listener});

      } else {

        ParameterListener[] new_listeners = new ParameterListener[listeners.length + 1];

        if (Constants.IS_CVS_VERSION && listeners.length > 100) {
          Debug.out(parameter);
        }

        int pos;

        if (new_listener instanceof PriorityParameterListener) {

          new_listeners[0] = new_listener;

          pos = 1;

        } else {

          new_listeners[listeners.length] = new_listener;

          pos = 0;
        }

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

          ParameterListener existing_listener = listeners[i];

          if (existing_listener == new_listener) {

            return;
          }

          new_listeners[pos++] = existing_listener;
        }

        if (DEBUG_PARAMETER_LISTENERS) {

          System.out.println(parameter + "->" + new_listeners.length);
        }

        parameterListenerz.put(parameter, new_listeners);
      }
    }
  }
示例#2
0
  public static void setAZTracker(URL tracker_url, boolean az_tracker) {
    String key = tracker_url.getHost() + ":" + tracker_url.getPort();

    synchronized (az_trackers) {
      boolean changed = false;

      if (az_trackers.get(key) == null) {

        if (az_tracker) {

          az_trackers.put(key, new Long(SystemTime.getCurrentTime()));

          changed = true;
        }
      } else {

        if (!az_tracker) {

          if (az_trackers.remove(key) != null) {

            changed = true;
          }
        }
      }

      if (changed) {

        COConfigurationManager.setParameter("Tracker Client AZ Instances", az_trackers);
      }
    }
  }
示例#3
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 AuthenticatorWindow() {
    SESecurityManager.addPasswordListener(this);

    // System.out.println( "AuthenticatorWindow");

    Map cache = COConfigurationManager.getMapParameter(CONFIG_PARAM, new HashMap());

    try {
      Iterator it = cache.entrySet().iterator();

      while (it.hasNext()) {

        Map.Entry entry = (Map.Entry) it.next();

        String key = (String) entry.getKey();
        Map value = (Map) entry.getValue();

        String user = new String((byte[]) value.get("user"), "UTF-8");
        char[] pw = new String((byte[]) value.get("pw"), "UTF-8").toCharArray();

        auth_cache.put(key, new authCache(key, new PasswordAuthentication(user, pw), true));
      }

    } catch (Throwable e) {

      COConfigurationManager.setParameter(CONFIG_PARAM, new HashMap());

      Debug.printStackTrace(e);
    }
  }
  private ConfigurationManager(Map data) {
    // default state of play for config initialised from map is debug log files off unless already
    // specified

    if (data.get("Logger.DebugFiles.Enabled") == null) {

      data.put("Logger.DebugFiles.Enabled", new Long(0));
    }

    propertiesMap = new ConcurrentHashMapWrapper<String, Object>(data);
  }
  private void loadExportedParameters() {
    synchronized (exported_parameters) {
      try {
        File parent_dir = new File(SystemProperties.getUserPath());

        File props = new File(parent_dir, "exported_params.properties");

        if (props.exists()) {

          LineNumberReader lnr =
              new LineNumberReader(new InputStreamReader(new FileInputStream(props), "UTF-8"));

          try {
            while (true) {

              String line = lnr.readLine();

              if (line == null) {

                break;
              }

              String[] bits = line.split("=");

              if (bits.length == 2) {

                String key = bits[0].trim();
                String value = bits[1].trim();

                if (key.length() > 0 && value.length() > 0) {

                  imported_parameters.put(key, value);
                }
              }
            }
          } finally {

            lnr.close();
          }
        }
      } catch (Throwable e) {

        e.printStackTrace();
      }
    }

    COConfigurationManager.setIntDefault("instance.port", Constants.INSTANCE_PORT);

    registerExportedParameter("instance.port", "instance.port");
  }
  public void removeParameterListener(String parameter, ParameterListener listener) {

    if (parameter == null || listener == null) {
      return;
    }

    synchronized (parameterListenerz) {
      ParameterListener[] listeners = parameterListenerz.get(parameter);

      if (listeners == null) {

        return;
      }

      if (listeners.length == 1) {

        if (listeners[0] == listener) {

          parameterListenerz.remove(parameter);
        }
      } else {

        ParameterListener[] new_listeners = new ParameterListener[listeners.length - 1];

        int pos = 0;

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

          ParameterListener existing_listener = listeners[i];

          if (existing_listener != listener) {

            if (pos == new_listeners.length) {

              return;
            }

            new_listeners[pos++] = existing_listener;
          }
        }

        if (DEBUG_PARAMETER_LISTENERS) {

          System.out.println(parameter + "->" + new_listeners.length);
        }

        parameterListenerz.put(parameter, new_listeners);
      }
    }
  }
  public void registerExportedParameter(String name, String key) {
    synchronized (exported_parameters) {
      String[] entry = exported_parameters.get(key);

      if (entry == null) {

        entry = new String[] {name, imported_parameters.remove(name)};

        exported_parameters.put(key, entry);
      }
    }

    addParameterListener(key, exportable_parameter_listener);

    updateExportableParameter(key);
  }
示例#9
0
  public static void setUDPProbeResult(URL tracker_url, boolean probe_ok) {
    String key = tracker_url.getHost();

    synchronized (udp_probe_results) {
      boolean changed = false;

      if (udp_probe_results.get(key) == null) {

        if (probe_ok) {

          // arbitrary max size here just in case something weird happens

          if (udp_probe_results.size() > 512) {

            udp_probe_results.clear();
          }

          udp_probe_results.put(key, new Long(SystemTime.getCurrentTime()));

          changed = true;
        }
      } else {

        if (!probe_ok) {

          if (udp_probe_results.remove(key) != null) {

            changed = true;
          }
        }
      }

      if (changed) {

        COConfigurationManager.setParameter("Tracker Client UDP Probe Results", udp_probe_results);
      }
    }
  }
  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();
    }
  }