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
43 lines
1.3 KiB
Rust
use rand::random;
|
|
use std::fs::File;
|
|
use std::io::Read;
|
|
use std::net::IpAddr;
|
|
use std::str::FromStr;
|
|
use torment_core::infohash::v1::U160;
|
|
use torment_core::metainfo::Torrent;
|
|
use torment_core::peer_id;
|
|
use torment_core::peer_storage::{PeerStorage, PeerStorageHolder};
|
|
use torment_manager::session_manager::SessionManager;
|
|
use torment_manager::torment_instance::TormentInstance;
|
|
use torment_manager::torrent_manager::{TorrentManager, TorrentTarget};
|
|
use torment_manager::tracker_manager::TrackerManager;
|
|
|
|
fn main() {
|
|
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);
|
|
|
|
let mut file = vec![];
|
|
File::open("test.torrent")
|
|
.unwrap()
|
|
.read_to_end(&mut file)
|
|
.unwrap();
|
|
let torrent = Torrent::from_bytes(file, Some("test".to_string())).unwrap();
|
|
|
|
println!("Downloading {:#?}", torrent);
|
|
let torrent_manager = TorrentManager::from_torrent(
|
|
torrent,
|
|
TorrentTarget {
|
|
path: "/tmp/test".into(),
|
|
is_base_path: true,
|
|
},
|
|
Some(session_manager.tracker_manager_mut()),
|
|
);
|
|
|
|
session_manager.add_torrent_manager(torrent_manager);
|
|
|
|
let mut instance = TormentInstance::new(50002, session_manager);
|
|
instance.logic_loop();
|
|
}
|