From 11f1c9adcaeb4077c4fdab120eb6197795a2a872 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 8 Mar 2013 20:25:17 +0100 Subject: Allow disabling previously enabled peers --- src/fastd.c | 15 ++++++++++++--- src/protocol_ec25519_fhmqvc.c | 37 +++++++++++++++++++++---------------- 2 files changed, 33 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/fastd.c b/src/fastd.c index fec0838..59a99ab 100644 --- a/src/fastd.c +++ b/src/fastd.c @@ -616,15 +616,24 @@ static void delete_peer_groups(fastd_context_t *ctx) { static void init_peers(fastd_context_t *ctx) { fastd_peer_config_t *peer_conf; for (peer_conf = ctx->conf->peers; peer_conf; peer_conf = peer_conf->next) { - if (peer_conf->enabled) - continue; + bool was_enabled = peer_conf->enabled; peer_conf->enabled = true; ctx->conf->protocol->peer_configure(ctx, peer_conf); - if (peer_conf->enabled) + if (peer_conf->enabled && !was_enabled) fastd_peer_add(ctx, peer_conf); } + + fastd_peer_t *peer, *next; + for (peer = ctx->peers; peer; peer = next) { + next = peer->next; + + if (!peer->config->enabled) { + pr_info(ctx, "previously enabled peer %P disabled, deleting.", peer); + fastd_peer_delete(ctx, peer); + } + } } static void delete_peers(fastd_context_t *ctx) { diff --git a/src/protocol_ec25519_fhmqvc.c b/src/protocol_ec25519_fhmqvc.c index 951cbbb..d804eac 100644 --- a/src/protocol_ec25519_fhmqvc.c +++ b/src/protocol_ec25519_fhmqvc.c @@ -160,28 +160,33 @@ static fastd_protocol_config_t* protocol_init(fastd_context_t *ctx) { } static void protocol_peer_configure(fastd_context_t *ctx, fastd_peer_config_t *peer_conf) { - ecc_int256_t key; + if (!peer_conf->protocol_config) { + if (!peer_conf->key) { + pr_warn(ctx, "no key configured for `%s', disabling peer", peer_conf->name); + peer_conf->enabled = false; + return; + } - if (!peer_conf->key) { - pr_warn(ctx, "no key configured for `%s', disabling peer", peer_conf->name); - peer_conf->enabled = false; - return; - } + ecc_int256_t key; + if (!read_key(key.p, peer_conf->key)) { + pr_warn(ctx, "invalid key configured for `%s', disabling peer", peer_conf->name); + peer_conf->enabled = false; + return; + } - if (!read_key(key.p, peer_conf->key)) { - pr_warn(ctx, "invalid key configured for `%s', disabling peer", peer_conf->name); - peer_conf->enabled = false; - return; - } + peer_conf->protocol_config = malloc(sizeof(fastd_protocol_peer_config_t)); + peer_conf->protocol_config->public_key = key; - if (memcmp(key.p, ctx->conf->protocol_config->public_key.p, 32) == 0) { - pr_debug(ctx, "found own key as `%s', ignoring peer", peer_conf->name); + if (memcmp(peer_conf->protocol_config->public_key.p, ctx->conf->protocol_config->public_key.p, 32) == 0) { + pr_debug(ctx, "found own key as `%s', ignoring peer", peer_conf->name); + peer_conf->enabled = false; + return; + } + } + else if (memcmp(peer_conf->protocol_config->public_key.p, ctx->conf->protocol_config->public_key.p, 32) == 0) { peer_conf->enabled = false; return; } - - peer_conf->protocol_config = malloc(sizeof(fastd_protocol_peer_config_t)); - peer_conf->protocol_config->public_key = key; } static void init_protocol_state(fastd_context_t *ctx) { -- cgit v1.2.3