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

NIP-35: Torrents #1175

Merged
merged 5 commits into from May 22, 2024
Merged

NIP-35: Torrents #1175

merged 5 commits into from May 22, 2024

Conversation

v0l
Copy link
Member

@v0l v0l commented Apr 14, 2024

Making a NIP for torrents with a few updates

read: https://github.com/nostr-protocol/nips/blob/feat/nip35/35.md

@v0l
Copy link
Member Author

v0l commented Apr 16, 2024

@hzrd149

@hzrd149
Copy link
Collaborator

hzrd149 commented Apr 16, 2024

This looks great. however It could be worth mentioning k:2004 events that dtan and noStrudel use for comments on torrents since I think they could be useful for other clients wanting to implement this nip

The comment events are similar to kind 1 and follow NIP-10

@utxo-one
Copy link
Contributor

Great NIP!

@hzrd149
Copy link
Collaborator

hzrd149 commented Apr 18, 2024

looks good, I like the addition of the comments 👍

@flox1an
Copy link

flox1an commented May 3, 2024

FYI this PR uses i tags for external references: #1185

Could make sense for imdb, tmdb, .. and the like.

@jb55
Copy link
Contributor

jb55 commented May 8, 2024

what about v2?

@jb55
Copy link
Contributor

jb55 commented May 8, 2024

v2 is a lot more interesting that v1: merkle torrents so you can incrementally update a torrent file over time while sharing parts, etc. the same file can share seeders across many different torrents. I having been looking at v2 for notedeck file sharing, but it looks like this is hardcoded to v1.

@fiatjaf
Copy link
Member

fiatjaf commented May 8, 2024

Is anyone using v2?

@jb55
Copy link
Contributor

jb55 commented May 8, 2024

they should be, but it is not widely adopted yet no.

@melvincarvalho
Copy link

Great idea. What about a tag for thumbnail or images? Some trackers and clients have a thumb which makes the navigation UX much better. Or hover over for a larger image.

@jb55
Copy link
Contributor

jb55 commented May 11, 2024

it would be useful if the torrent info-dictionary was embedded in the note itself, bencoded or as json. That way you could express v1 or v2 torrents, and you could see all of the files, their file-level merkle root hashes (in the case of v2), and the corresponding trackers (EDIT: looks like this is outside info-dictionary... so maybe that should be in their own tags)

Then nostr clients could open the note as a torrent, allowing you to download individual files from bittorrent or even blossom nodes by looking at file hashes. v2 aligns nicely with blossom because it switches to SHA256

https://www.bittorrent.org/beps/bep_0052.html

image

@jb55
Copy link
Contributor

jb55 commented May 11, 2024

Hmm started diving into the spec and the pieces root may not be the same has the file hash, so this may foil my plan to have it compatible with blossom. darn...

@fiatjaf
Copy link
Member

fiatjaf commented May 11, 2024

Regardless of that I like the idea of having the metainfo inside the event.

@jb55
Copy link
Contributor

jb55 commented May 11, 2024

although one interesting observation is by breaking a file into 16KiB blocks you can always reconstruct the corresponding bittorrent v2 file root hash for a given file:

image

so a smart blossom seeder that wanted to help seed v2 torrents would:

  • split entire file into N 16 KiB blocks, hash these blocks individually, and then hash these all together into the bittorrent-v2 sha2 file hash (root hash)
  • store this root hash alongside the standard sha2 hash of the file
  • A hybrid torrent/blossom client could check to see if a blossom server has a file from some torrent by making a HEAD request for the root hash

Notice because of a branching factor of 2, the fact that piece sizes must be powers of 2, and fixed 16KiB block sizes, the root merkle hash never changes, even if the piece size changes.

Let's say the client is only missing the 2nd block from the torrent file, we can make a range request against the blossom server for the second block:

GET /5584a1cc51f777b13b9de2a6a1012ee0e7a93652143c415901b8fe005ed1124c HTTP/1.1
Host: blobstr.xyz
Range: bytes=16384-32768

Where 5584a1cc51f777b13b9de2a6a1012ee0e7a93652143c415901b8fe005ed1124c is the root hash

