Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add the forgotten bittorrent tesh file. Change the way pieces are chosen in updateCur...
authorSamuel Lepetit <samuel.lepetit@inria.fr>
Tue, 5 Jun 2012 08:42:25 +0000 (10:42 +0200)
committerSamuel Lepetit <samuel.lepetit@inria.fr>
Tue, 5 Jun 2012 08:42:25 +0000 (10:42 +0200)
examples/bittorrent/Peer.java
examples/bittorrent/Tracker.java
examples/bittorrent/bittorrent.tesh [new file with mode: 0644]

index 7e3fb8c..c5a6653 100644 (file)
@@ -9,6 +9,7 @@ import org.simgrid.msg.Comm;
 import org.simgrid.msg.Host;
 import org.simgrid.msg.Msg;
 import org.simgrid.msg.MsgException;
+import org.simgrid.msg.RngStream;
 import org.simgrid.msg.Process;
 import org.simgrid.msg.Task;
 
@@ -20,6 +21,8 @@ public class Peer extends Process {
        
        protected double deadline;
        
+       protected static RngStream stream = new RngStream();
+       
        protected int id;
        protected String mailbox;
        protected String mailboxTracker;
@@ -317,7 +320,6 @@ public class Peer extends Process {
                                        if (bitfield[message.index] == '0') {
                                                piecesRequested--;
                                                //Removing the piece from our piece list.
-                                               //TODO: It can not work, I should test it
                                                if (!currentPieces.remove((Object)Integer.valueOf(message.index))) {
                                                }
                                                //Setting the fact that we have the piece
@@ -393,7 +395,7 @@ public class Peer extends Process {
                if (true || pieces < 3) {
                        int i = 0, peerPiece;
                        do {
-                               currentPiece = ((int)Msg.getClock() + id + i) % Common.FILE_PIECES;
+                               currentPiece = stream.randInt(0,Common.FILE_PIECES - 1);
                                i++;
                        } while (!(bitfield[currentPiece] == '0' && !currentPieces.contains(currentPiece)));
                }
@@ -448,6 +450,7 @@ public class Peer extends Process {
                                sendUnchoked(peerChoosed.mailbox);
                        }
                }
+               //TODO: Use the leecher choke algorithm.
        }
        /**     
         * Updates our "interested" state about peers: send "not interested" to peers
index 537a3a5..8f0d7f7 100644 (file)
@@ -56,7 +56,6 @@ public class Tracker extends Process {
                                        if (task instanceof TrackerTask) {
                                                TrackerTask tTask = (TrackerTask)task;
                                                //Sending peers to the peer
-                                               //TODO: Send RANDOM pairs using RngStreams.
                                                int nbPeers = 0;
                                                while (nbPeers < Common.MAXIMUM_PAIRS && nbPeers < peersList.size()) {
                                                        int nextPeer;
diff --git a/examples/bittorrent/bittorrent.tesh b/examples/bittorrent/bittorrent.tesh
new file mode 100644 (file)
index 0000000..3919b49
--- /dev/null
@@ -0,0 +1,27 @@
+#! ./tesh
+
+! output sort
+
+$ java -cp .:${srcdir:=.}/examples:${srcdir:=.}/simgrid.jar bittorrent/Bittorrent ${srcdir:=.}/examples/platform.xml ${srcdir:=.}/examples/bittorrent/bittorrent.xml
+> [0.000000] [jmsg/INFO] Ready to run MSG_MAIN
+> [5000.832370] [jmsg/INFO] Done running MSG_MAIN
+> [5000.832370] [jmsg/INFO] MSG_main finished
+> [5000.832370] [jmsg/INFO] Clean java world
+> [5000.832370] [jmsg/INFO] Clean native world
+> [Boivin:bittorrent.Peer:(2) 0.000000] [jmsg/INFO] Hi, I'm joining the network with id 2
+> [Boivin:bittorrent.Peer:(2) 5000.048882] [jmsg/INFO] Here is my current status: 1111111111
+> [Disney:bittorrent.Peer:(6) 0.000000] [jmsg/INFO] Hi, I'm joining the network with id 6
+> [Disney:bittorrent.Peer:(6) 5000.131405] [jmsg/INFO] Here is my current status: 1111111111
+> [Geoff:bittorrent.Peer:(5) 0.000000] [jmsg/INFO] Hi, I'm joining the network with id 5
+> [Geoff:bittorrent.Peer:(5) 5000.764583] [jmsg/INFO] Here is my current status: 1111111111
+> [Jacquelin:bittorrent.Tracker:(1) 0.000000] [jmsg/INFO] Tracker launched.
+> [Jacquelin:bittorrent.Tracker:(1) 3000.000000] [jmsg/INFO] Tracker is leaving
+> [Jean_Yves:bittorrent.Peer:(3) 0.000000] [jmsg/INFO] Hi, I'm joining the network with id 3
+> [Jean_Yves:bittorrent.Peer:(3) 5000.832370] [jmsg/INFO] Here is my current status: 1111111111
+> [McGee:bittorrent.Peer:(8) 0.000000] [jmsg/INFO] Hi, I'm joining the network with id 8
+> [McGee:bittorrent.Peer:(8) 5000.783574] [jmsg/INFO] Here is my current status: 1111111111
+> [TeX:bittorrent.Peer:(4) 0.000000] [jmsg/INFO] Hi, I'm joining the network with id 4
+> [TeX:bittorrent.Peer:(4) 5000.304959] [jmsg/INFO] Here is my current status: 1111111111
+> [iRMX:bittorrent.Peer:(7) 0.000000] [jmsg/INFO] Hi, I'm joining the network with id 7
+> [iRMX:bittorrent.Peer:(7) 5000.729205] [jmsg/INFO] Here is my current status: 1111111111
+