Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[Lua] Fixed garbage collection segfault
[simgrid.git] / examples / lua / bittorrent / tracker.lua
index e662990..cdf3e3b 100644 (file)
@@ -1,3 +1,9 @@
+-- Copyright (c) 2012, 2014. The SimGrid Team.
+-- All rights reserved.
+
+-- This program is free software; you can redistribute it and/or modify it
+-- under the terms of the license (GNU LGPL) which comes with this package.
+
 -- A SimGrid Lua implementation of the Bittorrent protocol.
 
 require("simgrid")
@@ -41,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