From 2174105d3010e159e46fe973f58e97f1d2dbf8c8 Mon Sep 17 00:00:00 2001 From: Izaya Date: Wed, 21 Feb 2018 10:46:53 +1100 Subject: [PATCH] implemented broadcasts --- OpenOS/etc/rc.d/minitel.lua | 9 ++++++--- protocol-3.md | 6 +++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/OpenOS/etc/rc.d/minitel.lua b/OpenOS/etc/rc.d/minitel.lua index 33fc80e..948d20f 100644 --- a/OpenOS/etc/rc.d/minitel.lua +++ b/OpenOS/etc/rc.d/minitel.lua @@ -22,6 +22,7 @@ local dbug = false local modems = {} local port = 4096 local retry = 30 +local route = true --[[ LKR format: @@ -136,14 +137,16 @@ function start() if packetType ~= 2 then computer.pushSignal("net_msg",sender,vport,data) 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) end - if not rcache[sender] then + if not rcache[sender] then -- add the sender to the rcache dprint("rcache: "..sender..":", localModem,from,computer.uptime()) rcache[sender] = {localModem,from,computer.uptime()+rctime} end - if not pcache[packetID] then + if not pcache[packetID] then -- add the packet ID to the pcache pcache[packetID] = computer.uptime()+pctime end end diff --git a/protocol-3.md b/protocol-3.md index 4a790f2..0dc5b63 100644 --- a/protocol-3.md +++ b/protocol-3.md @@ -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. ### 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 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. -For example, to send to nodes `a` and `b`, the address in the packet would be `a~b`. +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`. 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.