mirror of
https://github.com/XeonSquared/OC-Copper.git
synced 2024-11-23 01:48:06 +11:00
Write docs on a possible broadcast extension and tune culib.lua some more.
This commit is contained in:
parent
47ec74bc89
commit
e77c203514
57
culib.lua
57
culib.lua
@ -28,13 +28,15 @@ return function (hostname, transmit, onReceive, time)
|
||||
-- before 'panic' is the best response?
|
||||
local tuningMaxSeenBeforeCountBeforeEmergencyFlush = 0x300
|
||||
|
||||
-- Expect a response by this many seconds,
|
||||
-- or else clear the known receivers cache and resend.
|
||||
local tuningExpectResponse = 120
|
||||
-- Expect another packet after this amount of time,
|
||||
-- or else clear the known receivers cache entry.
|
||||
local tuningExpectContinue = 600 + math.random(1200)
|
||||
|
||||
-- Flush the loop detector every so often.
|
||||
-- This is not a complete clear.
|
||||
local tuningFlushLoopDetector = 120
|
||||
local tuningFlushLoopDetector = 60
|
||||
|
||||
local tuningRandomPathwarming = 0.1
|
||||
|
||||
-- Do not change this value unless protocol has changed accordingly.
|
||||
local tuningAutorejectLen = 1506
|
||||
@ -50,12 +52,17 @@ return function (hostname, transmit, onReceive, time)
|
||||
local seenBeforeCount = 0
|
||||
|
||||
-- [address] = {
|
||||
-- node,
|
||||
-- expiry,
|
||||
-- broadcastOnExpire
|
||||
-- node, -- the node that a message was received from
|
||||
-- expiry
|
||||
-- }
|
||||
local lastKnownReceiver = {}
|
||||
|
||||
local function encodeName(name)
|
||||
if name:len() > 256 then error("Bad name (l>256)") end
|
||||
if name == "" then error("No name") end
|
||||
return string.char(name:len() - 1) .. name
|
||||
end
|
||||
|
||||
local function refresh()
|
||||
local t = time()
|
||||
if t >= loopDetectorNext then
|
||||
@ -72,11 +79,12 @@ return function (hostname, transmit, onReceive, time)
|
||||
end
|
||||
for k, v in pairs(lastKnownReceiver) do
|
||||
if t >= v[2] then
|
||||
print("It was decided LKV[" .. k .. "] was out of date @ " .. v[2])
|
||||
lastKnownReceiver[k] = nil
|
||||
for _, m in ipairs(v[3]) do
|
||||
transmit(nil, m)
|
||||
--print("It was decided LKV[" .. k .. "] was out of date @ " .. v[2] .. " by " .. hostname)
|
||||
-- Keep the transmission path 'warm' with a null packet
|
||||
if math.random() < tuningRandomPathwarming then
|
||||
transmit(nil, "\xFF" .. encodeName(hostname) .. encodeName(k))
|
||||
end
|
||||
lastKnownReceiver[k] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -85,6 +93,11 @@ return function (hostname, transmit, onReceive, time)
|
||||
|
||||
-- Can be changed.
|
||||
culib.hostname = hostname
|
||||
|
||||
-- Stats.
|
||||
culib.lkrCacheMisses = 0
|
||||
culib.lkrCacheHits = 0
|
||||
|
||||
culib.input = function (node, message)
|
||||
local t = time()
|
||||
|
||||
@ -122,19 +135,7 @@ return function (hostname, transmit, onReceive, time)
|
||||
return
|
||||
end
|
||||
|
||||
local restart = true
|
||||
if lastKnownReceiver[fnam] then
|
||||
if lastKnownReceiver[fnam][1] == node then
|
||||
restart = false
|
||||
-- allow frequently-used links to last longer
|
||||
lastKnownReceiver[fnam][2] = lastKnownReceiver[fnam][2] + tuningExpectResponse
|
||||
lastKnownReceiver[fnam][3] = {}
|
||||
end
|
||||
else
|
||||
end
|
||||
if restart then
|
||||
lastKnownReceiver[fnam] = {node, t + tuningExpectResponse, {}}
|
||||
end
|
||||
lastKnownReceiver[fnam] = {node, t + tuningExpectContinue}
|
||||
|
||||
onReceive(fnam, tnam, message)
|
||||
if culib.hostname == tnam then return end
|
||||
@ -148,17 +149,13 @@ return function (hostname, transmit, onReceive, time)
|
||||
|
||||
local lkr = lastKnownReceiver[tnam]
|
||||
if lkr then
|
||||
culib.lkrCacheHits = culib.lkrCacheHits + 1
|
||||
transmit(lkr[1], rawmessage)
|
||||
table.insert(lkr[3], rawmessage)
|
||||
else
|
||||
culib.lkrCacheMisses = culib.lkrCacheMisses + 1
|
||||
transmit(nil, rawmessage)
|
||||
end
|
||||
end
|
||||
local function encodeName(name)
|
||||
if name:len() > 256 then error("Bad name (l>256)") end
|
||||
if name == "" then error("No name") end
|
||||
return string.char(name:len() - 1) .. name
|
||||
end
|
||||
culib.refresh = refresh
|
||||
culib.output = function (fnam, tnam, message)
|
||||
onReceive(fnam, tnam, message)
|
||||
|
12
protocol.0
12
protocol.0
@ -38,3 +38,15 @@ Should a situation be dire enough,
|
||||
and custom routing software in general,
|
||||
can be used to split networks however the system requires.
|
||||
|
||||
--- The Broadcast Address
|
||||
|
||||
The Broadcast Address is a possible feature which may or may not be actually used.
|
||||
For now it is not implemented.
|
||||
The idea is that if a name is directly equal to "*", it should be broadcast around the local network.
|
||||
|
||||
Hierarchial gateways do not need modification on the from-child rules
|
||||
("*" is local to them there,
|
||||
"<*" or such is dealt with correctly by the normal rules),
|
||||
but in the from-parent rules it may be desirable to forward "*" to child networks.
|
||||
|
||||
Or not.
|
||||
|
@ -71,6 +71,7 @@ local function generateMessage()
|
||||
na = targetables[math.random(#targetables)]
|
||||
nb = targetables[math.random(#targetables)]
|
||||
end
|
||||
print(nodenames[na], nodenames[nb], getsystime())
|
||||
nodes[na].output(nodenames[na], nodenames[nb], "T" .. tostring(math.random()))
|
||||
end
|
||||
|
||||
@ -97,3 +98,10 @@ while (generateCount > 0) or (#queuedCalls > 0) do
|
||||
end
|
||||
|
||||
print(#nodes, statSD, statPT)
|
||||
|
||||
local maxMisses, maxHits = 0, 0
|
||||
for i = 1, #nodes do
|
||||
maxMisses = math.max(maxMisses, nodes[i].lkrCacheMisses)
|
||||
maxHits = math.max(maxHits, nodes[i].lkrCacheHits)
|
||||
end
|
||||
print(maxMisses, maxHits)
|
||||
|
Loading…
Reference in New Issue
Block a user