summaryrefslogtreecommitdiffstats
path: root/src/peer_hashtable.h
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2015-01-20 22:51:40 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2015-01-20 22:51:40 +0100
commitb5d83e3988d346af26b479b7c1be96185de040aa (patch)
treeac1de596302c14d46a576f788b3fca31bb11a80c /src/peer_hashtable.h
parent9f1a5ab5614976e10c4cfaeb055b6c0058b8ba20 (diff)
downloadfastd-b5d83e3988d346af26b479b7c1be96185de040aa.tar
fastd-b5d83e3988d346af26b479b7c1be96185de040aa.zip
Implement new hash table to keep track of unknown peers handshakes have been sent to
This should significantly reduce the number of handshakes sent after restarting fastd with many active connections.
Diffstat (limited to 'src/peer_hashtable.h')
-rw-r--r--src/peer_hashtable.h24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/peer_hashtable.h b/src/peer_hashtable.h
index 0923a50..79b8f28 100644
--- a/src/peer_hashtable.h
+++ b/src/peer_hashtable.h
@@ -33,7 +33,29 @@
#pragma once
-#include "types.h"
+#include "hash.h"
+#include "peer.h"
+
+
+/** Hashes a peer address */
+static inline void fastd_peer_address_hash(uint32_t *hash, const fastd_peer_address_t *addr) {
+ switch(addr->sa.sa_family) {
+ case AF_INET:
+ fastd_hash(hash, &addr->in.sin_addr.s_addr, sizeof(addr->in.sin_addr.s_addr));
+ fastd_hash(hash, &addr->in.sin_port, sizeof(addr->in.sin_port));
+ break;
+
+ case AF_INET6:
+ fastd_hash(hash, &addr->in6.sin6_addr, sizeof(addr->in6.sin6_addr));
+ fastd_hash(hash, &addr->in6.sin6_port, sizeof(addr->in6.sin6_port));
+ if (IN6_IS_ADDR_LINKLOCAL(&addr->in6.sin6_addr))
+ fastd_hash(hash, &addr->in6.sin6_scope_id, sizeof(addr->in6.sin6_scope_id));
+ break;
+
+ default:
+ exit_bug("peer_address_bucket: unknown address family");
+ }
+}
void fastd_peer_hashtable_init(void);