Search in sources :

Example 16 with TrackerPeerSource

use of com.biglybt.core.tracker.TrackerPeerSource in project BiglyBT by BiglySoftware.

the class DHTTrackerPlugin method getTrackerPeerSources.

public TrackerPeerSource[] getTrackerPeerSources(final Torrent torrent) {
    TrackerPeerSource vuze_dht = new TrackerPeerSourceAdapter() {

        private volatile boolean query_done;

        private volatile int status = TrackerPeerSource.ST_INITIALISING;

        private volatile int seeds = 0;

        private volatile int leechers = 0;

        private void fixup() {
            if (initialised_sem.isReleasedForever()) {
                synchronized (this) {
                    if (query_done) {
                        return;
                    }
                    query_done = true;
                    status = TrackerPeerSource.ST_UPDATING;
                }
                dht.get(torrent.getHash(), "Availability lookup for '" + torrent.getName() + "'", DHTPlugin.FLAG_DOWNLOADING, NUM_WANT, ANNOUNCE_DERIVED_TIMEOUT, false, true, new DHTPluginOperationListener() {

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

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

                    @Override
                    public void valueRead(DHTPluginContact originator, DHTPluginValue value) {
                        if ((value.getFlags() & DHTPlugin.FLAG_DOWNLOADING) == 1) {
                            seeds++;
                        } else {
                            leechers++;
                        }
                    }

                    @Override
                    public void valueWritten(DHTPluginContact target, DHTPluginValue value) {
                    }

                    @Override
                    public void complete(byte[] key, boolean timeout_occurred) {
                        status = TrackerPeerSource.ST_ONLINE;
                    }
                });
            }
        }

        @Override
        public int getType() {
            return (TrackerPeerSource.TP_DHT);
        }

        @Override
        public String getName() {
            return (Constants.APP_NAME + " DHT");
        }

        @Override
        public int getStatus() {
            fixup();
            return (status);
        }

        @Override
        public int getSeedCount() {
            fixup();
            int result = seeds;
            if (result == 0 && status != TrackerPeerSource.ST_ONLINE) {
                return (-1);
            }
            return (result);
        }

        @Override
        public int getLeecherCount() {
            fixup();
            int result = leechers;
            if (result == 0 && status != TrackerPeerSource.ST_ONLINE) {
                return (-1);
            }
            return (result);
        }

        @Override
        public int getPeers() {
            return (-1);
        }

        @Override
        public boolean isUpdating() {
            return (status == TrackerPeerSource.ST_UPDATING);
        }
    };
    if (alt_lookup_handler != null) {
        TrackerPeerSource alt_dht = new TrackerPeerSourceAdapter() {

            private volatile int status = TrackerPeerSource.ST_UPDATING;

            private volatile int peers = 0;

            {
                alt_lookup_handler.get(torrent.getHash(), false, new DHTTrackerPluginAlt.LookupListener() {

                    @Override
                    public void foundPeer(InetSocketAddress address) {
                        peers++;
                    }

                    @Override
                    public boolean isComplete() {
                        return (false);
                    }

                    @Override
                    public void completed() {
                        status = TrackerPeerSource.ST_ONLINE;
                    }
                });
            }

            @Override
            public int getType() {
                return (TrackerPeerSource.TP_DHT);
            }

            @Override
            public String getName() {
                return ("Mainline DHT");
            }

            @Override
            public int getStatus() {
                return (status);
            }

            @Override
            public int getPeers() {
                int result = peers;
                if (result == 0 && status != TrackerPeerSource.ST_ONLINE) {
                    return (-1);
                }
                return (result);
            }

            @Override
            public boolean isUpdating() {
                return (status == TrackerPeerSource.ST_UPDATING);
            }
        };
        return (new TrackerPeerSource[] { vuze_dht, alt_dht });
    } else {
        return (new TrackerPeerSource[] { vuze_dht });
    }
}
Also used : DHTPluginValue(com.biglybt.plugin.dht.DHTPluginValue) TrackerPeerSource(com.biglybt.core.tracker.TrackerPeerSource) DHTPluginOperationListener(com.biglybt.plugin.dht.DHTPluginOperationListener) InetSocketAddress(java.net.InetSocketAddress) DHTPluginContact(com.biglybt.plugin.dht.DHTPluginContact) TrackerPeerSourceAdapter(com.biglybt.core.tracker.TrackerPeerSourceAdapter)

Example 17 with TrackerPeerSource

use of com.biglybt.core.tracker.TrackerPeerSource in project BiglyBT by BiglySoftware.

the class TrackerView method updateSelectedContent.

