summaryrefslogtreecommitdiffstats
path: root/src/babel.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/babel.c')
-rw-r--r--src/babel.c80
1 files changed, 40 insertions, 40 deletions
diff --git a/src/babel.c b/src/babel.c
index 1ca4dd4..7cf52b6 100644
--- a/src/babel.c
+++ b/src/babel.c
@@ -35,32 +35,32 @@ const char *gmrf_protocol_name = "babel";
const char *gmrf_protocol_version = "experimental";
-static void send_hellos(gmrf_t *gmrf, gmrf_context_t *ctx, void *arg) {
- gmrf_schedule(gmrf, send_hellos, NULL, GP_BABEL_HELLO_INTERVAL*10);
+static void send_hellos(gmrf_context_t *ctx, void *arg) {
+ gmrf_schedule(ctx->gmrf, send_hellos, NULL, GP_BABEL_HELLO_INTERVAL*10);
- gp_babel_send_hellos(gmrf, ctx);
+ gp_babel_send_hellos(ctx);
}
-static void send_updates(gmrf_t *gmrf, gmrf_context_t *ctx, void *arg) {
- gmrf_schedule(gmrf, send_updates, NULL, GP_BABEL_UPDATE_INTERVAL*10);
+static void send_updates(gmrf_context_t *ctx, void *arg) {
+ gmrf_schedule(ctx->gmrf, send_updates, NULL, GP_BABEL_UPDATE_INTERVAL*10);
- gmrf_logf(gmrf, LOG_DEBUG, "sending periodic updates.");
+ gmrf_logf(ctx->gmrf, LOG_DEBUG, "sending periodic updates.");
- gp_babel_iface_t *iface;
+ gmrf_iface_state_t *iface;
for (iface = ctx->interfaces; iface; iface = iface->next) {
- gp_babel_send_update(gmrf, ctx, iface, NULL, NULL, false);
+ gp_babel_send_update(ctx, iface, NULL, NULL, false);
}
}
-static void maintain_neighbours(gmrf_t *gmrf, gmrf_context_t *ctx) {
- gp_babel_iface_t *iface;
+static void maintain_neighbours(gmrf_context_t *ctx) {
+ gmrf_iface_state_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) == GP_BABEL_INFINITY && gp_babel_neigh_get_txcost(gmrf, neigh) == GP_BABEL_INFINITY && !neigh->ref) {
+ if (gp_babel_neigh_get_rxcost(ctx, neigh) == GP_BABEL_INFINITY && gp_babel_neigh_get_txcost(ctx, neigh) == GP_BABEL_INFINITY && !neigh->ref) {
*cur = *next;
next = cur;
free(neigh);
@@ -68,32 +68,32 @@ static void maintain_neighbours(gmrf_t *gmrf, gmrf_context_t *ctx) {
continue;
}
- gmrf_logf(gmrf, LOG_DEBUG, "maintenance: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x[%s]: %u (rx %u/tx %u)",
+ gmrf_logf(ctx->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_iface_get_name(ctx->gmrf, iface->gmrf_iface), gp_babel_neigh_get_cost(ctx, neigh),
+ gp_babel_neigh_get_rxcost(ctx, neigh), gp_babel_neigh_get_txcost(ctx, neigh));
}
}
}
-static void maintain_announces(gmrf_t *gmrf, gmrf_context_t *ctx) {
+static void maintain_announces(gmrf_context_t *ctx) {
gp_babel_announce_t **cur, **next;
for (cur = &ctx->announces; *cur; cur = next) {
gp_babel_announce_t *announce = *cur;
next = &announce->next;
- gp_babel_announce_update(gmrf, ctx, announce);
+ gp_babel_announce_update(ctx, announce);
if (!announce->nexthops) {
*cur = *next;
next = cur;
- gp_babel_announce_free(gmrf, ctx, announce);
+ gp_babel_announce_free(ctx, announce);
continue;
}
- gmrf_logf(gmrf, LOG_DEBUG, "node %04x%04x, type %04x, announce %04x (%u, seqno=%04x):",
+ gmrf_logf(ctx->gmrf, LOG_DEBUG, "node %04x%04x, type %04x, announce %04x (%u, seqno=%04x):",
ntohl(*(uint32_t*)announce->node.id), ntohl(*(uint32_t*)(announce->node.id+4)),
announce->type, announce->key, announce->metric.metric, announce->metric.seqno);
@@ -102,25 +102,25 @@ static void maintain_announces(gmrf_t *gmrf, gmrf_context_t *ctx) {
gp_babel_neigh_t *neigh = nexthop->neigh;
if (!neigh) {
- gmrf_logf(gmrf, LOG_DEBUG, " local");
+ gmrf_logf(ctx->gmrf, LOG_DEBUG, " local");
continue;
}
- gmrf_logf(gmrf, LOG_DEBUG, " nexthop: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x[%s] (%u, seqno=%04x, cost=%u%s)",
+ gmrf_logf(ctx->gmrf, LOG_DEBUG, " nexthop: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x[%s] (%u, seqno=%04x, cost=%u%s)",
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],
- neigh->iface ? gmrf_iface_get_name(gmrf, neigh->iface->gmrf_iface) : NULL,
- nexthop->metric_seqno.metric, nexthop->metric_seqno.seqno, gp_babel_neigh_get_cost(gmrf, neigh),
+ neigh->iface ? gmrf_iface_get_name(ctx->gmrf, neigh->iface->gmrf_iface) : NULL,
+ nexthop->metric_seqno.metric, nexthop->metric_seqno.seqno, gp_babel_neigh_get_cost(ctx, neigh),
(nexthop == announce->selected) ? ", selected" : "");
}
}
}
-static void maintenance(gmrf_t *gmrf, gmrf_context_t *ctx, void *arg) {
- gmrf_schedule(gmrf, maintenance, NULL, GP_BABEL_MAINTENANCE_INTERVAL*10);
+static void maintenance(gmrf_context_t *ctx, void *arg) {
+ gmrf_schedule(ctx->gmrf, maintenance, NULL, GP_BABEL_MAINTENANCE_INTERVAL*10);
- maintain_neighbours(gmrf, ctx);
- maintain_announces(gmrf, ctx);
+ maintain_neighbours(ctx);
+ maintain_announces(ctx);
}
gmrf_context_t* gmrf_protocol_init(gmrf_t *gmrf) {
@@ -131,9 +131,11 @@ gmrf_context_t* gmrf_protocol_init(gmrf_t *gmrf) {
gmrf_schedule(gmrf, maintenance, NULL, 0);
gmrf_context_t *ctx = calloc(1, sizeof(gmrf_context_t));
+
+ ctx->gmrf = gmrf;
gmrf_random_bytes(gmrf, &ctx->self, sizeof(gp_babel_node_id_t));
- gp_babel_announce_t *announce = gp_babel_announce_new(gmrf, ctx);
+ gp_babel_announce_t *announce = gp_babel_announce_new(ctx);
announce->node = ctx->self;
announce->type = 1;
announce->key = 1337;
@@ -143,27 +145,25 @@ gmrf_context_t* gmrf_protocol_init(gmrf_t *gmrf) {
return ctx;
}
-void gmrf_protocol_add_iface(gmrf_t *gmrf, gmrf_context_t *ctx, gmrf_iface_t *iface) {
- gmrf_logf(gmrf, LOG_INFO, "interface `%s' added.", gmrf_iface_get_name(gmrf, iface));
+gmrf_iface_state_t* gmrf_protocol_add_iface(gmrf_context_t *ctx, gmrf_iface_t *iface) {
+ gmrf_logf(ctx->gmrf, LOG_INFO, "interface `%s' added.", gmrf_iface_get_name(ctx->gmrf, iface));
- gp_babel_iface_t *b_iface = calloc(1, sizeof(gp_babel_iface_t));
- b_iface->gmrf_iface = iface;
+ gmrf_iface_state_t *state = calloc(1, sizeof(gmrf_iface_state_t));
+ state->gmrf_iface = iface;
- b_iface->next = ctx->interfaces;
- ctx->interfaces = b_iface;
+ state->next = ctx->interfaces;
+ ctx->interfaces = state;
+
+ return state;
}
-void gmrf_protocol_handle_packet(gmrf_t *gmrf, gmrf_context_t *ctx, gmrf_iface_t *iface, const gmrf_addr_t *source, const void *data, size_t len) {
+void gmrf_protocol_handle_packet(gmrf_context_t *ctx, gmrf_iface_state_t *iface, const gmrf_addr_t *source, const void *data, size_t len) {
const gp_babel_packet_t *packet = data;
if (len < sizeof(gp_babel_packet_t) || len < gp_babel_packet_size(packet)) {
- gmrf_logf(gmrf, LOG_DEBUG, "received short packet.");
+ gmrf_logf(ctx->gmrf, LOG_DEBUG, "received short packet.");
return;
}
- gp_babel_iface_t *b_iface = gp_babel_get_iface(ctx, iface);
- if (!b_iface)
- return;
-
- gp_babel_handle_packet(gmrf, ctx, b_iface, source, packet);
+ gp_babel_handle_packet(ctx, iface, source, packet);
}