How to divide block in piece when they overlap

Viewed 469

Some input I'm looking to build a simple minimal bittorrent client. I reading the protocol spec for a 2-3 days now.

here what my understanding on it thus far . Assuming that torrent has a piece length of 26000 bytes and according to non official spec block size is 16384. Something like this.

enter image description here Now upon request of a block of piece message would look like this

piece 0 
block offset 0
block length 16484

So far so good.

Now, for next block which overlap in piece 0 and 1 what should the request look like

piece 0  ## since the start of byte is in piece 0 use piece 0 instead of piece 1
block offset 16384
block length 16384

Now on the receiving end I need to recreate the piece of 26000 bytes so that I can compare that with pieces (hash) to match the piece for correctness.

Is my understanding correct ?

Also I'm let suppose the piece verification failed and may be it because of the first block i.e Block 0 (which is faulty or corrupt) then I should requeue Block 0 and Block 1 (which was valid btw and also a part of piece 1) to retransmit again.

And now suddenly the piece and block distribution become a bit complex then what I assume it be. and I hoping there is a simpler solution to this.

Any thought

3 Answers
Related