mirror of
https://github.com/XeonSquared/OC-Copper.git
synced 2024-11-08 10:58:10 +11:00
Relib bugfixes
Hopefully should just be in general *better* now
This commit is contained in:
parent
3497708747
commit
1cd7d82e98
38
relib.lua
38
relib.lua
@ -60,21 +60,22 @@ return function (hostname, transmit, onRReceive, time)
|
|||||||
local port = data:byte(2) + (data:byte(1) * 256)
|
local port = data:byte(2) + (data:byte(1) * 256)
|
||||||
local tp = data:byte(7)
|
local tp = data:byte(7)
|
||||||
local globalId = data:sub(1, 5)
|
local globalId = data:sub(1, 5)
|
||||||
if tp == 0x00 then
|
if (tp == 0x01) or (tp == 0x00) then
|
||||||
onRReceive(nfrom, nto, port, data:sub(8), true)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
if nto ~= node.hostname then return end
|
|
||||||
if (tp == 0x01) then
|
|
||||||
-- Only send one acknowledgement per packet,
|
-- Only send one acknowledgement per packet,
|
||||||
-- but only receive the packet once.
|
-- but only receive the packet once.
|
||||||
-- (This is why timers are counted - to prevent the weAcked pool from getting too big.)
|
-- (This is why timers are counted - to prevent the weAcked pool from getting too big.)
|
||||||
if not weAcked[nto .. globalId] then
|
if not weAcked[nto .. globalId] then
|
||||||
onRReceive(nfrom, nto, port, data:sub(8), false)
|
onRReceive(nfrom, nto, port, data:sub(8), tp == 0x00)
|
||||||
|
else
|
||||||
|
killTimer(weAcked[nto .. globalId])
|
||||||
end
|
end
|
||||||
weAcked[nto .. globalId] = addTimer(function ()
|
weAcked[nto .. globalId] = addTimer(function ()
|
||||||
weAcked[nto .. globalId] = nil
|
weAcked[nto .. globalId] = nil
|
||||||
end, tuningClearAntiduplicate)
|
end, tuningClearAntiduplicate)
|
||||||
|
|
||||||
|
-- Check if this should actually be ACKed
|
||||||
|
if tp ~= 0x01 then return end
|
||||||
|
if nto ~= node.hostname then return end
|
||||||
node.output(nto, nfrom, data:sub(1, 6) .. "\x02")
|
node.output(nto, nfrom, data:sub(1, 6) .. "\x02")
|
||||||
end
|
end
|
||||||
if (tp == 0x02) and needsAck[nfrom .. globalId] then
|
if (tp == 0x02) and needsAck[nfrom .. globalId] then
|
||||||
@ -114,8 +115,12 @@ return function (hostname, transmit, onRReceive, time)
|
|||||||
onSucceed = onSucceed or (function () end)
|
onSucceed = onSucceed or (function () end)
|
||||||
onFailure = onFailure or (function () end)
|
onFailure = onFailure or (function () end)
|
||||||
local gid = genGlobalId(port)
|
local gid = genGlobalId(port)
|
||||||
|
local tp = "\x01"
|
||||||
|
-- Unreliable packets:
|
||||||
|
-- 1. Can't be ACKed (not in the needsAck table)
|
||||||
|
-- 2. Are otherwise subject to the same rules as regular packets
|
||||||
if unreliable then
|
if unreliable then
|
||||||
node.output(node.hostname, nto, gid .. "\x00\x00" .. data)
|
tp = "\x00"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local na = {onSucceed}
|
local na = {onSucceed}
|
||||||
@ -124,13 +129,24 @@ return function (hostname, transmit, onRReceive, time)
|
|||||||
doAttempt = function ()
|
doAttempt = function ()
|
||||||
attempt = attempt + 1
|
attempt = attempt + 1
|
||||||
if attempt == tuningAttempts then
|
if attempt == tuningAttempts then
|
||||||
onFailure()
|
if not unreliable then
|
||||||
|
needsAck[nto .. gid] = nil
|
||||||
|
onFailure()
|
||||||
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
node.output(node.hostname, nto, gid .. string.char(attempt) .. "\x01" .. data)
|
node.output(node.hostname, nto, gid .. string.char(attempt) .. tp .. data)
|
||||||
na[2] = addTimer(doAttempt, tuningAttemptTime)
|
na[2] = addTimer(doAttempt, tuningAttemptTime)
|
||||||
|
if not na[2] then
|
||||||
|
needsAck[nto .. gid] = nil
|
||||||
|
if not unreliable then
|
||||||
|
onFailure()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not unreliable then
|
||||||
|
needsAck[nto .. gid] = na
|
||||||
end
|
end
|
||||||
needsAck[nto .. gid] = na
|
|
||||||
doAttempt()
|
doAttempt()
|
||||||
end
|
end
|
||||||
return relib
|
return relib
|
||||||
|
Loading…
Reference in New Issue
Block a user