Search in sources :

Example 1 with TRTrackerScraperResponse

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

the class TrackerCellUtils method updateColor.

public static void updateColor(TableCell cell, DownloadManager dm, boolean show_errors) {
    if (dm == null || cell == null)
        return;
    if (show_errors) {
        if (dm.isTrackerError()) {
            cell.setForegroundToErrorColor();
            return;
        }
    }
    TRTrackerScraperResponse response = dm.getTrackerScrapeResponse();
    if (response instanceof TRTrackerBTScraperResponseImpl && response.getStatus() == TRTrackerScraperResponse.ST_ONLINE) {
        boolean bMultiHashScrapes = ((TRTrackerBTScraperResponseImpl) response).getTrackerStatus().getSupportsMultipeHashScrapes();
        Color color = (bMultiHashScrapes) ? null : Colors.grey;
        cell.setForeground(Utils.colorToIntArray(color));
    } else {
        cell.setForeground(Utils.colorToIntArray(null));
    }
}
Also used : TRTrackerScraperResponse(com.biglybt.core.tracker.client.TRTrackerScraperResponse) Color(org.eclipse.swt.graphics.Color) TRTrackerBTScraperResponseImpl(com.biglybt.core.tracker.client.impl.bt.TRTrackerBTScraperResponseImpl)

Example 2 with TRTrackerScraperResponse

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

the class SeedToPeerRatioItem method refresh.

@Override
public void refresh(TableCell cell) {
    float ratio = -1;
    DownloadManager dm = (DownloadManager) cell.getDataSource();
    if (dm != null) {
        TRTrackerScraperResponse response = dm.getTrackerScrapeResponse();
        int seeds;
        int peers;
        if (response != null && response.isValid()) {
            seeds = Math.max(dm.getNbSeeds(), response.getSeeds());
            int trackerPeerCount = response.getPeers();
            peers = dm.getNbPeers();
            if (peers == 0 || trackerPeerCount > peers) {
                if (trackerPeerCount <= 0) {
                    peers = dm.getActivationCount();
                } else {
                    peers = trackerPeerCount;
                }
            }
        } else {
            seeds = dm.getNbSeeds();
            peers = dm.getNbPeers();
        }
        if (peers < 0 || seeds < 0) {
            ratio = 0;
        } else {
            if (peers == 0) {
                if (seeds == 0)
                    ratio = 0;
                else
                    ratio = Float.POSITIVE_INFINITY;
            } else {
                ratio = (float) seeds / peers;
            }
        }
    }
    if (!cell.setSortValue(ratio) && cell.isValid()) {
        return;
    }
    if (ratio == -1) {
        cell.setText("");
    } else if (ratio == 0) {
        cell.setText("??");
    } else {
        cell.setText(DisplayFormatters.formatDecimal(ratio, 3));
    }
}
Also used : TRTrackerScraperResponse(com.biglybt.core.tracker.client.TRTrackerScraperResponse) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 3 with TRTrackerScraperResponse

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

the class PEPeerControlImpl method updateTrackerAnnounceInterval.

private void updateTrackerAnnounceInterval() {
    if (mainloop_loop_count % MAINLOOP_FIVE_SECOND_INTERVAL != 0) {
        return;
    }
    final int WANT_LIMIT = 100;
    int[] _num_wanted = getMaxNewConnectionsAllowed();
    int num_wanted;
    if (_num_wanted[0] < 0) {
        // unlimited
        num_wanted = WANT_LIMIT;
    } else {
        num_wanted = _num_wanted[0] + _num_wanted[1];
        if (num_wanted > WANT_LIMIT) {
            num_wanted = WANT_LIMIT;
        }
    }
    final boolean has_remote = adapter.isNATHealthy();
    if (has_remote) {
        // is not firewalled, so can accept incoming connections,
        // which means no need to continually keep asking the tracker for peers
        num_wanted = (int) (num_wanted / 1.5);
    }
    int current_connection_count = PeerIdentityManager.getIdentityCount(_hash);
    final TRTrackerScraperResponse tsr = adapter.getTrackerScrapeResponse();
    if (tsr != null && tsr.isValid()) {
        // we've got valid scrape info
        final int num_seeds = tsr.getSeeds();
        final int num_peers = tsr.getPeers();
        final int swarm_size;
        if (seeding_mode) {
            // Only use peer count when seeding, as other seeds are unconnectable.
            // Since trackers return peers randomly (some of which will be seeds),
            // backoff by the seed2peer ratio since we're given only that many peers
            // on average each announce.
            final float ratio = (float) num_peers / (num_seeds + num_peers);
            swarm_size = (int) (num_peers * ratio);
        } else {
            swarm_size = num_peers + num_seeds;
        }
        if (swarm_size < num_wanted) {
            // lower limit to swarm size if necessary
            num_wanted = swarm_size;
        }
    }
    if (num_wanted < 1) {
        // we dont need any more connections
        // use normal announce interval
        adapter.setTrackerRefreshDelayOverrides(100);
        return;
    }
    // fudge it :)
    if (current_connection_count == 0)
        current_connection_count = 1;
    final int current_percent = (current_connection_count * 100) / (current_connection_count + num_wanted);
    // set dynamic interval override
    adapter.setTrackerRefreshDelayOverrides(current_percent);
}
Also used : TRTrackerScraperResponse(com.biglybt.core.tracker.client.TRTrackerScraperResponse)

