summaryrefslogtreecommitdiffstats
path: root/src/peer.c
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2014-04-19 23:54:10 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2014-04-19 23:54:10 +0200
commit0bf9268453d3af82bbd1257da547b1dd8f225ba2 (patch)
treec543378f2af2311683c741ec3111e16effd0ef28 /src/peer.c
parent194e1c878aa383994fef0cbbb3449fdaa599b53a (diff)
downloadfastd-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.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/peer.c b/src/peer.c
index ecb7e2c..e7574ef 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -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;