2020-03-17 10:11:53 -04:00
|
|
|
local computer = require "computer"
|
|
|
|
local minitel = require "minitel"
|
|
|
|
local rpc = require "rpc"
|
|
|
|
local netutil = {}
|
|
|
|
|
|
|
|
function netutil.importfs(host,rpath,lpath)
|
|
|
|
local px = rpc.proxy(host,rpath.."_")
|
|
|
|
function px.getLabel()
|
|
|
|
return host..":"..rpath
|
|
|
|
end
|
|
|
|
fs.mount(lpath,px)
|
|
|
|
end
|
|
|
|
|
|
|
|
function netutil.exportfs(path)
|
|
|
|
local path = "/"..table.concat(fs.segments(path),"/")
|
|
|
|
local px = ufs.create(path)
|
|
|
|
for k,v in pairs(px) do
|
|
|
|
rpcs.register(path.."_"..k,v)
|
|
|
|
print(path.."_"..k)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-17 20:54:35 -04:00
|
|
|
function netutil.ping(addr,times,timeout)
|
2020-03-17 10:11:53 -04:00
|
|
|
local times, timeout = times or 5, timeout or 30
|
|
|
|
for i = 1, times do
|
|
|
|
local ipt = computer.uptime()
|
|
|
|
local pid = minitel.genPacketID()
|
|
|
|
computer.pushSignal("net_send",1,addr,0,"ping",pid)
|
|
|
|
local t,a = event.pull(timeout,"net_ack")
|
|
|
|
if t == "net_ack" and a == pid then
|
|
|
|
print("Ping reply: "..tostring(computer.uptime()-ipt).." seconds.")
|
|
|
|
else
|
|
|
|
print("Timed out.")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return netutil
|