Implement default route generation in mesh router

Added a function to generate default routes for clients in the distance map.
This commit is contained in:
CadenCoaster
2025-10-19 13:42:46 -07:00
committed by GitHub
parent 5924cba842
commit 82615a9d82

View File

@@ -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