Reposted from here (http://www.computercraft.info/forums2/index.php?/topic/27228-blink-communication-api-with-sender-verification/)
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!Installationpastebin get YGTnaHtd blink (http://pastebin.com/YGTnaHtd)
UsageSetupThis 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.
blink.setDeviceKey( "MySecretPassword" )
After this step, you must tell the receiver what that key was. This is done using
pair.
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 UpWhile your computer is sending or receiving messages,
blink.run must be running in parallel with your program. This would look something like this:
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 (https://forums.computercraft.cc/index.php?topic=33.0), you are welcome to do so. However, this is by far the simplest way to use it.
Sending and Receiving MessagesThe 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.
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.
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.
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)
CreditAnavrins (http://www.computercraft.info/forums2/index.php?/user/12870-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.