- 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