From a04bcf247f4be7e3da4fe3895200f0b9709fc0bb Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 24 Aug 2014 01:00:45 +0200 Subject: Merge peer config into peer structure With this refactoring, the structure fastd_peer_config_t is merged into fastd_peer_t, and fastd_remote_config_t into fastd_remote_t. This also means we now create peers directly when reading their configurations, which significantly simplifies the whole reload process, and prepares for some future optimizations like a key hash table. Note: This commit is too big, but I couldn't come up with a nice way to split it into smaller pieces... --- src/fastd.c | 53 ++++++----------------------------------------------- 1 file changed, 6 insertions(+), 47 deletions(-) (limited to 'src/fastd.c') diff --git a/src/fastd.c b/src/fastd.c index 589a293..0f74984 100644 --- a/src/fastd.c +++ b/src/fastd.c @@ -199,51 +199,6 @@ static inline void on_post_down(void) { fastd_shell_command_exec(&conf.on_post_down, NULL); } -/** - Initializes the peers - - Is called after each reconfiguration to remove old peers and add new ones. -*/ -static void init_peers(void) { - fastd_peer_config_t *peer_conf; - for (peer_conf = ctx.peer_configs; peer_conf; peer_conf = peer_conf->next) { - conf.protocol->peer_configure(peer_conf); - - if (peer_conf->config_state == CONFIG_NEW) - fastd_peer_add(peer_conf); - } - - size_t i; - for (i = 0; i < VECTOR_LEN(ctx.peers);) { - fastd_peer_t *peer = VECTOR_INDEX(ctx.peers, i); - - if (fastd_peer_is_dynamic(peer)) { - if (!conf.protocol->peer_check_dynamic(peer)) { - fastd_peer_delete(peer); - continue; - } - } - else { - fastd_peer_config_state_t state = conf.protocol->peer_check(peer->config) ? CONFIG_STATIC : CONFIG_DISABLED; - if (state != peer->config->config_state) { - if (peer->config->config_state != CONFIG_NEW) - pr_info("peer %P is %s now.", peer, (state == CONFIG_DISABLED) ? "disabled" : "enabled"); - - peer->config->config_state = state; - fastd_peer_reset(peer); - } - } - - i++; - } -} - -/** Removes all peers */ -static void delete_peers(void) { - while (VECTOR_LEN(ctx.peers)) - fastd_peer_delete(VECTOR_INDEX(ctx.peers, VECTOR_LEN(ctx.peers)-1)); -} - /** Dumps statistics and the list of known peers to the logs */ static void dump_state(void) { pr_info("TX stats: %U packet(s), %U byte(s); dropped: %U packet(s), %U byte(s); error: %U packet(s), %U byte(s)", @@ -584,7 +539,6 @@ static inline void init(int argc, char *argv[]) { set_user(); fastd_config_load_peer_dirs(); - init_peers(); } @@ -629,7 +583,6 @@ static inline void handle_signals(void) { pr_info("reconfigure triggered"); fastd_config_load_peer_dirs(); - init_peers(); } if (dump) { @@ -653,6 +606,12 @@ static inline void run(void) { handle_signals(); } +/** Removes all peers */ +static void delete_peers(void) { + while (VECTOR_LEN(ctx.peers)) + fastd_peer_delete(VECTOR_INDEX(ctx.peers, VECTOR_LEN(ctx.peers)-1)); +} + /** Performs cleanup of resources used by fastd -- cgit v1.2.3