Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[Lua5.3] Updated lua/bittorent test to reflect changes
authorChristian Heinrich <franz-christian.heinrich@inria.fr>
Mon, 8 Jun 2015 16:05:04 +0000 (18:05 +0200)
committerChristian Heinrich <franz-christian.heinrich@inria.fr>
Thu, 15 Oct 2015 17:17:17 +0000 (19:17 +0200)
examples/lua/bittorrent/bittorrent.lua
examples/lua/bittorrent/peer.lua
examples/lua/bittorrent/tracker.lua

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
                                        peer_data.choked_upload = true
                                        peer_data.choked_download = true
-                                       data.peers[v] = peer_data
+                    data.peers[v] = peer_data
+                    simgrid.info("Added " .. v)
                                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
        elseif task.type == "PIECE" then
+        task.piece = math.tointeger(task.piece)
                if task.stalled == true then
                        simgrid.debug("The received piece is stalled")
                else
@@ -481,7 +492,7 @@ function send_piece(mailbox, piece, stalled)
        task:dsend(mailbox)     
 end
 function new_task(type)
-       local task = simgrid.task.new("", 0, common.MESSAGE_SIZE)
+       local task = simgrid.task.new(type, 0, common.MESSAGE_SIZE)
        task.type = type
        task.mailbox = data.mailbox
        task.peer_id = data.id  
index e39a2d9..cdf3e3b 100644 (file)
@@ -47,8 +47,8 @@ function tracker(...)
                        i = math.random(1,#tracker_data.peers_list)
                end
                while #peers < #tracker_data.peers_list and #peers < common_tracker.MAXIMUM_PEERS do
-                       table.insert(peers,tracker_data.peers_list[i])  
-                       i = (i + 1) % #tracker_data.peers_list
+                       table.insert(peers,tracker_data.peers_list[i])
+                       i = (i % #tracker_data.peers_list) +1
                end
                task.type = "ANSWER"
                task.peers = peers