Skip to content

Commit

Permalink
Convert dns to module
Browse files Browse the repository at this point in the history
  • Loading branch information
tomodachi94 committed Dec 9, 2022
1 parent 299bb1b commit f5c978c
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/dns/modules/dns.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
os.loadAPI("apis/util")
local util = require("util")
local dns = {}

local cache = util.initializeGlobalTable("dnsCache")

function resolve(url)
function dns.resolve(url)
local id = tonumber(url)
if id ~= nil then
return id
Expand All @@ -21,17 +22,17 @@ function resolve(url)
return unpack(entry)
end

function getHostname()
function dns.getHostname()
local hostname = os.getComputerLabel()
if hostname == nil then
hostname = tostring(os.computerID())
end
return hostname
end

function register(protocol, hostname)
function dns.register(protocol, hostname)
if hostname == nil then
hostname = getHostname()
hostname = dns.getHostname()
end
rednet.host(protocol, hostname)
end
end

0 comments on commit f5c978c

Please sign in to comment.