Merge branch 'master-MC1.7.10' of github.com:MightyPirates/OpenComputers into master-MC1.7.10

This commit is contained in:
Florian Nücke 2016-01-02 14:19:54 +01:00
commit ebb60e3213
15 changed files with 321 additions and 64 deletions

View File

@ -32,13 +32,13 @@ local mcnetTransportTypes = {
local mcnetTypes = {
["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)
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,
["R"] = function(localAddress, remoteAddress, 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,
["D"] = function(localAddress, remoteAddress, data)
local ttl = string.unpack(">B", data)
@ -52,7 +52,7 @@ local mcnetTypes = {
["E"] = function(localAddress, remoteAddress, data)
local ttl, dest, orig, dstart = string.unpack(">Bs1s1", data)
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
mcnetTransportTypes[dat:sub(1,1)](localAddress, remoteAddress, dat:sub(2))
else
@ -62,7 +62,10 @@ local mcnetTypes = {
}
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)
end,
["\1"] = function(localAddress, remoteAddress, msg) --PKT_REGISTER
@ -82,6 +85,7 @@ local ethTypes = {
["\3"] = function(localAddress, remoteAddress, msg) --PKT_QUIT
print("\t> L1 PKT_QUIT remote=" .. remoteAddress)
end,
}
function dataExpanders.modem_message(_, localAddress, remoteAddress, port, distance, msg)

View File

@ -320,11 +320,12 @@ end
control["!"] = function(char) --Disable
if commandMode == "9" then
charHandlers.active = function(c)
if c == "\255" then
if c == "\255" or c == "!" then
commandList = {}
commandBuf = ""
commandMode = ""
charHandlers.active = charHandlers.base
blink = true
end
end
blink = false

View File

@ -66,6 +66,7 @@ local distros = {
{desc = "[online] Plan9k - lightest, experimental", params = {"-SYy", "plan9k"}},
{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] Update - update installed system", params = {"--mirror=/", "-uyY"}},
}
for n, dist in pairs(distros) do

View File

@ -7,26 +7,38 @@ local function fillText(text, n)
return text
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")
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
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[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[5] = maxlen[5] < #tostring(route.dist)+1 and #tostring(route.dist)+1 or maxlen[5]
end
print(fillText("Destination", maxlen[1])..
fillText("Gateway", maxlen[2])..
fillText("Iface", maxlen[3])..
fillText("Age", maxlen[4]))
fillText("Age", maxlen[4])..
fillText("Dist", maxlen[5]))
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.interface, maxlen[3])..
fillText(tostring(route.age), maxlen[4]))
fillText(tostring(route.age), maxlen[4])..
fillText(tostring(route.dist), maxlen[5]))
end

View File

@ -1,18 +1,48 @@
local shell = require("shell")
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
print([[sandbox {-m,-s} [file]
Sandbox a process
-m, --module - sandbox modules
-s, --signal - sandbox signals
print([[sandbox [flow] [spawn [file] [args Nargs ...] ]...
Sandbox a processes/process tree
Options:
-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
end
--[[
local program = os.getenv("SHELL") or "/bin/sh.lua"
if #args > 0 then
@ -27,3 +57,55 @@ end
local pid = os.spawn(program, table.unpack(args))
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

View File

@ -310,6 +310,12 @@ builtin.alias("....", "cd", "../../..")
-------------------
-- Main loop
if fs.exists("~/.shrc") then
for line in io.lines("~/.shrc") do
execute(line)
end
end
while run do
--if term.getCursor() > 1 then
-- io.write("\n")

View File

@ -1,8 +1,99 @@
local component = kernel._K.component
local rawComponent = kernel._K.component
component = {}
local adding = {}
local removing = {}
local primaries = {}
kernel.userspace.component = component
kernel._K.component = component
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
return function(_, key)
if parent then
return next(primaries, key)
return next(getGroup().primaries, key)
else
local k, v = next(self, key)
if not k then
parent = true
return next(primaries)
return next(getGroup().primaries)
else
return k, v
end
@ -43,20 +134,20 @@ end
function component.isAvailable(componentType)
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
-- creation cause confusion by trying to create the proxy again,
-- causing the oom error to be thrown again.
component.setPrimary(componentType, component.list(componentType, true)())
end
return primaries[componentType] ~= nil
return getGroup().primaries[componentType] ~= nil
end
function component.isPrimary(address)
local componentType = component.type(address)
if componentType then
if component.isAvailable(componentType) then
return primaries[componentType].address == address
return getGroup().primaries[componentType].address == address
end
end
return false
@ -66,7 +157,7 @@ function component.getPrimary(componentType)
checkArg(1, componentType, "string")
assert(component.isAvailable(componentType),
"no primary '" .. componentType .. "' available")
return primaries[componentType]
return getGroup().primaries[componentType]
end
function component.setPrimary(componentType, address)
@ -77,19 +168,19 @@ function component.setPrimary(componentType, address)
assert(address, "no such component")
end
local wasAvailable = primaries[componentType]
local wasAvailable = getGroup().primaries[componentType]
if wasAvailable and address == wasAvailable.address then
return
end
local wasAdding = adding[componentType]
local wasAdding = getGroup().adding[componentType]
if wasAdding and address == wasAdding.address then
return
end
if wasAdding then
kernel.modules.timer.remove(wasAdding.timer)
end
primaries[componentType] = nil
adding[componentType] = nil
getGroup().primaries[componentType] = nil
getGroup().adding[componentType] = nil
local primary = address and component.proxy(address) or nil
if wasAvailable then
@ -97,16 +188,16 @@ function component.setPrimary(componentType, address)
end
if primary then
if wasAvailable or wasAdding then
adding[componentType] = {
getGroup().adding[componentType] = {
address=address,
timer=kernel.modules.timer.add(function()
adding[componentType] = nil
primaries[componentType] = primary
getGroup().adding[componentType] = nil
getGroup().primaries[componentType] = primary
--computer.pushSignal("component_available", componentType)
end, 0.1)
}
else
primaries[componentType] = primary
getGroup().primaries[componentType] = primary
computer.pushSignal("component_available", componentType)
end
end
@ -124,14 +215,14 @@ function start()
end
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)
end
end
local function onComponentRemoved(_, address, componentType)
if primaries[componentType] and primaries[componentType].address == address or
adding[componentType] and adding[componentType].address == address
if getGroup().primaries[componentType] and getGroup().primaries[componentType].address == address or
getGroup().adding[componentType] and getGroup().adding[componentType].address == address
then
component.setPrimary(componentType, component.list(componentType, true)())
end

View File

@ -192,7 +192,7 @@ kernel.userspace.io = io
setmetatable(io, {__index = function(_, k)
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
end
end})

View File

@ -178,10 +178,10 @@ startNetwork = function()
sent = nil
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)
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
@ -218,7 +218,7 @@ startNetwork = function()
end
end
local function processRouteRequests(host, age)
local function processRouteRequests(host, age, dist)
if routeRequests[host] then
age = age or (computer.uptime() - routeRequests[host].timeout)
for t, request in pairs(routeRequests[host]) do
@ -230,7 +230,7 @@ startNetwork = function()
sendRoutedDataAs(host, request.origin, request.data, request.ttl)
end
elseif request.type == "R" then
sendHostFound(request.host, age, host)
sendHostFound(request.host, age, host, dist or 1)
end
end
end
@ -249,8 +249,8 @@ startNetwork = function()
end
bindAddr = function(addr)
routes[addr] = {thisHost=true}
processRouteRequests(addr, 0)
routes[addr] = {thisHost=true, dist = 0}
processRouteRequests(addr, 0, 1)
end
kernel.modules.keventd.listen("hostname", function(_, name) bindAddr(name)end)
@ -307,7 +307,7 @@ startNetwork = function()
for host in pairs(n.hosts)do
if host == dest then
--Found it!
sendHostFound(origin, 0, dest)
sendHostFound(origin, 0, dest, 1)
return
end
end
@ -318,9 +318,9 @@ startNetwork = function()
if routes[dest] then
if routes[dest].thisHost then
--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
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()
end
return
@ -367,16 +367,31 @@ startNetwork = function()
routeRequests[dest][#routeRequests[dest]+1] = {type = "R", host = origin}
end
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)
if not isAccessible(host) then
if not routes[host] then
routes[host] = {router = origin, node = node, age = computer.uptime() - age, active = computer.uptime()}
processRouteRequests(host, age)
elseif routes[host].age < computer.uptime() - age then
routes[host] = {router = origin, node = node, age = computer.uptime() - age, active = routes[host].active}
end
routes[host] = {
router = origin,
node = node,
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
@ -402,14 +417,14 @@ startNetwork = function()
local now = computer.uptime()
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
for k,v in pairs(routes) do
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
res[k] = {router = computer.address(), interface = "lo", age = 0}
res[k] = {router = computer.address(), interface = "lo", age = 0, dist = 0}
end
end
return res
@ -436,7 +451,7 @@ startNetwork = function()
for host, request in pairs(routeRequests) do
if now - request.update >= cfg.routereq_retry then
if routes[host] then
processRouteRequests(host, now - routes[host].age)
processRouteRequests(host, now - routes[host].age, routes[host].dist + 1)
else
sendRouteRequest(host, now - request.update)
request.update = computer.uptime()

View File

@ -29,13 +29,41 @@ end
groupConstructors.module = function()
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.loading = {}
group.searchers = {}
return group
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()
if not kernel.modules.threading.currentThread then
return groupConstructors.signal(true)
@ -68,6 +96,15 @@ spawnGroupGetters.module = function()
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
function pushSignal(...)
@ -76,12 +113,20 @@ function pushSignal(...)
end
end
------------------------------
userConstructors = {}
function userConstructors.module()
return groupConstructors.module()
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, ...)
if kernel.modules.threading.currentThread.pid ~= pid and
(not kernel.modules.threading.threads[pid] or

View File

@ -90,7 +90,8 @@ function spawn(exec, child, name, isthread, _, ...)
signal = kernel.modules.cgroups.spawnGroupGetters["signal"](),
network = kernel.modules.cgroups.spawnGroupGetters["network"](),
filesystem = kernel.modules.cgroups.spawnGroupGetters["filesystem"](),
module = kernel.modules.cgroups.spawnGroupGetters["module"]()
module = kernel.modules.cgroups.spawnGroupGetters["module"](),
component = kernel.modules.cgroups.spawnGroupGetters["component"](),
}
}

View File

@ -12,7 +12,7 @@ local driver = {}
local nodes = {}
local eventHnd
local PKT_BEACON = "\0"
local PKT_BEACON = "\32"
local PKT_REGISTER = "\1"
local PKT_REGISTER_ACK = "\2"
local PKT_QUIT = "\3"

View File

@ -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