Search in sources :

Example 1 with DHTPluginImplAdapter

use of com.biglybt.plugin.dht.impl.DHTPluginImplAdapter in project BiglyBT by BiglySoftware.

the class DHTPlugin method initComplete.

protected void initComplete(final UITextField status_area, final boolean logging, final String override_ip) {
    AEThread2 t = new AEThread2("DHTPlugin.init", true) {

        @Override
        public void run() {
            boolean went_async = false;
            try {
                enabled = VersionCheckClient.getSingleton().DHTEnableAllowed();
                if (enabled) {
                    status_area.setText("Initialising");
                    final DelayedTask dt = plugin_interface.getUtilities().createDelayedTask(new Runnable() {

                        @Override
                        public void run() {
                            // go async again as don't want to block other tasks
                            new AEThread2("DHTPlugin.init2", true) {

                                @Override
                                public void run() {
                                    try {
                                        List plugins = new ArrayList();
                                        // adapter only added to first DHTPluginImpl we create
                                        DHTPluginImplAdapter adapter = new DHTPluginImplAdapter() {

                                            @Override
                                            public void localContactChanged(DHTPluginContact local_contact) {
                                                for (int i = 0; i < listeners.size(); i++) {
                                                    ((DHTPluginListener) listeners.get(i)).localAddressChanged(local_contact);
                                                }
                                            }
                                        };
                                        if (AZ_MAIN_DHT_ENABLE) {
                                            main_dht = new DHTPluginImpl(plugin_interface, CoreFactory.getSingleton().getNATTraverser(), adapter, DHTTransportUDP.PROTOCOL_VERSION_AZ_MAIN, DHT.NW_AZ_MAIN, false, override_ip, dht_data_port, reseed, warn_user, logging, log, dht_log);
                                            plugins.add(main_dht);
                                            adapter = null;
                                        }
                                        if (AZ_MAIN_DHT_V6_ENABLE) {
                                            if (NetworkAdmin.getSingleton().hasDHTIPV6()) {
                                                main_v6_dht = new DHTPluginImpl(plugin_interface, CoreFactory.getSingleton().getNATTraverser(), adapter, DHTTransportUDP.PROTOCOL_VERSION_AZ_MAIN, DHT.NW_AZ_MAIN_V6, true, null, dht_data_port, reseed, warn_user, logging, log, dht_log);
                                                plugins.add(main_v6_dht);
                                                adapter = null;
                                            }
                                        }
                                        if (Constants.isCVSVersion() && AZ_CVS_DHT_ENABLE) {
                                            cvs_dht = new DHTPluginImpl(plugin_interface, CoreFactory.getSingleton().getNATTraverser(), adapter, DHTTransportUDP.PROTOCOL_VERSION_AZ_CVS, DHT.NW_AZ_CVS, false, override_ip, dht_data_port, reseed, warn_user, logging, log, dht_log);
                                            plugins.add(cvs_dht);
                                            adapter = null;
                                        }
                                        if (BIGLYBT_MAIN_DHT_ENABLE) {
                                            biglybt_dht = new DHTPluginImpl(plugin_interface, CoreFactory.getSingleton().getNATTraverser(), adapter, DHTTransportUDP.PROTOCOL_VERSION_BIGLYBT, DHT.NW_BIGLYBT_MAIN, false, override_ip, dht_data_port, reseed, warn_user, logging, log, dht_log);
                                            plugins.add(biglybt_dht);
                                            adapter = null;
                                        }
                                        DHTPluginImpl[] _dhts = new DHTPluginImpl[plugins.size()];
                                        plugins.toArray(_dhts);
                                        dhts = _dhts;
                                        status = dhts[0].getStatus();
                                        status_area.setText(dhts[0].getStatusText());
                                    } catch (Throwable e) {
                                        enabled = false;
                                        status = STATUS_DISABLED;
                                        status_area.setText("Disabled due to error during initialisation");
                                        log.log(e);
                                        Debug.printStackTrace(e);
                                    } finally {
                                        init_sem.releaseForever();
                                    }
                                    if (status == STATUS_RUNNING) {
                                        changePort(dht_data_port);
                                    }
                                }
                            }.start();
                        }
                    });
                    dt.queue();
                    went_async = true;
                } else {
                    status = STATUS_DISABLED;
                    status_area.setText("Disabled administratively due to network problems");
                }
            } catch (Throwable e) {
                enabled = false;
                status = STATUS_DISABLED;
                status_area.setText("Disabled due to error during initialisation");
                log.log(e);
                Debug.printStackTrace(e);
            } finally {
                if (!went_async) {
                    init_sem.releaseForever();
                }
            }
        }
    };
    t.start();
}
Also used : DHTPluginImplAdapter(com.biglybt.plugin.dht.impl.DHTPluginImplAdapter) DHTPluginImpl(com.biglybt.plugin.dht.impl.DHTPluginImpl) DelayedTask(com.biglybt.pif.utils.DelayedTask)

Aggregations

DelayedTask (com.biglybt.pif.utils.DelayedTask)1 DHTPluginImpl (com.biglybt.plugin.dht.impl.DHTPluginImpl)1 DHTPluginImplAdapter (com.biglybt.plugin.dht.impl.DHTPluginImplAdapter)1