summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2013-03-19 00:20:02 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2013-03-19 00:20:02 +0100
commit415606c73661aa9788a6a16dfc8a75b305246992 (patch)
tree272a8d0707600a2b7e6f1f5964026c1a2955bac8 /src
parent2b3fe33c07b17b6bbc6515f73aef5efac89fd542 (diff)
downloadbabel-415606c73661aa9788a6a16dfc8a75b305246992.tar
babel-415606c73661aa9788a6a16dfc8a75b305246992.zip
Add maintenance function
Diffstat (limited to 'src')
-rw-r--r--src/babel.c28
-rw-r--r--src/babel.h2
2 files changed, 30 insertions, 0 deletions
diff --git a/src/babel.c b/src/babel.c
index 39cd6c8..4002df2 100644
--- a/src/babel.c
+++ b/src/babel.c
@@ -86,10 +86,38 @@ static void send_hellos(gmrf_t *gmrf, gmrf_context_t *ctx, void *arg) {
}
}
+static void maintenance(gmrf_t *gmrf, gmrf_context_t *ctx, void *arg) {
+ gmrf_schedule(gmrf, maintenance, NULL, GP_BABEL_MAINTENANCE_INTERVAL*10);
+
+ gp_babel_iface_t *iface;
+ for (iface = ctx->interfaces; iface; iface = iface->next) {
+ gp_babel_neigh_t **cur, **next;
+ for (cur = &iface->neighbours; *cur; cur = next) {
+ gp_babel_neigh_t *neigh = *cur;
+ next = &neigh->next;
+
+ if (gp_babel_neigh_get_rxcost(gmrf, neigh) == 0xffff && gp_babel_neigh_get_txcost(gmrf, neigh) == 0xffff && !neigh->ref) {
+ *cur = *next;
+ next = cur;
+ free(neigh);
+
+ continue;
+ }
+
+ gmrf_logf(gmrf, LOG_DEBUG, "maintenance: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x[%s]: %u (rx %u/tx %u)",
+ neigh->addr.d[0], neigh->addr.d[1], neigh->addr.d[2], neigh->addr.d[3],
+ neigh->addr.d[4], neigh->addr.d[5], neigh->addr.d[6], neigh->addr.d[7],
+ gmrf_iface_get_name(gmrf, iface->gmrf_iface), gp_babel_neigh_get_cost(gmrf, neigh),
+ gp_babel_neigh_get_rxcost(gmrf, neigh), gp_babel_neigh_get_txcost(gmrf, neigh));
+ }
+ }
+}
+
gmrf_context_t* gmrf_protocol_init(gmrf_t *gmrf) {
gmrf_logf(gmrf, LOG_INFO, "initalizing...");
gmrf_schedule(gmrf, send_hellos, NULL, GP_BABEL_HELLO_INTERVAL*10);
+ gmrf_schedule(gmrf, maintenance, NULL, GP_BABEL_MAINTENANCE_INTERVAL*10);
gmrf_context_t *ctx = calloc(1, sizeof(gmrf_context_t));
gmrf_random_bytes(gmrf, &ctx->self, sizeof(gp_babel_node_id_t));
diff --git a/src/babel.h b/src/babel.h
index 7ad5450..4e521cc 100644
--- a/src/babel.h
+++ b/src/babel.h
@@ -37,6 +37,8 @@
#define GP_BABEL_HELLO_TIMEOUT(interval) (16*(interval))
#define GP_BABEL_IHU_TIMEOUT(interval) ((interval)*7/2)
+#define GP_BABEL_MAINTENANCE_INTERVAL GP_BABEL_HELLO_INTERVAL
+
struct gmrf_context {
gp_babel_node_id_t self;