Compare commits
No commits in common. "0d01b03ddc286ce0cbfa8818b8f402e7091097aa" and "4ef792a06d60c4a8d63d8a04ae4d86269488b478" have entirely different histories.
0d01b03ddc
...
4ef792a06d
@ -126,7 +126,7 @@ function fs.mounts() -- returns a table containing the mount points of all mount
|
|||||||
return rt
|
return rt
|
||||||
end
|
end
|
||||||
|
|
||||||
function fs.address(path) -- returns the address of the filesystem at a given path, if applicable; do not expect a sensical response
|
function fs.address(path) -- returns the address of the filesystem at a given path, if applicable
|
||||||
local fsi,_ = fs.resolve(path)
|
local fsi,_ = fs.resolve(path)
|
||||||
return fsmounts[fsi].address
|
return fsmounts[fsi].address
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
do
|
do
|
||||||
local tTasks,nPid,nTimeout,cPid = {},1,0.25,0 -- table of tasks, next process ID, event timeout, current PID
|
local tTasks,nPid,nTimeout,cPid = {},1,1,0 -- table of tasks, next process ID, event timeout, current PID
|
||||||
function os.spawn(f,n) -- creates a process from function *f* with name *n*
|
function os.spawn(f,n) -- creates a process from function *f* with name *n*
|
||||||
tTasks[nPid] = {
|
tTasks[nPid] = {
|
||||||
c=coroutine.create(f), -- actual coroutine
|
c=coroutine.create(f), -- actual coroutine
|
||||||
|
@ -10,6 +10,7 @@ cfg.peers = {}
|
|||||||
cfg.rtimer = 5
|
cfg.rtimer = 5
|
||||||
cfg.katimer = 30
|
cfg.katimer = 30
|
||||||
local listeners = {}
|
local listeners = {}
|
||||||
|
local timers = {}
|
||||||
local proxies = {}
|
local proxies = {}
|
||||||
|
|
||||||
local function loadcfg()
|
local function loadcfg()
|
||||||
@ -83,7 +84,7 @@ local function createTunnel(host,port,addr,raddr)
|
|||||||
end
|
end
|
||||||
proxy.connect()
|
proxy.connect()
|
||||||
proxy.last = computer.uptime()
|
proxy.last = computer.uptime()
|
||||||
return proxy
|
return proxy, read
|
||||||
end
|
end
|
||||||
|
|
||||||
vt = {}
|
vt = {}
|
||||||
@ -93,8 +94,9 @@ function start()
|
|||||||
print(string.format("Connecting to %s:%d",v.host,v.port))
|
print(string.format("Connecting to %s:%d",v.host,v.port))
|
||||||
v.addr = v.addr or vcomponent.uuid()
|
v.addr = v.addr or vcomponent.uuid()
|
||||||
v.raddr = v.raddr or vcomponent.uuid()
|
v.raddr = v.raddr or vcomponent.uuid()
|
||||||
local px = createTunnel(v.host, v.port, v.addr, v.raddr)
|
local px,tr = createTunnel(v.host, v.port, v.addr, v.raddr)
|
||||||
vcomponent.register(v.addr, "tunnel", px)
|
vcomponent.register(v.addr, "tunnel", px)
|
||||||
|
timers[v.addr] = tr
|
||||||
proxies[v.addr] = px
|
proxies[v.addr] = px
|
||||||
end
|
end
|
||||||
for k,v in pairs(os.tasks()) do
|
for k,v in pairs(os.tasks()) do
|
||||||
@ -104,6 +106,12 @@ function start()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
function vt.stop()
|
function vt.stop()
|
||||||
|
for k,v in pairs(listeners) do
|
||||||
|
event.ignore(v[1],v[2])
|
||||||
|
end
|
||||||
|
for k,v in pairs(timers) do
|
||||||
|
event.cancel(v)
|
||||||
|
end
|
||||||
for k,v in pairs(proxies) do
|
for k,v in pairs(proxies) do
|
||||||
vcomponent.unregister(k)
|
vcomponent.unregister(k)
|
||||||
end
|
end
|
||||||
@ -149,14 +157,21 @@ end
|
|||||||
vt.start = start
|
vt.start = start
|
||||||
_G.libs.vtunnel = vt
|
_G.libs.vtunnel = vt
|
||||||
|
|
||||||
start()
|
print(pcall(start))
|
||||||
local last = computer.uptime()
|
local last = computer.uptime()
|
||||||
while true do
|
while true do
|
||||||
local tE = {coroutine.yield()}
|
local tE = {coroutine.yield()}
|
||||||
if computer.uptime() > last + cfg.rtimer then
|
if computer.uptime() > last + cfg.rtimer then
|
||||||
for k,v in pairs(proxies) do
|
for k,v in pairs(timers) do
|
||||||
v.read()
|
print(pcall(v))
|
||||||
end
|
end
|
||||||
last = computer.uptime()
|
last = computer.uptime()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--[[
|
||||||
|
_G.vtunnel = {}
|
||||||
|
|
||||||
|
_G.vtunnel.start = start
|
||||||
|
_G.vtunnel.delpeer = delpeer
|
||||||
|
]]
|
||||||
|
Loading…
Reference in New Issue
Block a user