Compare commits
No commits in common. "88bce6cd96d7de50097616380cf43b24b5c8a38b" and "026f2524e681fb5035467846ef4c493f95c1f35f" have entirely different histories.
88bce6cd96
...
026f2524e6
@ -5,7 +5,7 @@ local rpc = require "rpc"
|
||||
local netutil = {}
|
||||
|
||||
function netutil.importfs(host,rpath,lpath) -- string string string -- boolean -- Import filesystem *rpath* from *host* and attach it to *lpath*.
|
||||
local px = rpc.proxy(host,"fs_"..rpath.."_")
|
||||
local px = rpc.proxy(host,rpath.."_")
|
||||
function px.getLabel()
|
||||
return host..":"..rpath
|
||||
end
|
||||
@ -17,8 +17,8 @@ function netutil.exportfs(path) -- string -- boolean -- Export the directory *pa
|
||||
local path = "/"..table.concat(fs.segments(path),"/")
|
||||
local px = require("unionfs").create(path)
|
||||
for k,v in pairs(px) do
|
||||
rpc.register("fs_"..path.."_"..k,v)
|
||||
print("fs_"..path.."_"..k)
|
||||
rpc.register(path.."_"..k,v)
|
||||
print(path.."_"..k)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
44
lib/rpc.lua
44
lib/rpc.lua
@ -5,34 +5,19 @@ local rpc = {}
|
||||
_G.rpcf = {}
|
||||
rpc.port = 111
|
||||
|
||||
local function setacl(self, fname, host)
|
||||
self[fname] = self[fname] or {}
|
||||
self[fname][host] = true
|
||||
end
|
||||
rpc.allow = setmetatable({},{__call=setacl})
|
||||
rpc.deny = setmetatable({},{__call=setacl})
|
||||
|
||||
local function isPermitted(host,fn)
|
||||
if rpc.allow[fn] then
|
||||
return rpc.allow[fn][host] or false
|
||||
end
|
||||
if rpc.deny[fn] and rpc.deny[fn][host] then
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local function rpcexec(_, from, port, data)
|
||||
os.spawn(function()
|
||||
if port == rpc.port then
|
||||
local rpcrq = serial.unserialize(data) or {}
|
||||
if rpcf[rpcrq[1]] and isPermitted(from,rpcrq[1]) then
|
||||
minitel.send(from,port,serial.serialize({rpcrq[2],pcall(rpcf[rpcrq[1]],table.unpack(rpcrq,3))}))
|
||||
elseif type(rpcrq[2]) == "string" then
|
||||
minitel.send(from,port,serial.serialize({rpcrq[2],false,"function unavailable"}))
|
||||
local rpcrq = serial.unserialize(data)
|
||||
local rpcn, rpcid = table.remove(rpcrq,1), table.remove(rpcrq,1)
|
||||
if rpcf[rpcn] then
|
||||
local rt = {pcall(rpcf[rpcn],table.unpack(rpcrq))}
|
||||
if rt[1] == true then
|
||||
table.remove(rt,1)
|
||||
end
|
||||
minitel.send(from,port,serial.serialize({rpcid,table.unpack(rt)}))
|
||||
else
|
||||
end
|
||||
end
|
||||
end,"rpc worker for "..tostring(from))
|
||||
end
|
||||
function rpcf.list()
|
||||
local rt = {}
|
||||
@ -54,13 +39,10 @@ function rpc.call(hostname,fn,...) -- string string -- boolean -- Calls exported
|
||||
local _, from, port, data = event.pull(30, "net_msg", hostname, rpc.port)
|
||||
rt = serial.unserialize(tostring(data)) or {}
|
||||
until (type(rt) == "table" and rt[1] == rv) or computer.uptime() > st + 30
|
||||
if rt[1] == rv then
|
||||
if rt[2] then
|
||||
return table.unpack(rt,3)
|
||||
if table.remove(rt,1) == rv then
|
||||
return table.unpack(rt)
|
||||
end
|
||||
error(rt[3])
|
||||
end
|
||||
error("timed out")
|
||||
return false
|
||||
end
|
||||
function rpc.proxy(hostname,filter) -- string string -- table -- Returns a component.proxy()-like table from the functions on *hostname* with names matching *filter*.
|
||||
filter=(filter or "").."(.+)"
|
||||
@ -87,7 +69,7 @@ function rpc.register(name,fn) -- string function -- -- Registers a function to
|
||||
if not rpcrunning then
|
||||
os.spawn(function()
|
||||
while true do
|
||||
pcall(rpcexec,event.pull("net_msg"))
|
||||
rpcexec(event.pull("net_msg"))
|
||||
end
|
||||
end,"rpc daemon")
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user