Posted 24 September 2015 - 10:48 PM
A Peer-to-Peer Transfer Protocol*
* Yeah, great name, I know. I need a better one.
This is only a proof of concept, and should not really be taken seriously, as it is little more than a fancy thing I made up because I could. It probably also does not work well with other things using modems. That said…
AP2PTP is a modem wrapper that, in theory, can change the modem channel on every message. It does this by running a function to determine the next channel, and passing the result to the other computer via the replyChannel parameter of the modem.transmit function. This function is fully customizable and is passed the current channel and the message transmitted.
Docs
[indent=1]ap2ptp.init(modemBinding, starterChannel, nextChannelFunction)[/indent]
Does pretty much exactly what you think it does. Rather than just using modem everywhere, this requires you to wrap your peripheral yourself and pass the resulting binding to the function. nextChannelFunction should accept two arguments, the first numeric and the second a string. It returns an AP2PTP handle to pass to other methods.
[indent=1]ap2ptp.transmit(handle, msg)[/indent]
handle is an AP2PTP handle, which can be gotten from the init function. msg is the message you want to transmit.
[indent=1]ap2ptp.listen(handle)[/indent]
handle is an AP2PTP handle, which can be gotten from the init function. It returns, in order, the side, the channel it was sent from, the reply channel, the message, and the distance.
Download
To grab it, run pastebin run U6ZJtzX on your computer. This will install it to the default location of /ap2ptp. If you want to install it to somewhere else, append the file path to the command.
To-Do
* Yeah, great name, I know. I need a better one.
This is only a proof of concept, and should not really be taken seriously, as it is little more than a fancy thing I made up because I could. It probably also does not work well with other things using modems. That said…
AP2PTP is a modem wrapper that, in theory, can change the modem channel on every message. It does this by running a function to determine the next channel, and passing the result to the other computer via the replyChannel parameter of the modem.transmit function. This function is fully customizable and is passed the current channel and the message transmitted.
Docs
[indent=1]ap2ptp.init(modemBinding, starterChannel, nextChannelFunction)[/indent]
Does pretty much exactly what you think it does. Rather than just using modem everywhere, this requires you to wrap your peripheral yourself and pass the resulting binding to the function. nextChannelFunction should accept two arguments, the first numeric and the second a string. It returns an AP2PTP handle to pass to other methods.
[indent=1]ap2ptp.transmit(handle, msg)[/indent]
handle is an AP2PTP handle, which can be gotten from the init function. msg is the message you want to transmit.
[indent=1]ap2ptp.listen(handle)[/indent]
handle is an AP2PTP handle, which can be gotten from the init function. It returns, in order, the side, the channel it was sent from, the reply channel, the message, and the distance.
Download
To grab it, run pastebin run U6ZJtzX on your computer. This will install it to the default location of /ap2ptp. If you want to install it to somewhere else, append the file path to the command.
To-Do
- Add examples to the docs
- Metatable-ify everything, for OOP-style usage.
- Reorganize the order of the returned values from ap2ptp.listen(), as they do not make sense in the current form - AP2PTP abstracts away channels for the most part, it does not make sense to return those first.
- Make AP2PTP play well with others
- Get a better name.
Edited on 24 September 2015 - 08:50 PM