Compare commits

...

10 Commits

Author SHA1 Message Date
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
6 changed files with 693 additions and 10 deletions

672
disklock.lua Normal file

File diff suppressed because one or more lines are too long

View File

@@ -1,5 +1,7 @@
local max_distance = 220
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,7 +11,7 @@ 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 = max_distance}
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
@@ -34,9 +36,9 @@ 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 if distance > max_distance 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 = max_distance}
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
@@ -76,7 +78,7 @@ 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 > 200 then
canidate = {id = -1, distance = 170} canidate = {id = -1, distance = max_distance}
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

1
libDeflate.lua Normal file

File diff suppressed because one or more lines are too long

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 = {}

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 clients = {} local clients = {}
local message_queue = {} local message_queue = {}
@@ -126,7 +126,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 +195,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 +225,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

1
minified_disklock.lua Normal file

File diff suppressed because one or more lines are too long