Search in sources :

Example 1 with BasicPluginConfigModel

use of com.biglybt.pif.ui.model.BasicPluginConfigModel in project BiglyBT by BiglySoftware.

the class UIManagerImpl method createBasicPluginConfigModel.

@Override
public BasicPluginConfigModel createBasicPluginConfigModel(String parent_section, String section_name) {
    final BasicPluginConfigModel model = new BasicPluginConfigModelImpl(this, parent_section, section_name);
    try {
        class_mon.enter();
        configModels.add(model);
    } finally {
        class_mon.exit();
    }
    fireEvent(pi, UIManagerEvent.ET_PLUGIN_CONFIG_MODEL_CREATED, model);
    return (model);
}
Also used : BasicPluginConfigModelImpl(com.biglybt.pifimpl.local.ui.model.BasicPluginConfigModelImpl) BasicPluginConfigModel(com.biglybt.pif.ui.model.BasicPluginConfigModel)

Example 2 with BasicPluginConfigModel

use of com.biglybt.pif.ui.model.BasicPluginConfigModel in project BiglyBT by BiglySoftware.

the class DHTPlugin method initialize.

@Override
public void initialize(PluginInterface _plugin_interface) {
    status = STATUS_INITALISING;
    plugin_interface = _plugin_interface;
    dht_data_port = UDPNetworkManager.getSingleton().getUDPNonDataListeningPortNumber();
    log = plugin_interface.getLogger().getTimeStampedChannel(PLUGIN_NAME);
    UIManager ui_manager = plugin_interface.getUIManager();
    final BasicPluginViewModel model = ui_manager.createBasicPluginViewModel(PLUGIN_RESOURCE_ID);
    model.setConfigSectionID(PLUGIN_CONFIGSECTION_ID);
    BasicPluginConfigModel config = ui_manager.createBasicPluginConfigModel(ConfigSection.SECTION_PLUGINS, PLUGIN_CONFIGSECTION_ID);
    config.addLabelParameter2("dht.info");
    final BooleanParameter enabled_param = config.addBooleanParameter2("dht.enabled", "dht.enabled", true);
    plugin_interface.getPluginconfig().addListener(new PluginConfigListener() {

        @Override
        public void configSaved() {
            int new_dht_data_port = UDPNetworkManager.getSingleton().getUDPNonDataListeningPortNumber();
            if (new_dht_data_port != dht_data_port) {
                changePort(new_dht_data_port);
            }
        }
    });
    LabelParameter reseed_label = config.addLabelParameter2("dht.reseed.label");
    final StringParameter reseed_ip = config.addStringParameter2("dht.reseed.ip", "dht.reseed.ip", "");
    final IntParameter reseed_port = config.addIntParameter2("dht.reseed.port", "dht.reseed.port", 0);
    reseed = config.addActionParameter2("dht.reseed.info", "dht.reseed");
    reseed.setEnabled(false);
    config.createGroup("dht.reseed.group", new Parameter[] { reseed_label, reseed_ip, reseed_port, reseed });
    final BooleanParameter ipfilter_logging_param = config.addBooleanParameter2("dht.ipfilter.log", "dht.ipfilter.log", true);
    ipfilter_logging[0] = ipfilter_logging_param.getValue();
    ipfilter_logging_param.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter p) {
            ipfilter_logging[0] = ipfilter_logging_param.getValue();
        }
    });
    warn_user = config.addBooleanParameter2("dht.warn.user", "dht.warn.user", true);
    prefer_i2p = config.addBooleanParameter2("dht.prefer.i2p", "dht.prefer.i2p", false);
    BooleanParameter sleeping = config.addBooleanParameter2("dht.is.sleeping", "dht.is.sleeping", false);
    AERunStateHandler.addListener(new AERunStateHandler.RunStateChangeListener() {

        @Override
        public void runStateChanged(long run_state) {
            sleeping.setValue(AERunStateHandler.isDHTSleeping());
        }
    }, true);
    sleeping.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            AERunStateHandler.setDHTSleeping(sleeping.getValue());
        }
    });
    final BooleanParameter advanced = config.addBooleanParameter2("dht.advanced", "dht.advanced", false);
    LabelParameter advanced_label = config.addLabelParameter2("dht.advanced.label");
    final StringParameter override_ip = config.addStringParameter2("dht.override.ip", "dht.override.ip", "");
    config.createGroup("dht.advanced.group", new Parameter[] { advanced_label, override_ip });
    advanced.addEnabledOnSelection(advanced_label);
    advanced.addEnabledOnSelection(override_ip);
    final StringParameter command = config.addStringParameter2("dht.execute.command", "dht.execute.command", "print");
    ActionParameter execute = config.addActionParameter2("dht.execute.info", "dht.execute");
    final BooleanParameter logging = config.addBooleanParameter2("dht.logging", "dht.logging", false);
    config.createGroup("dht.diagnostics.group", new Parameter[] { command, execute, logging });
    logging.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            if (dhts != null) {
                for (int i = 0; i < dhts.length; i++) {
                    dhts[i].setLogging(logging.getValue());
                }
            }
        }
    });
    final DHTPluginOperationListener log_polistener = new DHTPluginOperationListener() {

        @Override
        public boolean diversified() {
            return (true);
        }

        @Override
        public void starts(byte[] key) {
        }

        @Override
        public void valueRead(DHTPluginContact originator, DHTPluginValue value) {
            log.log("valueRead: " + new String(value.getValue()) + " from " + originator.getName() + "/" + originator.getAddress() + ", flags=" + Integer.toHexString(value.getFlags() & 0x00ff));
            if ((value.getFlags() & DHTPlugin.FLAG_STATS) != 0) {
                DHTPluginKeyStats stats = decodeStats(value);
                log.log("    stats: size=" + (stats == null ? "null" : stats.getSize()));
            }
        }

        @Override
        public void valueWritten(DHTPluginContact target, DHTPluginValue value) {
            log.log("valueWritten:" + new String(value.getValue()) + " to " + target.getName() + "/" + target.getAddress());
        }

        @Override
        public void complete(byte[] key, boolean timeout_occurred) {
            log.log("complete: timeout = " + timeout_occurred);
        }
    };
    execute.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            AEThread2 t = new AEThread2("DHT:commandrunner", true) {

                @Override
                public void run() {
                    try {
                        if (dhts == null) {
                            return;
                        }
                        String c = command.getValue().trim();
                        String lc = c.toLowerCase();
                        if (lc.equals("suspend")) {
                            if (!setSuspended(true)) {
                                Debug.out("Suspend failed");
                            }
                            return;
                        } else if (lc.equals("resume")) {
                            if (!setSuspended(false)) {
                                Debug.out("Resume failed");
                            }
                            return;
                        } else if (lc.equals("bridge_put")) {
                            try {
                                List<DistributedDatabase> ddbs = plugin_interface.getUtilities().getDistributedDatabases(new String[] { AENetworkClassifier.AT_I2P });
                                DistributedDatabase ddb = ddbs.get(0);
                                DistributedDatabaseKey key = ddb.createKey("fred");
                                key.setFlags(DistributedDatabaseKey.FL_BRIDGED);
                                ddb.write(new DistributedDatabaseListener() {

                                    @Override
                                    public void event(DistributedDatabaseEvent event) {
                                    // TODO Auto-generated method stub
                                    }
                                }, key, ddb.createValue("bill"));
                            } catch (Throwable e) {
                                e.printStackTrace();
                            }
                            return;
                        }
                        for (int i = 0; i < dhts.length; i++) {
                            DHT dht = dhts[i].getDHT();
                            DHTTransportUDP transport = (DHTTransportUDP) dht.getTransport();
                            if (lc.equals("print")) {
                                dht.print(true);
                                dhts[i].logStats();
                            } else if (lc.equals("pingall")) {
                                if (i == 1) {
                                    dht.getControl().pingAll();
                                }
                            } else if (lc.equals("versions")) {
                                List<DHTRouterContact> contacts = dht.getRouter().getAllContacts();
                                Map<Byte, Integer> counts = new TreeMap<>();
                                for (DHTRouterContact r : contacts) {
                                    DHTControlContact contact = (DHTControlContact) r.getAttachment();
                                    byte v = contact.getTransportContact().getProtocolVersion();
                                    Integer count = counts.get(v);
                                    if (count == null) {
                                        counts.put(v, 1);
                                    } else {
                                        counts.put(v, count + 1);
                                    }
                                }
                                log.log("Net " + dht.getTransport().getNetwork());
                                int total = contacts.size();
                                if (total == 0) {
                                    log.log("   no contacts");
                                } else {
                                    String ver = "";
                                    for (Map.Entry<Byte, Integer> entry : counts.entrySet()) {
                                        ver += (ver.length() == 0 ? "" : ", ") + entry.getKey() + "=" + 100 * entry.getValue() / total + "%";
                                    }
                                    log.log("    contacts=" + total + ": " + ver);
                                }
                            } else if (lc.equals("testca")) {
                                ((DHTTransportUDPImpl) transport).testExternalAddressChange();
                            } else if (lc.equals("testnd")) {
                                ((DHTTransportUDPImpl) transport).testNetworkAlive(false);
                            } else if (lc.equals("testna")) {
                                ((DHTTransportUDPImpl) transport).testNetworkAlive(true);
                            } else {
                                int pos = c.indexOf(' ');
                                if (pos != -1) {
                                    String lhs = lc.substring(0, pos);
                                    String rhs = c.substring(pos + 1);
                                    if (lhs.equals("set")) {
                                        pos = rhs.indexOf('=');
                                        if (pos != -1) {
                                            DHTPlugin.this.put(rhs.substring(0, pos).getBytes(), "DHT Plugin: set", rhs.substring(pos + 1).getBytes(), (byte) 0, log_polistener);
                                        }
                                    } else if (lhs.equals("get")) {
                                        DHTPlugin.this.get(rhs.getBytes("UTF-8"), "DHT Plugin: get", (byte) 0, 1, 10000, true, false, log_polistener);
                                    } else if (lhs.equals("query")) {
                                        DHTPlugin.this.get(rhs.getBytes("UTF-8"), "DHT Plugin: get", DHTPlugin.FLAG_STATS, 1, 10000, true, false, log_polistener);
                                    } else if (lhs.equals("punch")) {
                                        Map originator_data = new HashMap();
                                        originator_data.put("hello", "mum");
                                        DHTNATPuncher puncher = dht.getNATPuncher();
                                        if (puncher != null) {
                                            puncher.punch("Test", transport.getLocalContact(), null, originator_data);
                                        }
                                    } else if (lhs.equals("stats")) {
                                        try {
                                            pos = rhs.lastIndexOf(":");
                                            DHTTransportContact contact;
                                            if (pos == -1) {
                                                contact = transport.getLocalContact();
                                            } else {
                                                String host = rhs.substring(0, pos);
                                                int port = Integer.parseInt(rhs.substring(pos + 1));
                                                contact = transport.importContact(new InetSocketAddress(host, port), transport.getProtocolVersion(), false);
                                            }
                                            log.log("Stats request to " + contact.getName());
                                            DHTTransportFullStats stats = contact.getStats();
                                            log.log("Stats:" + (stats == null ? "<null>" : stats.getString()));
                                            DHTControlActivity[] activities = dht.getControl().getActivities();
                                            for (int j = 0; j < activities.length; j++) {
                                                log.log("    act:" + activities[j].getString());
                                            }
                                        } catch (Throwable e) {
                                            Debug.printStackTrace(e);
                                        }
                                    }
                                }
                            }
                        }
                    } catch (Throwable e) {
                        Debug.out(e);
                    }
                }
            };
            t.start();
        }
    });
    reseed.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            reseed.setEnabled(false);
            AEThread2 t = new AEThread2("DHT:reseeder", true) {

                @Override
                public void run() {
                    try {
                        String ip = reseed_ip.getValue().trim();
                        if (dhts == null) {
                            return;
                        }
                        int port = reseed_port.getValue();
                        for (int i = 0; i < dhts.length; i++) {
                            DHTPluginImpl dht = dhts[i];
                            if (ip.length() == 0 || port == 0) {
                                dht.checkForReSeed(true);
                            } else {
                                DHTTransportContact seed = dht.importSeed(ip, port);
                                if (seed != null) {
                                    dht.integrateDHT(false, seed);
                                }
                            }
                        }
                    } finally {
                        reseed.setEnabled(true);
                    }
                }
            };
            t.start();
        }
    });
    model.getActivity().setVisible(false);
    model.getProgress().setVisible(false);
    log.addListener(new LoggerChannelListener() {

        @Override
        public void messageLogged(int type, String message) {
            model.getLogArea().appendText(message + "\n");
        }

        @Override
        public void messageLogged(String str, Throwable error) {
            model.getLogArea().appendText(error.toString() + "\n");
        }
    });
    dht_log = new DHTLogger() {

        @Override
        public void log(String str) {
            log.log(str);
        }

        @Override
        public void log(Throwable e) {
            log.log(e);
        }

        @Override
        public void log(int log_type, String str) {
            if (isEnabled(log_type)) {
                log.log(str);
            }
        }

        @Override
        public boolean isEnabled(int log_type) {
            if (log_type == DHTLogger.LT_IP_FILTER) {
                return ipfilter_logging[0];
            }
            return (true);
        }

        @Override
        public PluginInterface getPluginInterface() {
            return (log.getLogger().getPluginInterface());
        }
    };
    if (!enabled_param.getValue()) {
        model.getStatus().setText("Disabled");
        status = STATUS_DISABLED;
        init_sem.releaseForever();
        return;
    }
    setPluginInfo();
    plugin_interface.addListener(new PluginListener() {

        @Override
        public void initializationComplete() {
            PluginInterface pi_upnp = plugin_interface.getPluginManager().getPluginInterfaceByClass(UPnPPlugin.class);
            if (pi_upnp == null) {
                log.log("UPnP plugin not found, can't map port");
            } else {
                upnp_mapping = ((UPnPPlugin) pi_upnp.getPlugin()).addMapping(plugin_interface.getPluginName(), false, dht_data_port, true);
            }
            String ip = null;
            if (advanced.getValue()) {
                ip = override_ip.getValue().trim();
                if (ip.length() == 0) {
                    ip = null;
                }
            }
            initComplete(model.getStatus(), logging.getValue(), ip);
        }

        @Override
        public void closedownInitiated() {
            if (dhts != null) {
                for (int i = 0; i < dhts.length; i++) {
                    dhts[i].closedownInitiated();
                }
            }
            saveClockSkew();
        }

        @Override
        public void closedownComplete() {
        }
    });
    final int sample_frequency = 60 * 1000;
    // every 15 mins
    final int sample_stats_ticks = 15;
    plugin_interface.getUtilities().createTimer("DHTStats", true).addPeriodicEvent(sample_frequency, new UTTimerEventPerformer() {

        @Override
        public void perform(UTTimerEvent event) {
            if (dhts != null) {
                for (int i = 0; i < dhts.length; i++) {
                    dhts[i].updateStats(sample_stats_ticks);
                }
            }
            setPluginInfo();
            saveClockSkew();
        }
    });
}
Also used : DHTTransportUDP(com.biglybt.core.dht.transport.udp.DHTTransportUDP) LoggerChannelListener(com.biglybt.pif.logging.LoggerChannelListener) InetSocketAddress(java.net.InetSocketAddress) UIManager(com.biglybt.pif.ui.UIManager) DHTLogger(com.biglybt.core.dht.DHTLogger) DistributedDatabaseListener(com.biglybt.pif.ddb.DistributedDatabaseListener) DHTRouterContact(com.biglybt.core.dht.router.DHTRouterContact) DHTTransportFullStats(com.biglybt.core.dht.transport.DHTTransportFullStats) DHTTransportUDPImpl(com.biglybt.core.dht.transport.udp.impl.DHTTransportUDPImpl) DHTNATPuncher(com.biglybt.core.dht.nat.DHTNATPuncher) DistributedDatabaseEvent(com.biglybt.pif.ddb.DistributedDatabaseEvent) UTTimerEvent(com.biglybt.pif.utils.UTTimerEvent) DHTTransportContact(com.biglybt.core.dht.transport.DHTTransportContact) UPnPPlugin(com.biglybt.plugin.upnp.UPnPPlugin) DHTControlContact(com.biglybt.core.dht.control.DHTControlContact) DistributedDatabase(com.biglybt.pif.ddb.DistributedDatabase) BasicPluginViewModel(com.biglybt.pif.ui.model.BasicPluginViewModel) DHT(com.biglybt.core.dht.DHT) DHTControlActivity(com.biglybt.core.dht.control.DHTControlActivity) DHTPluginImpl(com.biglybt.plugin.dht.impl.DHTPluginImpl) DistributedDatabaseKey(com.biglybt.pif.ddb.DistributedDatabaseKey) BasicPluginConfigModel(com.biglybt.pif.ui.model.BasicPluginConfigModel) UTTimerEventPerformer(com.biglybt.pif.utils.UTTimerEventPerformer)

Example 3 with BasicPluginConfigModel

use of com.biglybt.pif.ui.model.BasicPluginConfigModel in project BiglyBT by BiglySoftware.

the class ClientIDPlugin method initializeSupport.

private void initializeSupport(PluginInterface pi) {
    ClientIDGenerator gen = ClientIDManagerImpl.getSingleton().getGenerator();
    if (gen != this) {
        return;
    }
    BasicPluginConfigModel config_model = pi.getUIManager().createBasicPluginConfigModel(ConfigSection.SECTION_PLUGINS, "bgclientid.name");
    config_model.addLabelParameter2("bgclientid.info");
    final StringListParameter client_param = config_model.addStringListParameter2(CONFIG_SELECTION, CONFIG_SELECTION, CLIENTS, CLIENT_DEFAULT);
    client = client_param.getValue();
    final BooleanParameter mainline = config_model.addBooleanParameter2(CONFIG_MAINLINE, CONFIG_MAINLINE, MAINLINE_DEFAULT);
    client_param.addListener(new ParameterListener() {

        public void parameterChanged(Parameter param) {
            client = client_param.getValue();
            mainline.setEnabled(client.equals(BIGLYBT_CLIENT_NAME));
        }
    });
    mainline.setEnabled(client.equals(BIGLYBT_CLIENT_NAME));
    mainline.addListener(new ParameterListener() {

        public void parameterChanged(Parameter param) {
            use_main_version = mainline.getValue();
        }
    });
    use_main_version = mainline.getValue();
}
Also used : ClientIDGenerator(com.biglybt.pif.clientid.ClientIDGenerator) BasicPluginConfigModel(com.biglybt.pif.ui.model.BasicPluginConfigModel)

