Re:Building a BitTorrent client from the ground up in Go
by war1025 on Sunday January 05, 2020 @08:47AM
(#21961218)
What I meant more-so was the math of a "piece" from a torrent is a fixed number of bytes.
The way the files are laid out for a torrent, they are listed in some order in the initial torrent file, along with their individual lengths.
The data for the torrent is then treated as the contiguous sequence of bytes for the files in the listed order.
That contiguous sequence is then broken into "pieces" of whatever fixed size. So finding which file(s) and what position within those files piece 148, for example, goes to involves some math that is pretty straight forward all in all, but is still rewarding when it's the first time you've done such a thing.
Can you explain a little bit how this is interesting mathematically? On first thought, it seems like you would probably use a lot of pwrite, or if want convenience over safety, mmap all the files and write directly to memory. Not to diminish your achievement, but I didn't immediately see anything interesting here. Can you explain a bit more?