feat: add BEP-0005 DHT bootstrap nodes support in .torrent files#583
feat: add BEP-0005 DHT bootstrap nodes support in .torrent files#583chantra wants to merge 1 commit into
Conversation
|
@ikatson I am not super psyche about the current DhtNode serde, but did not find a good way to have it working using the existing bencode crate. Mostly due to serialize_tuple . Let me know if there is ways you would prefer this written. |
| }; | ||
|
|
||
| // BEP-0005: inject nodes from .torrent as initial peers. | ||
| if !torrent.meta.nodes.is_empty() { |
There was a problem hiding this comment.
If I'm reading the spec correctly, these nodes aren't peers necessarily, but the closest DHT nodes.
Means they need to be queried through DHT to find peers, but not (just) added to initial parts
There was a problem hiding this comment.
yes, those are nodes that can be queried over DHT. Are you asking because then they should be added to a separate variable?
There was a problem hiding this comment.
I suppose in some ways, it is similar to #485 . Would you prefer that the initial torrent nodes are added to the Session.dht? I have not found a way to insert a node in the DhtState struct. Anything I am missing?
There was a problem hiding this comment.
@ikatson I have been spending a bit more time on this and I believe my test worked initially because it probably leaked to the DHT_BOOTSTRAP.
As much as I can see, in its current state, there is no way tell the Session to add those nodes to the dht table, right?
There was a problem hiding this comment.
Yes, and I think you need to add support for this to make this PR useful.
There was a problem hiding this comment.
let me put this into draft mode for now. Thanks for the feedback.
|
As to custom deserialize/serialize that's totally fine and how it's usually done anyway |
|
Re-requesting review in case this is needed to get it back on your radar. |
Add DhtNode type with custom serde that serializes as a 2-element bencode list ["<host>", <port>] per the BEP-5 spec. The Deserialize impl drains the sequence after reading host/port to properly consume the list end-marker, preventing a BytesRemaining(1) error when nodes appear before other fields in the outer torrent dict. - New `dht_node` module in librqbit_core with DhtNode struct - Add `nodes: Vec<DhtNode>` field to TorrentMetaV1 - Wire nodes through CreateTorrentOptions and create_torrent() - Inject torrent-embedded nodes as initial peers in session.rs - Add bencode roundtrip tests (single, vec, nested struct, empty vec) Test Plan: - `cargo test -p librqbit test_create_torrent_with_bootstrap_nodes` passes - `cargo test -p librqbit-core dht_node::tests` passes (5 tests: roundtrip single, vec, in-struct, empty vec, JSON) - `cargo clippy -p librqbit-core` clean
bfc4040 to
2baf72d
Compare
Add DhtNode type with custom serde that serializes as a 2-element bencode list ["", ] per the BEP-5 spec. The Deserialize impl drains the sequence after reading host/port to properly consume the list end-marker, preventing a BytesRemaining(1) error when nodes appear before other fields in the outer torrent dict.
dht_nodemodule in librqbit_core with DhtNode structnodes: Vec<DhtNode>field to TorrentMetaV1Test Plan:
cargo test -p librqbit test_create_torrent_with_bootstrap_nodespassescargo test -p librqbit-core dht_node::testspasses (5 tests: roundtrip single, vec, in-struct, empty vec, JSON)cargo clippy -p librqbit-corecleanAlso tested with an internal seeder/client
Note: Generated with Cursor