added some better copper configuration stuff.

This commit is contained in:
Izaya 2017-09-09 21:22:58 +10:00
parent 74c9030668
commit a7be3ada0d
1 changed files with 9 additions and 5 deletions

View File

@ -1,9 +1,12 @@
net = {}
net.id = computer.address():sub(1,8)
net.np = 4957
net.cache = true
net.cache_time = 16
net.log = false
net.tm = {}
if not component.list("ocemu")() then
_G.LKR_CACHE = true
net.cache = true
end
function net.send(id,po,msg) -- id, port, message
if id and po and msg then
@ -18,7 +21,7 @@ spawn("copperd",function() print(xpcall(function ()
local fcache = {}
local olog = log
local function log(...)
if COPPER_LOG then
if net.log then
olog(...)
end
end
@ -73,7 +76,7 @@ spawn("copperd",function() print(xpcall(function ()
end
else
if hops < 255 then
if fcache[dst] and _G.LKR_CACHE then
if fcache[dst] and net.cache then
component.invoke(fcache[dst][1],"send",fcache[dst][2],net.np,"copper",cdlib.encode(hops+1,src,dst,data))
else
for k,v in ipairs(net.tm) do
@ -87,7 +90,7 @@ spawn("copperd",function() print(xpcall(function ()
end
for k,v in pairs(ps) do
if v.lt < os.time()-1 then
if fcache[v.nid] and _G.LKR_CACHE then
if fcache[v.nid] and net.cache then
local lma = fcache[v.nid][1]
local rma = fcache[v.nid][2]
component.invoke(lma,"send",rma,net.np,"copper",cdlib.encode(0,net.id,v.nid,relib.encode(v)))
@ -111,7 +114,8 @@ spawn("copperd",function() print(xpcall(function ()
end
end
for k,v in pairs(fcache) do
if v[3] < cot - 60 then
if v[3] < cot - net.cache_time then
log(k.." derezzed")
fcache[k] = nil
end
end