From: Christian Heinrich Date: Mon, 8 Jun 2015 22:47:03 +0000 (+0200) Subject: [Lua5.3] Updated bittorent/peer.lua to Lua5.3 X-Git-Tag: v3_13~1644^2~26 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/88acaee76ef609f9dc66ae15c1a02aece991ce18?hp=683a00ebf5feedf304c6e528562ceec2cb23b3db [Lua5.3] Updated bittorent/peer.lua to Lua5.3 --- diff --git a/examples/lua/bittorrent/peer.lua b/examples/lua/bittorrent/peer.lua index cda12eb0db..7166c004eb 100644 --- a/examples/lua/bittorrent/peer.lua +++ b/examples/lua/bittorrent/peer.lua @@ -98,32 +98,32 @@ function leech_loop() simgrid.info("Starting main leech loop") local task, err while now < data.deadline and data.pieces < common.FILE_PIECES do - task, err = data.comm_received:test() - if task then - handle_message(task) - data.comm_received = simgrid.task.irecv(data.mailbox) - now = simgrid.get_clock() - elseif err then - data.comm_received = simgrid.task.irecv(data.mailbox) - else - -- If the user has a pending interesting - if data.current_piece ~= -1 then - send_interested_to_peers() - else - if table.getn(data.current_pieces) < common.MAX_PIECES then - update_current_piece() - end - end - -- We don't execute the choke algorithm if we don't already have a piece - if now >= next_choked_update and data.pieces > 0 then - update_choked_peers() - next_choked_update = next_choked_update + common.UPDATE_CHOKED_INTERVAL - now = simgrid.get_clock() - else - simgrid.process.sleep(1) - now = simgrid.get_clock() - end - end + task, err = data.comm_received:test() + if task then + handle_message(task) + data.comm_received = simgrid.task.irecv(data.mailbox) + now = simgrid.get_clock() + elseif err then + data.comm_received = simgrid.task.irecv(data.mailbox) + else + -- If the user has a pending interesting + if data.current_piece ~= -1 then + send_interested_to_peers() + else + if #data.current_pieces < common.MAX_PIECES then + update_current_piece() + end + end + -- We don't execute the choke algorithm if we don't already have a piece + if now >= next_choked_update and data.pieces > 0 then + update_choked_peers() + next_choked_update = next_choked_update + common.UPDATE_CHOKED_INTERVAL + now = simgrid.get_clock() + else + simgrid.process.sleep(1) + now = simgrid.get_clock() + end + end end end -- Peer main loop when it is seeding @@ -427,6 +427,7 @@ function send_interested(mailbox) end -- Send a "not interested" message to a peer. function send_not_interested(mailbox) + simgrid.info("Sending a send_not_interested") local task = new_task("NOTINTERESTED") task:dsend(mailbox) end @@ -457,6 +458,7 @@ function send_unchoked(mailbox) end -- Send a "HAVE" message to all peers we are connected to function send_have(piece) + simgrid.debug("Sending a HAVE message") for i,v in pairs(data.peers) do local task = new_task("HAVE") task.piece = piece @@ -465,6 +467,7 @@ function send_have(piece) end -- Send request messages to a peer that have unchoked us function send_requests_to_peer(remote_peer) + simgrid.debug("Sending a request to peer " .. remote_peer.mailbox) for i,v in pairs(data.current_pieces) do send_request(remote_peer.mailbox,i) end