Algorithmique Numérique Distribuée Public GIT Repository
 author Christian Heinrich Mon, 8 Jun 2015 16:05:04 +0000 (18:05 +0200) committer Christian Heinrich Thu, 15 Oct 2015 17:17:17 +0000 (19:17 +0200)

index 7be4395..0570ef0 100644 (file)
@@ -11,6 +11,9 @@ require("simgrid")
require("peer")
require("tracker")

-simgrid.platform(arg[1] or  "../../platforms/platform.xml")
-simgrid.application(arg[2] or "bittorrent.xml")
+-- Initialization of the random generator
+table.sort(math)
+math.randomseed(42)
+simgrid.platform("../../platforms/platform.xml")
+simgrid.application("bittorrent.xml")
simgrid.run()
index 496af85..cda12eb 100644 (file)
@@ -183,16 +183,26 @@ function get_peers_data()
if v ~= data.id then
--Add the peer to our list and build its data
local peer_data = {}
-                                       peer_data.id = v;
+                                       peer_data.id = math.tointeger(v);
peer_data.bitfield = nil
-                                       peer_data.mailbox = tostring(v);
+                                       peer_data.mailbox = math.tointeger(v);
peer_data.am_interested = false
peer_data.interested = false
-                                       data.peers[v] = peer_data
+                    data.peers[v] = peer_data
end
end
+            mt = {}
+            mt.__len = function(obj)
+                local len = 0;
+                for j,k in pairs(obj) do
+                    len = len+1
+                end
+                return len
+            end
+            setmetatable(data.peers, mt)
else
success = false
end
@@ -276,6 +286,7 @@ function handle_message(task)
end
end
else
@@ -481,7 +492,7 @@ function send_piece(mailbox, piece, stalled)
end