X-Git-Url: https://jfr.im/git/irc/rqf/shadowircd.git/blobdiff_plain/b37021a45e15eef2e937aa11f185b48cf766d772..dc83edfac4cf3f5725f7e1f8ba512a524953bce6:/src/hash.c diff --git a/src/hash.c b/src/hash.c index f10c5ae..10e3506 100644 --- a/src/hash.c +++ b/src/hash.c @@ -26,27 +26,28 @@ #include "stdinc.h" #include "ircd_defs.h" -#include "tools.h" #include "s_conf.h" #include "channel.h" #include "client.h" #include "common.h" #include "hash.h" -#include "irc_string.h" +#include "match.h" #include "ircd.h" #include "numeric.h" #include "send.h" -#include "memory.h" #include "msg.h" #include "cache.h" #include "s_newconf.h" -dlink_list *clientTable; -dlink_list *channelTable; -dlink_list *idTable; -dlink_list *resvTable; -dlink_list *hostTable; -dlink_list *helpTable; +#define hash_cli_fd(x) (x % CLI_FD_MAX) + +static rb_dlink_list clientbyfdTable[U_MAX]; + +rb_dlink_list *clientTable; +rb_dlink_list *channelTable; +rb_dlink_list *idTable; +rb_dlink_list *resvTable; +rb_dlink_list *hostTable; /* * look in whowas.c for the missing ...[WW_MAX]; entry @@ -92,12 +93,11 @@ dlink_list *helpTable; void init_hash(void) { - clientTable = MyMalloc(sizeof(dlink_list) * U_MAX); - idTable = MyMalloc(sizeof(dlink_list) * U_MAX); - channelTable = MyMalloc(sizeof(dlink_list) * CH_MAX); - hostTable = MyMalloc(sizeof(dlink_list) * HOST_MAX); - resvTable = MyMalloc(sizeof(dlink_list) * R_MAX); - helpTable = MyMalloc(sizeof(dlink_list) * HELP_MAX); + clientTable = rb_malloc(sizeof(rb_dlink_list) * U_MAX); + idTable = rb_malloc(sizeof(rb_dlink_list) * U_MAX); + channelTable = rb_malloc(sizeof(rb_dlink_list) * CH_MAX); + hostTable = rb_malloc(sizeof(rb_dlink_list) * HOST_MAX); + resvTable = rb_malloc(sizeof(rb_dlink_list) * R_MAX); } #ifndef RICER_HASHING @@ -111,7 +111,8 @@ fnv_hash_upper(const unsigned char *s, int bits) h ^= ToUpper(*s++); h += (h<<1) + (h<<4) + (h<<7) + (h << 8) + (h << 24); } - h = (h >> bits) ^ (h & ((2^bits)-1)); + if (bits < 32) + h = ((h >> bits) ^ h) & ((1<> bits) ^ (h & ((2^bits)-1)); + if (bits < 32) + h = ((h >> bits) ^ h) & ((1<> bits) ^ (h & ((2^bits)-1)); + if (bits < 32) + h = ((h >> bits) ^ h) & ((1<> bits) ^ (h & ((2^bits)-1)); + if (bits < 32) + h = ((h >> bits) ^ h) & ((1<data); - dlinkDestroy(ptr, &helpTable[i]); - } - HASH_WALK_END + rb_dlinkFindDestroy(aconf, &resvTable[hashv]); } /* find_id() @@ -419,7 +383,7 @@ struct Client * find_id(const char *name) { struct Client *target_p; - dlink_node *ptr; + rb_dlink_node *ptr; unsigned int hashv; if(EmptyString(name)) @@ -427,7 +391,7 @@ find_id(const char *name) hashv = hash_id(name); - DLINK_FOREACH(ptr, idTable[hashv].head) + RB_DLINK_FOREACH(ptr, idTable[hashv].head) { target_p = ptr->data; @@ -446,7 +410,7 @@ struct Client * find_client(const char *name) { struct Client *target_p; - dlink_node *ptr; + rb_dlink_node *ptr; unsigned int hashv; s_assert(name != NULL); @@ -459,7 +423,7 @@ find_client(const char *name) hashv = hash_nick(name); - DLINK_FOREACH(ptr, clientTable[hashv].head) + RB_DLINK_FOREACH(ptr, clientTable[hashv].head) { target_p = ptr->data; @@ -478,7 +442,7 @@ struct Client * find_named_client(const char *name) { struct Client *target_p; - dlink_node *ptr; + rb_dlink_node *ptr; unsigned int hashv; s_assert(name != NULL); @@ -487,7 +451,7 @@ find_named_client(const char *name) hashv = hash_nick(name); - DLINK_FOREACH(ptr, clientTable[hashv].head) + RB_DLINK_FOREACH(ptr, clientTable[hashv].head) { target_p = ptr->data; @@ -506,7 +470,7 @@ struct Client * find_server(struct Client *source_p, const char *name) { struct Client *target_p; - dlink_node *ptr; + rb_dlink_node *ptr; unsigned int hashv; if(EmptyString(name)) @@ -521,7 +485,7 @@ find_server(struct Client *source_p, const char *name) hashv = hash_nick(name); - DLINK_FOREACH(ptr, clientTable[hashv].head) + RB_DLINK_FOREACH(ptr, clientTable[hashv].head) { target_p = ptr->data; @@ -535,11 +499,11 @@ find_server(struct Client *source_p, const char *name) /* find_hostname() * - * finds a hostname dlink list from the hostname hash table. - * we return the full dlink list, because you can have multiple + * finds a hostname rb_dlink list from the hostname hash table. + * we return the full rb_dlink list, because you can have multiple * entries with the same hostname */ -dlink_node * +rb_dlink_node * find_hostname(const char *hostname) { unsigned int hashv; @@ -560,7 +524,7 @@ struct Channel * find_channel(const char *name) { struct Channel *chptr; - dlink_node *ptr; + rb_dlink_node *ptr; unsigned int hashv; s_assert(name != NULL); @@ -569,7 +533,7 @@ find_channel(const char *name) hashv = hash_channel(name); - DLINK_FOREACH(ptr, channelTable[hashv].head) + RB_DLINK_FOREACH(ptr, channelTable[hashv].head) { chptr = ptr->data; @@ -595,7 +559,7 @@ struct Channel * get_or_create_channel(struct Client *client_p, const char *chname, int *isnew) { struct Channel *chptr; - dlink_node *ptr; + rb_dlink_node *ptr; unsigned int hashv; int len; const char *s = chname; @@ -621,7 +585,7 @@ get_or_create_channel(struct Client *client_p, const char *chname, int *isnew) hashv = hash_channel(s); - DLINK_FOREACH(ptr, channelTable[hashv].head) + RB_DLINK_FOREACH(ptr, channelTable[hashv].head) { chptr = ptr->data; @@ -638,11 +602,11 @@ get_or_create_channel(struct Client *client_p, const char *chname, int *isnew) chptr = allocate_channel(s); - dlinkAdd(chptr, &chptr->node, &global_channel_list); + rb_dlinkAdd(chptr, &chptr->node, &global_channel_list); - chptr->channelts = CurrentTime; /* doesn't hurt to set it here */ + chptr->channelts = rb_current_time(); /* doesn't hurt to set it here */ - dlinkAddAlloc(chptr, &channelTable[hashv]); + rb_dlinkAddAlloc(chptr, &channelTable[hashv]); return chptr; } @@ -655,7 +619,7 @@ struct ConfItem * hash_find_resv(const char *name) { struct ConfItem *aconf; - dlink_node *ptr; + rb_dlink_node *ptr; unsigned int hashv; s_assert(name != NULL); @@ -664,7 +628,7 @@ hash_find_resv(const char *name) hashv = hash_resv(name); - DLINK_FOREACH(ptr, resvTable[hashv].head) + RB_DLINK_FOREACH(ptr, resvTable[hashv].head) { aconf = ptr->data; @@ -678,36 +642,12 @@ hash_find_resv(const char *name) return NULL; } -struct cachefile * -hash_find_help(const char *name, int flags) -{ - struct cachefile *hptr; - dlink_node *ptr; - unsigned int hashv; - - if(EmptyString(name)) - return NULL; - - hashv = hash_help(name); - - DLINK_FOREACH(ptr, helpTable[hashv].head) - { - hptr = ptr->data; - - if((irccmp(name, hptr->name) == 0) && - (hptr->flags & flags)) - return hptr; - } - - return NULL; -} - void clear_resv_hash(void) { struct ConfItem *aconf; - dlink_node *ptr; - dlink_node *next_ptr; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; int i; HASH_WALK_SAFE(i, R_MAX, ptr, next_ptr, resvTable) @@ -719,24 +659,57 @@ clear_resv_hash(void) continue; free_conf(ptr->data); - dlinkDestroy(ptr, &resvTable[i]); + rb_dlinkDestroy(ptr, &resvTable[i]); } HASH_WALK_END } +void +add_to_cli_fd_hash(struct Client *client_p) +{ + rb_dlinkAddAlloc(client_p, &clientbyfdTable[hash_cli_fd(rb_get_fd(client_p->localClient->F))]); +} + + +void +del_from_cli_fd_hash(struct Client *client_p) +{ + unsigned int hashv; + hashv = hash_cli_fd(rb_get_fd(client_p->localClient->F)); + rb_dlinkFindDestroy(client_p, &clientbyfdTable[hashv]); +} + +struct Client * +find_cli_fd_hash(int fd) +{ + struct Client *target_p; + rb_dlink_node *ptr; + unsigned int hashv; + hashv = hash_cli_fd(fd); + RB_DLINK_FOREACH(ptr, clientbyfdTable[hashv].head) + { + target_p = ptr->data; + if(rb_get_fd(target_p->localClient->F) == fd) + return target_p; + } + return NULL; +} + static void output_hash(struct Client *source_p, const char *name, int length, int *counts, int deepest) { unsigned long total = 0; int i; + char buf[128]; sendto_one_numeric(source_p, RPL_STATSDEBUG, "B :%s Hash Statistics", name); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "B :Size: %d Empty: %d (%.3f%%)", - length, counts[0], + snprintf(buf, sizeof buf, "%.3f%%", (float) ((counts[0]*100) / (float) length)); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "B :Size: %d Empty: %d (%s)", + length, counts[0], buf); for(i = 1; i < 11; i++) { @@ -745,10 +718,14 @@ output_hash(struct Client *source_p, const char *name, int length, int *counts, /* dont want to divide by 0! --fl */ if(counts[0] != length) - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "B :Average depth: %.3f/%.3f Highest depth: %d", + { + snprintf(buf, sizeof buf, "%.3f/%.3f", (float) (total / (length - counts[0])), - (float) (total / length), deepest); + (float) (total / length)); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "B :Average depth: %s Highest depth: %d", + buf, deepest); + } for(i = 0; i < 11; i++) { @@ -760,7 +737,7 @@ output_hash(struct Client *source_p, const char *name, int length, int *counts, static void -count_hash(struct Client *source_p, dlink_list *table, int length, const char *name) +count_hash(struct Client *source_p, rb_dlink_list *table, int length, const char *name) { int counts[11]; int deepest = 0; @@ -770,13 +747,13 @@ count_hash(struct Client *source_p, dlink_list *table, int length, const char *n for(i = 0; i < length; i++) { - if(dlink_list_length(&table[i]) >= 10) + if(rb_dlink_list_length(&table[i]) >= 10) counts[10]++; else - counts[dlink_list_length(&table[i])]++; + counts[rb_dlink_list_length(&table[i])]++; - if(dlink_list_length(&table[i]) > deepest) - deepest = dlink_list_length(&table[i]); + if(rb_dlink_list_length(&table[i]) > deepest) + deepest = rb_dlink_list_length(&table[i]); } output_hash(source_p, name, length, counts, deepest);