Browse Source

Nasty bug somewhere in async/net/dns/dhcp. Can't figure out where

master
BuildTools 1 year ago
parent
commit
ea09f449b6
  1. 7
      dhclient.lua
  2. 7
      get-all.lua
  3. 15
      lib/async.lua
  4. 14
      lib/dhcp.lua
  5. 16
      lib/dns.lua

7
dhclient.lua

@ -2,7 +2,12 @@ local io = require("io")
local serial = require("serialization")
local dhcp = require("dhcp")
local pkt = dhcp.query()
local pkt, err = dhcp.query()
if pkt == nil then
print("Error: "..err)
return
end
print("Received response from "..pkt.raddr)
print("Writing to /etc/resolv.cfg")

7
get-all.lua

@ -113,7 +113,12 @@ local function getFiles(url, result, workDir)
end
-- Grab all files on the server
local path = shell.getWorkingDirectory()
local path = ""
if args[2] == nil then
path = shell.getWorkingDirectory()
else
path = args[2]
end
getFiles(makeRequest(fixURL(args[1])))
shell.setWorkingDirectory(path)

15
lib/async.lua

@ -9,7 +9,7 @@ local async = {}
-- An async wrapper for event.pullFiltered
function async.pullFiltered(...)
local start = computer.uptime()
local args = {...}
@ -82,7 +82,6 @@ function async.pullFiltered(...)
until #tmp > 0
end
else
print(timeout, blocking)
if timeout ~= nil then
-- Check if not in a coroutine
if blocking then
@ -168,20 +167,18 @@ function async.roundRobin(loop, ignoreError)
local i = 1
repeat
local b = loop.live[i]
print(b)
local r = {coroutine.resume(b.coro, table.unpack(b.args))}
local blocking, results = r[1], ll.slice(r, 2)
local status, results = r[1], ll.slice(r, 2)
-- Fail and exit if a function is bad
if blocking and not ignoreError then
if not status and not ignoreError then
io.stderr:write(results[1])
return
-- Don't exit but print the bad message
elseif blocking then
print(results[1])
elseif not status then
end
-- Stop running dead coroutines and add the results
if coroutine.blocking(b.coro) == "dead" then
if coroutine.status(b.coro) == "dead" then
b.results = results
table.insert(loop.dead, #loop.dead+1, table.remove(loop.live, i))
else
@ -193,4 +190,4 @@ end
return async
-- wget -f http://mc.bashed.rocks:13699/lib/async.lua /usr/lib/async.lua
-- wget -f http://mc.bashed.rocks:13699/lib/async.lua lib/async.lua

14
lib/dhcp.lua

@ -103,17 +103,20 @@ function dhcp.startServer(servPort, clientPort, nonblocking, cacheConfig)
while true do
local pkt, err = net.recv{servPort, filter = dhcp.serverMsg, nonblocking = nonblocking}
if pkt == nil and err == "interrupted" then
print("Interrupted")
return
return pkt, err
end
print("Received request from "..pkt.raddr)
-- os.sleep(1)
if cacheConfig then
net.send(pkt.raddr, clientPort, "dhcp", serial.serialize(config))
else
print("Here")
net.send(pkt.raddr, clientPort, "dhcp", serial.serialize(dhcp.getServerConfig()))
end
end
end
@ -147,14 +150,11 @@ function dhcp.query(servPort, clientPort, nonblocking)
clientPort,
timeout = 3,
filter = dhcp.clientMsg,
nonblocking = nonblocking
nonblocking = not not nonblocking
}
return pkt, err
end
-- dhcp.startServer()
-- wget -f http://localhost:8080/dhcp.lua /usr/lib/dhcp.lua
-- wget -f http://localhost:8080/net.lua /usr/lib/net.lua
-- wget -f http://mc.bashed.rocks:13699/lib/dhcp.lua lib/dhcp.lua
return dhcp

16
lib/dns.lua

@ -89,7 +89,7 @@ function getRecord(data, records)
return record
end
function dns.startServer(port, cacheRecords)
function dns.startServer(port, nonblocking, cacheRecords)
-- Make sure ports aren't invalid
if type(port) ~= "number" then
port = dns.PORT
@ -128,11 +128,15 @@ function dns.startServer(port, cacheRecords)
end
while true do
local pkt = {async.pullFiltered(dns.serverMsg, not nonblocking)}
if pkt[1] == "interrupted" then
local pkt, err = {async.pullFiltered(dns.serverMsg, not nonblocking)}
print(#pkt)
if #pkt == 0 then
return pkt, err
elseif pkt[1] == "interrupted" then
print("Interrupted")
return
return pkt, err
end
local raddr, port = pkt[3], pkt[4]
local data = ll.slice(pkt, 6)
print("Received request for "..data[4].." from "..raddr)
@ -250,8 +254,6 @@ function dns.revQuery(host, useCache, nonblocking)
return query(host, useCache, "reverse", nonblocking)
end
-- dns.startServer()
-- wget -f http://localhost:8080/lib/dns.lua /usr/lib/dns.lua
-- wget -f http://localhost:8080/lib/dns.lua lib/dns.lua
return dns
Loading…
Cancel
Save