Example #1
0
  public static boolean isPlatformHost(String host) {
    Object[] domains = getPlatformHosts().toArray();

    host = host.toLowerCase();

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

      String domain = (String) domains[i];

      if (domain.equals(host)) {

        return (true);
      }

      if (host.endsWith("." + domain)) {

        return (true);
      }
    }

    if (Constants.isCVSVersion()) {

      // allow local addresses for testing

      try {
        InetAddress ia = InetAddress.getByName(host);

        return (ia.isLoopbackAddress() || ia.isLinkLocalAddress() || ia.isSiteLocalAddress());

      } catch (Throwable e) {
      }
    }

    return (false);
  }
Example #2
0
 protected void addDropTest(MdiEntry entry) {
   if (!Constants.isCVSVersion()) {
     return;
   }
   entry.addListener(
       new MdiEntryDropListener() {
         public boolean mdiEntryDrop(MdiEntry entry, Object droppedObject) {
           String s =
               "You just dropped " + droppedObject.getClass() + "\n" + droppedObject + "\n\n";
           if (droppedObject.getClass().isArray()) {
             Object[] o = (Object[]) droppedObject;
             for (int i = 0; i < o.length; i++) {
               s += "" + i + ":  ";
               Object object = o[i];
               if (object == null) {
                 s += "null";
               } else {
                 s += object.getClass() + ";" + object;
               }
               s += "\n";
             }
           }
           new MessageBoxShell(SWT.OK, "test", s).open(null);
           return true;
         }
       });
 }
Example #3
0
  /** @param azureus_core */
  public UIMagnetHandler(AzureusCore core) {
    int val = Integer.parseInt(Constants.getBaseVersion().replaceAll("\\.", ""));

    String ui = COConfigurationManager.getStringParameter("ui");
    if (!"az2".equals(ui)) {
      val += 10000;
    }

    MagnetURIHandler magnetURIHandler = MagnetURIHandler.getSingleton();
    magnetURIHandler.addInfo("get-version-info", val);
  }
Example #4
0
  public static boolean isUDPProbeOK(URL tracker_url) {
    String host = tracker_url.getHost();

    if (Constants.isAzureusDomain(host)) {

      return (false);
    }

    synchronized (udp_probe_results) {
      return (udp_probe_results.containsKey(host));
    }
  }
Example #5
0
  public static boolean isAZTracker(URL tracker_url) {
    String host = tracker_url.getHost();

    if (Constants.isAzureusDomain(host)) {

      return (true);
    }

    synchronized (az_trackers) {
      return (az_trackers.containsKey(host + ":" + tracker_url.getPort()));
    }
  }
  public static UTPProvider createProvider() {
    if (isAndroid || Constants.IS_CVS_VERSION || Constants.isCurrentVersionGE("5.0.0.0")) {

      return (new UTPProviderLocal());

    } else if (Constants.isOSX || Constants.isWindows) {

      return (new UTPProviderNative());

    } else {

      return (new UTPProviderLocal());
    }

    // return( new UTPProviderTester( new UTPProviderLocal( true )));
    // return( new UTPProviderTester( new UTPProviderNative( true )));
  }
Example #7
0
  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));
    }
  }
  protected ContentNetworkManagerImpl() {
    loadConfig();

    addNetwork(new ContentNetworkVuze(this));

    AEDiagnostics.addEvidenceGenerator(this);

    CustomizationManager cust_man = CustomizationManagerFactory.getSingleton();

    Customization cust = cust_man.getActiveCustomization();

    if (cust != null) {

      String cust_name = COConfigurationManager.getStringParameter("cnetworks.custom.name", "");
      String cust_version =
          COConfigurationManager.getStringParameter("cnetworks.custom.version", "0");

      boolean new_name = !cust_name.equals(cust.getName());
      boolean new_version = Constants.compareVersions(cust_version, cust.getVersion()) < 0;

      if (new_name || new_version) {

        try {
          InputStream[] streams = cust.getResources(Customization.RT_CNETWORKS);

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

            InputStream is = streams[i];

            try {
              VuzeFile vf = VuzeFileHandler.getSingleton().loadVuzeFile(is);

              if (vf != null) {

                VuzeFileComponent[] comps = vf.getComponents();

                for (int j = 0; j < comps.length; j++) {

                  VuzeFileComponent comp = comps[j];

                  int type = comp.getType();

                  if (type == VuzeFileComponent.COMP_TYPE_CONTENT_NETWORK) {

                    try {
                      // change here as we always add all networks upfront so
                      // we always set the customisation flag regardless of
                      // whether existing or not

                      ContentNetwork imported = importNetwork(comp.getContent());

                      imported.setPersistentProperty(ContentNetwork.PP_IS_CUSTOMIZATION, true);

                      comp.setProcessed();

                    } catch (Throwable e) {

                      log("Failed to import customisation network", e);
                    }
                  }
                }
              }
            } finally {

              try {
                is.close();

              } catch (Throwable e) {
              }
            }
          }
        } finally {

          COConfigurationManager.setParameter("cnetworks.custom.name", cust.getName());
          COConfigurationManager.setParameter("cnetworks.custom.version", cust.getVersion());
        }
      }
    }

    SimpleTimer.addPeriodicEvent(
        "MetaSearchRefresh",
        23 * 60 * 60 * 1000,
        new TimerEventPerformer() {
          public void perform(TimerEvent event) {
            checkForUpdates();
          }
        });

    if (networks.size() > 1 || LOAD_ALL_NETWORKS) {

      new AEThread2("CNetwork:init", true) {
        public void run() {
          checkForUpdates();
        }
      }.start();
    }
  }