Compare commits

...

31 Commits

Author SHA1 Message Date
beafcfd29f Update lua-minify.lua 2025-12-24 23:19:38 +00:00
5f64113546 Update lua-minify.lua 2025-12-24 23:18:32 +00:00
52afc41061 Update meshrouterentrypoint.lua 2025-12-24 23:16:15 +00:00
8eb9766874 Update entrypointclient.lua 2025-12-24 23:15:48 +00:00
9820bd4fa0 Update meshrouterentrypoint.lua 2025-12-24 22:29:55 +00:00
464b692f69 Update entrypointclient.lua 2025-12-24 21:48:18 +00:00
8d0bcf6599 i tried 2025-12-24 21:42:06 +00:00
f330830e6c made it safer 2025-12-24 21:23:21 +00:00
34d9397ab4 made the network safer 2025-12-24 21:22:30 +00:00
533b8f126d Update lua-minify.lua 2025-12-24 05:18:14 +00:00
5ad67d6f3a Update lua-minify.lua 2025-12-24 05:16:44 +00:00
358c7aeb54 Add lua-minify.lua 2025-12-24 05:12:02 +00:00
21573b57b4 Update containers_minified.lua 2025-11-20 08:20:20 +00:00
27ded0f69a Update containers.lua 2025-11-20 08:18:09 +00:00
5ef412e9f3 Update conatiners_minified.lua 2025-11-20 05:55:54 +00:00
c25899c22b Update conatiners_minified.lua 2025-11-20 05:27:35 +00:00
6f24903281 Update conatiners.lua 2025-11-20 05:26:25 +00:00
e8f6ee2a50 Add conatiners_minified.lua 2025-11-20 00:55:22 +00:00
53bfcd57fb Add conatiners.lua 2025-11-20 00:54:22 +00:00
f408acc81e Update minified_disklock.lua 2025-11-19 04:13:31 +00:00
1814070fb6 Update disklock.lua 2025-11-19 04:12:04 +00:00
CadenCoaster
6ec10e2edf Replace fixed distance with max_distance variable 2025-10-21 09:20:53 -07:00
CadenCoaster
5f09b5b81d Update print statement from 'Hello' to 'Goodbye' 2025-10-20 15:12:11 -07:00
CadenCoaster
c318867d6d Create disklock.lua 2025-10-20 15:11:31 -07:00
CadenCoaster
8c41220f9a libDeflate.lua 2025-10-19 19:12:05 -07:00
CadenCoaster
374d239407 Update meshrouter.lua 2025-10-19 13:51:56 -07:00
CadenCoaster
b1c4a68490 Update modem initialization to check for wireless 2025-10-19 13:51:27 -07:00
CadenCoaster
9cd255c938 Update modem initialization to check for wireless 2025-10-19 13:51:14 -07:00
CadenCoaster
feb764c379 Ensure os.shutdown() is called with a newline 2025-10-19 13:44:50 -07:00
CadenCoaster
fe7accadb7 Update meshrouter.lua 2025-10-19 13:44:17 -07:00
CadenCoaster
82615a9d82 Implement default route generation in mesh router
Added a function to generate default routes for clients in the distance map.
2025-10-19 13:42:46 -07:00
9 changed files with 3836 additions and 19 deletions

1061
containers.lua Normal file

File diff suppressed because one or more lines are too long

1
containers_minified.lua Normal file

File diff suppressed because one or more lines are too long

680
disklock.lua Normal file

File diff suppressed because one or more lines are too long

View File