Example 4 with BasicPluginConfigModel

use of com.biglybt.pif.ui.model.BasicPluginConfigModel in project BiglyBT by BiglySoftware.

the class StartStopRulesDefaultPlugin method initialize.

@Override
public void initialize(PluginInterface _plugin_interface) {
    if (bAlreadyInitialized) {
        System.err.println("StartStopRulesDefaultPlugin Already initialized!!");
    } else {
        bAlreadyInitialized = true;
    }
    AEDiagnostics.addWeakEvidenceGenerator(this);
    monoStartedOn = SystemTime.getMonotonousTime();
    pi = _plugin_interface;
    plugin_config = pi.getPluginconfig();
    plugin_config.setPluginConfigKeyPrefix("");
    download_manager = pi.getDownloadManager();
    // Create a configModel for StartStopRules
    // We always need to do this in order to set up configuration defaults
    UIManager manager = pi.getUIManager();
    // TODO: don't name it Q
    final BasicPluginConfigModel configModel = manager.createBasicPluginConfigModel(ConfigSection.SECTION_ROOT, "Q");
    setupConfigModel(configModel);
    pi.addListener(new PluginListener() {

        @Override
        public void initializationComplete() {
        }

        @Override
        public void closedownInitiated() {
            closingDown = true;
            // we don't want to go off recalculating stuff when config is saved
            // on closedown
            COConfigurationManager.removeListener(StartStopRulesDefaultPlugin.this);
        }

        @Override
        public void closedownComplete() {
        /* not implemented */
        }
    });
    Runnable r = new Runnable() {

        @Override
        public void run() {
            download_manager.addListener(new StartStopDMListener());
            SimpleTimer.addPeriodicEvent("StartStop:gross", CHECK_FOR_GROSS_CHANGE_PERIOD, new ChangeCheckerTimerTask());
            SimpleTimer.addPeriodicEvent("StartStop:check", PROCESS_CHECK_PERIOD, new ChangeFlagCheckerTask());
        }
    };
    pi.getUtilities().createDelayedTask(r).queue();
    log = pi.getLogger().getTimeStampedChannel("StartStopRules");
    log.log(LoggerChannel.LT_INFORMATION, "Default StartStopRules Plugin Initialisation");
    COConfigurationManager.addListener(this);
    try {
        pi.getUIManager().createLoggingViewModel(log, true);
        pi.getUIManager().addUIListener(new UIManagerListener() {

            @Override
            public void UIAttached(UIInstance instance) {
                TableManager tm = pi.getUIManager().getTableManager();
                seedingRankColumn = tm.createColumn(TableManager.TABLE_MYTORRENTS_COMPLETE, "SeedingRank");
                seedingRankColumn.initialize(TableColumn.ALIGN_TRAIL, TableColumn.POSITION_LAST, 80, TableColumn.INTERVAL_LIVE);
                TableCellRefreshListener columnListener = new SeedingRankColumnListener(downloadDataMap, plugin_config);
                seedingRankColumn.addCellRefreshListener(columnListener);
                tm.addColumn(seedingRankColumn);
                TableColumn downloadingRankColumn = tm.createColumn(TableManager.TABLE_MYTORRENTS_INCOMPLETE, "DownloadingRank");
                downloadingRankColumn.setMinimumRequiredUserMode(1);
                downloadingRankColumn.initialize(TableColumn.ALIGN_TRAIL, TableColumn.POSITION_INVISIBLE, 80, TableColumn.INTERVAL_LIVE);
                columnListener = new DownloadingRankColumnListener(StartStopRulesDefaultPlugin.this);
                downloadingRankColumn.addCellRefreshListener(columnListener);
                tm.addColumn(downloadingRankColumn);
                if (instance.getUIType().equals(UIInstance.UIT_SWT)) {
                    // We have our own config model :)
                    configModel.destroy();
                    try {
                        swt_ui = (UIAdapter) Class.forName("com.biglybt.plugin.startstoprules.defaultplugin.ui.swt.StartStopRulesDefaultPluginSWTUI").getConstructor(new Class[] { PluginInterface.class }).newInstance(new Object[] { pi });
                    } catch (Throwable e) {
                        Debug.out(e);
                    }
                }
            }

            @Override
            public void UIDetached(UIInstance instance) {
            }
        });
    } catch (Throwable e) {
        Debug.printStackTrace(e);
    }
    reloadConfigParams();
}
Also used : UIManager(com.biglybt.pif.ui.UIManager) PluginListener(com.biglybt.pif.PluginListener) UIManagerListener(com.biglybt.pif.ui.UIManagerListener) UIInstance(com.biglybt.pif.ui.UIInstance) BasicPluginConfigModel(com.biglybt.pif.ui.model.BasicPluginConfigModel)

