Add auto-updating address list
This commit is contained in:
45
startup.lua
45
startup.lua
@ -16,6 +16,40 @@
|
||||
---------------------------------------------
|
||||
|
||||
local config = require("config")
|
||||
|
||||
-- Auto-update addresses file if enabled
|
||||
local function updateAddressesFile()
|
||||
if config.autoUpdateAddresses and http then
|
||||
print("Checking for addresses file update...")
|
||||
local response = http.get(config.addressesRepoUrl)
|
||||
if response then
|
||||
local content = response.readAll()
|
||||
response.close()
|
||||
|
||||
local file = fs.open("addresses.lua", "w")
|
||||
if file then
|
||||
file.write(content)
|
||||
file.close()
|
||||
print("Addresses file updated successfully")
|
||||
return true
|
||||
else
|
||||
print("Failed to write addresses file")
|
||||
end
|
||||
else
|
||||
print("Failed to download addresses file - using local version")
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
-- Try to update addresses file
|
||||
local addressesUpdated = updateAddressesFile()
|
||||
|
||||
-- Reload addresses module if updated
|
||||
if addressesUpdated then
|
||||
package.loaded["addresses"] = nil
|
||||
end
|
||||
|
||||
local addresses = require("addresses")
|
||||
local utils = require("utils")
|
||||
local display = require("display")
|
||||
@ -51,9 +85,17 @@ if gate.getIris() == nil then
|
||||
config.irisEnabled = false
|
||||
end
|
||||
|
||||
-- Get local gate address
|
||||
local localGateAddress = gate.getLocalAddress()
|
||||
if localGateAddress then
|
||||
print("Local gate address: " .. gate.addressToString(localGateAddress))
|
||||
else
|
||||
print("WARNING: Could not read local gate address")
|
||||
end
|
||||
|
||||
-- Initialize modules
|
||||
utils.init(config, gate)
|
||||
display.init(mon, config, addresses, utils)
|
||||
display.init(mon, config, addresses, utils, localGateAddress)
|
||||
handlers.init(config, gate, mon, utils, display, events)
|
||||
|
||||
-- Ensure gate starts disconnected
|
||||
@ -572,6 +614,7 @@ local function handleOutgoingDial()
|
||||
|
||||
-- Open local iris for outgoing connection
|
||||
if config.irisEnabled then
|
||||
sleep(2)
|
||||
utils.openIris()
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user