This set of programs and APIs aims to provide easy to use mesh networking.
The "main" part consists of the router software and the client software.
Common Routing Framework - Router:
This provides most of the functionality of the CRF set.
It handles route discovery, route generation, relaying packets, and managing its LAN, if it has one.
Most of the time this program will be run in the foreground, though it can be run in the background.
If run as a program, the router software will automatically start itself. Usage:
router [network name] [network key] [debug flags]
If loaded as an API (with os.loadAPI), the router software will expose two APIs:
- Common Routing Framework API ("CRF"):
- This API connects to the "internetworking" part of the router.
- CRF.run(debug_flags): Start the router; this function runs forever until it encounters an error.
- CRF.getRoutingTable(): Get a copy of the routing table; this contains next-hop interfaces for all known hosts.
- CRF.getRoute(host): Get the entire route to host.
- CRF.send(to, msg): Send a message msg to host to.
- CRF.setWANKey(key): Set the WAN encryption key to SHA2(key). This enables encryption on messages addressed to routers also using the same WAN key.
- CRF.setHMACVerifyStatus(inbound, outbound): Enable or disable hash generation for incoming and/or outgoing messages. Disabling either of these makes the system less secure, but increases efficency.
- To be specific:
- inbound determines whether we verify messages that are addressed to us or our LAN clients.
- outbound determines whether we append an HMAC (hash) to messages that we send.
- If a host with outbound set to false tries to send a message to a host with inbound set to true, then all of the sender's messages will be rejected.
- inbound and outbound are true by default.
- CRF.compileDebugFlags(ev, tm, rg, sr, de, pe, le, lan): Create a debug bitmask to be passed to CRF.run; this determines what debug messages are emitted.
- Debug flags:
- "ev" - "EVents": Show all debug messages.
- "tm" - "TiMing": Show debug messages related to periodic events.
- "rg" - "RouteGen": Show debug messages related to routing table generation.
- "sr" - "Search algoRithm": Show debug messages related to the breadth-first search algorithm used in route generation.
- "de" - "Data Events": Show events related to the processing of incoming data.
- "pe" - "Ping Events": Show events related to the local reachability protocol.
- "lan" - "Local Area Network events": Show events related to LAN clients.
- CRF.getStatus(): Returns true if CRF is or was running.
- Local Area Network API ("LAN"):
- LAN.getStatus(): Returns true if the LAN segment is or was running. This is equivalent to CRF.getStatus().
- LAN.isSecure(): Returns true if the network is using AES encryption.
- LAN.setNetworkName(name): Sets the announced name of the LAN.
- LAN.setNetworkKey(key): Sets the encryption key the network uses.
- LAN.getNetworkName(name): Gets the announced name of the LAN.
- LAN.send(id, data): Sends a LAN data packet addressed to id with data data.
- LAN.broadcast(data): Sends a LAN data packet addressed to everyone with data data.
This provides client-to-router functionality for computers on a LAN.
It handles sending and receiving messages, authenticating to and joining LANs, and joining and leaving multicast groups (see below).
When loaded as an API, it exposes the following functions under the "LANClient" name:
- LANClient.associate(side, id): Connect to the LAN hosted by the router with computer number id.
- LANClient.disassociate(): Attempt to disconnect from the LAN we are currently connected to.
- LANClient.authenticate(side, id, key): Attempt to authenticate to the LAN specified, allowing us to associate with it if the attempt is successful.
- LANClient.requiresAuth(side, id): Ask the router hosting the specified LAN if authentication is required to join its LAN.
- LANClient.connect(side, id, key): Connect to the specified LAN, authenticating beforehand if necessary.
- LANClient.get_router(): Get the ID of the router we're currently connected to.
- LANClient.get_id_list(): Get a list of every router and host we can reach.
- LANClient.get_lan_list(): Get a list of every other client on our current LAN.
- LANClient.get_networks(): Get a list of every network that we've received "beacon" messages from.
- LANClient.send(id, data): Send a message to computer id; the computer does not have to be on our LAN; the local router will handle delivering the message as necessary.
- LANClient.broadcast(data): Send a message to every computer on the current LAN.
- LANClient.receive(timeout, id): Block until a message addressed to us is received, or until timeout seconds have passed, whichever comes first. Works similar to the old rednet.receive(), only without a directional component.
- LANClient.join_group(group_id): Join multicast group group_id, allowing us to receive messages addressed to that multicast group.
- LANClient.leave_group(group_id): Leave multicast group group_id.
- LANClient.background_loop(): This function is meant to run in the background. It provides a few auxillary functions such as network discovery and event generation. This API can still function without this running.
Modem Emulator:
This API allows users to create "virtual modems", which act like real modems, but transmit messages over CRF (using multicast) to every computer on the network who is also running the API. This allows practically any program to run over CRF.
Virtual modems act and are used just like real peripherals.
When loaded as an API, it exposes these functions under the "modem_emulator" name:
- modem_emulator.backgroundListener(): This function is meant to run in the background as a coroutine, listening for data packets and emitting fake "modem_message" events.
- modem_emulator.register_modem(side): This function tries to create a new virtual modem at side.
- modem_emulator.unregister_modem(side): This function deletes the virtual modem at side if one exists.
modem_emulator [register/unregister] [side]
File Transfers:
This isn't really part of the CRF set. This is just an example of what is possible with CRF.
This, as its name implies, allows users to transfer files over a CRF network or a LAN.
File Transfer Server:
This program services file transfer requests. By default, files are saved to and read from "server/", regardless of whether it exists or not.
This program is not meant to be loaded as an API.
This program does not take any parameters.
File Transfer Client:
This program makes file transfer requests.
When loaded as an API, it exposes the following functions under the "ftp" name:
- ftp.readFile(server, file, binary): Retrieve a file from a FTP server. The return type is determined by the binary parameter; if it is true, then the returned value is a table of bytes. If it is false, then the returned value is a string.
- ftp.writeFile(server, file, data, binary): Write a file to a FTP server. The file is written according to the binary parameter, if it is true, then data is assumed to be a table of bytes. Otherwise, data is assumed to be a string.
- ftp.deleteFile(server, file): Delete a file from a FTP server.
- ftp.mkDir(server, dir): Make a directory on a FTP server.
- ftp.listDir(server, dir): Get a directory listing from a FTP server.
ftp [action] [server] [parameters]
Downloads: