Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into actor-yield
[simgrid.git] / examples / java / app / bittorrent / Peer.java
index 94d0a68..8c07d84 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2006-2014, 2016. The SimGrid Team.
+/* Copyright (c) 2006-2014, 2016-2017. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -325,6 +325,9 @@ public class Peer extends Process {
           }
         }
       break;
+      default:
+        Msg.error("Unexpected message type: " + message.type);
+        break;
     }
     if (remotePeer != null) {
       remotePeer.addSpeedValue(1 / (Msg.getClock() - beginReceiveTime));
@@ -384,14 +387,12 @@ public class Peer extends Process {
     if (currentPieces.size() >= (Common.FILE_PIECES - pieces)) {
       return;
     }
-//    if (pieces < 3) {
-      do {
-        currentPiece = stream.randInt(0,Common.FILE_PIECES - 1);
-      } while (!(bitfield[currentPiece] == '0' && !currentPieces.contains(currentPiece)));
-//    }
-//    else {
-      //TODO trivial min algorithm.
-//    }
+
+    //TODO: trivial min algorithm when pieces >= 3
+    do {
+      currentPiece = stream.randInt(0,Common.FILE_PIECES - 1);
+    } while (!(bitfield[currentPiece] == '0' && !currentPieces.contains(currentPiece)));
+
     currentPieces.add(currentPiece);
     Msg.debug("New interested piece: " + currentPiece);
     assert currentPiece >= 0 && currentPiece < Common.FILE_PIECES;