mirror of
https://github.com/matrix-construct/construct
synced 2025-01-14 00:34:18 +01:00
Reverting to 398.. trying again with native charybdis hash
This commit is contained in:
parent
002bc9e82c
commit
ae78a57163
6 changed files with 913 additions and 980 deletions
|
@ -287,9 +287,9 @@ struct LocalUser
|
||||||
unsigned long random_ping;
|
unsigned long random_ping;
|
||||||
auth_request_t *auth_request;
|
auth_request_t *auth_request;
|
||||||
|
|
||||||
/* target change stuff */
|
/* target change stuff */
|
||||||
void *targets[10]; /* targets were aware of */
|
uint32_t targets[10]; /* targets were aware of (fnv32(use_id(target_p))) */
|
||||||
rb_uint8_t targinfo[2]; /* cyclic array, no in use */
|
unsigned int targinfo[2]; /* cyclic array, no in use */
|
||||||
time_t target_last; /* last time we cleared a slot */
|
time_t target_last; /* last time we cleared a slot */
|
||||||
|
|
||||||
list_client_t *safelist_data;
|
list_client_t *safelist_data;
|
||||||
|
|
218
include/hash.h
218
include/hash.h
|
@ -1,115 +1,103 @@
|
||||||
/*
|
/*
|
||||||
* ircd-ratbox: A slightly useful ircd.
|
* ircd-ratbox: A slightly useful ircd.
|
||||||
* hash.h: A header for the ircd hashtable code.
|
* hash.h: A header for the ircd hashtable code.
|
||||||
*
|
*
|
||||||
* Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
|
* Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
|
||||||
* Copyright (C) 1996-2002 Hybrid Development Team
|
* Copyright (C) 1996-2002 Hybrid Development Team
|
||||||
* Copyright (C) 2002-2005 ircd-ratbox development team
|
* Copyright (C) 2002-2004 ircd-ratbox development team
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
* USA
|
* USA
|
||||||
*
|
*
|
||||||
* $Id: hash.h 24794 2007-12-28 02:36:59Z androsyn $
|
* $Id: hash.h 3177 2007-02-01 00:19:14Z jilles $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef INCLUDED_hash_h
|
#ifndef INCLUDED_hash_h
|
||||||
#define INCLUDED_hash_h
|
#define INCLUDED_hash_h
|
||||||
|
|
||||||
extern struct Dictionary *nd_dict;
|
struct Dictionary;
|
||||||
|
|
||||||
extern rb_dlink_list resvTable[];
|
extern rb_dlink_list *clientTable;
|
||||||
extern rb_dlink_list ndTable[];
|
extern rb_dlink_list *channelTable;
|
||||||
|
extern rb_dlink_list *idTable;
|
||||||
/* Magic value for FNV hash functions */
|
extern rb_dlink_list *resvTable;
|
||||||
#define FNV1_32_INIT 0x811c9dc5UL
|
extern rb_dlink_list *hostTable;
|
||||||
|
extern rb_dlink_list *helpTable;
|
||||||
/* Client hash table size, used in hash.c/s_debug.c */
|
|
||||||
#define U_MAX_BITS 17
|
extern struct Dictionary *nd_dict;
|
||||||
#define U_MAX (1<<U_MAX_BITS)
|
|
||||||
|
/* Magic value for FNV hash functions */
|
||||||
/* Client fd hash table size, used in hash.c */
|
#define FNV1_32_INIT 0x811c9dc5UL
|
||||||
#define CLI_FD_MAX 4096
|
|
||||||
|
/* Client hash table size, used in hash.c/s_debug.c */
|
||||||
/* Channel hash table size, hash.c/s_debug.c */
|
#define U_MAX_BITS 17
|
||||||
#define CH_MAX_BITS 16
|
#define U_MAX 131072 /* 2^17 */
|
||||||
#define CH_MAX (1<<CH_MAX_BITS) /* 2^16 */
|
|
||||||
|
/* Channel hash table size, hash.c/s_debug.c */
|
||||||
/* hostname hash table size */
|
#define CH_MAX_BITS 16
|
||||||
#define HOST_MAX_BITS 17
|
#define CH_MAX 65536 /* 2^16 */
|
||||||
#define HOST_MAX (1<<HOST_MAX_BITS) /* 2^17 */
|
|
||||||
|
/* hostname hash table size */
|
||||||
/* RESV/XLINE hash table size, used in hash.c */
|
#define HOST_MAX_BITS 17
|
||||||
#define R_MAX_BITS 10
|
#define HOST_MAX 131072 /* 2^17 */
|
||||||
#define R_MAX (1<<R_MAX_BITS) /* 2^10 */
|
|
||||||
|
/* RESV/XLINE hash table size, used in hash.c */
|
||||||
|
#define R_MAX_BITS 10
|
||||||
#define HASH_WALK(i, max, ptr, table) for (i = 0; i < max; i++) { RB_DLINK_FOREACH(ptr, table[i].head)
|
#define R_MAX 1024 /* 2^10 */
|
||||||
#define HASH_WALK_SAFE(i, max, ptr, nptr, table) for (i = 0; i < max; i++) { RB_DLINK_FOREACH_SAFE(ptr, nptr, table[i].head)
|
|
||||||
#define HASH_WALK_END }
|
|
||||||
|
#define HASH_WALK(i, max, ptr, table) for (i = 0; i < max; i++) { RB_DLINK_FOREACH(ptr, table[i].head)
|
||||||
typedef enum
|
#define HASH_WALK_SAFE(i, max, ptr, nptr, table) for (i = 0; i < max; i++) { RB_DLINK_FOREACH_SAFE(ptr, nptr, table[i].head)
|
||||||
{
|
#define HASH_WALK_END }
|
||||||
HASH_CLIENT,
|
|
||||||
HASH_ID,
|
struct Client;
|
||||||
HASH_CHANNEL,
|
struct Channel;
|
||||||
HASH_HOSTNAME,
|
struct ConfItem;
|
||||||
HASH_RESV
|
struct cachefile;
|
||||||
} hash_type;
|
struct nd_entry;
|
||||||
|
|
||||||
struct Client;
|
extern u_int32_t fnv_hash_upper(const unsigned char *s, int bits);
|
||||||
struct Channel;
|
extern u_int32_t fnv_hash(const unsigned char *s, int bits);
|
||||||
struct ConfItem;
|
extern u_int32_t fnv_hash_len(const unsigned char *s, int bits, int len);
|
||||||
struct cachefile;
|
extern u_int32_t fnv_hash_upper_len(const unsigned char *s, int bits, int len);
|
||||||
struct nd_entry;
|
|
||||||
|
extern void init_hash(void);
|
||||||
uint32_t fnv_hash_upper(const unsigned char *s, unsigned int bits, unsigned int unused);
|
|
||||||
uint32_t fnv_hash(const unsigned char *s, unsigned int bits, unsigned int unused);
|
extern void add_to_client_hash(const char *name, struct Client *client);
|
||||||
uint32_t fnv_hash_len(const unsigned char *s, unsigned int bits, unsigned int len);
|
extern void del_from_client_hash(const char *name, struct Client *client);
|
||||||
uint32_t fnv_hash_upper_len(const unsigned char *s, unsigned int bits, unsigned int len);
|
extern struct Client *find_client(const char *name);
|
||||||
|
extern struct Client *find_named_client(const char *name);
|
||||||
void init_hash(void);
|
extern struct Client *find_server(struct Client *source_p, const char *name);
|
||||||
|
|
||||||
void add_to_hash(hash_type, const char *, void *);
|
extern void add_to_id_hash(const char *, struct Client *);
|
||||||
void del_from_hash(hash_type, const char *, void *);
|
extern void del_from_id_hash(const char *name, struct Client *client);
|
||||||
|
extern struct Client *find_id(const char *name);
|
||||||
struct Client *find_any_client(const char *name);
|
|
||||||
struct Client *find_client(const char *name);
|
extern struct Channel *get_or_create_channel(struct Client *client_p, const char *chname, int *isnew);
|
||||||
struct Client *find_named_client(const char *name);
|
extern void del_from_channel_hash(const char *name, struct Channel *chan);
|
||||||
struct Client *find_server(struct Client *source_p, const char *name);
|
extern struct Channel *find_channel(const char *name);
|
||||||
|
|
||||||
struct Client *find_id(const char *name);
|
extern void add_to_hostname_hash(const char *, struct Client *);
|
||||||
|
extern void del_from_hostname_hash(const char *, struct Client *);
|
||||||
struct Channel *get_or_create_channel(struct Client *client_p, const char *chname, int *isnew);
|
extern rb_dlink_node *find_hostname(const char *);
|
||||||
struct Channel *find_channel(const char *name);
|
|
||||||
|
extern void add_to_resv_hash(const char *name, struct ConfItem *aconf);
|
||||||
rb_dlink_node *find_hostname(const char *);
|
extern void del_from_resv_hash(const char *name, struct ConfItem *aconf);
|
||||||
|
extern struct ConfItem *hash_find_resv(const char *name);
|
||||||
struct ConfItem *hash_find_resv(const char *name);
|
extern void clear_resv_hash(void);
|
||||||
void clear_resv_hash(void);
|
|
||||||
|
extern void hash_stats(struct Client *);
|
||||||
void add_to_help_hash(const char *name, struct cachefile *hptr);
|
|
||||||
void clear_help_hash(void);
|
#endif /* INCLUDED_hash_h */
|
||||||
struct cachefile *hash_find_help(const char *name, int flags);
|
|
||||||
|
|
||||||
void add_to_nd_hash(const char *name, struct nd_entry *nd);
|
|
||||||
struct nd_entry *hash_find_nd(const char *name);
|
|
||||||
|
|
||||||
void add_to_cli_fd_hash(struct Client *client_p);
|
|
||||||
void del_from_cli_fd_hash(struct Client *client_p);
|
|
||||||
struct Client *find_cli_fd_hash(int fd);
|
|
||||||
|
|
||||||
void hash_stats(struct Client *);
|
|
||||||
|
|
||||||
#endif /* INCLUDED_hash_h */
|
|
||||||
|
|
|
@ -246,14 +246,11 @@ extern int valid_wild_card_simple(const char *);
|
||||||
extern int clean_resv_nick(const char *);
|
extern int clean_resv_nick(const char *);
|
||||||
time_t valid_temp_time(const char *p);
|
time_t valid_temp_time(const char *p);
|
||||||
|
|
||||||
struct nd_entry
|
struct nd_entry
|
||||||
{
|
{
|
||||||
char name[NICKLEN+1];
|
char name[NICKLEN+1];
|
||||||
time_t expire;
|
time_t expire;
|
||||||
unsigned int hashv;
|
rb_dlink_node lnode; /* node in ll */
|
||||||
|
|
||||||
rb_dlink_node hnode; /* node in hash */
|
|
||||||
rb_dlink_node lnode; /* node in ll */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern void add_nd_entry(const char *name);
|
extern void add_nd_entry(const char *name);
|
||||||
|
|
|
@ -140,7 +140,8 @@ extern int errno;
|
||||||
# define __noreturn
|
# define __noreturn
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* XXX must be removed in future!!! -- dwr */
|
|
||||||
|
|
||||||
#ifdef strdupa
|
#ifdef strdupa
|
||||||
#define LOCAL_COPY(s) strdupa(s)
|
#define LOCAL_COPY(s) strdupa(s)
|
||||||
#else
|
#else
|
||||||
|
@ -149,28 +150,4 @@ extern int errno;
|
||||||
#else
|
#else
|
||||||
# define LOCAL_COPY(s) strcpy(alloca(strlen(s) + 1), s) /* XXX Is that allowed? */
|
# define LOCAL_COPY(s) strcpy(alloca(strlen(s) + 1), s) /* XXX Is that allowed? */
|
||||||
#endif /* defined(__INTEL_COMPILER) || defined(__GNUC__) */
|
#endif /* defined(__INTEL_COMPILER) || defined(__GNUC__) */
|
||||||
|
|
||||||
/* LOCAL_COPY_N copies n part of string and adds one to terminate the string */
|
|
||||||
#ifdef strndupa
|
|
||||||
#define LOCAL_COPY_N(s, n) strndupa(s, n)
|
|
||||||
#else
|
|
||||||
#if defined(__INTEL_COMPILER) || defined(__GNUC__)
|
|
||||||
#define LOCAL_COPY_N(s, n) __extension__({ size_t _l = strlen(s); _l = n > _l ? _l : n; char *_s = alloca(_l+1); memcpy(_s, s, _l); _s[_l] = '\0' ; _s; })
|
|
||||||
#else
|
|
||||||
#define LOCAL_COPY_N(s, n) xc_strlcpy(alloca(strlen(s)+1), s, n)
|
|
||||||
INLINE_FUNC size_t
|
|
||||||
xc_strlcpy(char *dest, const char *src, size_t size)
|
|
||||||
{
|
|
||||||
size_t ret = strlen(src);
|
|
||||||
|
|
||||||
if (size) {
|
|
||||||
size_t len = (ret >= size) ? size-1 : ret;
|
|
||||||
memcpy(dest, src, len);
|
|
||||||
dest[len] = '\0';
|
|
||||||
}
|
|
||||||
return dest;
|
|
||||||
}
|
|
||||||
#endif /* defined(__INTEL_COMPILER) || defined(__GNUC__) */
|
|
||||||
#endif /* strndupa */
|
|
||||||
|
|
||||||
#endif /* strdupa */
|
#endif /* strdupa */
|
||||||
|
|
|
@ -561,63 +561,75 @@ expire_tgchange(void *unused)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
add_target(struct Client *source_p, struct Client *target_p)
|
add_target(struct Client *source_p, struct Client *target_p)
|
||||||
{
|
{
|
||||||
unsigned int i, j;
|
int i, j;
|
||||||
/* messaging themselves, doesnt incur any penalties */
|
uint32_t hashv;
|
||||||
if(source_p == target_p)
|
|
||||||
return 1;
|
/* can msg themselves or services without using any target slots */
|
||||||
|
if(source_p == target_p || IsService(target_p))
|
||||||
if(USED_TARGETS(source_p))
|
return 1;
|
||||||
{
|
|
||||||
/* hunt for an existing target */
|
/* special condition for those who have had PRIVMSG crippled to allow them
|
||||||
for(i = PREV_FREE_TARGET(source_p), j = USED_TARGETS(source_p);
|
* to talk to IRCops still.
|
||||||
j;
|
*
|
||||||
--j, PREV_TARGET(i))
|
* XXX: is this controversial?
|
||||||
{
|
*/
|
||||||
if(source_p->localClient->targets[i] == target_p)
|
if(source_p->localClient->target_last > rb_current_time() && IsOper(target_p))
|
||||||
return 1;
|
return 1;
|
||||||
}
|
|
||||||
|
hashv = fnv_hash_upper((const unsigned char *)use_id(target_p), 32);
|
||||||
/* first message after connect, we may only start clearing
|
|
||||||
* slots after this message --anfl
|
if(USED_TARGETS(source_p))
|
||||||
*/
|
{
|
||||||
if(!IsTGChange(source_p))
|
/* hunt for an existing target */
|
||||||
{
|
for(i = PREV_FREE_TARGET(source_p), j = USED_TARGETS(source_p);
|
||||||
SetTGChange(source_p);
|
j; --j, PREV_TARGET(i))
|
||||||
source_p->localClient->target_last = rb_current_time();
|
{
|
||||||
}
|
if(source_p->localClient->targets[i] == hashv)
|
||||||
/* clear as many targets as we can */
|
return 1;
|
||||||
else if((i = (rb_current_time() - source_p->localClient->target_last) / 60))
|
}
|
||||||
{
|
|
||||||
if(i > USED_TARGETS(source_p))
|
/* first message after connect, we may only start clearing
|
||||||
USED_TARGETS(source_p) = 0;
|
* slots after this message --anfl
|
||||||
else
|
*/
|
||||||
USED_TARGETS(source_p) -= i;
|
if(!IsTGChange(source_p))
|
||||||
|
{
|
||||||
source_p->localClient->target_last = rb_current_time();
|
SetTGChange(source_p);
|
||||||
}
|
source_p->localClient->target_last = rb_current_time();
|
||||||
/* cant clear any, full target list */
|
}
|
||||||
else if(USED_TARGETS(source_p) == 10)
|
/* clear as many targets as we can */
|
||||||
{
|
else if((i = (rb_current_time() - source_p->localClient->target_last) / 60))
|
||||||
add_tgchange(source_p->sockhost);
|
{
|
||||||
return 0;
|
if(i > USED_TARGETS(source_p))
|
||||||
}
|
USED_TARGETS(source_p) = 0;
|
||||||
}
|
else
|
||||||
/* no targets in use, reset their target_last so that they cant
|
USED_TARGETS(source_p) -= i;
|
||||||
* abuse a long idle to get targets back more quickly
|
|
||||||
*/
|
source_p->localClient->target_last = rb_current_time();
|
||||||
else
|
}
|
||||||
{
|
/* cant clear any, full target list */
|
||||||
source_p->localClient->target_last = rb_current_time();
|
else if(USED_TARGETS(source_p) == 10)
|
||||||
SetTGChange(source_p);
|
{
|
||||||
}
|
ServerStats->is_tgch++;
|
||||||
|
add_tgchange(source_p->sockhost);
|
||||||
source_p->localClient->targets[FREE_TARGET(source_p)] = target_p;
|
return 0;
|
||||||
NEXT_TARGET(FREE_TARGET(source_p));
|
}
|
||||||
++USED_TARGETS(source_p);
|
}
|
||||||
return 1;
|
/* no targets in use, reset their target_last so that they cant
|
||||||
|
* abuse a long idle to get targets back more quickly
|
||||||
|
*/
|
||||||
|
else
|
||||||
|
{
|
||||||
|
source_p->localClient->target_last = rb_current_time();
|
||||||
|
SetTGChange(source_p);
|
||||||
|
}
|
||||||
|
|
||||||
|
source_p->localClient->targets[FREE_TARGET(source_p)] = hashv;
|
||||||
|
NEXT_TARGET(FREE_TARGET(source_p));
|
||||||
|
++USED_TARGETS(source_p);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
1503
src/hash.c
1503
src/hash.c
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue