Skip to main content

dht_crawler/
protocol.rs

1use serde::Deserialize;
2
3#[derive(Deserialize, Debug, Clone)]
4#[allow(dead_code)]
5/// Decoded KRPC envelope.
6pub struct DhtMessage {
7    /// Transaction ID bytes.
8    pub t: serde_bytes::ByteBuf,
9    #[allow(dead_code)]
10    /// Message kind (`q`, `r`, or `e`).
11    pub y: String,
12    #[allow(dead_code)]
13    /// Query method when `y == q`.
14    pub q: Option<String>,
15    /// Query arguments.
16    pub a: Option<DhtArgs>,
17    /// Response dictionary.
18    pub r: Option<DhtResponse>,
19}
20
21#[derive(Deserialize, Debug, Clone)]
22/// Supported BEP-5 query arguments.
23pub struct DhtArgs {
24    /// Sender node ID.
25    pub id: Option<serde_bytes::ByteBuf>,
26    /// find_node target ID.
27    pub target: Option<serde_bytes::ByteBuf>,
28    /// get_peers/announce InfoHash.
29    pub info_hash: Option<serde_bytes::ByteBuf>,
30    /// announce validation token.
31    pub token: Option<serde_bytes::ByteBuf>,
32    /// Explicit announced Peer port.
33    pub port: Option<u16>,
34    /// Non-zero means use the UDP source port.
35    pub implied_port: Option<u8>,
36}
37
38#[derive(Deserialize, Debug, Clone)]
39/// Supported BEP-5 response fields.
40pub struct DhtResponse {
41    #[serde(default)]
42    #[allow(dead_code)]
43    /// Responder node ID.
44    pub id: Option<serde_bytes::ByteBuf>,
45    #[serde(default)]
46    /// Compact IPv4 node tuples.
47    pub nodes: Option<serde_bytes::ByteBuf>,
48    #[serde(default)]
49    /// Compact IPv6 node tuples.
50    pub nodes6: Option<serde_bytes::ByteBuf>,
51    #[serde(default)]
52    /// Compact Peer endpoints returned by `get_peers`.
53    pub values: Option<Vec<serde_bytes::ByteBuf>>,
54}