summaryrefslogtreecommitdiffstats
path: root/src/peer.c
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2014-08-19 00:10:48 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2014-08-19 00:21:38 +0200
commit35a18b1dea21f006b38694dcf5c99f817411ad4d (patch)
treec6922a55085eba524ad9a997816429c6437b7430 /src/peer.c
parent21ade840c989e9fcebef63e2999f5c31843c47b6 (diff)
downloadfastd-35a18b1dea21f006b38694dcf5c99f817411ad4d.tar
fastd-35a18b1dea21f006b38694dcf5c99f817411ad4d.zip
Create peer structures for disabled peers as well
We have a 1:1 association between peers and peer configs now.
Diffstat (limited to 'src/peer.c')
-rw-r--r--src/peer.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/peer.c b/src/peer.c
index 8609894..19b10d8 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -136,7 +136,7 @@ static int peer_id_cmp(fastd_peer_t *const *a, fastd_peer_t *const *b) {
}
/** Finds the entry for a peer with a specified ID in the array \e ctx.peers */
-static fastd_peer_t** peer_p_find_by_id(uint64_t id) {
+static fastd_peer_t ** peer_p_find_by_id(uint64_t id) {
fastd_peer_t key = {.id = id};
fastd_peer_t *const keyp = &key;
@@ -304,6 +304,11 @@ static bool is_peer_in_group(const fastd_peer_t *peer, const fastd_peer_group_t
After a call to reset_peer a peer must be deleted by delete_peer or re-initialized by setup_peer.
*/
static void reset_peer(fastd_peer_t *peer) {
+ if (peer->state == STATE_INACTIVE)
+ return;
+
+ pr_debug("resetting peer %P", peer);
+
if (fastd_peer_is_established(peer)) {
on_disestablish(peer);
pr_info("connection with %P disestablished.", peer);
@@ -311,8 +316,6 @@ static void reset_peer(fastd_peer_t *peer) {
free_socket(peer);
- memset(&peer->local_address, 0, sizeof(peer->local_address));
-
conf.protocol->reset_peer_state(peer);
size_t i, deleted = 0;
@@ -328,6 +331,12 @@ static void reset_peer(fastd_peer_t *peer) {
VECTOR_RESIZE(ctx.eth_addrs, VECTOR_LEN(ctx.eth_addrs)-deleted);
fastd_peer_unschedule_handshake(peer);
+
+ fastd_peer_hashtable_remove(peer);
+
+ peer->address.sa.sa_family = AF_UNSPEC;
+ peer->local_address.sa.sa_family = AF_UNSPEC;
+ peer->state = STATE_INACTIVE;
}
/**
@@ -367,13 +376,6 @@ static inline bool has_remote_hostname(const fastd_remote_t *remote) {
/** Initializes a peer */
static void setup_peer(fastd_peer_t *peer) {
- fastd_peer_hashtable_remove(peer);
- peer->address.sa.sa_family = AF_UNSPEC;
-
- peer->local_address.sa.sa_family = AF_UNSPEC;
-
- peer->state = STATE_INIT;
-
if (VECTOR_LEN(peer->remotes) == 0) {
peer->next_remote = -1;
}
@@ -393,6 +395,10 @@ static void setup_peer(fastd_peer_t *peer) {
peer->establish_handshake_timeout = ctx.now;
+ if (!fastd_peer_is_enabled(peer))
+ /* Keep the peer in STATE_INACTIVE */
+ return;
+
if (!peer->protocol_state)
conf.protocol->init_peer_state(peer);
@@ -409,6 +415,9 @@ static void setup_peer(fastd_peer_t *peer) {
init_handshake(peer);
}
}
+ else {
+ peer->state = STATE_PASSIVE;
+ }
}
/** Frees a peer */
@@ -599,6 +608,9 @@ bool fastd_peer_claim_address(fastd_peer_t *new_peer, fastd_socket_t *sock, cons
if (peer == new_peer)
continue;
+ if (!fastd_peer_is_enabled(peer))
+ continue;
+
if (fastd_peer_owns_address(peer, remote_addr)) {
reset_peer_address(new_peer);
return false;
@@ -667,8 +679,6 @@ bool fastd_peer_config_equal(const fastd_peer_config_t *peer1, const fastd_peer_
/** Resets and re-initializes a peer */
void fastd_peer_reset(fastd_peer_t *peer) {
- pr_debug("resetting peer %P", peer);
-
reset_peer(peer);
setup_peer(peer);
}