You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.3 KiB
Rust

4 years ago
use rand::random;
4 years ago
use std::fs::File;
4 years ago
use std::io::Read;
use std::net::IpAddr;
use std::str::FromStr;
4 years ago
use torment_core::infohash::v1::U160;
use torment_core::metainfo::Torrent;
use torment_core::peer_id;
4 years ago
use torment_core::peer_storage::{PeerStorage, PeerStorageHolder};
4 years ago
use torment_manager::session_manager::SessionManager;
4 years ago
use torment_manager::torment_instance::TormentInstance;
4 years ago
use torment_manager::torrent_manager::{TorrentManager, TorrentTarget};
4 years ago
use torment_manager::tracker_manager::TrackerManager;
4 years ago
fn main() {
4 years ago
let ip = IpAddr::from_str("0.0.0.0").unwrap();
let peer_id = U160::from(peer_id(random()));
let mut session_manager = SessionManager::new(ip, 50002, peer_id);
4 years ago
4 years ago
let mut file = vec![];
File::open("test.torrent")
4 years ago
.unwrap()
4 years ago
.read_to_end(&mut file)
4 years ago
.unwrap();
4 years ago
let torrent = Torrent::from_bytes(file, Some("test".to_string())).unwrap();
println!("Downloading {:#?}", torrent);
4 years ago
let torrent_manager = TorrentManager::from_torrent(
4 years ago
torrent,
4 years ago
TorrentTarget {
4 years ago
path: "/tmp/test".into(),
4 years ago
is_base_path: true,
},
4 years ago
Some(session_manager.tracker_manager_mut()),
4 years ago
);
session_manager.add_torrent_manager(torrent_manager);
4 years ago
let mut instance = TormentInstance::new(50002, session_manager);
instance.logic_loop();
4 years ago
}