1
0
mirror of https://github.com/ShadowKatStudios/OC-Minitel.git synced 2024-11-23 10:38:05 +11:00

implemented broadcasts

This commit is contained in:
Izaya 2018-02-21 10:46:53 +11:00
parent 3d45735361
commit 2174105d30
2 changed files with 9 additions and 6 deletions

View File

@ -22,6 +22,7 @@ local dbug = false
local modems = {} local modems = {}
local port = 4096 local port = 4096
local retry = 30 local retry = 30
local route = true
--[[ --[[
LKR format: LKR format:
@ -136,14 +137,16 @@ function start()
if packetType ~= 2 then if packetType ~= 2 then
computer.pushSignal("net_msg",sender,vport,data) computer.pushSignal("net_msg",sender,vport,data)
end end
else elseif dest:sub(1,1) == "~" then -- broadcasts start with ~
computer.pushSignal("net_broadcast",sender,vport,data)
elseif route then -- repeat packets if route is enabled
sendPacket(packetID,packetType,dest,sender,vport,data) sendPacket(packetID,packetType,dest,sender,vport,data)
end end
if not rcache[sender] then 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())
rcache[sender] = {localModem,from,computer.uptime()+rctime} rcache[sender] = {localModem,from,computer.uptime()+rctime}
end end
if not pcache[packetID] then if not pcache[packetID] then -- add the packet ID to the pcache
pcache[packetID] = computer.uptime()+pctime pcache[packetID] = computer.uptime()+pctime
end end
end end

View File

@ -34,12 +34,12 @@ It is recommended to keep the data in the cache for 30 seconds or so, then drop
When sending a message, check the cache for the given destination. If there is a hardware address in the cache for the destination, send the message straight to that address. Otherwise, broadcast the message. When sending a message, check the cache for the given destination. If there is a hardware address in the cache for the destination, send the message straight to that address. Otherwise, broadcast the message.
### Optional: Broadcast address ### Optional: Broadcast address
Packets addressed to the broadcast address, an address of just the tilde character, `~`, ASCII 126, can optionally be received by all nodes of the same layer 2 network. While a node MAY forward a broadcast packet to other nodes, it SHOULD NOT, unless both sides of the forward are prepared to handle such a packet, to avoid it going around the entire layer 3 network. Packets addressed to the broadcast address, an address beginning with the tilde character, `~`, ASCII 126, can optionally be received by all nodes of the same layer 2 network. While a node MAY forward a broadcast packet to other nodes, it SHOULD NOT, unless both sides of the forward are prepared to handle such a packet, to avoid it going around the entire layer 3 network.
### Optional: Multicast ### Optional: Multicast
A multicast packet has a specially formatted address part. A multicast packet has a specially formatted address part.
The address must be a list of valid addresses, seperated by the tilde character, `~`, ASCII 126. The address must be a list of valid addresses, beginning with `~` seperated by the tilde character, `~`, ASCII 126.
For example, to send to nodes `a` and `b`, the address in the packet would be `a~b`. For example, to send to nodes `a` and `b`, the address in the packet would be `~a~b`.
Each node should send multicasts as layer 2 broadcasts, unless it is known (using the address cache) that all layer 3 destination addresses have to be sent to or forwarded by one layer 2 address. Each node should send multicasts as layer 2 broadcasts, unless it is known (using the address cache) that all layer 3 destination addresses have to be sent to or forwarded by one layer 2 address.