Blink - Communication API with Sender Verification

Started by KingofGamesYami, Aug 13, 2018, 02:07 am

Previous topic - Next topic

KingofGamesYami

Aug 13, 2018, 02:07 am Last Edit: Aug 13, 2018, 02:11 am by KingofGamesYami Reason: Update statemachine URL
Reposted from here

Blink is essentially a replacement for rednet, adding a way to verify the identity of the sender. This does not encrypt or otherwise secure your messages!
Installation
pastebin get YGTnaHtd blink
Usage
Setup
This doesn't have to happen every time you run the program, your choices are automatically saved to a file
Before transmitting messages, you must tell the sender what it's secret key is. This is done using setDeviceKey.
Code Select
blink.setDeviceKey( "MySecretPassword" )
After this step, you must tell the receiver what that key was. This is done using pair.
Code Select
blink.pair( SENDER_ID, "MySecretPassword" )
SENDER_ID is the id of the sending computer with that secret key. This can be obtained by running "id" in the shell of that computer.
Starting Up
While your computer is sending or receiving messages, blink.run must be running in parallel with your program. This would look something like this:
Code Select
parallel.waitForAny( blink.run, function()
-- your program here
end )
If you wish to use an alternative means of running blink.run, such as multishell or statemachine, you are welcome to do so. However, this is by far the simplest way to use it.
Sending and Receiving Messages
The receiving computer must be paired and blink.run must be appropriately integrated
To send a message, you need to know the ID of the computer you wish to contact in addition to your message contents. Optionally, you can specify a timeout, because the function will hang indefinitely if the receiver is not available.
Code Select
local success = blink.send( 3, "Hello, World!", 1 ) --sends "Hello, World!" to computer 3 (times out after 1 second)
To receive a message, you can either pull a "blink_message" event or use blink.receive.
Code Select
local id, message = blink.receive( SENDER_ID )
SENDER_ID must be the id you wish to receive from. The function need not return id, but I do so to retain some similarity with recnet.receive.
Code Select
local event, message, from = os.pullEvent( "blink_message" )
Really not anything to explain here, if you're at all familiar with the computercraft event system.
Features
  • All computers act as repeaters, therefor a repeat program is as simple as os.loadAPI( "blink" ) blink.run()!
  • Passwords are not send directly, preventing repeat attacks. They are stored in plaintext, however, since any user with access to the computer would be able to send messages as that computer (duh)
  • Automatically finds a wireless modem and opens it. Will provide an error message if no wireless modem is detected.
  • Automatically downloads hash API
  • Saves paired devices and own private key (insecurely, for reasons mentioned above)
Credit
Anavrins, for his sha256 API (downloaded as "hash" automatically).
Alex Kloss for the implementation of base64 I'm using
*Credits are given in more detail in the code itself.
I'm a ComputerCraft veteran with over 3k posts on the old ComputerCraft Forum.  I'm mostly inactive in CC having moved on to bigger, more interesting projects but still contribute to the community.