@@ -1,5 +1,5 @@
local pullEvent = os.pullEventRaw local pullEvent = os.pullEventRaw
local modem = peripheral.find("modem") local modem = peripheral.find("modem",function (s) return peripheral.wrap(s).isWireless() end)
term.clear() term.clear()
term.setCursorPos(1,1) term.setCursorPos(1,1)
_G.network = {} _G.network = {}
@@ -9,14 +9,15 @@ if not modem then
end end
local message_queue = {} local message_queue = {}
modem.open(15125) modem.open(15125)
local canidate = {id = -1, distance = 170} local canidate = {id = -1, distance = 764, max_distance=0}
parallel.waitForAny(function () repeat sleep(0.1) until canidate.id ~= -1 end, parallel.waitForAny(function () repeat sleep(0.1) until canidate.id ~= -1 end,
function () function ()
while true do while true do
local _, _, channel, _, msg, distance = pullEvent("modem_message") local _, _, channel, _, msg, distance = pullEvent("modem_message")
if channel == 15125 then if channel == 15125 then
if msg.protocol == "entrypoint_advertise" then if msg.protocol == "entrypoint_advertise" then
if distance < canidate.distance then if distance < canidate.distance and distance < (msg.max_distance or 128) then
canidate.max_distance = (msg.max_distance or 128)
canidate.id = msg.sender canidate.id = msg.sender
canidate.distance = distance canidate.distance = distance
end end
@@ -34,9 +35,11 @@ local function receive()
if msg.protocol == "heartbeat" and msg.target == os.getComputerID() and msg.sender == canidate.id then if msg.protocol == "heartbeat" and msg.target == os.getComputerID() and msg.sender == canidate.id then
last_heartbeat = os.epoch("utc") last_heartbeat = os.epoch("utc")
modem.transmit(15125,15125,{protocol="heartbeat_response",sender=os.getComputerID(),target=canidate.id}) modem.transmit(15125,15125,{protocol="heartbeat_response",sender=os.getComputerID(),target=canidate.id})
if distance > 170 then canidate.distance = distance
canidate.max_distance = msg.max_distance
if distance > (msg.max_distance or 764) then
modem.transmit(15125,15125,{protocol="entrypoint_disconnect",sender=os.getComputerID(),target=canidate.id}) modem.transmit(15125,15125,{protocol="entrypoint_disconnect",sender=os.getComputerID(),target=canidate.id})
canidate = {id = -1, distance = 170} canidate = {id = -1, distance = 764, max_distance=0}
parallel.waitForAny(function () repeat sleep(0.1) until canidate.id ~= -1 end, parallel.waitForAny(function () repeat sleep(0.1) until canidate.id ~= -1 end,
function () function ()
while true do while true do
@@ -44,6 +47,7 @@ local function receive()
if channel == 15125 then if channel == 15125 then
if msg.protocol == "entrypoint_advertise" then if msg.protocol == "entrypoint_advertise" then
if distance < canidate.distance then if distance < canidate.distance then
canidate.max_distance = msg.max_distance
canidate.id = msg.sender canidate.id = msg.sender
canidate.distance = distance canidate.distance = distance
end end
@@ -75,15 +79,18 @@ end
local function connect() local function connect()
while true do while true do
if os.epoch("utc") - last_heartbeat > 200 then if os.epoch("utc") - last_heartbeat > math.max((300*canidate.distance)/100,300) then
canidate = {id = -1, distance = 170} canidate = {id = -1, distance = 764, max_distance=0}
parallel.waitForAny(function () repeat sleep(0.1) until canidate.id ~= -1 end, parallel.waitForAny(function () repeat sleep(0.1) until canidate.id ~= -1 end,
function () function ()
while true do while true do
local _, _, channel, _, msg, distance = pullEvent("modem_message") local _, _, channel, _, msg, distance = pullEvent("modem_message")
if channel == 15125 then if channel == 15125 then
if msg.protocol == "entrypoint_advertise" then if msg.protocol == "entrypoint_advertise" then
if distance < canidate.distance then if distance > (msg.max_distance or 128) then
modem.transmit(15125,15125,{protocol="out_of_range",sender=os.getComputerID(),target=msg.sender})
elseif distance < canidate.distance then
canidate.max_distance = msg.max_distance
canidate.id = msg.sender canidate.id = msg.sender
canidate.distance = distance canidate.distance = distance
end end
@@ -94,8 +101,12 @@ local function connect()
if canidate.id == -1 then if canidate.id == -1 then
sleep(5) sleep(5)
else else
modem.transmit(15125,15125,{protocol="entrypoint_connect",sender=os.getComputerID(),target=canidate.id}) if canidate.distance > (canidate.max_distance or 128) then
last_heartbeat = os.epoch("utc") modem.transmit(15125,15125,{protocol="out_of_range",sender=os.getComputerID(),target=canidate.id})
else
modem.transmit(15125,15125,{protocol="entrypoint_connect",sender=os.getComputerID(),target=canidate.id})
last_heartbeat = os.epoch("utc")
end
end end
else else
local msg = table.remove(message_queue,1) local msg = table.remove(message_queue,1)
@@ -106,5 +117,8 @@ local function connect()
sleep() sleep()
end end
end end
function _G.network.getCandidate()
return canidate
end
parallel.waitForAny(receive, connect,function () shell.run("shell") end) parallel.waitForAny(receive, connect,function () shell.run("shell") end)
os.shutdown() os.shutdown()

1
libDeflate.lua Normal file

File diff suppressed because one or more lines are too long

2045
lua-minify.lua Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
local interactions = {} local interactions = {}
local radio = peripheral.find("radio_tower") local radio = peripheral.find("radio_tower")
local modem = peripheral.find("modem") local modem = peripheral.find("modem",function (s) return peripheral.wrap(s).isWireless() end)
local distancemap = {} local distancemap = {}
local message_queue = {} local message_queue = {}
@@ -41,7 +41,7 @@ if radio and modem then
local data = {os.pullEvent()} local data = {os.pullEvent()}
if data[1] == "radio_message" then if data[1] == "radio_message" then
data[3] = textutils.unserialise(data[3]) data[3] = textutils.unserialise(data[3])
if data[3]._target == os.getComputerID() or data[3]._target == nil then return data[2], data[3], data[4] end if data[3]._target == os.getComputerID() or data[3]._target == nil and data[4] < 2611 then return data[2], data[3], data[4] end
elseif data[1] == "modem_message" then elseif data[1] == "modem_message" then
if data[5]._target == os.getComputerID() or data[5]._target == nil then return data[2], data[5], data[6] end if data[5]._target == os.getComputerID() or data[5]._target == nil then return data[2], data[5], data[6] end
end end
@@ -61,7 +61,7 @@ elseif radio then
while true do while true do
local data = {os.pullEvent("radio_message")} local data = {os.pullEvent("radio_message")}
data[3] = textutils.unserialise(data[3]) data[3] = textutils.unserialise(data[3])
if data[3]._target == os.getComputerID() or data[3]._target == nil then return data[2], data[3], data[4] end if data[3]._target == os.getComputerID() or data[3]._target == nil and data[4] < 2611 then return data[2], data[3], data[4] end
end end
end end
function interactions.send(message,target) function interactions.send(message,target)

View File

@@ -1,6 +1,8 @@
local interactions = {} local interactions = {}
local radio = peripheral.find("radio_tower") local radio = peripheral.find("radio_tower")
local modem = peripheral.find("modem") local modem = peripheral.find("modem",function (s) return peripheral.wrap(s).isWireless() end)
local max_distance = 128
local distancemap = {} local distancemap = {}
local clients = {} local clients = {}
local message_queue = {} local message_queue = {}
@@ -48,6 +50,8 @@ local function entrypoint_recieving(channel, msg)
print("No route to",msg.destination) print("No route to",msg.destination)
end end
end end
elseif msg.protocol == "out_of_range" then
print("readjusting range")
end end
end end
end end
@@ -84,6 +88,8 @@ if radio and modem then
data[3] = textutils.unserialise(data[3]) data[3] = textutils.unserialise(data[3])
if data[3]._target == os.getComputerID() or data[3]._target == nil then return data[2], data[3], data[4] end if data[3]._target == os.getComputerID() or data[3]._target == nil then return data[2], data[3], data[4] end
elseif data[1] == "modem_message" then elseif data[1] == "modem_message" then
print(data[6])
max_distance = math.max(data[6] or 0,max_distance)
if data[5]._target == os.getComputerID() or data[5]._target == nil and data[3] == 15124 then return data[2], data[5], data[6] end if data[5]._target == os.getComputerID() or data[5]._target == nil and data[3] == 15124 then return data[2], data[5], data[6] end
if data[3] == 15125 then if data[3] == 15125 then
entrypoint_recieving(data[3], data[5]) entrypoint_recieving(data[3], data[5])
@@ -107,6 +113,7 @@ elseif modem then
local data = {[5]={_target=-1}} local data = {[5]={_target=-1}}
while true do while true do
data = {os.pullEvent("modem_message")} data = {os.pullEvent("modem_message")}
max_distance = math.max(data[6] or 0,max_distance)
if data[5]._target == os.getComputerID() or data[5]._target == nil and data[3] == 15124 then return data[2], data[5], data[6] end if data[5]._target == os.getComputerID() or data[5]._target == nil and data[3] == 15124 then return data[2], data[5], data[6] end
if data[3] == 15125 then if data[3] == 15125 then
entrypoint_recieving(data[3], data[5]) entrypoint_recieving(data[3], data[5])
@@ -126,7 +133,14 @@ queue_message({protocol="getroutes"})
interactions.send({protocol="route_erase",destination=os.getComputerID()}) interactions.send({protocol="route_erase",destination=os.getComputerID()})
queue_message({protocol="route",destination=os.getComputerID(),distance=0}) queue_message({protocol="route",destination=os.getComputerID(),distance=0})
local heartbeat = false local heartbeat = false
local function generate_default_routes()
local map = {}
map[os.computerID()] = {dist = 0, sender = os.computerID()}
for client,_ in pairs(clients) do
map[client] = {dist = 1, sender = client}
end
return map
end
local function recieve() local function recieve()
while true do while true do
local _, msg = interactions.receive() local _, msg = interactions.receive()
@@ -188,8 +202,7 @@ while true do
if (not msg.visited) then msg.visited = {} end if (not msg.visited) then msg.visited = {} end
msg.visited[#msg.visited+1] = os.getComputerID() msg.visited[#msg.visited+1] = os.getComputerID()
print("rerouting") print("rerouting")
distancemap = {} distancemap = generate_default_routes()
distancemap[os.computerID()] = {dist = 0, sender = os.computerID()}
queue_message({protocol="getroutes"}) queue_message({protocol="getroutes"})
queue_message(msg) queue_message(msg)
end end
@@ -219,6 +232,7 @@ local function heartbeat_f()
end end
end) end)
if not heartbeat then if not heartbeat then
print(k, "timed out")
distancemap[k] = nil distancemap[k] = nil
queue_message({protocol="reroute"}) queue_message({protocol="reroute"})
end end
@@ -229,7 +243,7 @@ local function heartbeat_f()
end end
local function entrypoint_advertising() local function entrypoint_advertising()
while true do while true do
modem.transmit(15125,15125,{protocol="entrypoint_advertise",sender=os.getComputerID()}) modem.transmit(15125,15125,{protocol="entrypoint_advertise",sender=os.getComputerID(),max_distance=max_distance-10})
sleep(0.1) sleep(0.1)
end end
end end
@@ -242,7 +256,7 @@ local function healthcheck()
sleep(0.1) sleep(0.1)
end, function() end, function()
while not heartbeat_entrypoint do while not heartbeat_entrypoint do
modem.transmit(15125,15125,{protocol="heartbeat",sender=os.getComputerID(),target=client}) modem.transmit(15125,15125,{protocol="heartbeat",sender=os.getComputerID(),target=client,max_distance=max_distance-10})
sleep() sleep()
end end
end) end)

1
minified_disklock.lua Normal file

File diff suppressed because one or more lines are too long