Compare commits

...

6 Commits

Author SHA1 Message Date
Tristan B. Velloza Kildaire a431aaad60 Router
- Documented `getRoutes()`
2024-01-20 23:42:33 +02:00
Tristan B. Velloza Kildaire 9cbadcbc30 Router
- Documented `installSelfRoute()`
2024-01-20 23:41:57 +02:00
Tristan B. Velloza Kildaire 51d9d0bff2 Route
- Documented `handle_ADV(Link link, Message recvMesg)`
2024-01-20 23:41:17 +02:00
Tristan B. Velloza Kildaire 5a7eac1584 Router
- Documented `dumpRoutes()`
2024-01-20 23:40:33 +02:00
Tristan B. Velloza Kildaire 301309a8fd Route
- Documented `sendData(byte[] payload, string to)`
2024-01-20 23:37:47 +02:00
Tristan B. Velloza Kildaire 5081758ab6 Route
- Documented `onReceive(Link link, byte[] data, string srcAddr)`
2024-01-20 23:25:37 +02:00
1 changed files with 50 additions and 1 deletions

View File

@ -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();