This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
skwerlman's profile picture

Rednet Data Transfer Protocol (alpha r3)

Started by skwerlman, 10 March 2014 - 02:56 PM
skwerlman #1
Posted 10 March 2014 - 03:56 PM
IMPORTANT NOTE: This is a Protocol API. It does not implement a server/client setup. That's up to you.

RDTP
A networking framework designed to emulate the World Wide Web (to a small degree). Basically the goal of this project is to standardize Rednet in a way that allows for HTML-like pages to be transferred from one computer to another. At the moment, this is just a basic API that gets the basics of data transfer in place. I have a long list of ideas for this project, but I need feedback on the current system as it is before I can get moving towards loftier goals.

RDTPs
RDTPs is to RDTP as HTTPS is to HTTP. It's Rednet Data Transfer Protocol + security. While it doesn't automatically encrypt data, it's designed to support asymmetric encryption, as well as content verification methods such as SHA-256 hashing. This protocol works especially well with Immibis's Peripherals, since that's the mod I used to test this protocol. Of course, you can use any algorithm you'd like, so long as both the client and server know it.
This protocol will be updated alongside RDTP, so any features in one *should* be released in the other simultaneously.

Help Wanted!
Are you proficient in Lua? Know anything (literally anything at all, I don't care what) about how data is moved on the internet? Can you draw? Any of the above? I need your help!
PM me if you're interested.

Download:
Spoileralpha r3:
.zip - link
ccAppStore pkg: link

The zip version contains example implementations of RDTP, but you can install the AppStore pkg in-game.

Installation:
SpoilerZip:
1. Download the files from the above link.
2. Unzip the archive.
3. Copy the contents of /rdtp/ into .../.minecraft/saves/[YourWorldNameHere]/computer/[TheIDOfTheComputer]/
The included startup file will load both versions of the API by default. This can be changed, as they are each fully independent.

AppStore:
1. Install the AppStore installer, following these instructions.
2. Run
appstore install 25
to install RDTP.
3. To run the startup file, you'll need to run
cd /programs/RDTP/
startup

Methods
SpoilerThere are no open or close methods because that's all handled automatically. The modem is dynamically detected, so the first call to send() will take longer than the others, etc.

rdtp.send(target, code, format, data, label, srcid)
[indent=1]Sends a table to the target:[/indent]
[indent=1]msg = { code = "code", format = "format", data = "data", label = "label", srcid = srcid }[/indent]
[indent=2]code: A hex string from '00' to 'ff' indicating the meaning of the message.[/indent]
[indent=2]format: A string declaring the type of content in 'data'. This allows us to support picture, video, and other formats.[/indent]
[indent=2]data: A string containing the message itself.[/indent]
[indent=2]label: A string containing the label of the sender. Clients can send nil instead, but servers must send their label.[/indent]
[indent=2]srcid: The ID of the origin computer. This allows us to use rednet repeaters without really needing to try too hard.[/indent]
[indent=1]Returns a table received from the target. This method will wait up to ten seconds for a response from the target before giving up.[/indent]

rdtp.receive(t)
[indent=1]Waits for any rednet message. Usually for servers only.[/indent]
[indent=1]If it times out, it will likely lead to a 10 error.[/indent]
[indent=1]Returns a table.[/indent]

rdtp.replyTo(targetID, code, format, data, label, srcid)
[indent=1]Sends a table to the target:[/indent]
[indent=1]msg = { code = "code", format = "format", data = "data", label = "label", srcid = srcid }[/indent]
[indent=2]code: A hex string from '00' to 'ff' indicating the meaning of the message.[/indent]
[indent=2]format: A string declaring the type of content in 'data'. This allows us to support picture, video, and other formats.[/indent]
[indent=2]data: A string containing the message itself.[/indent]
[indent=2]label: A string containing the label of the sender. Clients can send nil instead, but servers must send their label.[/indent]
[indent=2]srcid: The ID of the origin computer. This allows us to use rednet repeaters without really needing to try too hard.[/indent]
[indent=1]Doesn't return anything.[/indent]

rdtps.send(target, code, format, data, label, srcid, algorithm, pubkey, hash, hashtype)
[indent=1]Sends a table to the target:[/indent]
[indent=1]msg = { code = "code", format = "format", data = "data", label = "label", srcid = srcid, algorithm = "algorithm", pubkey = "pubkey", hash = "hash", hashtype = "hash" }[/indent]
[indent=2]code: A hex string from '00' to 'ff' indicating the meaning of the message.[/indent]
[indent=2]format: A string declaring the type of content in 'data'. This allows us to support picture, video, and other formats.[/indent]
[indent=2]data: A string containing the message itself.[/indent]
[indent=2]label: A string containing the label of the sender. Clients can send nil instead, but servers must send their label.[/indent]
[indent=2]srcid: The ID of the origin computer. This allows us to use rednet repeaters without really needing to try too hard.[/indent]
[indent=2]algorithm: The algorithm used to encrypt the info in 'data'.[/indent]
[indent=2]pubkey: The public key to be used for encrypting the reply (if any).[/indent]
[indent=2]hash: A hash of the original, unencrypted message to be used in verifying that the data was decrypted properly. It must be sent, but it does not have to be used.[/indent]
[indent=2]hashtype: The algorithm used to generate the hash.[/indent]
[indent=1]Returns a table received from the target. This method will wait up to ten seconds for a response from the target before giving up.[/indent]

rdtps.receive(t)
[indent=1]Waits for any rednet message. Usually for servers only.[/indent]
[indent=1]If it times out, it will likely lead to a 10 error.[/indent]
[indent=1]Returns a table.[/indent]

rdtps.replyTo(targetID, code, format, data, label, srcid, algorithm, pubkey, hash, hashtype)
[indent=1]Sends a table to the target:[/indent]
[indent=1]msg = { code = "code", format = "format", data = "data", label = "label", srcid = srcid, algorithm = "algorithm", pubkey = "pubkey", hash = "hash", hashtype = "hash" }[/indent]
[indent=2]code: A hex string from '00' to 'ff' indicating the meaning of the message.[/indent]
[indent=2]format: A string declaring the type of content in 'data'. This allows us to support picture, video, and other formats.[/indent]
[indent=2]data: A string containing the message itself.[/indent]
[indent=2]label: A string containing the label of the sender. Clients can send nil instead, but servers must send their label.[/indent]
[indent=2]srcid: The ID of the origin computer. This allows us to use rednet repeaters without really needing to try too hard.[/indent]
[indent=2]algorithm: The algorithm used to encrypt the info in 'data'.[/indent]
[indent=2]pubkey: The public key to be used for encrypting the reply (if any).[/indent]
[indent=2]hash: A hash of the original, unencrypted message to be used in verifying that the data was decrypted properly. It must be sent, but it does not have to be used.[/indent]
[indent=2]hashtype: The algorithm used to generate the hash.[/indent]
[indent=1]Doesn't return anything.[/indent]

Status/Error Codes
Spoiler

00 - GET: asks for a resource
01 - RESPWAIT: replies to a GET without the resource, because the server is still obtaining it
02 - RESPOK: replies to a GET with the resource
03 - RESPFAIL1: replies to a GET without the resource, because it could not be found
04 - RESPFAIL2: replies to a GET without the resource, because the client is not allowed to access it
05 - RESPFAIL3: replies to a GET without the resource, because the request was impossible to serve
06 - RESPFAIL4: replies to a GET without the resource, but gives no reason
07 - RESPFAIL5: replies to a GET without the resource, and supplies a custom reason
08 - RESPBADREQ: replies to a MSG, indicating that the message format was not recognized
09 - NORESP: the server failed to respond
0a - RESPNODATA: replies to a GET without the resource, because the server is a test server. This is not an error.
10 - BADRESP: response did not have a valid format
20 - TIMEOUT: no response received

Please post bugs and suggestions here. It helps me keep track of them.
Edited on 22 April 2014 - 09:07 AM
Uberblockminer #2
Posted 23 March 2014 - 08:04 AM
Umm…. A pastebin link would be great ^^
skwerlman #3
Posted 20 April 2014 - 07:26 AM
Umm…. A pastebin link would be great ^^

Since it's more than one file, but not enough to warrant me writing an installer, I'm only going to host it as a zip as well as on the AppStore. The AppStore is the best (only) way to get it in-game.

EDIT: I had forgotten to post a link to the appstore version, sorry
Edited on 20 April 2014 - 05:45 AM
konradinius2 #4
Posted 23 April 2014 - 01:45 PM
i think i will use it in my future projects