mirror of
https://github.com/ShadowKatStudios/OC-Minitel.git
synced 2024-11-25 19:38:07 +11:00
Compare commits
6 Commits
67c5790bd4
...
7ed7452428
Author | SHA1 | Date | |
---|---|---|---|
7ed7452428 | |||
e6e7a6b6b6 | |||
|
02e4eb1794 | ||
|
9cdce20847 | ||
|
0e2b3a9e91 | ||
|
b624918e88 |
9
.editorconfig
Normal file
9
.editorconfig
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
insert_final_newline = true
|
||||||
|
|
||||||
|
[*.lua]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 1
|
@ -40,10 +40,8 @@ sender: original sender of packet
|
|||||||
data: the actual packet data, duh.
|
data: the actual packet data, duh.
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
local listeners = {}
|
|
||||||
local timers = {}
|
local timers = {}
|
||||||
local hostname = computer.address():sub(1,8)
|
local hostname = computer.address():sub(1,8)
|
||||||
local listener = false
|
|
||||||
local dbug = false
|
local dbug = false
|
||||||
local modems = {}
|
local modems = {}
|
||||||
local port = 4096
|
local port = 4096
|
||||||
@ -112,7 +110,7 @@ local function genPacketID()
|
|||||||
return npID
|
return npID
|
||||||
end
|
end
|
||||||
|
|
||||||
local function sendPacket(packetID,packetType,dest,sender,vport,data)
|
local function sendPacket(packetID,packetType,dest,sender,vport,data,repeatingFrom)
|
||||||
if rcache[dest] then
|
if rcache[dest] then
|
||||||
dprint("Cached", rcache[dest][1],"send",rcache[dest][2],port,packetID,packetType,dest,sender,vport,data)
|
dprint("Cached", rcache[dest][1],"send",rcache[dest][2],port,packetID,packetType,dest,sender,vport,data)
|
||||||
if modems[rcache[dest][1]].type == "modem" then
|
if modems[rcache[dest][1]].type == "modem" then
|
||||||
@ -123,10 +121,14 @@ local function sendPacket(packetID,packetType,dest,sender,vport,data)
|
|||||||
else
|
else
|
||||||
dprint("Not cached", port,packetID,packetType,dest,sender,vport,data)
|
dprint("Not cached", port,packetID,packetType,dest,sender,vport,data)
|
||||||
for k,v in pairs(modems) do
|
for k,v in pairs(modems) do
|
||||||
|
-- do not send message back to the wired or linked modem it came from
|
||||||
|
-- the check for tunnels is for short circuiting `v.isWireless()`, which does not exist for tunnels
|
||||||
|
if v.address ~= repeatingFrom or (v.type ~= "tunnel" and v.isWireless()) then
|
||||||
if v.type == "modem" then
|
if v.type == "modem" then
|
||||||
v.broadcast(port,packetID,packetType,dest,sender,vport,data)
|
v.broadcast(port,packetID,packetType,dest,sender,vPort,data)
|
||||||
elseif v.type == "tunnel" then
|
elseif v.type == "tunnel" then
|
||||||
v.send(packetID,packetType,dest,sender,vport,data)
|
v.send(packetID,packetType,dest,sender,vPort,data)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -19,10 +19,11 @@ local event = require "event"
|
|||||||
local component = require "component"
|
local component = require "component"
|
||||||
local computer = require "computer"
|
local computer = require "computer"
|
||||||
local serial = require "serialization"
|
local serial = require "serialization"
|
||||||
|
|
||||||
local hostname = computer.address():sub(1,8)
|
local hostname = computer.address():sub(1,8)
|
||||||
local listener = false
|
|
||||||
cfg.debug = false
|
|
||||||
local modems = {}
|
local modems = {}
|
||||||
|
|
||||||
|
cfg.debug = false
|
||||||
cfg.port = 4096
|
cfg.port = 4096
|
||||||
cfg.retry = 10
|
cfg.retry = 10
|
||||||
cfg.retrycount = 64
|
cfg.retrycount = 64
|
||||||
@ -91,7 +92,9 @@ function start()
|
|||||||
f:close()
|
f:close()
|
||||||
end
|
end
|
||||||
print("Hostname: "..hostname)
|
print("Hostname: "..hostname)
|
||||||
if listener then return end
|
|
||||||
|
if next(listeners) ~= nil then return end
|
||||||
|
|
||||||
modems={}
|
modems={}
|
||||||
for a,t in component.list("modem") do
|
for a,t in component.list("modem") do
|
||||||
modems[#modems+1] = component.proxy(a)
|
modems[#modems+1] = component.proxy(a)
|
||||||
@ -112,7 +115,7 @@ function start()
|
|||||||
return npID
|
return npID
|
||||||
end
|
end
|
||||||
|
|
||||||
local function sendPacket(packetID,packetType,dest,sender,vPort,data)
|
local function sendPacket(packetID,packetType,dest,sender,vPort,data,repeatingFrom)
|
||||||
if rcache[dest] then
|
if rcache[dest] then
|
||||||
dprint("Cached", rcache[dest][1],"send",rcache[dest][2],cfg.port,packetID,packetType,dest,sender,vPort,data)
|
dprint("Cached", rcache[dest][1],"send",rcache[dest][2],cfg.port,packetID,packetType,dest,sender,vPort,data)
|
||||||
if component.type(rcache[dest][1]) == "modem" then
|
if component.type(rcache[dest][1]) == "modem" then
|
||||||
@ -123,6 +126,9 @@ function start()
|
|||||||
else
|
else
|
||||||
dprint("Not cached", cfg.port,packetID,packetType,dest,sender,vPort,data)
|
dprint("Not cached", cfg.port,packetID,packetType,dest,sender,vPort,data)
|
||||||
for k,v in pairs(modems) do
|
for k,v in pairs(modems) do
|
||||||
|
-- do not send message back to the wired or linked modem it came from
|
||||||
|
-- the check for tunnels is for short circuiting `v.isWireless()`, which does not exist for tunnels
|
||||||
|
if v.address ~= repeatingFrom or (v.type ~= "tunnel" and v.isWireless()) then
|
||||||
if v.type == "modem" then
|
if v.type == "modem" then
|
||||||
v.broadcast(cfg.port,packetID,packetType,dest,sender,vPort,data)
|
v.broadcast(cfg.port,packetID,packetType,dest,sender,vPort,data)
|
||||||
elseif v.type == "tunnel" then
|
elseif v.type == "tunnel" then
|
||||||
@ -131,6 +137,7 @@ function start()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function pruneCache()
|
local function pruneCache()
|
||||||
for k,v in pairs(rcache) do
|
for k,v in pairs(rcache) do
|
||||||
@ -177,7 +184,7 @@ function start()
|
|||||||
elseif dest:sub(1,1) == "~" then -- broadcasts start with ~
|
elseif dest:sub(1,1) == "~" then -- broadcasts start with ~
|
||||||
computer.pushSignal("net_broadcast",sender,vPort,data)
|
computer.pushSignal("net_broadcast",sender,vPort,data)
|
||||||
elseif cfg.route then -- repeat packets if route is enabled
|
elseif cfg.route then -- repeat packets if route is enabled
|
||||||
sendPacket(packetID,packetType,dest,sender,vPort,data)
|
sendPacket(packetID,packetType,dest,sender,vPort,data,localModem)
|
||||||
end
|
end
|
||||||
if not rcache[sender] then -- add the sender to the rcache
|
if not rcache[sender] then -- add the sender to the rcache
|
||||||
dprint("rcache: "..sender..":", localModem,from,computer.uptime())
|
dprint("rcache: "..sender..":", localModem,from,computer.uptime())
|
||||||
@ -233,10 +240,12 @@ end
|
|||||||
function stop()
|
function stop()
|
||||||
for k,v in pairs(listeners) do
|
for k,v in pairs(listeners) do
|
||||||
event.ignore(k,v)
|
event.ignore(k,v)
|
||||||
|
listeners[k] = nil
|
||||||
print("Stopped listener: "..tostring(v))
|
print("Stopped listener: "..tostring(v))
|
||||||
end
|
end
|
||||||
for k,v in pairs(timers) do
|
for k,v in pairs(timers) do
|
||||||
event.cancel(v)
|
event.cancel(v)
|
||||||
|
timers[k] = nil
|
||||||
print("Stopped timer: "..tostring(v))
|
print("Stopped timer: "..tostring(v))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -12,7 +12,7 @@ Upon a node receiving a message addressed to itself, it should:
|
|||||||
2. Check if the packet is addressed to the node, and if so, queue it as a net_msg event
|
2. Check if the packet is addressed to the node, and if so, queue it as a net_msg event
|
||||||
3. If the packet is indeed addressed to this node, and the packet type is 1 (reliable), send an acknowledgement packet.
|
3. If the packet is indeed addressed to this node, and the packet type is 1 (reliable), send an acknowledgement packet.
|
||||||
4. Optional: Add the sender to the address cache if it isn't already in the cache
|
4. Optional: Add the sender to the address cache if it isn't already in the cache
|
||||||
5. Optional: If the packet is addressed to a different node, repeat the packet, preferably respecting the address cache
|
5. Optional: If the packet is addressed to a different node, repeat the packet via all wireless modems and all wired/linked modems, preferably excluding the one receiving the packet, and preferably respecting the address cache
|
||||||
|
|
||||||
If the packet is, for some reason invalid, simply drop the packet.
|
If the packet is, for some reason invalid, simply drop the packet.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user