Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge "if" statements.
[simgrid.git] / examples / msg / app-bittorrent / peer.c
index ee19ff2..427df2b 100644 (file)
@@ -167,7 +167,7 @@ void seed_loop(peer_t peer, double deadline)
   }
 }
 
-/** @brief Retrieves the peer list from the tracker
+/** @brief Retrieves the peer list from the tracker
  *  @param peer current peer data
  */
 int get_peers_data(peer_t peer)
@@ -263,7 +263,7 @@ void peer_free(peer_t peer)
   xbt_free(peer);
 }
 
-/** @brief Returns if a peer has finished downloading the file
+/** @brief Returns if a peer has finished downloading the file
  *  @param bitfield peer bitfield
  */
 int has_finished(unsigned int bitfield)
@@ -454,7 +454,7 @@ void remove_current_piece(peer_t peer, connection_t remote_peer, unsigned int cu
 void update_pieces_count_from_bitfield(peer_t peer, unsigned int bitfield)
 {
   for (int i = 0; i < FILE_PIECES; i++) {
-    if ((bitfield & (1U << i))) {
+    if (bitfield & (1U << i)) {
       peer->pieces_count[i]++;
     }
   }
@@ -672,10 +672,9 @@ void update_interested_after_receive(peer_t peer)
   char *key;
   xbt_dict_cursor_t cursor;
   connection_t connection;
-  int interested;
   xbt_dict_foreach(peer->peers, cursor, key, connection) {
-    interested = 0;
     if (connection->am_interested != 0) {
+      int interested = 0;
       //Check if the peer still has a piece we want.
       for (int i = 0; i < FILE_PIECES; i++) {
         if (peer_has_not_piece(peer, i) && connection_has_piece(connection,i)) {
@@ -743,10 +742,9 @@ int is_interested_and_free(peer_t peer, connection_t remote_peer)
 int partially_downloaded_piece(peer_t peer, connection_t remote_peer)
 {
   for (int i = 0; i < FILE_PIECES; i++) {
-    if (peer_has_not_piece(peer, i) && connection_has_piece(remote_peer,i)&& peer_is_not_downloading_piece(peer, i)) {
-      if (get_first_block(peer, i) > 0)
-        return i;
-    }
+    if (peer_has_not_piece(peer, i) && connection_has_piece(remote_peer, i) && peer_is_not_downloading_piece(peer, i) &&
+        get_first_block(peer, i) > 0)
+      return i;
   }
   return -1;
 }