gameyfin icon indicating copy to clipboard operation
gameyfin copied to clipboard

[Feature suggestion] Include torrent client and tracker or allow to specify tracker to create and announce torrents to

Open mdPlusPlus opened this issue 2 years ago • 5 comments

I think Gameyfin could be a great tool for LAN parties, but especially on bigger ones it could easily overwhelm a server, especially if there's only gigabit connectivity or the files are served from hard drives. To share the load between all participants, it would be cool if Gameyfin was able to also create and seed torrents from the given game files. That way everyone could use their torrent client of choice and share the files between each other.

UI-wise you could have a little torrent button besides the regular download button or maybe even have it configurable to only show regular downloads or only show torrent ones..

mdPlusPlus avatar Oct 05 '22 18:10 mdPlusPlus

That's definitely a good idea! I will have to think about how to implement it, but I think your idea has some potential.

grimsi avatar Oct 07 '22 13:10 grimsi

I could give it a go during the next two weeks if you are fine with it. I would use https://github.com/mpetazzoni/ttorrent as a library, as this covers all bases:

  1. Has a torrent tracker with filtering, so only Gameyfin Torrents can be announced
  2. Can create torrent files so they can be created on-demand
  3. Has a torrent client with which Gameyfin can seed it's Torrents

The probable solution would be:

When starting Gameyfin, the torrent tracker gets started and registers all locally saved .torrent files. This allows users to use it to share the games they have downloaded with torrent files from Gameyfin to be distributed to other users. At this point, Gameyfin is not seeding by itself.

Then, as soon as someone clicks on a "Torrent" Button next to a game, Gameyfin:

  1. Creates a torrent file with the same content as the zip file via direct download
  2. Serves it to the user
  3. Saves it in a local directory and registers this torrent file on its tracker
  4. Gameyfin creates a client instance, loads the created .torrent file and it's matching game files and starts seeding the game
  5. User loads downloaded .torrent on computer and so on...

For 4., there are two possible solutions: Either wait until the torrent has been seeded for e.g. one hour and then stop seeding (or 24h, whatever seems matching) OR wait until the torrent has been seeded one time to 100% and then stop. This would need the least server resources and the games will still be distributed further, as other users will just leech from the client that got the 100% instead of the Gameyfin client. This would be entirely sufficient on LANs, as OP requested, as people there can theoretically keep it in seed for the whole time or at least until everyone has a copy, and if the user with 100% quits so no seeder is left, other users can just click on the "Torrent" Button in Gameyfin and it will start seeding again.

I would prefer the second solution, as it is much cleaner, but there is also the possibility to implement both methods and allow the user to set the wanted method using config flags. Then the seedtime could also be set manually.

Pfuenzle avatar Oct 09 '22 21:10 Pfuenzle

That would be great! I also agree that the second solution sounds cleaner.

grimsi avatar Oct 10 '22 06:10 grimsi

If I may, I think I know how this can be made even simpler and avoid some overcomplications in Gameyfin:

Why not use web seeds? Most modern clients support them.

This would require a path by which you can serve files without zipping them(which would answer #97 as well), but then you wouldn't need to worry about seed times or threading out a seed client.

Gameyfin's "Torrent" button would compile a torrent file with the needed information(hashes, tracker, API seed links), or serve one from a (short-lived) cache, and the first client(s) would download from web seeds until they end up with enough data that they start contributing to the swarm over torrent protocol.

Seed client or web seed, either method would saturate the Gameyfin server's connection, but no worse than everyone downloading zip files, until it doesn't because the users are saturating their own connections downloading from each other.

Also, again for simplicity, I don't see a need for a filtered/registered tracker. The scope of Gameyfin is for personal libraries and LAN parties, therefore, there is a limited expectation of abuse as all users should be within a private network. So just a simple running tracker that is agnostic of what it is serving should be fine.

With these suggestions, the process looks like this:

  1. On startup, Gameyfin starts the tracker and web server, immediately returning to duty serving files over the web API, and coordinating peers with the tracker, regardless of how or when these shares started.
  2. User decides they are missing something and selects the "Torrent" option on a game page.
  3. Gameyfin serves an old torrent file from the cache if it is less than X time old(I'll get to why in a footnote), OR generates a new one. This might involve a progress bar or animation to let the user know this is in process, as hashing a large file set can take time. This torrent file includes the needed filenames and hashes, tracker location, and URLs to get the files over the web API.
  4. User inputs this torrent file into their favorite client, since we'll say they are the first user, their client starts downloading from the web API.
  5. User2 also wants this content, gets the torrent file(from the cache, quick), and starts their client, which finds that User has data and starts to get that from them, as well as other content from the web API.
  6. Additional users join, and get most of their content from User and User2, but the web API is still there should they drop off.
  7. And that's it.

And now the footnote...there is one issue with torrents and that is, they are immutable. Once a torrent file is generated, the files it is referencing cannot be changed, or they can no longer be served as the hashes will change and the torrent rendered useless. Additionally, hashing files can take a long time, so building the torrent on the fly could be rather slow. Therefore, a cache of torrent files should be implemented so that they are quick to retrieve after the first user spends the time generating it, but they also need to expire to allow for regeneration after a change(say, a new patch). Or this generation could be a manual process triggered in the admin panel.

Thoughts?

Jamie96ITS avatar Mar 24 '23 14:03 Jamie96ITS

I lack in-depth knowledge about how torrents work, but your comment sounds reasonable

grimsi avatar Mar 28 '23 13:03 grimsi