Search in sources :

Example 1 with DHTPlugin

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

the class VivaldiView method init.

private void init(Core core) {
    try {
        PluginInterface dht_pi = core.getPluginManager().getPluginInterfaceByClass(DHTPlugin.class);
        if (dht_pi == null) {
            return;
        }
        DHT[] dhts = ((DHTPlugin) dht_pi.getPlugin()).getDHTs();
        for (int i = 0; i < dhts.length; i++) {
            if (dhts[i].getTransport().getNetwork() == dht_type) {
                dht = dhts[i];
                break;
            }
        }
        if (dht == null) {
            return;
        }
    } catch (Exception e) {
        Debug.printStackTrace(e);
    }
}
Also used : DHT(com.biglybt.core.dht.DHT) PluginInterface(com.biglybt.pif.PluginInterface) DHTPlugin(com.biglybt.plugin.dht.DHTPlugin)

Example 2 with DHTPlugin

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

the class ClientMyInstanceImpl method readExternalAddress.

private InetAddress readExternalAddress() {
    InetAddress external_address = null;
    if (manager.isClosing()) {
        external_address = last_external_address;
        if (external_address == null) {
            try {
                external_address = InetAddress.getByName("127.0.0.1");
            } catch (Throwable e) {
                Debug.printStackTrace(e);
            }
        }
        return (external_address);
    }
    DHTPlugin dht = adapter.getDHTPlugin();
    if (dht_address != null && dht_address_time <= SystemTime.getCurrentTime()) {
        ClientInstanceManagerAdapter.VCPublicAddress a = adapter.getVCPublicAddress();
        if (a != null) {
            long cache_time = a.getCacheTime();
            if (cache_time <= dht_address_time) {
                external_address = dht_address;
            }
        }
    }
    if (external_address == null && (dht == null || dht.getStatus() != DHTPlugin.STATUS_RUNNING)) {
        // use cached version if available and the DHT isn't
        ClientInstanceManagerAdapter.VCPublicAddress a = adapter.getVCPublicAddress();
        if (a != null) {
            try {
                external_address = InetAddress.getByName(a.getAddress());
            } catch (Throwable e) {
                Debug.printStackTrace(e);
            }
        }
    }
    if (external_address == null && dht != null) {
        try {
            InetAddress latest_dht_address = dht.getLocalAddress().getAddress().getAddress();
            if (sameFamily(internal_address, latest_dht_address)) {
                external_address = latest_dht_address;
            }
        } catch (Throwable e) {
        }
    }
    long now = SystemTime.getCurrentTime();
    if (last_force_read_ext > now) {
        last_force_read_ext = now;
    }
    boolean ok_to_try_ext = now - last_force_read_ext > FORCE_READ_EXT_MIN;
    if (external_address == null && last_external_address != null) {
        if (last_upnp_read > now) {
            last_upnp_read = now;
        }
        if (now - last_upnp_read > UPNP_READ_MIN || ok_to_try_ext) {
            last_upnp_read = now;
            try {
                UPnPPlugin upnp = adapter.getUPnPPlugin();
                if (upnp != null) {
                    String[] addresses = upnp.getExternalIPAddresses();
                    for (int i = 0; i < addresses.length; i++) {
                        if (addresses[i].equals(last_external_address.getHostAddress())) {
                            external_address = last_external_address;
                            break;
                        }
                    }
                }
            } catch (Throwable e) {
            }
        }
    }
    if (external_address == null) {
        if (ok_to_try_ext) {
            last_force_read_ext = now;
            external_address = adapter.getPublicAddress();
        }
    }
    if (external_address == null) {
        if (last_external_address != null) {
            external_address = last_external_address;
        } else {
            try {
                external_address = InetAddress.getByName("127.0.0.1");
            } catch (Throwable e) {
                Debug.printStackTrace(e);
            }
        }
    } else {
        last_external_address = external_address;
    }
    return (external_address);
}
Also used : UPnPPlugin(com.biglybt.plugin.upnp.UPnPPlugin) DHTPlugin(com.biglybt.plugin.dht.DHTPlugin) ClientInstanceManagerAdapter(com.biglybt.core.instancemanager.ClientInstanceManagerAdapter) InetAddress(java.net.InetAddress)

Example 3 with DHTPlugin

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

the class Show method showDHTStats.

protected void showDHTStats(ConsoleInput ci) {
    try {
        PluginInterface def = ci.core.getPluginManager().getDefaultPluginInterface();
        PluginInterface dht_pi = def.getPluginManager().getPluginInterfaceByClass(DHTPlugin.class);
        if (dht_pi == null) {
            ci.out.println("\tDHT isn't present");
            return;
        }
        DHTPlugin dht_plugin = (DHTPlugin) dht_pi.getPlugin();
        if (dht_plugin.getStatus() != DHTPlugin.STATUS_RUNNING) {
            ci.out.println("\tDHT isn't running yet (disabled or initialising)");
            return;
        }
        DHT[] dhts = dht_plugin.getDHTs();
        for (int i = 0; i < dhts.length; i++) {
            if (i > 0) {
                ci.out.println("");
            }
            DHT dht = dhts[i];
            DHTTransport transport = dht.getTransport();
            DHTTransportStats t_stats = transport.getStats();
            DHTDBStats d_stats = dht.getDataBase().getStats();
            DHTControlStats c_stats = dht.getControl().getStats();
            DHTRouterStats r_stats = dht.getRouter().getStats();
            long[] rs = r_stats.getStats();
            DHTNetworkPosition[] nps = transport.getLocalContact().getNetworkPositions();
            String np_str = "";
            for (int j = 0; j < nps.length; j++) {
                np_str += (j == 0 ? "" : ",") + nps[j];
            }
            ci.out.println("DHT:ip=" + transport.getLocalContact().getAddress() + ",net=" + transport.getNetwork() + ",prot=V" + transport.getProtocolVersion() + ",np=" + np_str + ",sleeping=" + dht.isSleeping());
            ci.out.println("Router" + ":nodes=" + rs[DHTRouterStats.ST_NODES] + ",leaves=" + rs[DHTRouterStats.ST_LEAVES] + ",contacts=" + rs[DHTRouterStats.ST_CONTACTS] + ",replacement=" + rs[DHTRouterStats.ST_REPLACEMENTS] + ",live=" + rs[DHTRouterStats.ST_CONTACTS_LIVE] + ",unknown=" + rs[DHTRouterStats.ST_CONTACTS_UNKNOWN] + ",failing=" + rs[DHTRouterStats.ST_CONTACTS_DEAD]);
            ci.out.println("Transport" + ":" + t_stats.getString());
            int[] dbv_details = d_stats.getValueDetails();
            ci.out.println("Control:dht=" + c_stats.getEstimatedDHTSize() + ", Database:keys=" + d_stats.getKeyCount() + ",vals=" + dbv_details[DHTDBStats.VD_VALUE_COUNT] + ",loc=" + dbv_details[DHTDBStats.VD_LOCAL_SIZE] + ",dir=" + dbv_details[DHTDBStats.VD_DIRECT_SIZE] + ",ind=" + dbv_details[DHTDBStats.VD_INDIRECT_SIZE] + ",div_f=" + dbv_details[DHTDBStats.VD_DIV_FREQ] + ",div_s=" + dbv_details[DHTDBStats.VD_DIV_SIZE]);
            dht.getRouter().print();
        }
    } catch (Throwable e) {
        e.printStackTrace(ci.out);
    }
}
Also used : DHTDBStats(com.biglybt.core.dht.db.DHTDBStats) PluginInterface(com.biglybt.pif.PluginInterface) DHT(com.biglybt.core.dht.DHT) DHTNetworkPosition(com.biglybt.core.dht.netcoords.DHTNetworkPosition) DHTPlugin(com.biglybt.plugin.dht.DHTPlugin) DHTRouterStats(com.biglybt.core.dht.router.DHTRouterStats) DHTControlStats(com.biglybt.core.dht.control.DHTControlStats)

Example 4 with DHTPlugin

use of com.biglybt.plugin.dht.DHTPlugin 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)

Example 5 with DHTPlugin

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

the class RelatedContentSearcher method getDHTInfos.

private List<DownloadInfo> getDHTInfos(boolean search_cvs_only) {
    List<DHTPluginValue> vals;
    if (search_cvs_only) {
        if (dht_plugin instanceof DHTPlugin) {
            vals = ((DHTPlugin) dht_plugin).getValues(DHTPlugin.NW_AZ_CVS, false);
        } else {
            vals = dht_plugin.getValues();
        }
    } else {
        vals = dht_plugin.getValues();
    }
    Set<String> unique_keys = new HashSet<>();
    List<DownloadInfo> dht_infos = new ArrayList<>();
    for (DHTPluginValue val : vals) {
        if (!val.isLocal()) {
            byte[] bytes = val.getValue();
            String test = new String(bytes);
            if (test.startsWith("d1:d") && test.endsWith("ee") && test.contains("1:h20:")) {
                try {
                    Map map = BDecoder.decode(bytes);
                    DownloadInfo info = manager.decodeInfo(map, null, 1, false, unique_keys);
                    if (info != null) {
                        dht_infos.add(info);
                    }
                } catch (Throwable e) {
                }
            }
        }
    }
    return (dht_infos);
}
Also used : DHTPluginValue(com.biglybt.plugin.dht.DHTPluginValue) DownloadInfo(com.biglybt.core.content.RelatedContentManager.DownloadInfo) DHTPlugin(com.biglybt.plugin.dht.DHTPlugin)

Aggregations

DHTPlugin (com.biglybt.plugin.dht.DHTPlugin)10 PluginInterface (com.biglybt.pif.PluginInterface)8 DHT (com.biglybt.core.dht.DHT)7 DHTTransportContact (com.biglybt.core.dht.transport.DHTTransportContact)2 InetAddress (java.net.InetAddress)2 InetSocketAddress (java.net.InetSocketAddress)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 DownloadInfo (com.biglybt.core.content.RelatedContentManager.DownloadInfo)1 DHTControlActivity (com.biglybt.core.dht.control.DHTControlActivity)1 DHTControlListener (com.biglybt.core.dht.control.DHTControlListener)1 DHTControlStats (com.biglybt.core.dht.control.DHTControlStats)1 DHTDBStats (com.biglybt.core.dht.db.DHTDBStats)1 DHTNATPuncher (com.biglybt.core.dht.nat.DHTNATPuncher)1 DHTNATPuncherListener (com.biglybt.core.dht.nat.DHTNATPuncherListener)1 DHTNetworkPosition (com.biglybt.core.dht.netcoords.DHTNetworkPosition)1 DHTRouterStats (com.biglybt.core.dht.router.DHTRouterStats)1 DHTTransportStats (com.biglybt.core.dht.transport.DHTTransportStats)1 ClientInstanceManagerAdapter (com.biglybt.core.instancemanager.ClientInstanceManagerAdapter)1 NATTraversalHandler (com.biglybt.core.nat.NATTraversalHandler)1