protected void updateSelectedContent() {
    if (tv == null) {
        return;
    }
    Object[] dataSources = tv.getSelectedDataSources(true);
    if (dataSources.length == 0) {
        String id = "DMDetails_Sources";
        if (manager != null) {
            if (manager.getTorrent() != null) {
                id += "." + manager.getInternalName();
            } else {
                id += ":" + manager.getSize();
            }
            SelectedContentManager.changeCurrentlySelectedContent(id, new SelectedContent[] { new SelectedContent(manager) });
        } else {
            SelectedContentManager.changeCurrentlySelectedContent(id, null);
        }
    } else {
        SelectedContent[] sc = new SelectedContent[dataSources.length];
        for (int i = 0; i < sc.length; i++) {
            Object ds = dataSources[i];
            if (ds instanceof TrackerPeerSource) {
                sc[i] = new SelectedContent("Source: " + ((TrackerPeerSource) ds).getName());
            } else {
                sc[i] = new SelectedContent("Source: " + ds);
            }
        }
        SelectedContentManager.changeCurrentlySelectedContent(tv.getTableID(), sc, tv);
    }
}
Also used : SelectedContent(com.biglybt.ui.selectedcontent.SelectedContent) TrackerPeerSource(com.biglybt.core.tracker.TrackerPeerSource)

Example 18 with TrackerPeerSource

use of com.biglybt.core.tracker.TrackerPeerSource in project BiglyBT by BiglySoftware.

the class PeersItem method refresh.

@Override
public void refresh(TableCell cell) {
    TrackerPeerSource ps = (TrackerPeerSource) cell.getDataSource();
    int value = (ps == null) ? -1 : ps.getPeers();
    if (!cell.setSortValue(value) && cell.isValid()) {
        return;
    }
    cell.setText(value < 0 ? "" : String.valueOf(value));
}
Also used : TrackerPeerSource(com.biglybt.core.tracker.TrackerPeerSource)

Example 19 with TrackerPeerSource

use of com.biglybt.core.tracker.TrackerPeerSource in project BiglyBT by BiglySoftware.

the class ReportedDownItem method refresh.

@Override
public void refresh(TableCell cell) {
    TrackerPeerSource ps = (TrackerPeerSource) cell.getDataSource();
    long[] stats = (ps == null) ? null : ps.getReportedStats();
    long sort;
    String str;
    if (stats != null) {
        long gu = stats[1];
        long uu = stats[3];
        long su = stats[5];
        sort = gu != 0 ? gu : (uu != 0 ? uu : su);
        if (sort == 0) {
            str = "";
        } else {
            if (uu > 0) {
                str = DisplayFormatters.formatByteCountToKiBEtc(uu);
            } else {
                str = "";
            }
            if (gu != 0 && gu != uu) {
                str = DisplayFormatters.formatByteCountToKiBEtc(gu) + (str.isEmpty() ? "" : ("/" + str));
            }
            if (su > 0) {
                str += " (" + DisplayFormatters.formatByteCountToKiBEtc(su) + ")";
            }
        }
    } else {
        sort = -1;
        str = "";
    }
    if (!cell.setSortValue(sort) && cell.isValid()) {
        return;
    }
    cell.setText(str);
}
Also used : TrackerPeerSource(com.biglybt.core.tracker.TrackerPeerSource)

Example 20 with TrackerPeerSource

use of com.biglybt.core.tracker.TrackerPeerSource in project BiglyBT by BiglySoftware.

the class SeedsItem method refresh.

@Override
public void refresh(TableCell cell) {
    TrackerPeerSource ps = (TrackerPeerSource) cell.getDataSource();
    int value = (ps == null) ? -1 : ps.getSeedCount();
    if (!cell.setSortValue(value) && cell.isValid()) {
        return;
    }
    cell.setText(value < 0 ? "" : String.valueOf(value));
}
Also used : TrackerPeerSource(com.biglybt.core.tracker.TrackerPeerSource)

Aggregations

TrackerPeerSource (com.biglybt.core.tracker.TrackerPeerSource)22 URL (java.net.URL)3 TrackerPeerSourceAdapter (com.biglybt.core.tracker.TrackerPeerSourceAdapter)2 TRTrackerScraperResponse (com.biglybt.core.tracker.client.TRTrackerScraperResponse)2 TOTorrent (com.biglybt.core.torrent.TOTorrent)1 TRTrackerAnnouncer (com.biglybt.core.tracker.client.TRTrackerAnnouncer)1 AERunnable (com.biglybt.core.util.AERunnable)1 PluginInterface (com.biglybt.pif.PluginInterface)1 Download (com.biglybt.pif.download.Download)1 DownloadImpl (com.biglybt.pifimpl.local.download.DownloadImpl)1 DHTPluginContact (com.biglybt.plugin.dht.DHTPluginContact)1 DHTPluginOperationListener (com.biglybt.plugin.dht.DHTPluginOperationListener)1 DHTPluginValue (com.biglybt.plugin.dht.DHTPluginValue)1 ExternalSeedPlugin (com.biglybt.plugin.extseed.ExternalSeedPlugin)1 SelectedContent (com.biglybt.ui.selectedcontent.SelectedContent)1 MultiTrackerEditor (com.biglybt.ui.swt.maketorrent.MultiTrackerEditor)1 TrackerEditorListener (com.biglybt.ui.swt.maketorrent.TrackerEditorListener)1 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)1 TableSelectedRowsListener (com.biglybt.ui.swt.views.table.TableSelectedRowsListener)1 InetSocketAddress (java.net.InetSocketAddress)1