LKR cache improvements.

This commit is contained in:
Izaya 2017-09-05 19:06:24 +10:00
parent 437f65e0dc
commit e8bd168ad8

View File

@ -2,6 +2,9 @@ net = {}
net.id = computer.address():sub(1,8)
net.np = 4957
net.tm = {}
if not component.list("ocemu")() then
_G.LKR_CACHE = true
end
function net.send(id,po,msg) -- id, port, message
if id and po and msg then
event.push("sendmsg",id,po,msg)
@ -13,6 +16,12 @@ spawn("copperd",function() print(xpcall(function ()
local pt = {}
local ps = {}
local fcache = {}
local olog = log
local function log(...)
if COPPER_LOG then
olog(...)
end
end
for a,t in component.list("modem") do
table.insert(net.tm,component.proxy(a))
component.proxy(a).open(net.np)
@ -81,7 +90,6 @@ spawn("copperd",function() print(xpcall(function ()
if fcache[v.nid] and _G.LKR_CACHE then
local lma = fcache[v.nid][1]
local rma = fcache[v.nid][2]
print(lma,rma)
component.invoke(lma,"send",rma,net.np,"copper",cdlib.encode(0,net.id,v.nid,relib.encode(v)))
else
for l,m in ipairs(net.tm) do
@ -102,6 +110,11 @@ spawn("copperd",function() print(xpcall(function ()
pt[k] = nil
end
end
for k,v in pairs(fcache) do
if v[3] < cot - 60 then
fcache[k] = nil
end
end
end
end)) end)
end