0

In order to learn Rust, I plan to develop a bittorrent tracker. But I ran into a problem:

async fn announce(
    RawQuery(rawquery): RawQuery,
    Query(query_map): Query<BTreeMap<String, String>>,
) -> impl IntoResponse {
    let rawquery = rawquery.unwrap();
    dbg!(&rawquery, query_map);

    "todo!"
}

I use qBittorrent to try to access this tracker:

&rawquery = "token=token&info_hash=%f9%98%fc%fa%a4%06%85a%08*********%f8%3b9%1f%fd%b5%bf%91&peer_id=-qB4540-Cm**********&port=39718&uploaded=0&downloaded=0&left=0&corrupt=0&key=42A5****&event=started&numwant=200&compact=1&no_peer_id=1&supportcrypto=1&redundant=0"
query_map = {
    "compact": "1",
    "corrupt": "0",
    "downloaded": "0",
    "event": "started",
    "info_hash": "�����\u{6}�\u{8}�a۶�;\u{1f}���9�",
    "key": "42A5****",
    "left": "0",
    "no_peer_id": "1",
    "numwant": "200",
    "peer_id": "-qB4540-Cm**********",
    "port": "39718",
    "redundant": "0",
    "supportcrypto": "1",
    "token": "token",
    "uploaded": "0",
}

I know that info_hash is the hexadecimal representation [u8; 20], but no better way to serialize/deserialize has been found.

3moredays
  • 25
  • 3
  • I also can't parse `info_hash` when I use `BTreeMap` – 3moredays Aug 09 '23 at 12:55
  • I found its use in the source code of axum [axum](https://github.com/tokio-rs/axum/blob/d30375925dd22cc44aeaae2871f8ead1630fadf8/axum/src/extract/query.rs#L85). [serde_urlencoded] (https://docs.rs/serde_urlencoded/latest/serde_urlencoded/fn.from_str.html) to deserialize 'Query', does that mean I have to manually parse 'info_hash' by implementing 'FromRequestParts'? But I still can't serialize/deserialize in url query '[u8; 20]`. – 3moredays Aug 09 '23 at 13:10

0 Answers0