0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 10:12:39 +01:00

ircd: hash: client connection id hashtables are now dictionaries keyed by uint32

This commit is contained in:
William Pitcock 2016-01-09 04:25:41 -06:00
parent 45dfdf46c8
commit 5c7c7d65c2
2 changed files with 20 additions and 42 deletions

View file

@ -103,7 +103,7 @@ extern void clear_resv_hash(void);
void add_to_cli_connid_hash(struct Client *client_p); void add_to_cli_connid_hash(struct Client *client_p);
void del_from_cli_connid_hash(struct Client *client_p); void del_from_cli_connid_hash(struct Client *client_p);
struct Client *find_cli_connid_hash(int connid); struct Client *find_cli_connid_hash(uint32_t connid);
void add_to_zconnid_hash(struct Client *client_p); void add_to_zconnid_hash(struct Client *client_p);
void del_from_zconnid_hash(struct Client *client_p); void del_from_zconnid_hash(struct Client *client_p);

View file

@ -39,14 +39,7 @@
#include "cache.h" #include "cache.h"
#include "s_newconf.h" #include "s_newconf.h"
#include "s_assert.h" #include "s_assert.h"
#include "irc_dictionary.h"
#define ZCONNID_MAX 64 /* i doubt we'll have this many ziplinks ;) */
#define hash_cli_connid(x) (x % CLI_CONNID_MAX)
#define hash_zconnid(x) (x % ZCONNID_MAX)
static rb_dlink_list clientbyconnidTable[CLI_CONNID_MAX];
static rb_dlink_list clientbyzconnidTable[ZCONNID_MAX];
rb_dlink_list *clientTable; rb_dlink_list *clientTable;
rb_dlink_list *channelTable; rb_dlink_list *channelTable;
@ -54,6 +47,9 @@ rb_dlink_list *idTable;
rb_dlink_list *resvTable; rb_dlink_list *resvTable;
rb_dlink_list *hostTable; rb_dlink_list *hostTable;
struct Dictionary *client_connid_tree = NULL;
struct Dictionary *client_zconnid_tree = NULL;
/* /*
* look in whowas.c for the missing ...[WW_MAX]; entry * look in whowas.c for the missing ...[WW_MAX]; entry
*/ */
@ -103,9 +99,11 @@ init_hash(void)
channelTable = rb_malloc(sizeof(rb_dlink_list) * CH_MAX); channelTable = rb_malloc(sizeof(rb_dlink_list) * CH_MAX);
hostTable = rb_malloc(sizeof(rb_dlink_list) * HOST_MAX); hostTable = rb_malloc(sizeof(rb_dlink_list) * HOST_MAX);
resvTable = rb_malloc(sizeof(rb_dlink_list) * R_MAX); resvTable = rb_malloc(sizeof(rb_dlink_list) * R_MAX);
client_connid_tree = irc_dictionary_create("client connid", irc_uint32cmp);
client_zconnid_tree = irc_dictionary_create("client zconnid", irc_uint32cmp);
} }
#ifndef RICER_HASHING
u_int32_t u_int32_t
fnv_hash_upper(const unsigned char *s, int bits) fnv_hash_upper(const unsigned char *s, int bits)
{ {
@ -165,7 +163,6 @@ fnv_hash_upper_len(const unsigned char *s, int bits, int len)
h = ((h >> bits) ^ h) & ((1<<bits)-1); h = ((h >> bits) ^ h) & ((1<<bits)-1);
return h; return h;
} }
#endif
/* hash_nick() /* hash_nick()
* *
@ -672,56 +669,39 @@ clear_resv_hash(void)
void void
add_to_zconnid_hash(struct Client *client_p) add_to_zconnid_hash(struct Client *client_p)
{ {
unsigned int hashv; irc_dictionary_add(client_zconnid_tree, IRC_UINT_TO_POINTER(client_p->localClient->zconnid), client_p);
hashv = hash_zconnid(client_p->localClient->zconnid);
rb_dlinkAddAlloc(client_p, &clientbyzconnidTable[hashv]);
} }
void void
del_from_zconnid_hash(struct Client *client_p) del_from_zconnid_hash(struct Client *client_p)
{ {
unsigned int hashv; irc_dictionary_delete(client_zconnid_tree, IRC_UINT_TO_POINTER(client_p->localClient->zconnid));
hashv = hash_zconnid(client_p->localClient->zconnid);
rb_dlinkFindDestroy(client_p, &clientbyzconnidTable[hashv]);
} }
void void
add_to_cli_connid_hash(struct Client *client_p) add_to_cli_connid_hash(struct Client *client_p)
{ {
unsigned int hashv; irc_dictionary_add(client_connid_tree, IRC_UINT_TO_POINTER(client_p->localClient->connid), client_p);
hashv = hash_cli_connid(client_p->localClient->connid);
rb_dlinkAddAlloc(client_p, &clientbyconnidTable[hashv]);
} }
void void
del_from_cli_connid_hash(struct Client *client_p) del_from_cli_connid_hash(struct Client *client_p)
{ {
unsigned int hashv; irc_dictionary_delete(client_connid_tree, IRC_UINT_TO_POINTER(client_p->localClient->connid));
hashv = hash_cli_connid(client_p->localClient->connid);
rb_dlinkFindDestroy(client_p, &clientbyconnidTable[hashv]);
} }
struct Client * struct Client *
find_cli_connid_hash(int connid) find_cli_connid_hash(uint32_t connid)
{ {
struct Client *target_p; struct Client *target_p;
rb_dlink_node *ptr;
unsigned int hashv;
hashv = hash_cli_connid(connid);
RB_DLINK_FOREACH(ptr, clientbyconnidTable[hashv].head)
{
target_p = ptr->data;
if(target_p->localClient->connid == connid)
return target_p;
}
hashv = hash_zconnid(connid); target_p = irc_dictionary_retrieve(client_connid_tree, IRC_UINT_TO_POINTER(connid));
RB_DLINK_FOREACH(ptr, clientbyzconnidTable[hashv].head) if (target_p != NULL)
{ return target_p;
target_p = ptr->data;
if(target_p->localClient->zconnid == connid) target_p = irc_dictionary_retrieve(client_zconnid_tree, IRC_UINT_TO_POINTER(connid));
if (target_p != NULL)
return target_p; return target_p;
}
return NULL; return NULL;
} }
@ -800,6 +780,4 @@ hash_stats(struct Client *source_p)
count_hash(source_p, idTable, U_MAX, "ID"); count_hash(source_p, idTable, U_MAX, "ID");
sendto_one_numeric(source_p, RPL_STATSDEBUG, "B :--"); sendto_one_numeric(source_p, RPL_STATSDEBUG, "B :--");
count_hash(source_p, hostTable, HOST_MAX, "Hostname"); count_hash(source_p, hostTable, HOST_MAX, "Hostname");
sendto_one_numeric(source_p, RPL_STATSDEBUG, "B :--");
count_hash(source_p, clientbyconnidTable, CLI_CONNID_MAX, "Client by connection id");
} }