From 35a18b1dea21f006b38694dcf5c99f817411ad4d Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 19 Aug 2014 00:10:48 +0200 Subject: Create peer structures for disabled peers as well We have a 1:1 association between peers and peer configs now. --- src/peer.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/peer.h') diff --git a/src/peer.h b/src/peer.h index eec7bb0..f1187d8 100644 --- a/src/peer.h +++ b/src/peer.h @@ -37,7 +37,8 @@ /** The state of a peer */ typedef enum fastd_peer_state { - STATE_INIT = 0, /**< The peer peer was just created */ + STATE_INACTIVE = 0, /**< The peer is not active at the moment */ + STATE_PASSIVE, /**< The peer is waiting for incoming connections */ STATE_RESOLVING, /**< The peer is currently resolving its first remote */ STATE_HANDSHAKE, /**< The peer has tried to perform a handshake */ STATE_ESTABLISHED, /**< The peer has established a connection */ @@ -45,8 +46,9 @@ typedef enum fastd_peer_state { /** The config state of a peer */ typedef enum fastd_peer_config_state { - CONFIG_DISABLED = 0, /**< The peer is configured statically, but has been not yet been enabled or disabled because of a configuration error */ + CONFIG_NEW = 0, /**< The peer is configured statically, but has been not been enabled yet */ CONFIG_STATIC, /**< The peer is configured statically */ + CONFIG_DISABLED, /**< The peer is configured statically, but has been disabled because of a configuration error */ #ifdef WITH_DYNAMIC_PEERS CONFIG_DYNAMIC, /**< The peer is configured dynamically (using a on-verify handler) */ #endif @@ -245,6 +247,19 @@ static inline bool fastd_peer_is_dynamic(const fastd_peer_t *peer UNUSED) { #endif } +/** Checks if a peer is enabled */ +static inline bool fastd_peer_is_enabled(const fastd_peer_t *peer) { + switch (peer->config->config_state) { + case CONFIG_STATIC: +#ifdef WITH_DYNAMIC_PEERS + case CONFIG_DYNAMIC: +#endif + return true; + default: + return false; + } +} + /** Returns the currently active remote entry */ static inline fastd_remote_t * fastd_peer_get_next_remote(fastd_peer_t *peer) { if (peer->next_remote < 0) -- cgit v1.2.3