From f739c99dc08526f29d4a3eca35a502685f824629 Mon Sep 17 00:00:00 2001 From: Igor Katson Date: Mon, 18 Oct 2021 13:11:45 +0100 Subject: [PATCH] Update readme --- README.md | 24 ++++++++++++++++++++---- crates/peer_binary_protocol/src/lib.rs | 10 +++++----- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 7efdab7..cb541ab 100644 --- a/README.md +++ b/README.md @@ -74,8 +74,8 @@ Use a regex here to select files by their names. Below points are all easily fixable, PRs welcome. - The CLI support only one mode of operation: download one torrent to a given folder. -- If you try to run multiple instances, there's some port conflicts (already listening on port). This happens because DHT stores persistence information on disk, and that includes the port it last listened on. So all instances try to listen on the same port. Which means we need to add support for managing multiple torrents rather than trying to run the client multiple times. Or at least add a switch like --disable-dht-persistence. -- HTTP API is rudimentary, mostly for looking at stats. E.g. you can't add a torrent through it. +- If you try to run multiple instances, there's some port conflicts (already listening on port). This happens because DHT stores persistence information on disk, and that includes the port it last listened on. + To work around this either use ```--disable-dht-persistence``` flag on the second (3rd, etc) instance of rqbit, or add the other torrent with HTTP API like this ```curl -d 'magnet:?...' http://127.0.0.1:3030/torrents``` - Only supports BitTorrent V1 over TCP - As this was created for personal needs, and for educational purposes, documentation, commit message quality etc. leave a lot to be desired. - Doesn't survive switching networks, i.e. doesn't reconnect to a peer once the TCP connection is closed. @@ -105,6 +105,22 @@ By default it listens on http://127.0.0.1:3030. "GET /torrents": "List torrents (default torrent is 0)", "GET /torrents/{index}": "Torrent details", "GET /torrents/{index}/haves": "The bitfield of have pieces", - "GET /torrents/{index}/stats": "Torrent stats" + "GET /torrents/{index}/stats": "Torrent stats", + "POST /torrents/": "Add a torrent here. magnet: or http:// or a local file." } - } \ No newline at end of file + } + +### Add torrent through HTTP API + +```curl -d 'magnet:?...' http://127.0.0.1:3030/torrents``` + +OR + +```curl -d 'http://.../file.torrent' http://127.0.0.1:3030/torrents``` + +OR + +```curl -d '/some/local/file.torrent' http://127.0.0.1:3030/torrents``` + +Supported query parameters: +- overwrite=true|false \ No newline at end of file diff --git a/crates/peer_binary_protocol/src/lib.rs b/crates/peer_binary_protocol/src/lib.rs index 514a4da..ff563fb 100644 --- a/crates/peer_binary_protocol/src/lib.rs +++ b/crates/peer_binary_protocol/src/lib.rs @@ -383,7 +383,7 @@ where MSGID_HAVE => { let expected_len = 4; match rest.get(..expected_len as usize) { - Some(h) => Ok((Message::Have(BE::read_u32(&h)), PREAMBLE_LEN + expected_len)), + Some(h) => Ok((Message::Have(BE::read_u32(h)), PREAMBLE_LEN + expected_len)), None => { let missing = expected_len - rest.len(); Err(MessageDeserializeError::NotEnoughData(missing, "have")) @@ -414,7 +414,7 @@ where let expected_len = 12; match rest.get(..expected_len as usize) { Some(b) => { - let request = decoder_config.deserialize::(&b).unwrap(); + let request = decoder_config.deserialize::(b).unwrap(); Ok((Message::Request(request), PREAMBLE_LEN + expected_len)) } None => { @@ -435,7 +435,7 @@ where let expected_len = len_prefix as usize - 9 + 8; match rest.get(..expected_len) { Some(b) => Ok(( - Message::Piece(Piece::deserialize(&b)), + Message::Piece(Piece::deserialize(b)), PREAMBLE_LEN + expected_len, )), None => Err(MessageDeserializeError::NotEnoughData( @@ -456,7 +456,7 @@ where let expected_len = len_prefix as usize - 1; match rest.get(..expected_len) { Some(b) => Ok(( - Message::Extended(ExtendedMessage::deserialize(&b)?), + Message::Extended(ExtendedMessage::deserialize(b)?), PREAMBLE_LEN + expected_len, )), None => Err(MessageDeserializeError::NotEnoughData( @@ -520,7 +520,7 @@ impl<'a> Handshake<'a> { ))?; Ok(( Self::bopts() - .deserialize(&hbuf) + .deserialize(hbuf) .map_err(|e| MessageDeserializeError::Other(e.into()))?, expected_len, ))