Then we can hash the response and match it against our torrent metadata piece layers to confirm it's correct.

Alternatively the blossom node can become a bittorrent peer. Anything uploaded to the blossom server could serve pieces to v2 swarms. bittorrent v1 has the concept of web seeds, so maybe this idea is just extending that to v2

This is getting a bit off topic, but just wanted to put this out for consideration when it comes to torrents + nostr.

@v0l
Copy link
Member Author

v0l commented May 13, 2024

compatible with blossom

Not a huge fan of Blossom, there is a lot of overlap with NIP96, it would have been nicer to reuse that spec and expand.

it would be useful if the torrent info-dictionary was embedded in the note itself,

Sounds good to me, i can add this to the spec if you still think its a good idea?

@arthurfranca
Copy link
Contributor

Not a huge fan of Blossom, there is a lot of overlap with NIP96, it would have been nicer to reuse that spec and expand.

Finally someone said it! Never got people praising blossom. It is a NIP-96 rip-off hurting interop.

Blossom spec is exactly the same as NIP-96 but with small changes that bring incompatiblity like kind:10063 for discovery instead of kind:10096 and JSON responses that have the same fields from NIP-96 but with different structure for no reason.

Blossom only additions that could be simply added to NIP-96: a route to list uploaded items of a pubkey, a HEAD one to check for an item existence.

@jb55
Copy link
Contributor

jb55 commented May 13, 2024

blossom, nip-96, blobstr, it's all the same, the only relevant thing to my proposal above is and endpoint for fetching data in a CAS-way. blobstr is the most minimal that is needed to support this:

@v0l
Copy link
Member Author

v0l commented May 14, 2024

blossom, nip-96, blobstr, it's all the same, the only relevant thing to my proposal above is and endpoint for fetching data in a CAS-way. blobstr is the most minimal that is needed to support this:

Fair enough, ive been building a Blossom/NIP-96 server over here: https://git.v0l.io/Kieran/void-cat-rs would be cool to trial the bittorrent compat with this.

One thing im not sure of is how you get the hash of each file from the torrent, since we're only storing the root hash, do we also need to store the hash of each file? because we have the file entry already, maybe we should include the sha256 in those tags?

And once we have a way to link these torrent files which servers would you lookup?

@jb55
Copy link
Contributor

jb55 commented May 14, 2024

One thing im not sure of is how you get the hash of each file from the torrent, since we're only storing the root hash, do we also need to store the hash of each file? because we have the file entry already, maybe we should include the sha256 in those tags?

And once we have a way to link these torrent files which servers would you lookup?

I think the embedded torrent file should maybe be an optional thing, because some torrent files can be quite large. yeah I think the sha256 hash would be nice to have, bonus points for the v2 file hash (16KiB block sha2 merkle tree with branch factor 2)

maybe disregard my crazy idea alltogether, I realize v2 implementations are still far off so probably won't be relevant for awhile, and v1 torrent metadata format is horrible.

Comment on lines +62 to +66
## Torrent Comments

A torrent comment is a `kind 2004` event which is used to reply to a torrent event.

This event works exactly like a `kind 1` and should follow `NIP-10` for tagging.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Save the planetnostr, guys! Support #1233 with a 👍? =D

Copy link
Collaborator

@hzrd149 hzrd149 May 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not read through the entirety of #1233 but I think there is merit in having a specific kind for torrent comments and using a simple schema like NIP-10 for marking replies and threads

It seems reasonable that a NIP would define its primary event kind (in this case 2003) and a comment / reply kind that is specifically used for it. It seems like a better solution then using k tags as a "meta" kind

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thread roots should be defined by the NIP. Replies can be generalized.

Otherwise, should we have reactions, zap, labels, and report kinds for each NIP as well? Replies are no different than reactions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable, but im not sold on the new tag structure

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going to merge anyway, we can always change it later once your PR is merged, nobody is really using comments on torrents yet. I only see 24 comments so far.

@v0l v0l merged commit 5971aa2 into master May 22, 2024
@v0l v0l deleted the feat/nip35 branch May 22, 2024 08:37
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

Successfully merging this pull request may close these issues.

None yet

9 participants