Example 5 with BasicPluginConfigModel

use of com.biglybt.pif.ui.model.BasicPluginConfigModel in project BiglyBT by BiglySoftware.

the class DHTTrackerPlugin method initialize.

@Override
public void initialize(PluginInterface _plugin_interface) {
    plugin_interface = _plugin_interface;
    log = plugin_interface.getLogger().getTimeStampedChannel(PLUGIN_NAME);
    ta_networks = plugin_interface.getTorrentManager().getAttribute(TorrentAttribute.TA_NETWORKS);
    ta_peer_sources = plugin_interface.getTorrentManager().getAttribute(TorrentAttribute.TA_PEER_SOURCES);
    UIManager ui_manager = plugin_interface.getUIManager();
    model = ui_manager.createBasicPluginViewModel(PLUGIN_RESOURCE_ID);
    model.setConfigSectionID(PLUGIN_CONFIGSECTION_ID);
    BasicPluginConfigModel config = ui_manager.createBasicPluginConfigModel(ConfigSection.SECTION_PLUGINS, PLUGIN_CONFIGSECTION_ID);
    track_normal_when_offline = config.addBooleanParameter2("dhttracker.tracknormalwhenoffline", "dhttracker.tracknormalwhenoffline", TRACK_NORMAL_DEFAULT);
    track_limited_when_online = config.addBooleanParameter2("dhttracker.tracklimitedwhenonline", "dhttracker.tracklimitedwhenonline", TRACK_LIMITED_DEFAULT);
    track_limited_when_online.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            configChanged();
        }
    });
    track_normal_when_offline.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            track_limited_when_online.setEnabled(track_normal_when_offline.getValue());
            configChanged();
        }
    });
    if (!track_normal_when_offline.getValue()) {
        track_limited_when_online.setEnabled(false);
    }
    interesting_pub_max = plugin_interface.getPluginconfig().getPluginIntParameter("dhttracker.presencepubmax", INTERESTING_PUB_MAX_DEFAULT);
    if (!TRACK_NORMAL_DEFAULT) {
        // should be TRUE by default
        System.out.println("**** DHT Tracker default set for testing purposes ****");
    }
    BooleanParameter enable_alt = config.addBooleanParameter2("dhttracker.enable_alt", "dhttracker.enable_alt", true);
    IntParameter alt_port = config.addIntParameter2("dhttracker.alt_port", "dhttracker.alt_port", 0, 0, 65535);
    enable_alt.addEnabledOnSelection(alt_port);
    config.createGroup("dhttracker.alt_group", new Parameter[] { enable_alt, alt_port });
    if (enable_alt.getValue()) {
        alt_lookup_handler = new DHTTrackerPluginAlt(alt_port.getValue());
    }
    model.getActivity().setVisible(false);
    model.getProgress().setVisible(false);
    model.getLogArea().setMaximumSize(80000);
    log.addListener(new LoggerChannelListener() {

        @Override
        public void messageLogged(int type, String message) {
            model.getLogArea().appendText(message + "\n");
        }

        @Override
        public void messageLogged(String str, Throwable error) {
            model.getLogArea().appendText(error.toString() + "\n");
        }
    });
    model.getStatus().setText(MessageText.getString("ManagerItem.initializing"));
    log.log("Waiting for Distributed Database initialisation");
    plugin_interface.addListener(new PluginListener() {

        @Override
        public void initializationComplete() {
            boolean release_now = true;
            try {
                final PluginInterface dht_pi = plugin_interface.getPluginManager().getPluginInterfaceByClass(DHTPlugin.class);
                if (dht_pi != null) {
                    dht = (DHTPlugin) dht_pi.getPlugin();
                    final DelayedTask dt = plugin_interface.getUtilities().createDelayedTask(new Runnable() {

                        @Override
                        public void run() {
                            AEThread2 t = new AEThread2("DHTTrackerPlugin:init", true) {

                                @Override
                                public void run() {
                                    try {
                                        if (dht.isEnabled()) {
                                            log.log("DDB Available");
                                            model.getStatus().setText(MessageText.getString("DHTView.activity.status.false"));
                                            initialise();
                                        } else {
                                            log.log("DDB Disabled");
                                            model.getStatus().setText(MessageText.getString("dht.status.disabled"));
                                            notRunning();
                                        }
                                    } catch (Throwable e) {
                                        log.log("DDB Failed", e);
                                        model.getStatus().setText(MessageText.getString("DHTView.operations.failed"));
                                        notRunning();
                                    } finally {
                                        initialised_sem.releaseForever();
                                    }
                                }
                            };
                            t.start();
                        }
                    });
                    dt.queue();
                    release_now = false;
                } else {
                    log.log("DDB Plugin missing");
                    model.getStatus().setText(MessageText.getString("DHTView.operations.failed"));
                    notRunning();
                }
            } finally {
                if (release_now) {
                    initialised_sem.releaseForever();
                }
            }
        }

        @Override
        public void closedownInitiated() {
        }

        @Override
        public void closedownComplete() {
        }
    });
}
Also used : LoggerChannelListener(com.biglybt.pif.logging.LoggerChannelListener) PluginInterface(com.biglybt.pif.PluginInterface) UIManager(com.biglybt.pif.ui.UIManager) PluginListener(com.biglybt.pif.PluginListener) DelayedTask(com.biglybt.pif.utils.DelayedTask) DHTPlugin(com.biglybt.plugin.dht.DHTPlugin) BasicPluginConfigModel(com.biglybt.pif.ui.model.BasicPluginConfigModel)

Aggregations

BasicPluginConfigModel (com.biglybt.pif.ui.model.BasicPluginConfigModel)18 PluginListener (com.biglybt.pif.PluginListener)6 UIManager (com.biglybt.pif.ui.UIManager)6 LoggerChannelListener (com.biglybt.pif.logging.LoggerChannelListener)5 BasicPluginViewModel (com.biglybt.pif.ui.model.BasicPluginViewModel)5 UIInstance (com.biglybt.pif.ui.UIInstance)4 UIManagerListener (com.biglybt.pif.ui.UIManagerListener)4 AERunnable (com.biglybt.core.util.AERunnable)3 BooleanParameter (com.biglybt.pif.ui.config.BooleanParameter)3 DelayedTask (com.biglybt.pif.utils.DelayedTask)3 PluginInterface (com.biglybt.pif.PluginInterface)2 Torrent (com.biglybt.pif.torrent.Torrent)2 ParameterListener (com.biglybt.pif.ui.config.ParameterListener)2 UTTimerEvent (com.biglybt.pif.utils.UTTimerEvent)2 UTTimerEventPerformer (com.biglybt.pif.utils.UTTimerEventPerformer)2 File (java.io.File)2 InetSocketAddress (java.net.InetSocketAddress)2 URL (java.net.URL)2 ParameterListener (com.biglybt.core.config.ParameterListener)1 DHT (com.biglybt.core.dht.DHT)1