Example 4 with TRTrackerScraperResponse

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

the class TRHostTorrentPublishImpl method updateStats.

protected void updateStats() {
    TRTrackerScraperResponse resp = null;
    TRTrackerAnnouncer tc = host.getTrackerClient(this);
    if (tc != null) {
        resp = TRTrackerScraperFactory.getSingleton().scrape(tc);
    }
    if (resp == null) {
        resp = TRTrackerScraperFactory.getSingleton().scrape(torrent);
    }
    try {
        this_mon.enter();
        if (resp != null && resp.isValid()) {
            peer_count = resp.getPeers();
            seed_count = resp.getSeeds();
            peers = new TRHostPeer[peer_count + seed_count];
            for (int i = 0; i < peers.length; i++) {
                peers[i] = new TRHostPeerPublishImpl(i < seed_count);
            }
        } else {
            peers = new TRHostPeer[0];
        }
    } finally {
        this_mon.exit();
    }
}
Also used : TRTrackerScraperResponse(com.biglybt.core.tracker.client.TRTrackerScraperResponse) TRTrackerAnnouncer(com.biglybt.core.tracker.client.TRTrackerAnnouncer)

Example 5 with TRTrackerScraperResponse

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

the class GeneralView method refresh.

public void refresh() {
    if (gFile == null || gFile.isDisposed() || manager == null)
        return;
    loopFactor++;
    if ((loopFactor % graphicsUpdate) == 0) {
        updateAvailability();
        availabilityImage.redraw();
        updatePiecesInfo(false);
        piecesImage.redraw();
    }
    DiskManager dm = manager.getDiskManager();
    String remaining;
    String eta = DisplayFormatters.formatETA(manager.getStats().getSmoothedETA());
    if (dm != null) {
        long rem = dm.getRemainingExcludingDND();
        String data_rem = DisplayFormatters.formatByteCountToKiBEtc(rem);
        if (rem > 0) {
            remaining = eta + (eta.length() == 0 ? "" : " ") + data_rem;
        } else {
            if (eta.length() == 0) {
                remaining = data_rem;
            } else {
                remaining = eta;
            }
        }
    } else {
        // only got eta value, just use that
        remaining = eta;
    }
    setTime(manager.getStats().getElapsedTime(), remaining);
    TRTrackerScraperResponse hd = manager.getTrackerScrapeResponse();
    String seeds_str = manager.getNbSeeds() + " " + MessageText.getString("GeneralView.label.connected");
    String peers_str = manager.getNbPeers() + " " + MessageText.getString("GeneralView.label.connected");
    String completed;
    if (hd != null && hd.isValid()) {
        seeds_str += " ( " + hd.getSeeds() + " " + MessageText.getString("GeneralView.label.in_swarm") + " )";
        peers_str += " ( " + hd.getPeers() + " " + MessageText.getString("GeneralView.label.in_swarm") + " )";
        completed = hd.getCompleted() > -1 ? Integer.toString(hd.getCompleted()) : "?";
    } else {
        completed = "?";
    }
    String _shareRatio = "";
    int sr = manager.getStats().getShareRatio();
    if (sr == -1)
        _shareRatio = Constants.INFINITY_STRING;
    if (sr > 0) {
        String partial = "" + sr % 1000;
        while (partial.length() < 3) partial = "0" + partial;
        _shareRatio = (sr / 1000) + "." + partial;
    }
    DownloadManagerStats stats = manager.getStats();
    String swarm_speed = DisplayFormatters.formatByteCountToKiBEtcPerSec(stats.getTotalAverage()) + " ( " + DisplayFormatters.formatByteCountToKiBEtcPerSec(stats.getTotalAveragePerPeer()) + " " + MessageText.getString("GeneralView.label.averagespeed") + " )";
    String swarm_completion = "";
    String distributedCopies = "0.000";
    String piecesDoneAndSum = "" + manager.getNbPieces();
    PEPeerManager pm = manager.getPeerManager();
    if (pm != null) {
        int comp = pm.getAverageCompletionInThousandNotation();
        if (comp >= 0) {
            swarm_completion = DisplayFormatters.formatPercentFromThousands(comp);
        }
        piecesDoneAndSum = pm.getPiecePicker().getNbPiecesDone() + "/" + piecesDoneAndSum;
        distributedCopies = new DecimalFormat("0.000").format(pm.getPiecePicker().getMinAvailability() - pm.getNbSeeds() - (pm.isSeeding() && stats.getDownloadCompleted(false) == 1000 ? 1 : 0));
    }
    int kInB = DisplayFormatters.getKinB();
    setStats(DisplayFormatters.formatDownloaded(stats), DisplayFormatters.formatByteCountToKiBEtc(stats.getTotalDataBytesSent()), DisplayFormatters.formatByteCountToKiBEtcPerSec(stats.getDataReceiveRate()), DisplayFormatters.formatByteCountToKiBEtcPerSec(stats.getDataSendRate()), swarm_speed, "" + manager.getStats().getDownloadRateLimitBytesPerSecond() / kInB, "" + (manager.getStats().getUploadRateLimitBytesPerSecond() / kInB), seeds_str, peers_str, completed, DisplayFormatters.formatHashFails(manager), _shareRatio, swarm_completion, distributedCopies);
    TOTorrent torrent = manager.getTorrent();
    String creation_date = DisplayFormatters.formatDate(manager.getTorrentCreationDate() * 1000);
    byte[] created_by = torrent == null ? null : torrent.getCreatedBy();
    if (created_by != null) {
        try {
            creation_date = MessageText.getString("GeneralView.torrent_created_on_and_by", new String[] { creation_date, new String(created_by, Constants.DEFAULT_ENCODING) });
        } catch (java.io.UnsupportedEncodingException e) {
        /* forget it */
        }
    }
    setInfos(manager.getDisplayName(), DisplayFormatters.formatByteCountToKiBEtc(manager.getSize()), DisplayFormatters.formatDownloadStatus(manager), manager.getState() == DownloadManager.STATE_ERROR, manager.getSaveLocation().toString(), TorrentUtils.nicePrintTorrentHash(torrent), piecesDoneAndSum, manager.getPieceLength(), manager.getTorrentComment(), creation_date, manager.getDownloadState().getUserComment(), MessageText.getString("GeneralView." + (torrent != null && torrent.getPrivate() ? "yes" : "no")));
    // the initial layout fails.
    if (loopFactor == 2) {
        getComposite().layout(true);
    }
}
Also used : TRTrackerScraperResponse(com.biglybt.core.tracker.client.TRTrackerScraperResponse) DecimalFormat(java.text.DecimalFormat) TOTorrent(com.biglybt.core.torrent.TOTorrent) PEPeerManager(com.biglybt.core.peer.PEPeerManager) DownloadManagerStats(com.biglybt.core.download.DownloadManagerStats) DiskManager(com.biglybt.core.disk.DiskManager)

