mirror of https://github.com/deavmi/twine
Compare commits
6 Commits
60e0cffff0
...
a431aaad60
Author | SHA1 | Date |
---|---|---|
Tristan B. Velloza Kildaire | a431aaad60 | |
Tristan B. Velloza Kildaire | 9cbadcbc30 | |
Tristan B. Velloza Kildaire | 51d9d0bff2 | |
Tristan B. Velloza Kildaire | 5a7eac1584 | |
Tristan B. Velloza Kildaire | 301309a8fd | |
Tristan B. Velloza Kildaire | 5081758ab6 |
|
@ -390,11 +390,34 @@ public class Router : Receiver
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever we receive a packet
|
||||
* from one of the links associated
|
||||
* with this router
|
||||
*
|
||||
* Params:
|
||||
* link = the `Link` from which the
|
||||
* packet came from
|
||||
* data = the packet itself
|
||||
* srcAddr = the link-layer source
|
||||
* address of the packet
|
||||
*/
|
||||
public void onReceive(Link link, byte[] data, string srcAddr)
|
||||
{
|
||||
process(link, data, srcAddr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a piece of data to the given
|
||||
* network-layer address
|
||||
*
|
||||
* Params:
|
||||
* payload = the data to send
|
||||
* to = the destination network-layer
|
||||
* address
|
||||
* Returns: `true` if sending succeeded
|
||||
* but if not then `false`
|
||||
*/
|
||||
public bool sendData(byte[] payload, string to)
|
||||
{
|
||||
// lookup route to host
|
||||
|
@ -509,6 +532,11 @@ public class Router : Receiver
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints out all the routes
|
||||
* currently in the routing
|
||||
* table
|
||||
*/
|
||||
public void dumpRoutes()
|
||||
{
|
||||
import std.stdio : writeln;
|
||||
|
@ -583,7 +611,15 @@ public class Router : Receiver
|
|||
}
|
||||
}
|
||||
|
||||
// Handles all sort of advertisement messages
|
||||
/**
|
||||
* Handles incoming advertisement
|
||||
* messages
|
||||
*
|
||||
* Params:
|
||||
* link = the `Link` from which
|
||||
* the message was received
|
||||
* recvMesg = the message itself
|
||||
*/
|
||||
private void handle_ADV(Link link, Message recvMesg)
|
||||
{
|
||||
Advertisement advMesg;
|
||||
|
@ -621,12 +657,25 @@ public class Router : Receiver
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Installs a route to ourselves
|
||||
* which has a distance of `0`,
|
||||
* a destination of our public
|
||||
* key and no link
|
||||
*/
|
||||
private void installSelfRoute()
|
||||
{
|
||||
Route selfR = Route(getPublicKey(), null, 0);
|
||||
installRoute(selfR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all
|
||||
* the currently installled
|
||||
* routes
|
||||
*
|
||||
* Returns: a `Route[]`
|
||||
*/
|
||||
private Route[] getRoutes()
|
||||
{
|
||||
this.routesLock.lock();
|
||||
|
|
Loading…
Reference in New Issue