proto: basic peer wire protocol that can download
This commit is contained in:
@@ -3,12 +3,14 @@ extern crate magnolia;
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::io::{self, Read};
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use std::str;
|
||||
|
||||
use magnolia::bencode::*;
|
||||
use magnolia::metainfo::Metainfo;
|
||||
use magnolia::torrent::Torrent;
|
||||
use magnolia::tracker::http;
|
||||
use magnolia::net::session::Session;
|
||||
|
||||
fn load_file(path: &str) -> io::Result<()> {
|
||||
let mut buf = Vec::new();
|
||||
@@ -18,16 +20,14 @@ fn load_file(path: &str) -> io::Result<()> {
|
||||
let obj = decode(&buf).unwrap();
|
||||
let meta = Metainfo::from_bencode(obj).unwrap();
|
||||
|
||||
let t = Torrent {
|
||||
metainfo: meta,
|
||||
uploaded: 0,
|
||||
downloaded: 0,
|
||||
left: 0,
|
||||
};
|
||||
println!("{}", meta.pieces.len());
|
||||
|
||||
let resp = http::get_peers([1u8; 20], 55555, &t).unwrap();
|
||||
let s = Session::new();
|
||||
s.add_torrent(meta);
|
||||
|
||||
print!("{:?}", resp);
|
||||
loop {
|
||||
thread::sleep(Duration::from_secs(1));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user