From d5e2d82a50447d4766c9ec9b86af4ef5e34f4881 Mon Sep 17 00:00:00 2001 From: Izaya Date: Fri, 30 Mar 2018 00:40:16 +1100 Subject: [PATCH] made microtel-5-flisten actually work --- Embedded/microtel-3-mini.lua | 79 ---------------------------- Embedded/microtel-4-mini.lua | 11 ---- Embedded/microtel-5-core-mini.lua | 14 ----- Embedded/microtel-5-flisten-mini.lua | 10 ---- Embedded/microtel-5-flisten.lua | 3 +- Embedded/microtel-5-listen-mini.lua | 9 ---- Embedded/microtel-5-open-mini.lua | 14 ----- 7 files changed, 2 insertions(+), 138 deletions(-) delete mode 100644 Embedded/microtel-3-mini.lua delete mode 100644 Embedded/microtel-4-mini.lua delete mode 100644 Embedded/microtel-5-core-mini.lua delete mode 100644 Embedded/microtel-5-flisten-mini.lua delete mode 100644 Embedded/microtel-5-listen-mini.lua delete mode 100644 Embedded/microtel-5-open-mini.lua diff --git a/Embedded/microtel-3-mini.lua b/Embedded/microtel-3-mini.lua deleted file mode 100644 index d7f6b13..0000000 --- a/Embedded/microtel-3-mini.lua +++ /dev/null @@ -1,79 +0,0 @@ -_G.net={} -do -local M,pQ,pC,rC,C,Y={},{},{},{},computer,table.unpack -net.port,net.hostname,net.route,net.hook,U=4096,C.address():sub(1,8),true,{},C.uptime -for a in component.list("modem") do -M[a]=component.proxy(a) -M[a].open(net.port) -end -local function gP() -local pID="" -for i=1,16 do -pID=pID .. string.char(math.random(32,126)) -end -return pID -end -local function sP(pID,pT,T,vP,D) -pC[pID]=U() -if rC[T] then -M[rC[T][1]].send(rC[T][2],net.port,pID,pT,T,net.hostname,vP,D) -else -for k,v in pairs(M) do -v.broadcast(net.port,pID,pT,T,net.hostname,vP,D) -end -end -end -function net.send(T,vP,D,pT,pID) -pT,pID=pT or 1,pID or gP() -pQ[pID]={pT,T,vP,D,0} -sP(pID,pT,T,vP,D) -end -local function cC(pID) -for k,v in pairs(pC) do -if k==pID then -return false -end -end -return true -end -local rCPE=C.pullSignal -function C.pullSignal(t) -local Z={rCPE(t)} -for k,v in pairs(net.hook) do -pcall(v,Y(Z)) -end -for k,v in pairs(pC) do -if U()>v+30 then -pC[k]=nil -end -end -for k,v in pairs(rC) do -if U()>v[3]+30 then -rC[k]=nil -end -end -if Z[1]=="modem_message" and (Z[4]==net.port or Z[4]==0) and cC(Z[6]) then -rC[Z[9]]={Z[2],Z[3],U()} -if Z[8]==net.hostname then -if Z[7]~=2 then -C.pushSignal("net_msg",Z[9],Z[10],Z[11]) -if Z[7]==1 then -sP(gP(),2,Z[9],Z[10],Z[6]) -end -else -pQ[Z[11]]=nil -end -elseif net.route and cC(Z[6]) then -sP(Z[6],Z[7],Z[8],Z[9],Z[10],Z[11]) -end -pC[Z[6]]=U() -end -for k,v in pairs(pQ) do -if U()>v[5] then -sP(k,Y(v)) -v[5]=U()+30 -end -end -return Y(Z) -end -end diff --git a/Embedded/microtel-4-mini.lua b/Embedded/microtel-4-mini.lua deleted file mode 100644 index b72289c..0000000 --- a/Embedded/microtel-4-mini.lua +++ /dev/null @@ -1,11 +0,0 @@ -net.mtu=4096 -function net.lsend(T,P,L) -local D={} -for i=1,L:len(),net.mtu do -D[#D+1]=L:sub(1,net.mtu) -L=L:sub(net.mtu+1) -end -for k,v in ipairs(D) do -net.send(T,P,v) -end -end diff --git a/Embedded/microtel-5-core-mini.lua b/Embedded/microtel-5-core-mini.lua deleted file mode 100644 index d5fbacf..0000000 --- a/Embedded/microtel-5-core-mini.lua +++ /dev/null @@ -1,14 +0,0 @@ -net.timeout=60 -function net.open(A,V) -local st=computer.uptime() -net.send(A,P,"openstream") -repeat -_,F,P,D=computer.pullSignal(0.5) -if computer.uptime()>st+net.timeout then return false end -until F==A and P==V and tonumber(D) -V=tonumber(D) -repeat -_,F,P,D=computer.pullSignal(0.5) -until F==A and P==V -return socket(A,V,D) -end diff --git a/Embedded/microtel-5-flisten-mini.lua b/Embedded/microtel-5-flisten-mini.lua deleted file mode 100644 index 1f89fec..0000000 --- a/Embedded/microtel-5-flisten-mini.lua +++ /dev/null @@ -1,10 +0,0 @@ -function net.flisten(V,handler) - function net.hook[V](E,F,P,D) - if P == V and D == "openstream" then - local nP,S = math.random(2^15,2^16),tostring(math.random(-2^16,2^16)) - net.send(F,P,tostring(nP)) - net.send(F,nP,S) - handler(net.socket(F,nP,S)) - end - end -end diff --git a/Embedded/microtel-5-flisten.lua b/Embedded/microtel-5-flisten.lua index 9c801cf..90e24dd 100644 --- a/Embedded/microtel-5-flisten.lua +++ b/Embedded/microtel-5-flisten.lua @@ -1,5 +1,5 @@ function net.flisten(vport,handler) - function net.hook[vport](etype,from,port,data) + local function h(etype,from,port,data) if port == vport and data == "openstream" then local nport,sclose = math.random(2^15,2^16),tostring(math.random(-2^16,2^16)) net.send(from,port,tostring(nport)) @@ -7,4 +7,5 @@ function net.flisten(vport,handler) handler(net.socket(from,nport,sclose)) end end + net.hook[vport] = h end diff --git a/Embedded/microtel-5-listen-mini.lua b/Embedded/microtel-5-listen-mini.lua deleted file mode 100644 index c44b633..0000000 --- a/Embedded/microtel-5-listen-mini.lua +++ /dev/null @@ -1,9 +0,0 @@ -function net.listen(V) - repeat - local E, F, P, D = computer.pullSignal(0.5) - until P == V and D == "openstream" - local nP,S = math.random(2^15,2^16),tostring(math.random(-2^16,2^16)) - net.send(F,P,tostring(nP)) - net.send(F,nP,S) - return net.socket(F,nP,S) -end diff --git a/Embedded/microtel-5-open-mini.lua b/Embedded/microtel-5-open-mini.lua deleted file mode 100644 index 9f825fb..0000000 --- a/Embedded/microtel-5-open-mini.lua +++ /dev/null @@ -1,14 +0,0 @@ -net.timeout = 60 -function net.open(A,V) - local st=computer.uptime() - net.send(A,P,"openstream") - repeat - _, F, P, D = computer.pullSignal(0.5) - if computer.uptime() > st+net.timeout then return false end - until F == A and P == V and tonumber(D) - V=tonumber(D) - repeat - _, F, P, D = computer.pullSignal(0.5) - until F == A and P == V - return socket(A,V,D) -end