Compare commits
10 Commits
5924cba842
...
6ec10e2edf
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6ec10e2edf | ||
|
|
5f09b5b81d | ||
|
|
c318867d6d | ||
|
|
8c41220f9a | ||
|
|
374d239407 | ||
|
|
b1c4a68490 | ||
|
|
9cd255c938 | ||
|
|
feb764c379 | ||
|
|
fe7accadb7 | ||
|
|
82615a9d82 |
672
disklock.lua
Normal file
672
disklock.lua
Normal file
File diff suppressed because one or more lines are too long
@@ -1,5 +1,7 @@
|
||||
local max_distance = 220
|
||||
|
||||
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.setCursorPos(1,1)
|
||||
_G.network = {}
|
||||
@@ -9,7 +11,7 @@ if not modem then
|
||||
end
|
||||
local message_queue = {}
|
||||
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,
|
||||
function ()
|
||||
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
|
||||
last_heartbeat = os.epoch("utc")
|
||||
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})
|
||||
canidate = {id = -1, distance = 170}
|
||||
canidate = {id = -1, distance = max_distance}
|
||||
parallel.waitForAny(function () repeat sleep(0.1) until canidate.id ~= -1 end,
|
||||
function ()
|
||||
while true do
|
||||
@@ -76,7 +78,7 @@ end
|
||||
local function connect()
|
||||
while true do
|
||||
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,
|
||||
function ()
|
||||
while true do
|
||||
|
||||
1
libDeflate.lua
Normal file
1
libDeflate.lua
Normal file
File diff suppressed because one or more lines are too long
@@ -1,6 +1,6 @@
|
||||
local interactions = {}
|
||||
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 message_queue = {}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
local interactions = {}
|
||||
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 clients = {}
|
||||
local message_queue = {}
|
||||
@@ -126,7 +126,14 @@ queue_message({protocol="getroutes"})
|
||||
interactions.send({protocol="route_erase",destination=os.getComputerID()})
|
||||
queue_message({protocol="route",destination=os.getComputerID(),distance=0})
|
||||
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()
|
||||
while true do
|
||||
local _, msg = interactions.receive()
|
||||
@@ -188,8 +195,7 @@ while true do
|
||||
if (not msg.visited) then msg.visited = {} end
|
||||
msg.visited[#msg.visited+1] = os.getComputerID()
|
||||
print("rerouting")
|
||||
distancemap = {}
|
||||
distancemap[os.computerID()] = {dist = 0, sender = os.computerID()}
|
||||
distancemap = generate_default_routes()
|
||||
queue_message({protocol="getroutes"})
|
||||
queue_message(msg)
|
||||
end
|
||||
@@ -219,6 +225,7 @@ local function heartbeat_f()
|
||||
end
|
||||
end)
|
||||
if not heartbeat then
|
||||
print(k, "timed out")
|
||||
distancemap[k] = nil
|
||||
queue_message({protocol="reroute"})
|
||||
end
|
||||
|
||||
1
minified_disklock.lua
Normal file
1
minified_disklock.lua
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user