summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/peer.c15
-rw-r--r--src/peer.h10
-rw-r--r--src/types.h5
3 files changed, 20 insertions, 10 deletions
diff --git a/src/peer.c b/src/peer.c
index ebcb867..668b5c9 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -128,7 +128,7 @@ static bool is_peer_in_group(fastd_peer_t *peer, fastd_peer_group_t *group) {
}
static void reset_peer(fastd_context_t *ctx, fastd_peer_t *peer) {
- if (peer->established)
+ if (fastd_peer_is_established(peer))
on_disestablish(ctx, peer);
free_socket(ctx, peer);
@@ -160,7 +160,7 @@ static void setup_peer(fastd_context_t *ctx, fastd_peer_t *peer) {
memset(&peer->local_address, 0, sizeof(peer->local_address));
- peer->established = false;
+ peer->state = STATE_INIT;
peer->last_resolve = (struct timespec){0, 0};
peer->last_resolve_return = (struct timespec){0, 0};
@@ -463,13 +463,12 @@ void fastd_peer_enable_temporary(fastd_context_t *ctx, fastd_peer_t *peer) {
}
void fastd_peer_set_established(fastd_context_t *ctx, fastd_peer_t *peer) {
- if (!peer->established) {
- peer->established = true;
- on_establish(ctx, peer);
- pr_info(ctx, "connection with %P established.", peer);
- }
+ if (fastd_peer_is_established(peer))
+ return;
- return;
+ peer->state = STATE_ESTABLISHED;
+ on_establish(ctx, peer);
+ pr_info(ctx, "connection with %P established.", peer);
}
const fastd_eth_addr_t* fastd_get_source_address(const fastd_context_t *ctx, fastd_buffer_t buffer) {
diff --git a/src/peer.h b/src/peer.h
index 217e5e4..43a6d02 100644
--- a/src/peer.h
+++ b/src/peer.h
@@ -40,7 +40,7 @@ struct fastd_peer {
fastd_peer_address_t local_address;
fastd_peer_address_t address;
- bool established;
+ fastd_peer_state_t state;
struct timespec last_resolve;
struct timespec last_resolve_return;
@@ -144,7 +144,13 @@ static inline bool fastd_peer_is_temporary(const fastd_peer_t *peer) {
}
static inline bool fastd_peer_is_established(const fastd_peer_t *peer) {
- return peer->established;
+ switch(peer->state) {
+ case STATE_ESTABLISHED:
+ return true;
+
+ default:
+ return false;
+ }
}
static inline void fastd_peer_seen(fastd_context_t *ctx, fastd_peer_t *peer) {
diff --git a/src/types.h b/src/types.h
index fec723b..f3553c2 100644
--- a/src/types.h
+++ b/src/types.h
@@ -48,6 +48,11 @@ typedef enum fastd_drop_caps {
DROP_CAPS_EARLY,
} fastd_drop_caps_t;
+typedef enum fastd_peer_state {
+ STATE_INIT = 0,
+ STATE_ESTABLISHED,
+} fastd_peer_state_t;
+
typedef struct fastd_buffer fastd_buffer_t;
typedef union fastd_peer_address fastd_peer_address_t;