Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
used unsigned long long to have more than 50 bits
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Wed, 15 Feb 2017 20:34:23 +0000 (21:34 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Wed, 15 Feb 2017 20:34:23 +0000 (21:34 +0100)
examples/msg/app-bittorrent/peer.c
examples/msg/app-bittorrent/peer.h

index 3af98ed..7921e8a 100644 (file)
@@ -229,7 +229,7 @@ peer_t peer_init(int id, int seed)
 
   if (seed) {
     peer->bitfield = (1<<FILE_PIECES)-1;
 
   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;
   } else {
     peer->bitfield = 0;
     peer->bitfield_blocks = 0;
@@ -694,7 +694,7 @@ void update_bitfield_blocks(peer_t peer, int index, int block_index, int block_l
   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++) {
   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));
   }
 }
 
   }
 }
 
@@ -702,7 +702,7 @@ void update_bitfield_blocks(peer_t peer, int index, int block_index, int block_l
 int piece_complete(peer_t peer, int index)
 {
   for (int i = 0; i < 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;
     }
   }
       return 0;
     }
   }
@@ -713,7 +713,7 @@ int piece_complete(peer_t peer, int index)
 int get_first_block(peer_t peer, int piece)
 {
   for (int i = 0; i < PIECES_BLOCKS; i++) {
 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;
     }
   }
       return i;
     }
   }
index cca374b..4c28fc3 100644 (file)
@@ -18,7 +18,7 @@ typedef struct s_peer {
   int id;                       //peer id
 
   unsigned int bitfield;        //list of pieces the peer has.
   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
   short *pieces_count;          //number of peers that have each piece.
 
   unsigned int current_pieces;   //current pieces the peer is downloading