Search in sources :

Example 1 with DownloadAnnounceResult

use of com.biglybt.pif.download.DownloadAnnounceResult in project BiglyBT by BiglySoftware.

the class ExternalSeedReaderImpl method readyToActivate.

protected boolean readyToActivate(PeerManager peer_manager, Peer peer, long time_since_start) {
    boolean early_days = time_since_start < INITIAL_DELAY;
    try {
        Download download = peer_manager.getDownload();
        // first respect failure count
        int fail_count = getFailureCount();
        if (fail_count > 0) {
            int delay = reconnect_delay;
            for (int i = 1; i < fail_count; i++) {
                delay += delay;
                if (delay > 30 * 60 * 1000) {
                    break;
                }
            }
            long now = getSystemTime();
            long last_fail = getLastFailTime();
            if (last_fail < now && now - last_fail < delay) {
                return (false);
            }
        }
        if (ws_valid_until > 0 && getSystemTime() > ws_valid_until) {
            return (false);
        }
        if (download.getState() != Download.ST_DOWNLOADING) {
            return (false);
        }
        if (download.isComplete()) {
            return (false);
        }
        if (!PluginCoreUtils.unwrap(download).getDownloadState().isNetworkEnabled(host_net)) {
            return (false);
        }
        if (PluginCoreUtils.unwrap(torrent).getEffectiveTorrentType() == TOTorrent.TT_V2) {
            // don't activate if we are missing any piece hashes (safe hack for the mo)
            byte[][] pieces = torrent.getPieces();
            for (byte[] piece : pieces) {
                if (piece == null) {
                    return (false);
                }
            }
        }
        if (transient_seed) {
            // kick any existing peers that are running too slowly if the download appears
            // to be stalled
            Peer[] existing_peers = peer_manager.getPeers(getIP());
            int existing_peer_count = existing_peers.length;
            int global_limit = TransferSpeedValidator.getGlobalDownloadRateLimitBytesPerSecond();
            if (global_limit > 0) {
                // if we have a global limit in force and we are near it then no point in
                // activating
                int current_down = plugin.getGlobalDownloadRateBytesPerSec();
                if (global_limit - current_down < 5 * 1024) {
                    return (false);
                }
            }
            int download_limit = peer_manager.getDownloadRateLimitBytesPerSecond();
            if (global_limit > 0 && global_limit < download_limit) {
                download_limit = global_limit;
            }
            if ((download_limit == 0 || download_limit > STALLED_DOWNLOAD_SPEED + 5 * 1024) && peer_manager.getStats().getDownloadAverage() < STALLED_DOWNLOAD_SPEED) {
                for (int i = 0; i < existing_peers.length; i++) {
                    Peer existing_peer = existing_peers[i];
                    if (existing_peer instanceof ExternalSeedPeer) {
                        continue;
                    }
                    PeerStats stats = existing_peer.getStats();
                    if (stats.getTimeSinceConnectionEstablished() > INITIAL_DELAY) {
                        if (stats.getDownloadAverage() < STALLED_PEER_SPEED) {
                            existing_peer.close("Replacing slow peer with web-seed", false, false);
                            existing_peer_count--;
                        }
                    }
                }
            }
            if (existing_peer_count == 0) {
                if (peer_manager.getPendingPeers(getIP()).length == 0) {
                    log(getName() + ": activating as transient seed and nothing blocking it");
                    return (true);
                }
            }
        }
        if (!use_avail_to_activate) {
            log(getName() + ": activating as availability-based activation disabled");
            return (true);
        }
        if (ws_fast_activate || !early_days) {
            if (ws_min_availability > 0) {
                float availability = download.getStats().getAvailability();
                if (availability < ws_min_availability) {
                    log(getName() + ": activating as availability is poor (<" + ws_min_availability + ")");
                    return (true);
                }
            }
            int min_speed = ws_min_download_speed > 0 ? ws_min_download_speed : min_download_speed_default;
            if (min_speed > 0) {
                if (peer_manager.getStats().getDownloadAverage() < min_speed) {
                    log(getName() + ": activating as speed is slow (<" + DisplayFormatters.formatByteCountToKiBEtcPerSec(min_speed) + ")");
                    return (true);
                }
            }
        }
        // if we have an announce result and there are no seeds, or it failed then go for it
        DownloadAnnounceResult ar = download.getLastAnnounceResult();
        if (ar != null) {
            if (ar.getResponseType() == DownloadAnnounceResult.RT_ERROR) {
                log(getName() + ": activating as tracker unavailable");
                return (true);
            }
            if (ar.getSeedCount() == 0) {
                log(getName() + ": activating as no seeds");
                return (true);
            }
        }
    } catch (Throwable e) {
        Debug.printStackTrace(e);
    }
    return (false);
}
Also used : DownloadAnnounceResult(com.biglybt.pif.download.DownloadAnnounceResult) Download(com.biglybt.pif.download.Download)

Example 2 with DownloadAnnounceResult

use of com.biglybt.pif.download.DownloadAnnounceResult in project BiglyBT by BiglySoftware.

the class RankCalculatorReal method calcSeedsNoUs.

/**
 * Get # of seeds, not including us, AND including fake full copies
 *
 * @param download Download to get # of seeds for
 * @param numPeers # peers we know of, required to calculate Fake Full Copies
 * @return seed count
 */
private int calcSeedsNoUs(Download download, DownloadScrapeResult sr, int numPeers) {
    int numSeeds = 0;
    if (sr.getScrapeStartTime() > 0) {
        long seedingStartedOn = download.getStats().getTimeStartedSeeding();
        numSeeds = sr.getSeedCount();
        // Remove ourselves from count
        if ((numSeeds > 0) && (seedingStartedOn > 0) && (download.getState() == Download.ST_SEEDING) && (sr.getScrapeStartTime() > seedingStartedOn))
            numSeeds--;
    }
    if (numSeeds == 0) {
        // Fallback to the # of seeds we know of
        DownloadAnnounceResult ar = download.getLastAnnounceResult();
        if (ar != null && ar.getResponseType() == DownloadAnnounceResult.RT_SUCCESS)
            numSeeds = ar.getSeedCount();
    }
    if (numPeersAsFullCopy != 0 && numSeeds >= iFakeFullCopySeedStart)
        numSeeds += numPeers / numPeersAsFullCopy;
    return Math.max(numSeeds, 0);
}
Also used : DownloadAnnounceResult(com.biglybt.pif.download.DownloadAnnounceResult)

Aggregations

DownloadAnnounceResult (com.biglybt.pif.download.DownloadAnnounceResult)2 Download (com.biglybt.pif.download.Download)1