diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2014-04-19 23:54:10 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2014-04-19 23:54:10 +0200 |
commit | 0bf9268453d3af82bbd1257da547b1dd8f225ba2 (patch) | |
tree | c543378f2af2311683c741ec3111e16effd0ef28 /src/peer.c | |
parent | 194e1c878aa383994fef0cbbb3449fdaa599b53a (diff) | |
download | fastd-0bf9268453d3af82bbd1257da547b1dd8f225ba2.tar fastd-0bf9268453d3af82bbd1257da547b1dd8f225ba2.zip |
Keep peers in a hash table to allow fast address lookups
Diffstat (limited to 'src/peer.c')
-rw-r--r-- | src/peer.c | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -25,6 +25,7 @@ #include "peer.h" +#include "peer_hashtable.h" #include "poll.h" #include <arpa/inet.h> @@ -272,6 +273,8 @@ static void delete_peer(fastd_context_t *ctx, fastd_peer_t *peer) { } } + fastd_peer_hashtable_remove(ctx, peer); + ctx->conf->protocol->free_peer_state(ctx, peer); if (!peer->config) @@ -392,6 +395,7 @@ static inline void reset_peer_address(fastd_context_t *ctx, fastd_peer_t *peer) if (fastd_peer_is_established(peer)) fastd_peer_reset(ctx, peer); + fastd_peer_hashtable_remove(ctx, peer); memset(&peer->address, 0, sizeof(fastd_peer_address_t)); } @@ -455,7 +459,13 @@ bool fastd_peer_claim_address(fastd_context_t *ctx, fastd_peer_t *new_peer, fast } } + fastd_peer_hashtable_remove(ctx, new_peer); + new_peer->address = *remote_addr; + + if (remote_addr->sa.sa_family != AF_UNSPEC) + fastd_peer_hashtable_insert(ctx, new_peer); + if (sock && sock->addr && sock != new_peer->sock) { free_socket(ctx, new_peer); new_peer->sock = sock; |