Posted 27 December 2012 - 04:34 PM
As far as I can tell (the code is very messy and undocumented), Cookiebal's Skynetapi program unnecessarily broadcasts every message to every connected node every time, wasting system resources. What I would do is:
The first time a computer (computer #1) wants to send a message to another computer (computer #4), this happens:
#1 broadcasts a FINDPATH message (containing no data but the id of itself and the recipient) to all computers within range (routing computer #2).
Each computer which received the message then broadcasts another FINDPATH message (appending its own ID to the message) until the FINDPATH message reaches computer #4.
By this time, the FINDPATH message looks something like
Now computers #1 and #4 know the shortest path between them and can send data directly.
If a routing computer is unable to pass the data on to the next node in the list, the computer notifies the origin computer, which then sends another FINDPATH.
If the receipient computer receives two FINDPATH messages (two different possible routes to pass on a message), it uses the first FINDPATH received (the path requiring the least number number of in-between nodes)
The first time a computer (computer #1) wants to send a message to another computer (computer #4), this happens:
#1 broadcasts a FINDPATH message (containing no data but the id of itself and the recipient) to all computers within range (routing computer #2).
Each computer which received the message then broadcasts another FINDPATH message (appending its own ID to the message) until the FINDPATH message reaches computer #4.
By this time, the FINDPATH message looks something like
{FINDPATH, 1, 4, 2, 3}
{FINDPATH, origin computer, intended receipient, in-between nodes}
Computer #4 then records this path (1-2-3-4 or vice versa) and sends a PATH message to #3
{PATH, 4, 1, 3, 2}
{PATH, origin computer, intended receipient, in-between nodes}
#3 then sends a PATH message to the next node in the list (#2) containing the same message, until the PATH message reaches computer #1.Now computers #1 and #4 know the shortest path between them and can send data directly.
{DATA, 1, 4, 2, 3, hello!}
{DATA, origin computer, intended receipient, in-between nodes, data to send}
If a routing computer is unable to pass the data on to the next node in the list, the computer notifies the origin computer, which then sends another FINDPATH.
If the receipient computer receives two FINDPATH messages (two different possible routes to pass on a message), it uses the first FINDPATH received (the path requiring the least number number of in-between nodes)