mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-16 02:39:48 -04:00
Merge branch 'master-MC1.7.10' of github.com:MightyPirates/OpenComputers into master-MC1.7.10
This commit is contained in:
commit
ebb60e3213
@ -32,13 +32,13 @@ local mcnetTransportTypes = {
|
|||||||
|
|
||||||
local mcnetTypes = {
|
local mcnetTypes = {
|
||||||
["H"] = function(localAddress, remoteAddress, data)
|
["H"] = function(localAddress, remoteAddress, data)
|
||||||
local ttl, age, n = string.unpack(">BH", data)
|
local ttl, age, dist, n = string.unpack(">BHB", data)
|
||||||
local host = data:sub(n)
|
local host = data:sub(n)
|
||||||
print("\t>> L2 mcnet HOST_FOUND ttl=" .. ttl .. " age=" .. age .. " host=" .. host)
|
print("\t>> L2 mcnet HOST_FOUND ttl=" .. ttl .. " age=" .. age .. " dist=" .. dist .. " host=" .. normLine(host))
|
||||||
end,
|
end,
|
||||||
["R"] = function(localAddress, remoteAddress, data)
|
["R"] = function(localAddress, remoteAddress, data)
|
||||||
local ttl, dest, age = string.unpack(">Bs1H", data)
|
local ttl, dest, age = string.unpack(">Bs1H", data)
|
||||||
print("\t>> L2 mcnet SEEK_ROUTE ttl=" .. ttl .. " age=" .. age .. " dest=" .. dest)
|
print("\t>> L2 mcnet SEEK_ROUTE ttl=" .. ttl .. " age=" .. age .. " dest=" .. normLine(dest))
|
||||||
end,
|
end,
|
||||||
["D"] = function(localAddress, remoteAddress, data)
|
["D"] = function(localAddress, remoteAddress, data)
|
||||||
local ttl = string.unpack(">B", data)
|
local ttl = string.unpack(">B", data)
|
||||||
@ -52,7 +52,7 @@ local mcnetTypes = {
|
|||||||
["E"] = function(localAddress, remoteAddress, data)
|
["E"] = function(localAddress, remoteAddress, data)
|
||||||
local ttl, dest, orig, dstart = string.unpack(">Bs1s1", data)
|
local ttl, dest, orig, dstart = string.unpack(">Bs1s1", data)
|
||||||
local dat = data:sub(dstart)
|
local dat = data:sub(dstart)
|
||||||
print("\t>> L2 mcnet ROUTED_DATA ttl=" .. ttl .. " dest=" .. dest .. " origin=" .. orig)
|
print("\t>> L2 mcnet ROUTED_DATA ttl=" .. ttl .. " dest=" .. normLine(dest) .. " origin=" .. orig)
|
||||||
if mcnetTransportTypes[dat:sub(1,1)] then
|
if mcnetTransportTypes[dat:sub(1,1)] then
|
||||||
mcnetTransportTypes[dat:sub(1,1)](localAddress, remoteAddress, dat:sub(2))
|
mcnetTransportTypes[dat:sub(1,1)](localAddress, remoteAddress, dat:sub(2))
|
||||||
else
|
else
|
||||||
@ -62,7 +62,10 @@ local mcnetTypes = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
local ethTypes = {
|
local ethTypes = {
|
||||||
["\0"] = function(localAddress, remoteAddress, msg) --PKT_BEACON
|
["\0"] = function(localAddress, remoteAddress, msg) --PKT_BEACON_OLD
|
||||||
|
print("\t> L1 PKT_OLD_BEACON remote=" .. remoteAddress)
|
||||||
|
end,
|
||||||
|
["\32"] = function(localAddress, remoteAddress, msg) --PKT_BEACON
|
||||||
print("\t> L1 PKT_BEACON remote=" .. remoteAddress)
|
print("\t> L1 PKT_BEACON remote=" .. remoteAddress)
|
||||||
end,
|
end,
|
||||||
["\1"] = function(localAddress, remoteAddress, msg) --PKT_REGISTER
|
["\1"] = function(localAddress, remoteAddress, msg) --PKT_REGISTER
|
||||||
@ -82,6 +85,7 @@ local ethTypes = {
|
|||||||
["\3"] = function(localAddress, remoteAddress, msg) --PKT_QUIT
|
["\3"] = function(localAddress, remoteAddress, msg) --PKT_QUIT
|
||||||
print("\t> L1 PKT_QUIT remote=" .. remoteAddress)
|
print("\t> L1 PKT_QUIT remote=" .. remoteAddress)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function dataExpanders.modem_message(_, localAddress, remoteAddress, port, distance, msg)
|
function dataExpanders.modem_message(_, localAddress, remoteAddress, port, distance, msg)
|
||||||
|
@ -320,11 +320,12 @@ end
|
|||||||
control["!"] = function(char) --Disable
|
control["!"] = function(char) --Disable
|
||||||
if commandMode == "9" then
|
if commandMode == "9" then
|
||||||
charHandlers.active = function(c)
|
charHandlers.active = function(c)
|
||||||
if c == "\255" then
|
if c == "\255" or c == "!" then
|
||||||
commandList = {}
|
commandList = {}
|
||||||
commandBuf = ""
|
commandBuf = ""
|
||||||
commandMode = ""
|
commandMode = ""
|
||||||
charHandlers.active = charHandlers.base
|
charHandlers.active = charHandlers.base
|
||||||
|
blink = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
blink = false
|
blink = false
|
||||||
|
@ -66,6 +66,7 @@ local distros = {
|
|||||||
{desc = "[online] Plan9k - lightest, experimental", params = {"-SYy", "plan9k"}},
|
{desc = "[online] Plan9k - lightest, experimental", params = {"-SYy", "plan9k"}},
|
||||||
{desc = "[online] Plan9k-extra - experimental, contains tools, docs", params = {"-SYy", "plan9k-extra", "plan9k-docs"}},
|
{desc = "[online] Plan9k-extra - experimental, contains tools, docs", params = {"-SYy", "plan9k-extra", "plan9k-docs"}},
|
||||||
{desc = "[online] StarOS - Plan9k-extra distro with additional tools", params = {"-SYy", "staros"}},
|
{desc = "[online] StarOS - Plan9k-extra distro with additional tools", params = {"-SYy", "staros"}},
|
||||||
|
{desc = "[online] Update - update installed system", params = {"--mirror=/", "-uyY"}},
|
||||||
}
|
}
|
||||||
|
|
||||||
for n, dist in pairs(distros) do
|
for n, dist in pairs(distros) do
|
||||||
|
@ -7,26 +7,38 @@ local function fillText(text, n)
|
|||||||
return text
|
return text
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function normLine(data)
|
||||||
|
local res = ""
|
||||||
|
for c in data:gmatch(".") do
|
||||||
|
if c == "\n" or c == "\r" then c = "\x1b[31m.\x1b[39m" end
|
||||||
|
res = res .. (c:match("[%g%s]") or "\x1b[31m.\x1b[39m")
|
||||||
|
end
|
||||||
|
return res
|
||||||
|
end
|
||||||
|
|
||||||
print("MCNET routing table")
|
print("MCNET routing table")
|
||||||
local routes = network.info.getRoutes()
|
local routes = network.info.getRoutes()
|
||||||
local maxlen = {12, 8, 6, 4}
|
local maxlen = {12, 8, 6, 4, 5}
|
||||||
|
|
||||||
for host, route in pairs(routes) do
|
for host, route in pairs(routes) do
|
||||||
maxlen[1] = maxlen[1] < #host+1 and #host+1 or maxlen[1]
|
maxlen[1] = maxlen[1] < #normLine(host)+1 and #normLine(host)+1 or maxlen[1]
|
||||||
maxlen[2] = maxlen[2] < #route.router+1 and #route.router+1 or maxlen[2]
|
maxlen[2] = maxlen[2] < #route.router+1 and #route.router+1 or maxlen[2]
|
||||||
maxlen[3] = maxlen[3] < #route.interface+1 and #route.interface+1 or maxlen[3]
|
maxlen[3] = maxlen[3] < #route.interface+1 and #route.interface+1 or maxlen[3]
|
||||||
maxlen[4] = maxlen[4] < #tostring(route.age)+1 and #tostring(route.age)+1 or maxlen[4]
|
maxlen[4] = maxlen[4] < #tostring(route.age)+1 and #tostring(route.age)+1 or maxlen[4]
|
||||||
|
maxlen[5] = maxlen[5] < #tostring(route.dist)+1 and #tostring(route.dist)+1 or maxlen[5]
|
||||||
end
|
end
|
||||||
|
|
||||||
print(fillText("Destination", maxlen[1])..
|
print(fillText("Destination", maxlen[1])..
|
||||||
fillText("Gateway", maxlen[2])..
|
fillText("Gateway", maxlen[2])..
|
||||||
fillText("Iface", maxlen[3])..
|
fillText("Iface", maxlen[3])..
|
||||||
fillText("Age", maxlen[4]))
|
fillText("Age", maxlen[4])..
|
||||||
|
fillText("Dist", maxlen[5]))
|
||||||
|
|
||||||
for host, route in pairs(routes) do
|
for host, route in pairs(routes) do
|
||||||
print(fillText(host, maxlen[1])..
|
print(fillText(normLine(host), maxlen[1])..
|
||||||
fillText(route.router, maxlen[2])..
|
fillText(route.router, maxlen[2])..
|
||||||
fillText(route.interface, maxlen[3])..
|
fillText(route.interface, maxlen[3])..
|
||||||
fillText(tostring(route.age), maxlen[4]))
|
fillText(tostring(route.age), maxlen[4])..
|
||||||
|
fillText(tostring(route.dist), maxlen[5]))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,18 +1,48 @@
|
|||||||
local shell = require("shell")
|
local shell = require("shell")
|
||||||
local kernel = require("pipes")
|
local kernel = require("pipes")
|
||||||
|
local component = require("component")
|
||||||
|
|
||||||
local args, options = shell.parse(...)
|
local args = {...}
|
||||||
|
local options = {}
|
||||||
|
|
||||||
|
for _, v in ipairs(args) do
|
||||||
|
if v:sub(1,2) == "--" then
|
||||||
|
options[v:sub(3)] = true
|
||||||
|
elseif v:sub(1,1) == "-" then
|
||||||
|
options[v:sub(2)] = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if options.h or options.help then
|
if options.h or options.help then
|
||||||
print([[sandbox {-m,-s} [file]
|
print([[sandbox [flow] [spawn [file] [args Nargs ...] ]...
|
||||||
Sandbox a process
|
Sandbox a processes/process tree
|
||||||
-m, --module - sandbox modules
|
Options:
|
||||||
-s, --signal - sandbox signals
|
-h --help - this help
|
||||||
|
Commands:
|
||||||
|
spawn file [args Nargs ...] - spawn process
|
||||||
|
join - wait for last process to finish
|
||||||
|
module - create module cgroup
|
||||||
|
component - create component cgroup
|
||||||
|
befor this command put:
|
||||||
|
wl [addr] - whitelist a component
|
||||||
|
bl [addr] - blacklist a component
|
||||||
|
quietin, quietout, quieterr - disable stdin/out/err
|
||||||
|
Example usages:
|
||||||
|
sandbox module spawn /usr/bin/myprog.lua args 3 hello 123 world join
|
||||||
|
- Spawns myprog in new module cgroup with 3 arguments and wait for it
|
||||||
|
sandbox module spawn /bin/a.lua spawn /bin/b.lua
|
||||||
|
- Spawns 2 programs in new common module cgroup
|
||||||
|
sandbox bl 0ab component spawn /bin/a.lua
|
||||||
|
- Spawn process with disallowed access to componet starting with address 0ab
|
||||||
|
sandbox wl fc0 wl fcd component spawn /bin/a.lua
|
||||||
|
- Spawns process wich can only acces 2 specified components
|
||||||
|
sandbox -b quietin quietout /bin/a.lua
|
||||||
|
- Spawns process in background
|
||||||
]])
|
]])
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--[[
|
||||||
local program = os.getenv("SHELL") or "/bin/sh.lua"
|
local program = os.getenv("SHELL") or "/bin/sh.lua"
|
||||||
|
|
||||||
if #args > 0 then
|
if #args > 0 then
|
||||||
@ -27,3 +57,55 @@ end
|
|||||||
local pid = os.spawn(program, table.unpack(args))
|
local pid = os.spawn(program, table.unpack(args))
|
||||||
|
|
||||||
kernel.joinThread(pid)
|
kernel.joinThread(pid)
|
||||||
|
]]
|
||||||
|
|
||||||
|
local lastpid = nil
|
||||||
|
local stdin = io.stdin
|
||||||
|
local stdout = io.stdout
|
||||||
|
local stderr = io.stderr
|
||||||
|
|
||||||
|
local module
|
||||||
|
local componentcg
|
||||||
|
local wl = nil
|
||||||
|
local bl = nil
|
||||||
|
local n =1
|
||||||
|
while n <= #args do
|
||||||
|
if args[n]:sub(1,1) == "-" then
|
||||||
|
elseif args[n] == "spawn" then
|
||||||
|
local name = args[n + 1]
|
||||||
|
local arg = {}
|
||||||
|
if args[n+2] == "args" then
|
||||||
|
local narg = tonumber(args[n + 3])
|
||||||
|
for i = 1, narg do
|
||||||
|
arg[#arg + 1]= args[n + 3 + i]
|
||||||
|
end
|
||||||
|
n = n + 2 + narg
|
||||||
|
end
|
||||||
|
n = n + 1
|
||||||
|
lastpid = os.spawnp(name, stdin, stdout, stderr, table.unpack(arg))
|
||||||
|
elseif args[n] == "join" then
|
||||||
|
kernel.joinThread(lastpid)
|
||||||
|
elseif args[n] == "quietin" then
|
||||||
|
stdin = io.open("/dev/null", "r")
|
||||||
|
elseif args[n] == "quietout" then
|
||||||
|
stdout = io.open("/dev/null", "w")
|
||||||
|
elseif args[n] == "quieterr" then
|
||||||
|
stderr = io.open("/dev/null", "w")
|
||||||
|
elseif args[n] == "module" then
|
||||||
|
module = kernel.setns(kernel.getPid(), "module")
|
||||||
|
elseif args[n] == "wl" then
|
||||||
|
if not wl then wl = {} end
|
||||||
|
wl[component.get(args[n + 1])] = true
|
||||||
|
n = n + 1
|
||||||
|
elseif args[n] == "bl" then
|
||||||
|
if not bl then bl = {} end
|
||||||
|
bl[component.get(args[n + 1])] = true
|
||||||
|
n = n + 1
|
||||||
|
elseif args[n] == "component" then
|
||||||
|
componentcg = kernel.setns(kernel.getPid(), "component", wl, bl)
|
||||||
|
else
|
||||||
|
print("Unknown command '"..args[n] .."'")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
n = n + 1
|
||||||
|
end
|
||||||
|
@ -310,6 +310,12 @@ builtin.alias("....", "cd", "../../..")
|
|||||||
-------------------
|
-------------------
|
||||||
-- Main loop
|
-- Main loop
|
||||||
|
|
||||||
|
if fs.exists("~/.shrc") then
|
||||||
|
for line in io.lines("~/.shrc") do
|
||||||
|
execute(line)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
while run do
|
while run do
|
||||||
--if term.getCursor() > 1 then
|
--if term.getCursor() > 1 then
|
||||||
-- io.write("\n")
|
-- io.write("\n")
|
||||||
|
@ -1 +0,0 @@
|
|||||||
enabled = {}
|
|
@ -1,8 +1,99 @@
|
|||||||
local component = kernel._K.component
|
local rawComponent = kernel._K.component
|
||||||
|
component = {}
|
||||||
|
|
||||||
local adding = {}
|
kernel.userspace.component = component
|
||||||
local removing = {}
|
kernel._K.component = component
|
||||||
local primaries = {}
|
|
||||||
|
kernelGroup = {
|
||||||
|
adding = {},
|
||||||
|
removing = {},
|
||||||
|
primaries = {},
|
||||||
|
}
|
||||||
|
|
||||||
|
local function getGroup()
|
||||||
|
return kernel.modules.threading.currentThread and kernel.modules.threading.currentThread.cgroups.component or kernelGroup
|
||||||
|
end
|
||||||
|
|
||||||
|
local function allow(addr)
|
||||||
|
if not kernel.modules.threading then return true end
|
||||||
|
return not kernel.modules.threading.currentThread or kernel.modules.threading.currentThread.cgroups.component.allow(addr)
|
||||||
|
end
|
||||||
|
|
||||||
|
component.doc = function(addr, method)
|
||||||
|
if allow(addr) then
|
||||||
|
return rawComponent.doc(addr, method)
|
||||||
|
else
|
||||||
|
error("no such component")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
component.invoke = function(addr, ...)
|
||||||
|
if allow(addr) then
|
||||||
|
return rawComponent.invoke(addr, ...)
|
||||||
|
else
|
||||||
|
error("no such component")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
component.list = function(filter, exact)
|
||||||
|
local list = {}
|
||||||
|
for k, v in pairs(rawComponent.list(filter, not not exact)) do
|
||||||
|
if allow(k) then
|
||||||
|
list[k] = v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local key = nil
|
||||||
|
return setmetatable(list, {__call=function()
|
||||||
|
key = next(list, key)
|
||||||
|
if key then
|
||||||
|
return key, list[key]
|
||||||
|
end
|
||||||
|
end})
|
||||||
|
end
|
||||||
|
|
||||||
|
component.methods = function(addr)
|
||||||
|
if allow(addr) then
|
||||||
|
return rawComponent.methods(addr)
|
||||||
|
else
|
||||||
|
return nil, "no such component"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
component.fields = function(addr)
|
||||||
|
if allow(addr) then
|
||||||
|
return rawComponent.fields(addr)
|
||||||
|
else
|
||||||
|
return nil, "no such component"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
component.proxy = function(addr)
|
||||||
|
if allow(addr) then
|
||||||
|
return rawComponent.proxy(addr)
|
||||||
|
else
|
||||||
|
return nil, "no such component"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
component.type = function(addr)
|
||||||
|
if allow(addr) then
|
||||||
|
return rawComponent.type(addr)
|
||||||
|
else
|
||||||
|
return nil, "no such component"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
component.slot = function(addr)
|
||||||
|
if allow(addr) then
|
||||||
|
return rawComponent.slot(addr)
|
||||||
|
else
|
||||||
|
return nil, "no such component"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--local adding = {}
|
||||||
|
--local removing = {}
|
||||||
|
--local primaries = {}
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -16,12 +107,12 @@ setmetatable(component, {
|
|||||||
local parent = false
|
local parent = false
|
||||||
return function(_, key)
|
return function(_, key)
|
||||||
if parent then
|
if parent then
|
||||||
return next(primaries, key)
|
return next(getGroup().primaries, key)
|
||||||
else
|
else
|
||||||
local k, v = next(self, key)
|
local k, v = next(self, key)
|
||||||
if not k then
|
if not k then
|
||||||
parent = true
|
parent = true
|
||||||
return next(primaries)
|
return next(getGroup().primaries)
|
||||||
else
|
else
|
||||||
return k, v
|
return k, v
|
||||||
end
|
end
|
||||||
@ -43,20 +134,20 @@ end
|
|||||||
|
|
||||||
function component.isAvailable(componentType)
|
function component.isAvailable(componentType)
|
||||||
checkArg(1, componentType, "string")
|
checkArg(1, componentType, "string")
|
||||||
if not primaries[componentType] and not adding[componentType] then
|
if not getGroup().primaries[componentType] and not getGroup().adding[componentType] then
|
||||||
-- This is mostly to avoid out of memory errors preventing proxy
|
-- This is mostly to avoid out of memory errors preventing proxy
|
||||||
-- creation cause confusion by trying to create the proxy again,
|
-- creation cause confusion by trying to create the proxy again,
|
||||||
-- causing the oom error to be thrown again.
|
-- causing the oom error to be thrown again.
|
||||||
component.setPrimary(componentType, component.list(componentType, true)())
|
component.setPrimary(componentType, component.list(componentType, true)())
|
||||||
end
|
end
|
||||||
return primaries[componentType] ~= nil
|
return getGroup().primaries[componentType] ~= nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function component.isPrimary(address)
|
function component.isPrimary(address)
|
||||||
local componentType = component.type(address)
|
local componentType = component.type(address)
|
||||||
if componentType then
|
if componentType then
|
||||||
if component.isAvailable(componentType) then
|
if component.isAvailable(componentType) then
|
||||||
return primaries[componentType].address == address
|
return getGroup().primaries[componentType].address == address
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
@ -66,7 +157,7 @@ function component.getPrimary(componentType)
|
|||||||
checkArg(1, componentType, "string")
|
checkArg(1, componentType, "string")
|
||||||
assert(component.isAvailable(componentType),
|
assert(component.isAvailable(componentType),
|
||||||
"no primary '" .. componentType .. "' available")
|
"no primary '" .. componentType .. "' available")
|
||||||
return primaries[componentType]
|
return getGroup().primaries[componentType]
|
||||||
end
|
end
|
||||||
|
|
||||||
function component.setPrimary(componentType, address)
|
function component.setPrimary(componentType, address)
|
||||||
@ -77,19 +168,19 @@ function component.setPrimary(componentType, address)
|
|||||||
assert(address, "no such component")
|
assert(address, "no such component")
|
||||||
end
|
end
|
||||||
|
|
||||||
local wasAvailable = primaries[componentType]
|
local wasAvailable = getGroup().primaries[componentType]
|
||||||
if wasAvailable and address == wasAvailable.address then
|
if wasAvailable and address == wasAvailable.address then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local wasAdding = adding[componentType]
|
local wasAdding = getGroup().adding[componentType]
|
||||||
if wasAdding and address == wasAdding.address then
|
if wasAdding and address == wasAdding.address then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if wasAdding then
|
if wasAdding then
|
||||||
kernel.modules.timer.remove(wasAdding.timer)
|
kernel.modules.timer.remove(wasAdding.timer)
|
||||||
end
|
end
|
||||||
primaries[componentType] = nil
|
getGroup().primaries[componentType] = nil
|
||||||
adding[componentType] = nil
|
getGroup().adding[componentType] = nil
|
||||||
|
|
||||||
local primary = address and component.proxy(address) or nil
|
local primary = address and component.proxy(address) or nil
|
||||||
if wasAvailable then
|
if wasAvailable then
|
||||||
@ -97,16 +188,16 @@ function component.setPrimary(componentType, address)
|
|||||||
end
|
end
|
||||||
if primary then
|
if primary then
|
||||||
if wasAvailable or wasAdding then
|
if wasAvailable or wasAdding then
|
||||||
adding[componentType] = {
|
getGroup().adding[componentType] = {
|
||||||
address=address,
|
address=address,
|
||||||
timer=kernel.modules.timer.add(function()
|
timer=kernel.modules.timer.add(function()
|
||||||
adding[componentType] = nil
|
getGroup().adding[componentType] = nil
|
||||||
primaries[componentType] = primary
|
getGroup().primaries[componentType] = primary
|
||||||
--computer.pushSignal("component_available", componentType)
|
--computer.pushSignal("component_available", componentType)
|
||||||
end, 0.1)
|
end, 0.1)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
primaries[componentType] = primary
|
getGroup().primaries[componentType] = primary
|
||||||
computer.pushSignal("component_available", componentType)
|
computer.pushSignal("component_available", componentType)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -124,14 +215,14 @@ function start()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function onComponentAdded(_, address, componentType)
|
local function onComponentAdded(_, address, componentType)
|
||||||
if not (primaries[componentType] or adding[componentType]) then
|
if not (getGroup().primaries[componentType] or getGroup().adding[componentType]) then
|
||||||
component.setPrimary(componentType, address)
|
component.setPrimary(componentType, address)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function onComponentRemoved(_, address, componentType)
|
local function onComponentRemoved(_, address, componentType)
|
||||||
if primaries[componentType] and primaries[componentType].address == address or
|
if getGroup().primaries[componentType] and getGroup().primaries[componentType].address == address or
|
||||||
adding[componentType] and adding[componentType].address == address
|
getGroup().adding[componentType] and getGroup().adding[componentType].address == address
|
||||||
then
|
then
|
||||||
component.setPrimary(componentType, component.list(componentType, true)())
|
component.setPrimary(componentType, component.list(componentType, true)())
|
||||||
end
|
end
|
||||||
|
@ -192,7 +192,7 @@ kernel.userspace.io = io
|
|||||||
|
|
||||||
setmetatable(io, {__index = function(_, k)
|
setmetatable(io, {__index = function(_, k)
|
||||||
if k == "stdout" then return io.output()
|
if k == "stdout" then return io.output()
|
||||||
elseif k == "stdout" then return io.output()
|
elseif k == "stdin" then return io.input()
|
||||||
elseif k == "stderr" then return kernel.modules.threading.currentThread.io_error
|
elseif k == "stderr" then return kernel.modules.threading.currentThread.io_error
|
||||||
end
|
end
|
||||||
end})
|
end})
|
||||||
|
@ -178,10 +178,10 @@ startNetwork = function()
|
|||||||
sent = nil
|
sent = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local function sendHostFound(dest, age, addr)--H[ttl-byte][age-short][Found host]
|
local function sendHostFound(dest, age, addr, dist)--H[ttl-byte][age-short][distance][Found host]
|
||||||
--kernel.io.println("found "..addr.." for "..dest)
|
--kernel.io.println("found "..addr.." for "..dest)
|
||||||
if dest ~= "localhost" then
|
if dest ~= "localhost" then
|
||||||
return rawSend(dest, "H"..string.pack(">BH", cfg.ttl, math.floor(age + cfg.route_relayage))..addr)
|
return rawSend(dest, "H"..string.pack(">BHB", cfg.ttl, math.floor(age + cfg.route_relayage), dist)..addr)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -218,7 +218,7 @@ startNetwork = function()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function processRouteRequests(host, age)
|
local function processRouteRequests(host, age, dist)
|
||||||
if routeRequests[host] then
|
if routeRequests[host] then
|
||||||
age = age or (computer.uptime() - routeRequests[host].timeout)
|
age = age or (computer.uptime() - routeRequests[host].timeout)
|
||||||
for t, request in pairs(routeRequests[host]) do
|
for t, request in pairs(routeRequests[host]) do
|
||||||
@ -230,7 +230,7 @@ startNetwork = function()
|
|||||||
sendRoutedDataAs(host, request.origin, request.data, request.ttl)
|
sendRoutedDataAs(host, request.origin, request.data, request.ttl)
|
||||||
end
|
end
|
||||||
elseif request.type == "R" then
|
elseif request.type == "R" then
|
||||||
sendHostFound(request.host, age, host)
|
sendHostFound(request.host, age, host, dist or 1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -249,8 +249,8 @@ startNetwork = function()
|
|||||||
end
|
end
|
||||||
|
|
||||||
bindAddr = function(addr)
|
bindAddr = function(addr)
|
||||||
routes[addr] = {thisHost=true}
|
routes[addr] = {thisHost=true, dist = 0}
|
||||||
processRouteRequests(addr, 0)
|
processRouteRequests(addr, 0, 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
kernel.modules.keventd.listen("hostname", function(_, name) bindAddr(name)end)
|
kernel.modules.keventd.listen("hostname", function(_, name) bindAddr(name)end)
|
||||||
@ -307,7 +307,7 @@ startNetwork = function()
|
|||||||
for host in pairs(n.hosts)do
|
for host in pairs(n.hosts)do
|
||||||
if host == dest then
|
if host == dest then
|
||||||
--Found it!
|
--Found it!
|
||||||
sendHostFound(origin, 0, dest)
|
sendHostFound(origin, 0, dest, 1)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -318,9 +318,9 @@ startNetwork = function()
|
|||||||
if routes[dest] then
|
if routes[dest] then
|
||||||
if routes[dest].thisHost then
|
if routes[dest].thisHost then
|
||||||
--sendHostFound(origin, nodes[node].selfAddr)
|
--sendHostFound(origin, nodes[node].selfAddr)
|
||||||
sendHostFound(origin, 0 ,dest)
|
sendHostFound(origin, 0 , dest, 1)
|
||||||
elseif routes[dest].router ~= origin then--Router might have rebooted and is asking about route
|
elseif routes[dest].router ~= origin then--Router might have rebooted and is asking about route
|
||||||
sendHostFound(origin, computer.uptime() - routes[dest].age, dest)
|
sendHostFound(origin, computer.uptime() - routes[dest].age, dest, routes[dest].dist + 1)
|
||||||
--routes[dest].active = computer.uptime()
|
--routes[dest].active = computer.uptime()
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
@ -367,15 +367,30 @@ startNetwork = function()
|
|||||||
routeRequests[dest][#routeRequests[dest]+1] = {type = "R", host = origin}
|
routeRequests[dest][#routeRequests[dest]+1] = {type = "R", host = origin}
|
||||||
end
|
end
|
||||||
elseif data:sub(1,1) == "H" then --Host found
|
elseif data:sub(1,1) == "H" then --Host found
|
||||||
local nttl, age, n = string.unpack(">BH", data, 2)
|
local nttl, age, dist, n = string.unpack(">BHB", data, 2)
|
||||||
local host = data:sub(n)
|
local host = data:sub(n)
|
||||||
|
|
||||||
if not isAccessible(host) then
|
if not isAccessible(host) then
|
||||||
if not routes[host] then
|
if not routes[host] then
|
||||||
routes[host] = {router = origin, node = node, age = computer.uptime() - age, active = computer.uptime()}
|
routes[host] = {
|
||||||
processRouteRequests(host, age)
|
router = origin,
|
||||||
elseif routes[host].age < computer.uptime() - age then
|
node = node,
|
||||||
routes[host] = {router = origin, node = node, age = computer.uptime() - age, active = routes[host].active}
|
age = computer.uptime() - age,
|
||||||
|
active = computer.uptime(),
|
||||||
|
dist = dist
|
||||||
|
}
|
||||||
|
processRouteRequests(host, age, dist + 1)
|
||||||
|
else
|
||||||
|
if (routes[host].dist > dist) or
|
||||||
|
((routes[host].age < computer.uptime() - age) and (routes[host].dist >= dist)) then
|
||||||
|
routes[host] = {
|
||||||
|
router = origin,
|
||||||
|
node = node,
|
||||||
|
age = computer.uptime() - age,
|
||||||
|
active = routes[host].active,
|
||||||
|
dist = dist
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -402,14 +417,14 @@ startNetwork = function()
|
|||||||
local now = computer.uptime()
|
local now = computer.uptime()
|
||||||
|
|
||||||
for k,v in pairs(routeRequests) do
|
for k,v in pairs(routeRequests) do
|
||||||
res[k] = {router = "", interface = "", age = now - v.timeout}
|
res[k] = {router = "", interface = "", age = now - v.timeout, dist = 0}
|
||||||
end
|
end
|
||||||
|
|
||||||
for k,v in pairs(routes) do
|
for k,v in pairs(routes) do
|
||||||
if v.router then
|
if v.router then
|
||||||
res[k] = {router = v.router, interface = v.node, age = now - v.age}
|
res[k] = {router = v.router, interface = v.node, age = now - v.age, dist = v.dist}
|
||||||
elseif v.thisHost then
|
elseif v.thisHost then
|
||||||
res[k] = {router = computer.address(), interface = "lo", age = 0}
|
res[k] = {router = computer.address(), interface = "lo", age = 0, dist = 0}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return res
|
return res
|
||||||
@ -436,7 +451,7 @@ startNetwork = function()
|
|||||||
for host, request in pairs(routeRequests) do
|
for host, request in pairs(routeRequests) do
|
||||||
if now - request.update >= cfg.routereq_retry then
|
if now - request.update >= cfg.routereq_retry then
|
||||||
if routes[host] then
|
if routes[host] then
|
||||||
processRouteRequests(host, now - routes[host].age)
|
processRouteRequests(host, now - routes[host].age, routes[host].dist + 1)
|
||||||
else
|
else
|
||||||
sendRouteRequest(host, now - request.update)
|
sendRouteRequest(host, now - request.update)
|
||||||
request.update = computer.uptime()
|
request.update = computer.uptime()
|
||||||
|
@ -29,13 +29,41 @@ end
|
|||||||
|
|
||||||
groupConstructors.module = function()
|
groupConstructors.module = function()
|
||||||
local group = newGroup()
|
local group = newGroup()
|
||||||
group.preload = {}
|
|
||||||
|
group.preload = {
|
||||||
|
package = kernel.userspace.package, --TODO TODO TODO: METATABLE THIZ!!!!!!!!
|
||||||
|
filesystem = setmetatable({}, {__index = kernel.modules.vfs}),
|
||||||
|
buffer = setmetatable({}, {__index = kernel.modules.buffer}),
|
||||||
|
bit32 = setmetatable({}, {__index = kernel.userspace.bit32}),
|
||||||
|
component = setmetatable({}, {__index = kernel.userspace.component}),
|
||||||
|
computer = setmetatable({}, {__index = kernel.userspace.computer}),
|
||||||
|
io = setmetatable({}, {__index = kernel.modules.io.io}),
|
||||||
|
unicode = setmetatable({}, {__index = kernel.userspace.unicode}),
|
||||||
|
}
|
||||||
group.loaded = {}
|
group.loaded = {}
|
||||||
group.loading = {}
|
group.loading = {}
|
||||||
group.searchers = {}
|
group.searchers = {}
|
||||||
return group
|
return group
|
||||||
end
|
end
|
||||||
|
|
||||||
|
groupConstructors.component = function(parent, wl, bl)
|
||||||
|
local group = newGroup()
|
||||||
|
group.parent = parent
|
||||||
|
group.whitelist = wl
|
||||||
|
group.blacklist = bl
|
||||||
|
group.adding = not parent and kernel.modules.component.kernelGroup.adding or {}
|
||||||
|
group.removing = not parent and kernel.modules.component.kernelGroup.removing or {}
|
||||||
|
group.primaries = not parent and kernel.modules.component.kernelGroup.primaries or {}
|
||||||
|
group.allow = function(addr)
|
||||||
|
if not group.parent or group.parent.allow(addr) then
|
||||||
|
return (not group.whitelist or group.whitelist[addr]) and (not group.blacklist or (not group.blacklist[addr]))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return group
|
||||||
|
end
|
||||||
|
|
||||||
|
------------------------------
|
||||||
|
|
||||||
spawnGroupGetters.signal = function()
|
spawnGroupGetters.signal = function()
|
||||||
if not kernel.modules.threading.currentThread then
|
if not kernel.modules.threading.currentThread then
|
||||||
return groupConstructors.signal(true)
|
return groupConstructors.signal(true)
|
||||||
@ -68,6 +96,15 @@ spawnGroupGetters.module = function()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
spawnGroupGetters.component = function()
|
||||||
|
if not kernel.modules.threading.currentThread then
|
||||||
|
return groupConstructors.component()
|
||||||
|
else
|
||||||
|
return kernel.modules.threading.currentThread.cgroups.component
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
------------------------------
|
||||||
--Signal group functions
|
--Signal group functions
|
||||||
|
|
||||||
function pushSignal(...)
|
function pushSignal(...)
|
||||||
@ -76,12 +113,20 @@ function pushSignal(...)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
------------------------------
|
||||||
|
|
||||||
userConstructors = {}
|
userConstructors = {}
|
||||||
|
|
||||||
function userConstructors.module()
|
function userConstructors.module()
|
||||||
return groupConstructors.module()
|
return groupConstructors.module()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function userConstructors.component(wl, bl)
|
||||||
|
return groupConstructors.component(kernel.modules.threading.currentThread and kernel.modules.threading.currentThread.cgroups.component, wl, bl)
|
||||||
|
end
|
||||||
|
|
||||||
|
------------------------------
|
||||||
|
|
||||||
function new(pid, name, ...)
|
function new(pid, name, ...)
|
||||||
if kernel.modules.threading.currentThread.pid ~= pid and
|
if kernel.modules.threading.currentThread.pid ~= pid and
|
||||||
(not kernel.modules.threading.threads[pid] or
|
(not kernel.modules.threading.threads[pid] or
|
||||||
|
@ -90,7 +90,8 @@ function spawn(exec, child, name, isthread, _, ...)
|
|||||||
signal = kernel.modules.cgroups.spawnGroupGetters["signal"](),
|
signal = kernel.modules.cgroups.spawnGroupGetters["signal"](),
|
||||||
network = kernel.modules.cgroups.spawnGroupGetters["network"](),
|
network = kernel.modules.cgroups.spawnGroupGetters["network"](),
|
||||||
filesystem = kernel.modules.cgroups.spawnGroupGetters["filesystem"](),
|
filesystem = kernel.modules.cgroups.spawnGroupGetters["filesystem"](),
|
||||||
module = kernel.modules.cgroups.spawnGroupGetters["module"]()
|
module = kernel.modules.cgroups.spawnGroupGetters["module"](),
|
||||||
|
component = kernel.modules.cgroups.spawnGroupGetters["component"](),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ local driver = {}
|
|||||||
local nodes = {}
|
local nodes = {}
|
||||||
local eventHnd
|
local eventHnd
|
||||||
|
|
||||||
local PKT_BEACON = "\0"
|
local PKT_BEACON = "\32"
|
||||||
local PKT_REGISTER = "\1"
|
local PKT_REGISTER = "\1"
|
||||||
local PKT_REGISTER_ACK = "\2"
|
local PKT_REGISTER_ACK = "\2"
|
||||||
local PKT_QUIT = "\3"
|
local PKT_QUIT = "\3"
|
||||||
|
@ -1 +1 @@
|
|||||||
{cacheDir="/var/lib/mpt/cache/",frontend={mpt={api="http://mpt.magik6k.net/api/"}},database="/var/lib/mpt/base.db"}
|
{database="/var/lib/mpt/base.db",frontend={mpt={api="http://mpt.magik6k.net/api/"}},cacheDir="/var/lib/mpt/cache/"}
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user