Open Jajasek opened 3 years ago
I have done some more playtesting and revealed another 2, much more severe, mistakes.
local function processPacket(_,localModem,from,pport,_,packetID,packetType,dest,sender,vPort,data,...)
pruneCache()
if pport == cfg.port or pport == 0 then -- for linked cards
dprint(cfg.port,vPort,packetType,dest)
if checkPCache(packetID) then return end
dprint("rcache: "..sender..":", localModem,from,computer.uptime())
rcache[sender] = {localModem,from,computer.uptime()+cfg.rctime}
if dest:sub(1,1) == "~" then -- broadcasts start with ~
computer.pushSignal("net_broadcast",sender,vPort,data)
end
if dest == hostname then
if packetType == 1 then
sendPacket(genPacketID(),2,sender,hostname,vPort,packetID)
end
if packetType == 2 then
dprint("Dropping "..data.." from queue")
pqueue[data] = nil
computer.pushSignal("net_ack",data)
end
if packetType ~= 2 then
computer.pushSignal("net_msg",sender,vPort,data)
end
elseif cfg.route then -- repeat packets if route is enabled
sendPacket(packetID,packetType,dest,sender,vPort,data,localModem)
end
if not pcache[packetID] then -- add the packet ID to the pcache
pcache[packetID] = computer.uptime()+cfg.pctime
end
end
end
Thanks a lot for the fix!
Can you add this as a pull request?
rcache[dest][1]
is the same modem the packet arrived through, the packet should not be repeated. This could be solved by adding a condition in the function sendPacket (on line 119).rcache[sender] = {localModem,from,computer.uptime()+cfg.rctime}
should be executed for all packets. Therefore when 2 computers periodically communicate, the servers between them never forgot the route. Also, it should be executed before the ack packet is sent. I therefore suggest to move it before the line 172.