Aggregations

TRTrackerScraperResponse (com.biglybt.core.tracker.client.TRTrackerScraperResponse)11 TOTorrent (com.biglybt.core.torrent.TOTorrent)3 TRTrackerAnnouncer (com.biglybt.core.tracker.client.TRTrackerAnnouncer)3 DownloadManager (com.biglybt.core.download.DownloadManager)2 TRTrackerBTScraperResponseImpl (com.biglybt.core.tracker.client.impl.bt.TRTrackerBTScraperResponseImpl)2 URL (java.net.URL)2 DecimalFormat (java.text.DecimalFormat)2 DiskManager (com.biglybt.core.disk.DiskManager)1 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)1 DownloadManagerStats (com.biglybt.core.download.DownloadManagerStats)1 PEPeerManager (com.biglybt.core.peer.PEPeerManager)1 TOTorrentAnnounceURLGroup (com.biglybt.core.torrent.TOTorrentAnnounceURLGroup)1 TOTorrentAnnounceURLSet (com.biglybt.core.torrent.TOTorrentAnnounceURLSet)1 TrackerPeerSource (com.biglybt.core.tracker.TrackerPeerSource)1 DownloadTypeComplete (com.biglybt.pif.download.DownloadTypeComplete)1 DownloadTypeIncomplete (com.biglybt.pif.download.DownloadTypeIncomplete)1 UIPluginViewToolBarListener (com.biglybt.pif.ui.UIPluginViewToolBarListener)1 TableColumnCore (com.biglybt.ui.common.table.TableColumnCore)1 TableColumnManager (com.biglybt.ui.common.table.impl.TableColumnManager)1 BufferedLabel (com.biglybt.ui.swt.components.BufferedLabel)1