From 071a692f118d4c9bf706e706a563f59e6bc426c4 Mon Sep 17 00:00:00 2001 From: Izzy Date: Sat, 16 Mar 2024 12:30:25 +1000 Subject: [PATCH] Check network device MTUs and split packets accordingly depending on capacity and overhead. Tally of packet overhead: - 16 bytes packet ID - 8 bytes type - N bytes dest - N bytes source - 8 bytes port - N bytes data - 6*2 bytes network card overhead --- OpenOS/usr/lib/minitel.lua | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/OpenOS/usr/lib/minitel.lua b/OpenOS/usr/lib/minitel.lua index 48afd0e..a49c31f 100644 --- a/OpenOS/usr/lib/minitel.lua +++ b/OpenOS/usr/lib/minitel.lua @@ -1,12 +1,18 @@ local computer = require "computer" local event = require "event" local net = {} -net.mtu = 4096 +net.mtu = 8192 net.streamdelay = 30 net.minport = 32768 net.maxport = 65535 net.openports = {} +for k,v in pairs(computer.getDeviceInfo()) do + if v.class == "network" then + net.mtu = math.min(net.mtu, tonumber(v.capacity)) + end +end + function net.genPacketID() local npID = "" for i = 1, 16 do @@ -31,17 +37,13 @@ function net.rsend(to,port,data,block) end -- ordered packet delivery, layer 4? - function net.send(to,port,ldata) - local tdata = {} - if ldata:len() > net.mtu then - for i = 1, ldata:len(), net.mtu do - tdata[#tdata+1] = ldata:sub(1,net.mtu) - ldata = ldata:sub(net.mtu+1) - end - else - tdata = {ldata} + local tdata, hsize = {}, 44 + #(os.getenv("HOSTNAME") or computer.address():sub(1,8)) + #to + while hsize+#ldata > net.mtu do + tdata[#tdata+1] = ldata:sub(1, net.mtu - hsize) + ldata = ldata:sub(#tdata[#tdata]+1) end + tdata[#tdata+1] = ldata for k,v in ipairs(tdata) do if not net.rsend(to,port,v) then return false end end