Posts Tagged ‘bitfield’

The bitfield tracks which pieces of the transfer are already downloaded, and which aren’t. We therefore only need a structure which can track two states per value, which is why we use a bitarray library. In fact, we use only a subset of these functions, and rename a few to make them more expressive.

We also need to be able to translate the bitfield from/to the network where the high bit (right-most in network order) in the first byte corresponds to piece index 0.

Read more »