proto: basic peer wire protocol that can download

This commit is contained in:
2016-12-13 00:59:36 -05:00
parent 74e82a0127
commit 0f76269952
16 changed files with 828 additions and 42 deletions

View File

@@ -5,7 +5,7 @@ use hyper::Client;
use url::form_urlencoded::byte_serialize;
use bencode::{decode, Dict};
use torrent::Torrent;
use metainfo::{Hash, Metainfo};
use tracker::{Peer, TrackerError, TrackerResponse, TrackerResult};
macro_rules! ts {
@@ -17,16 +17,16 @@ macro_rules! ts {
}
}
pub fn get_peers(peer_id: [u8; 20], port: u16, torrent: &Torrent) -> TrackerResult {
pub fn get_peers(peer_id: Hash, port: u16, metainfo: &Metainfo, uploaded: u64, downloaded: u64, left: u64) -> TrackerResult {
let url = format!("{}?info_hash={}&peer_id={}&port={}&uploaded={}\
&downloaded={}&left={}&compact=1",
torrent.metainfo.announce,
urlencode(&torrent.metainfo.info_hash),
metainfo.announce,
urlencode(&metainfo.info_hash),
urlencode(&peer_id),
port,
torrent.uploaded,
torrent.downloaded,
torrent.left);
uploaded,
downloaded,
left);
let client = Client::new();
let mut resp = client.get(&url).send()?;