if (seed) {
peer->bitfield = (1<<FILE_PIECES)-1;
- peer->bitfield_blocks = (1L<<(FILE_PIECES * PIECES_BLOCKS))-1;
+ peer->bitfield_blocks = (1ULL<<(FILE_PIECES * PIECES_BLOCKS))-1;
} else {
peer->bitfield = 0;
peer->bitfield_blocks = 0;
xbt_assert((index >= 0 && index <= FILE_PIECES), "Wrong piece.");
xbt_assert((block_index >= 0 && block_index <= PIECES_BLOCKS), "Wrong block : %d.", block_index);
for (int i = block_index; i < (block_index + block_length); i++) {
- peer->bitfield_blocks |= (1L<<(index * PIECES_BLOCKS + i));
+ peer->bitfield_blocks |= (1ULL<<(index * PIECES_BLOCKS + i));
}
}
int piece_complete(peer_t peer, int index)
{
for (int i = 0; i < PIECES_BLOCKS; i++) {
- if (!(peer->bitfield_blocks & 1L<<(index * PIECES_BLOCKS + i))) {
+ if (!(peer->bitfield_blocks & 1ULL<<(index * PIECES_BLOCKS + i))) {
return 0;
}
}
int get_first_block(peer_t peer, int piece)
{
for (int i = 0; i < PIECES_BLOCKS; i++) {
- if (!(peer->bitfield_blocks & 1L<<(piece * PIECES_BLOCKS + i))) {
+ if (!(peer->bitfield_blocks & 1ULL<<(piece * PIECES_BLOCKS + i))) {
return i;
}
}
int id; //peer id
unsigned int bitfield; //list of pieces the peer has.
- unsigned long bitfield_blocks; //list of blocks the peer has.
+ unsigned long long bitfield_blocks; //list of blocks the peer has.
short *pieces_count; //number of peers that have each piece.
unsigned int current_pieces; //current pieces the peer is downloading