I just finished the first (more or less) working version of 'the internet'.
Latest version: 0.02 (10-03-2012 11:15)
Spoiler
10-03-2012 0.02Misc bugfixes
Code cleanup
Added impersonation protection from terminals
09-03-2012 0.01
Initial release
WHAT IS IT?
wireless signals can carry only 50 blocks far. Suppose two terminals, A and B are too far away. There is no way to communicate wirelessly. With wires, it would become difficult to communicate with multiple devices. What to do?
Consider the following setup:
A(id=1) ——— gateway(id=2) ———– B(id=3)
The gateway runs a special program, listening for incoming connections. If A wants internet access, it first registers using the REGISTER command. This broadcasts a request to which any gateway in range will reply. A will choose one of the gateways and send it a registration confirmation. This gateway now will be able to forward incoming packets for A to A. Suppose A and B register.
The message protocol is simple: a message has the following form: <dest_id>|<source_id>|<message>|<misc info>
Example: if A would want to send 'hi' to B, it sends the following to the gateway: 3|1|hi!|
The gateway knows how to find B and will deliver the message.
IT GETS BETTER THOUGH!
Imagine the following. All nodes are gateways, and each may be attached to one or more terminals. The lines mean that the gateways are in each others range.
Let's repeat our last example. If a terminal 1 would be connected to gateway 0, and he wants to send a packet to terminal 3, connected to 2? No problem. Same packet as before: 3|1|hi!|. The gateways will take care of the shortest path from 1 to 3!
There are 4 files, to be found as attachments to this message
The main api, called 'mnet'
The gateway program
The register program for terminals
And a small tool, NetCat. Use it like this: nc <id> (must be in range)
You can then type commands, and it will wait a few secs for an answer. useful for debugging.
REMOVE THE FILE EXTENSION from all 4 files. I wasn't allowed to upload it with another extension than .txt..
HOW TO USE
- Install: put the three programs in .minecraft/mods/ComputerCraft/lua/rom/programs, and the api, mnet, in ./minecraft/mods/ComputerCraft/lua/rom/apisM
- Make a few terminals
- Put wifi on top
- (optionally, put lamp block underneath, will light up while processing a packet.)
- run gateway or terminal
UNDERSTANDING THE SYSTEM
Spoiler
For debugging purposes, you can use the get_gwlist (get gateway list) that requests a list of the network. It can be obtained as follows: (0 is the gateway, 2 is the client)nc 0
0|2|get_gwlist|
The server will reply with:
2|0|gateway_gwlist|0>3 0>1 3>4 :2>0 6>4
What does this mean? The part before the semicolon describes the gateways, and connections between gateways. Thus, there are 4 gateway: 0, 1, 3 and 4. 0 is connected to 3 and 1, and only 3 is connected to 4.
The part after the semicolon describes hosts, and a>b means "For a, send to gateway b". So, 2 is registered to gateway 0 and 6 is registered to gateway 4.
PLEASE
If anyone has suggestions of how to improve the code or functionality, please let me know!
Please test it, it's not completely done yet. It should work, as long as no gateways are removed from the system. In the future, and with enough enthousiasm from you guys, I might add support for this all.