diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/babel.c | 28 | ||||
-rw-r--r-- | src/babel.h | 2 |
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; |