diff options
Diffstat (limited to 'src/peer_hashtable.h')
-rw-r--r-- | src/peer_hashtable.h | 24 |
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); |