Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Torrent Details from Infohash #5

Open
arpitjindal97 opened this issue Jul 29, 2022 · 6 comments
Open

Get Torrent Details from Infohash #5

arpitjindal97 opened this issue Jul 29, 2022 · 6 comments

Comments

@arpitjindal97
Copy link

I have an Infohash of a torrent. Looking for a code by which I can get the details of it using DHT only (no tracker involvement).
Can bootstrap using a router DHT node.

From details, I mean MetaInfo struct

https://github.com/xgfone/bt/blob/master/metainfo/metainfo.go#L95

I tried understanding it from source-code but couldn't

@xgfone
Copy link
Owner

xgfone commented Jul 30, 2022

  1. In the early days, there is no DHT.
  2. The .torrent file is used to download the original file, so it should contain some trackers and the file information. The tracker is used to trace what nodes have the original file. Therefore, BEP 3 defines the field announce to record trackers and info to represent the information of the original file.
  3. MetaInfo is used to represent the information of the .torrent file. So it contains the fields announce and info.
  4. BEP 12 adds a new field announce-list to extend the field announce, both of which represent the trackers.
  5. BEP 19 adds a new field url-list to support WebSeed.
  6. The trakcer has the restriction and is blocked very easily, so BEP 5 has defined DHT, and added the new field nodes into the .torrent file.
  7. So, the .torrent file contains two kinds of metadatas:
    • Tracker, DHT Node and WebSeed: they are used to trace who has the original file to be downloaded, which are optional.
    • The information of the original file: The filename, the length, the piece hash, etc. That's the field info, which is mandatory. We will download the original file by these information, especially the pieces.
  8. MetaInfo also contains some unspecified information, such as creator and created-time of the .torrent file, which may be supported by other BT clients. So we have also added them.
  9. BEP 9 extends BT Peer Protocol, which allows the client or user to download the .torrent file. For example, when DHT server receives a announce_peer request, we can download the .torrent file from the peer announced by in the request announce_peer.

@arpitjindal97
Copy link
Author

Emphasizing on 9th Point, I have a DHT node running. When I do server1.GetPeers, which will give me list of peers by contacting other nodes.

Do you have the code by which .torrent file can be downloaded from peers ?

@xgfone
Copy link
Owner

xgfone commented Jul 30, 2022

get_peers is used to search the peers which have the original file from other DHT server. If the DHT server has no peers, it will returns a list of other DHT servers in its route table. The client calling get_peers search the peers from the returned DHT servers recursively. So the caller of get_peers should set the depth, which is 8 by default in the bt library.

BEP 9 defines the extension ut_metadata in the peer protocol to download the .torrent file from the peer. See TorrentDownloader.

@xgfone
Copy link
Owner

xgfone commented Jul 30, 2022

TorrentDownloader is implemented as the background task pool, which is inspired by dht.Wire. You can refer to the implementation to implement yourself downloader.

@arpitjindal97
Copy link
Author

I have a question, similar to this issue so thought of asking here instead of opening new issue.

Can we have a timeout here? Some tracker might not be running and this code take longer than usual & keep waiting

https://github.com/xgfone/bt/blob/master/tracker/udptracker/udp_test.go#L106-L114

@xgfone
Copy link
Owner

xgfone commented Aug 2, 2022

Yes, but we maybe use context.WithTimeout() instead of context.Background(), for example,

ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
defer cancel()

hs := []metainfo.Hash{metainfo.NewRandomHash(), metainfo.NewRandomHash()}
rs, err := client.Scrape(ctx, hs)
// ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants