From c71a4e608a02b874b006b6e71184fed3911f40ed Mon Sep 17 00:00:00 2001 From: Samuel Lepetit Date: Tue, 5 Jun 2012 10:42:25 +0200 Subject: [PATCH] Add the forgotten bittorrent tesh file. Change the way pieces are chosen in updateCurrentPieces (using RngStream). --- examples/bittorrent/Peer.java | 7 +++++-- examples/bittorrent/Tracker.java | 1 - examples/bittorrent/bittorrent.tesh | 27 +++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 examples/bittorrent/bittorrent.tesh diff --git a/examples/bittorrent/Peer.java b/examples/bittorrent/Peer.java index 7e3fb8ce3e..c5a66533bb 100644 --- a/examples/bittorrent/Peer.java +++ b/examples/bittorrent/Peer.java @@ -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 diff --git a/examples/bittorrent/Tracker.java b/examples/bittorrent/Tracker.java index 537a3a5ed1..8f0d7f79fb 100644 --- a/examples/bittorrent/Tracker.java +++ b/examples/bittorrent/Tracker.java @@ -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 index 0000000000..3919b4920b --- /dev/null +++ b/examples/bittorrent/bittorrent.tesh @@ -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 + -- 2.20.1