mirror of
https://github.com/XeonSquared/OC-Copper.git
synced 2024-11-23 09:58: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?
|
-- before 'panic' is the best response?
|
||||||
local tuningMaxSeenBeforeCountBeforeEmergencyFlush = 0x300
|
local tuningMaxSeenBeforeCountBeforeEmergencyFlush = 0x300
|
||||||
|
|
||||||
-- Expect a response by this many seconds,
|
-- Expect another packet after this amount of time,
|
||||||
-- or else clear the known receivers cache and resend.
|
-- or else clear the known receivers cache entry.
|
||||||
local tuningExpectResponse = 120
|
local tuningExpectContinue = 600 + math.random(1200)
|
||||||
|
|
||||||
-- Flush the loop detector every so often.
|
-- Flush the loop detector every so often.
|
||||||
-- This is not a complete clear.
|
-- 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.
|
-- Do not change this value unless protocol has changed accordingly.
|
||||||
local tuningAutorejectLen = 1506
|
local tuningAutorejectLen = 1506
|
||||||
@ -50,12 +52,17 @@ return function (hostname, transmit, onReceive, time)
|
|||||||
local seenBeforeCount = 0
|
local seenBeforeCount = 0
|
||||||
|
|
||||||
-- [address] = {
|
-- [address] = {
|
||||||
-- node,
|
-- node, -- the node that a message was received from
|
||||||
-- expiry,
|
-- expiry
|
||||||
-- broadcastOnExpire
|
|
||||||
-- }
|
-- }
|
||||||
local lastKnownReceiver = {}
|
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 function refresh()
|
||||||
local t = time()
|
local t = time()
|
||||||
if t >= loopDetectorNext then
|
if t >= loopDetectorNext then
|
||||||
@ -72,11 +79,12 @@ return function (hostname, transmit, onReceive, time)
|
|||||||
end
|
end
|
||||||
for k, v in pairs(lastKnownReceiver) do
|
for k, v in pairs(lastKnownReceiver) do
|
||||||
if t >= v[2] then
|
if t >= v[2] then
|
||||||
print("It was decided LKV[" .. k .. "] was out of date @ " .. v[2])
|
--print("It was decided LKV[" .. k .. "] was out of date @ " .. v[2] .. " by " .. hostname)
|
||||||
lastKnownReceiver[k] = nil
|
-- Keep the transmission path 'warm' with a null packet
|
||||||
for _, m in ipairs(v[3]) do
|
if math.random() < tuningRandomPathwarming then
|
||||||
transmit(nil, m)
|
transmit(nil, "\xFF" .. encodeName(hostname) .. encodeName(k))
|
||||||
end
|
end
|
||||||
|
lastKnownReceiver[k] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -85,6 +93,11 @@ return function (hostname, transmit, onReceive, time)
|
|||||||
|
|
||||||
-- Can be changed.
|
-- Can be changed.
|
||||||
culib.hostname = hostname
|
culib.hostname = hostname
|
||||||
|
|
||||||
|
-- Stats.
|
||||||
|
culib.lkrCacheMisses = 0
|
||||||
|
culib.lkrCacheHits = 0
|
||||||
|
|
||||||
culib.input = function (node, message)
|
culib.input = function (node, message)
|
||||||
local t = time()
|
local t = time()
|
||||||
|
|
||||||
@ -122,19 +135,7 @@ return function (hostname, transmit, onReceive, time)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local restart = true
|
lastKnownReceiver[fnam] = {node, t + tuningExpectContinue}
|
||||||
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
|
|
||||||
|
|
||||||
onReceive(fnam, tnam, message)
|
onReceive(fnam, tnam, message)
|
||||||
if culib.hostname == tnam then return end
|
if culib.hostname == tnam then return end
|
||||||
@ -148,17 +149,13 @@ return function (hostname, transmit, onReceive, time)
|
|||||||
|
|
||||||
local lkr = lastKnownReceiver[tnam]
|
local lkr = lastKnownReceiver[tnam]
|
||||||
if lkr then
|
if lkr then
|
||||||
|
culib.lkrCacheHits = culib.lkrCacheHits + 1
|
||||||
transmit(lkr[1], rawmessage)
|
transmit(lkr[1], rawmessage)
|
||||||
table.insert(lkr[3], rawmessage)
|
|
||||||
else
|
else
|
||||||
|
culib.lkrCacheMisses = culib.lkrCacheMisses + 1
|
||||||
transmit(nil, rawmessage)
|
transmit(nil, rawmessage)
|
||||||
end
|
end
|
||||||
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.refresh = refresh
|
||||||
culib.output = function (fnam, tnam, message)
|
culib.output = function (fnam, tnam, message)
|
||||||
onReceive(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,
|
and custom routing software in general,
|
||||||
can be used to split networks however the system requires.
|
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)]
|
na = targetables[math.random(#targetables)]
|
||||||
nb = targetables[math.random(#targetables)]
|
nb = targetables[math.random(#targetables)]
|
||||||
end
|
end
|
||||||
|
print(nodenames[na], nodenames[nb], getsystime())
|
||||||
nodes[na].output(nodenames[na], nodenames[nb], "T" .. tostring(math.random()))
|
nodes[na].output(nodenames[na], nodenames[nb], "T" .. tostring(math.random()))
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -97,3 +98,10 @@ while (generateCount > 0) or (#queuedCalls > 0) do
|
|||||||
end
|
end
|
||||||
|
|
||||||
print(#nodes, statSD, statPT)
|
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