ikatson/rqbit

unable to get peers without DHT

Closed this issue · 2 comments

use std::time::Duration;
use librqbit::{AddTorrent, AddTorrentOptions, Session, SessionOptions};
use log::{info, LevelFilter};
use simple_logger::SimpleLogger;

fn main() {
    SimpleLogger::new().with_level(LevelFilter::Debug).init().unwrap();
    tokio_test::block_on(async {
        let session = Session::new_with_opts("test".into(), SessionOptions {
            disable_dht: true,
            disable_dht_persistence: true,
            dht_config: None,
            persistence: false,
            persistence_filename: None,
            peer_id: None,
            peer_opts: None,
            listen_port_range: Some(10000..12000),
            enable_upnp_port_forwarding: true,
        }).await.unwrap();
        let managed_torrent_handle = session.add_torrent(
            AddTorrent::from_local_filename("test.torrent").unwrap(),
            Some(AddTorrentOptions {
                paused: false,
                only_files_regex: None,
                only_files: None,
                overwrite: true,
                list_only: false,
                output_folder: None,
                sub_folder: None,
                peer_opts: None,
                force_tracker_interval: Some(Duration::from_secs(16)),
                disable_trackers: false,
                initial_peers: None,
                preferred_id: None,
            }) // options
        ).await.unwrap().into_handle().unwrap();
        loop {
            tokio::time::sleep(Duration::from_secs(1)).await;
            let snapshot = managed_torrent_handle.stats().live.map(|x| x.snapshot);
            let downloaded = managed_torrent_handle.live().map(|x| x.get_downloaded_bytes());
            let left = managed_torrent_handle.live().map(|x| x.get_left_to_download_bytes());
            let stats = managed_torrent_handle.stats().state;
            info!("downloaded {downloaded:?}/{left:?}, {stats}");
            info!("{snapshot:#?}");
        }
        //managed_torrent_handle.wait_until_completed().await.unwrap();
    });
}

i was porting librqbit to very constrained environment, disabled dht since it crashed

it didn't get a single peer

so i ran same code on pc, same no peers

tried gui client, disabled DHT, no peers

also, is there a way i can limit peer count?

test.torrent was torrent file for single 3MB file
it downloaded just in 1min with dht

Without DHT, the peers are polled from trackers.

The trackers are stored in the torrent file itself.

So a few reasons why without DHT it might not have downloaded:

  1. The trackers list is empty
  2. The trackers are non-responsive
  3. rqbit supports only HTTP/HTTPS trackers, but maybe other types (like UDP) were listed there.

This is the code where it's talking to trackers if you want to debug https://github.com/ikatson/rqbit/blob/main/crates/librqbit/src/torrent_state/live/mod.rs#L320

also, is there a way i can limit peer count?

as far as I remember, no. It's hardcoded to I think 128 live peers per torrent