[IRC-Dev CVS] [CVS] Module ircd-ircdev: Change committed
Brought to you by:
zolty
From: Toni G. <zo...@us...> - 2005-05-16 22:50:36
|
CVSROOT : /cvsroot/irc-dev Module : ircd-ircdev Commit time: 2005-05-16 10:17:37 UTC Modified files: ChangeLog ChangeLog.es include/ddb.h include/patchlevel.h ircd/Makefile.in ircd/ddb.c ircd/ddb_db_native.c ircd/ddb_db_template.c ircd/ddb_events.c ircd/ircd_log.c ircd/m_db.c ircd/m_dbq.c ircd/m_ghost.c ircd/m_nick.c ircd/m_svsnick.c ircd/s_bsd.c ircd/s_conf.c ircd/s_serv.c ircd/s_user.c Log message: Author: zoltan <zo...@ir...> Log message: 2005-05-16 Toni García <zo...@ir...> 1.0.alpha33 * Fix de bugs * Documentación Doxygen ---------------------- diff included ---------------------- Index: ircd-ircdev/ChangeLog diff -u ircd-ircdev/ChangeLog:1.34 ircd-ircdev/ChangeLog:1.35 --- ircd-ircdev/ChangeLog:1.34 Sat May 7 15:23:39 2005 +++ ircd-ircdev/ChangeLog Mon May 16 03:17:26 2005 @@ -1,10 +1,14 @@ # # ChangeLog for ircd-ircdev # -# $Id: ChangeLog,v 1.34 2005/05/07 22:23:39 zolty Exp $ +# $Id: ChangeLog,v 1.35 2005/05/16 10:17:26 zolty Exp $ # # Insert new changes at beginning of the change list. # +2005-05-16 Toni García <zo...@ir...> 1.0.alpha33 + * Fix bugs + * Doxygen documentation + 2005-05-08 Toni García <zo...@ir...> 1.0.alpha32 * Fix bugs Index: ircd-ircdev/ChangeLog.es diff -u ircd-ircdev/ChangeLog.es:1.34 ircd-ircdev/ChangeLog.es:1.35 --- ircd-ircdev/ChangeLog.es:1.34 Sat May 7 15:23:39 2005 +++ ircd-ircdev/ChangeLog.es Mon May 16 03:17:26 2005 @@ -1,10 +1,14 @@ # # Log de Cambios para ircd-ircdev # -# $Id: ChangeLog.es,v 1.34 2005/05/07 22:23:39 zolty Exp $ +# $Id: ChangeLog.es,v 1.35 2005/05/16 10:17:26 zolty Exp $ # # Insertar los nuevos cambios al principio de esta lista de cambios. # +2005-05-16 Toni García <zo...@ir...> 1.0.alpha33 + * Fix de bugs + * Documentación Doxygen + 2005-05-08 Toni García <zo...@ir...> 1.0.alpha32 * Fix de bugs Index: ircd-ircdev/include/ddb.h diff -u ircd-ircdev/include/ddb.h:1.7 ircd-ircdev/include/ddb.h:1.8 --- ircd-ircdev/include/ddb.h:1.7 Sat May 7 05:43:28 2005 +++ ircd-ircdev/include/ddb.h Mon May 16 03:17:26 2005 @@ -18,8 +18,10 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: ddb.h,v 1.7 2005/05/07 12:43:28 zolty Exp $ - * + */ +/** @file + * @brief Distributed DataBases structures, macros and functions. + * @version $Id: ddb.h,v 1.8 2005/05/16 10:17:26 zolty Exp $ */ #ifndef INCLUDED_ddb_h #define INCLUDED_ddb_h @@ -34,64 +36,77 @@ /* * General defines */ -/* Las tablas con los registros, serie, version */ +/** Maxium number of tables */ #define DDB_TABLE_MAX 256 -/*Numero de peticiones de registros antes de que haya que empezar a reciclar */ +/** Number of keys is caching */ #define DDB_BUF_CACHE 32 + /* - * Distributed DataBase Tables + * Distributed DataBases Tables */ -#define DDB_INIT 'a' /* First table */ - -#define DDB_CHANDB 'c' /* ChanDB table */ -#define DDB_ILINEDB 'i' /* IlineDB table */ -#define DDB_NICKDB 'n' /* NickDB table */ -#define DDB_CONFIGDB 'z' /* ConfigDB table */ -#define DDB_END 'z' /* Last table */ +/** First table of %DDB Distributed Databases. */ +#define DDB_INIT 'a' +/** Channels table of %DDB Distributed Databases. */ +#define DDB_CHANDB 'c' +/** Ilines table of %DDB Distributed Databases. */ +#define DDB_ILINEDB 'i' +/** Nicks table of %DDB Distributed Databases. */ +#define DDB_NICKDB 'n' +/** Config table of %DDB Distributed Databases. */ +#define DDB_CONFIGDB 'z' +/** Last table of %DDB Distributed Databases. */ +#define DDB_END 'z' +/* + * Config keys of config table 'z' + */ +/** Number of max clones per ip */ #define DDB_CONFIGDB_MAX_CLONES_PER_IP "maxclones" +/** Message to clients with too many clones from your ip */ #define DDB_CONFIGDB_MSG_TOO_MANY_FROM_IP "msgmanyperip" + /* * PseudoBots */ +/** Nickname of virtual bot for nicks registers */ #define DDB_NICKSERV "NickServ" -/* - * Structures +/** Describes a key on one table. */ struct Ddb { - char *key; - char *content; - struct Ddb *next; + char* ddb_key; /**< Key of the register */ + char* ddb_content; /**< Content of the key */ + struct Ddb* ddb_next; /**< Next key on the table */ }; -struct ddb_stat { - dev_t dev; /* ID of device containing a directory entry for this file */ - ino_t ino; /* Inode number */ - off_t size; /* File size in bytes */ - time_t mtime; /* Time of last data modification */ -}; +/** Get key of the register. */ +#define ddb_key(ddb) ((ddb)->ddb_key) +/** Get content of the key. */ +#define ddb_content(ddb) ((ddb)->ddb_content) +/** Get next key on the table. */ +#define ddb_next(ddb) ((ddb)->ddb_next) -/* - * ddb_db_native + +/** An copy of kernel structure stat. */ -struct ddb_memory_table { - struct ddb_stat file_stat; - char *position; /* Posicion */ - char *point_r; /* Lectura */ -#if 0 - char *point_w; /* Escritura */ -#endif +struct ddb_stat { + dev_t dev; /**< ID of device containing a directory entry for this file */ + ino_t ino; /**< Inode number */ + off_t size; /**< File size in bytes */ + time_t mtime; /**< Time of last data modification */ }; +/** DDB Macro for allocations. */ #define DdbMalloc(x) MyMalloc(x) +/** DDB Macro for freeing memory. */ #define DdbFree(x) MyFree(x) + /* * Prototypes */ @@ -114,9 +129,10 @@ extern void ddb_events_init(void); extern void ddb_end(void); -extern void ddb_new_register(struct Client *cptr, unsigned char table, char *mask, unsigned int id, char *key, char *content); +extern void ddb_new_register(struct Client *cptr, unsigned char table, unsigned int id, char *mask, char *key, char *content); extern void ddb_drop(unsigned char table); extern void ddb_drop_memory(unsigned char table, int events); +extern void ddb_compact(unsigned char table, unsigned int id, char *content); extern void ddb_burst(struct Client *cptr); extern int ddb_table_burst(struct Client *cptr, unsigned char table, unsigned int id); @@ -130,14 +146,14 @@ extern void ddb_die(const char *pattern, ...); extern void ddb_report_stats(struct Client* to, const struct StatDesc* sd, char* param); -/* Externs de ddb_db_*.c */ +/* ddb_db_*.c externs */ extern void ddb_db_init(void); extern int ddb_db_read(struct Client *cptr, unsigned char table, unsigned int id, int count); -extern void ddb_db_write(unsigned char table, char *mask, unsigned int id, char *key, char *content); +extern void ddb_db_write(unsigned char table, unsigned int id, char *mask, char *key, char *content); extern void ddb_db_drop(unsigned char table); -extern void ddb_compact(unsigned char table, char *mask, unsigned int id, char *comment); -extern void ddb_hash_read(unsigned char table, unsigned int *hi, unsigned int *lo); -extern void ddb_hash_write(unsigned char table); +extern void ddb_db_compact(unsigned char table); +extern void ddb_db_hash_read(unsigned char table, unsigned int *hi, unsigned int *lo); +extern void ddb_db_hash_write(unsigned char table); extern void ddb_db_end(void); #endif /* defined(DDB) */ Index: ircd-ircdev/include/patchlevel.h diff -u ircd-ircdev/include/patchlevel.h:1.33 ircd-ircdev/include/patchlevel.h:1.34 --- ircd-ircdev/include/patchlevel.h:1.33 Sat May 7 15:23:40 2005 +++ ircd-ircdev/include/patchlevel.h Mon May 16 03:17:26 2005 @@ -17,10 +17,10 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: patchlevel.h,v 1.33 2005/05/07 22:23:40 zolty Exp $ + * $Id: patchlevel.h,v 1.34 2005/05/16 10:17:26 zolty Exp $ * */ -#define PATCHLEVEL ".alpha32" +#define PATCHLEVEL ".alpha33" #define RELEASE "1.0" Index: ircd-ircdev/ircd/Makefile.in diff -u ircd-ircdev/ircd/Makefile.in:1.25 ircd-ircdev/ircd/Makefile.in:1.26 --- ircd-ircdev/ircd/Makefile.in:1.25 Sat May 7 05:43:29 2005 +++ ircd-ircdev/ircd/Makefile.in Mon May 16 03:17:26 2005 @@ -18,7 +18,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA -# $Id: Makefile.in,v 1.25 2005/05/07 12:43:29 zolty Exp $ +# $Id: Makefile.in,v 1.26 2005/05/16 10:17:26 zolty Exp $ #### Start of system configuration section. #### @@ -1649,31 +1649,36 @@ ../include/ircd_events.h ../include/ircd_handler.h ../include/res.h \ ../include/capab.h ../include/ircd.h ../include/struct.h \ ../include/ircd_alloc.h ../include/ircd_chattr.h ../include/ircd_log.h \ - ../include/ircd_reply.h ../include/ircd_string.h ../include/ircd_tea.h \ - ../include/list.h ../include/match.h ../include/msg.h \ - ../include/numeric.h ../include/s_bsd.h ../include/s_debug.h \ - ../include/s_misc.h ../include/send.h + ../include/ircd_reply.h ../include/ircd_snprintf.h \ + ../include/ircd_string.h ../include/ircd_tea.h ../include/list.h \ + ../include/match.h ../include/msg.h ../include/numeric.h \ + ../include/s_bsd.h ../include/s_debug.h ../include/s_misc.h \ + ../include/send.h # 1 "/usr/home/zoltan/ircd-ircdev/ircd//" ddb_db_native.o: ddb_db_native.c ../config.h ../include/ddb.h ../config.h \ ../include/client.h ../include/ircd_defs.h ../include/dbuf.h \ ../include/msgq.h ../include/ircd_events.h ../include/ircd_handler.h \ - ../include/res.h ../include/capab.h ../include/ircd_features.h \ - ../include/ircd_log.h ../include/ircd_snprintf.h ../include/numnicks.h + ../include/res.h ../include/capab.h ../include/client.h \ + ../include/ircd.h ../include/struct.h ../include/ircd_features.h \ + ../include/ircd_log.h ../include/ircd_snprintf.h \ + ../include/ircd_string.h ../include/ircd_chattr.h ../include/msg.h \ + ../include/numnicks.h ../include/s_debug.h ../include/send.h # 1 "/usr/home/zoltan/ircd-ircdev/ircd//" ddb_events.o: ddb_events.c ../config.h ../include/ddb.h ../config.h \ ../include/client.h ../include/ircd_defs.h ../include/dbuf.h \ ../include/msgq.h ../include/ircd_events.h ../include/ircd_handler.h \ ../include/res.h ../include/capab.h ../include/client.h \ ../include/hash.h ../include/ircd.h ../include/struct.h \ - ../include/ircd_tea.h ../include/msg.h ../include/numnicks.h \ - ../include/s_user.h ../include/send.h + ../include/ircd_snprintf.h ../include/ircd_tea.h ../include/msg.h \ + ../include/numnicks.h ../include/s_user.h ../include/send.h # 1 "/usr/home/zoltan/ircd-ircdev/ircd//" m_db.o: m_db.c ../config.h ../include/ddb.h ../config.h \ ../include/client.h ../include/ircd_defs.h ../include/dbuf.h \ ../include/msgq.h ../include/ircd_events.h ../include/ircd_handler.h \ ../include/res.h ../include/capab.h ../include/client.h \ - ../include/ircd.h ../include/struct.h ../include/ircd_log.h \ - ../include/ircd_reply.h ../include/list.h ../include/match.h \ + ../include/ircd.h ../include/struct.h ../include/ircd_features.h \ + ../include/ircd_log.h ../include/ircd_reply.h \ + ../include/ircd_snprintf.h ../include/list.h ../include/match.h \ ../include/msg.h ../include/numnicks.h ../include/send.h \ ../include/s_debug.h # 1 "/usr/home/zoltan/ircd-ircdev/ircd//" @@ -1700,9 +1705,10 @@ ../include/capab.h ../include/ddb.h ../config.h ../include/client.h \ ../include/hash.h ../include/ircd.h ../include/struct.h \ ../include/ircd_features.h ../include/ircd_log.h \ - ../include/ircd_string.h ../include/ircd_chattr.h ../include/ircd_tea.h \ - ../include/msg.h ../include/numnicks.h ../include/s_conf.h \ - ../include/s_user.h ../include/send.h ../include/sys.h + ../include/ircd_snprintf.h ../include/ircd_string.h \ + ../include/ircd_chattr.h ../include/ircd_tea.h ../include/msg.h \ + ../include/numnicks.h ../include/s_conf.h ../include/s_user.h \ + ../include/send.h ../include/sys.h # 1 "/usr/home/zoltan/ircd-ircdev/ircd//" m_svsnick.o: m_svsnick.c ../config.h ../include/client.h \ ../include/ircd_defs.h ../include/dbuf.h ../include/msgq.h \ @@ -1710,9 +1716,10 @@ ../include/capab.h ../include/ddb.h ../config.h ../include/client.h \ ../include/hash.h ../include/ircd.h ../include/struct.h \ ../include/ircd_features.h ../include/ircd_log.h \ - ../include/ircd_string.h ../include/ircd_chattr.h ../include/ircd_tea.h \ - ../include/msg.h ../include/numnicks.h ../include/s_conf.h \ - ../include/s_user.h ../include/send.h ../include/sys.h + ../include/ircd_snprintf.h ../include/ircd_string.h \ + ../include/ircd_chattr.h ../include/ircd_tea.h ../include/msg.h \ + ../include/numnicks.h ../include/s_conf.h ../include/s_user.h \ + ../include/send.h ../include/sys.h # 1 "/usr/home/zoltan/ircd-ircdev/ircd//" # 1 "/usr/home/zoltan/ircd-ircdev/ircd//" # 1 "/usr/home/zoltan/ircd-ircdev/ircd//" Index: ircd-ircdev/ircd/ddb.c diff -u ircd-ircdev/ircd/ddb.c:1.8 ircd-ircdev/ircd/ddb.c:1.9 --- ircd-ircdev/ircd/ddb.c:1.8 Sat May 7 15:23:40 2005 +++ ircd-ircdev/ircd/ddb.c Mon May 16 03:17:26 2005 @@ -2,7 +2,8 @@ * IRC-Dev IRCD - An advanced and innovative IRC Daemon, ircd/ddb.c * * Copyright (C) 2002-2005 IRC-Dev Development Team <de...@ir...> - * Copyright (C) 2004 Toni Garcia (zoltan) <zo...@ir...> + * Copyright (C) 2004-2005 Toni Garcia (zoltan) <zo...@ir...> + * Copyright (C) 1999-2003 Jesus Cea Avion <jc...@ar...> Esnet IRC Network * * 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 @@ -21,7 +22,7 @@ */ /** @file * @brief Implementation of Distributed DataBase. - * @version $Id: ddb.c,v 1.8 2005/05/07 22:23:40 zolty Exp $ + * @version $Id: ddb.c,v 1.9 2005/05/16 10:17:26 zolty Exp $ */ #include "config.h" @@ -46,31 +47,53 @@ /* #include <assert.h> -- Now using assert in ircd_log.h */ #include <stdarg.h> #include <stdio.h> -/*#include <stdlib.h> */ #include <string.h> #include <time.h> +/** @page ddb Distributed DataBase + * + * + * TODO, explicacion del sistema + */ + +/** DDB registers cache. */ static struct Ddb ddb_buf_cache[DDB_BUF_CACHE]; +/** Buffer cache. */ static int ddb_buf_cache_i = 0; +/** Tables of %DDB. */ struct Ddb **ddb_data_table[DDB_TABLE_MAX]; -short ddb_corrupt_table[DDB_TABLE_MAX]; +/** Residents tables of %DDB. */ unsigned int ddb_resident_table[DDB_TABLE_MAX]; +/** Registers count of %DDB tables. */ unsigned int ddb_count_table[DDB_TABLE_MAX]; +/** ID number of %DDB tables. */ unsigned int ddb_id_table[DDB_TABLE_MAX]; +/** Hi hash table. */ unsigned int ddb_hashtable_hi[DDB_TABLE_MAX]; +/** Lo hash table. */ unsigned int ddb_hashtable_lo[DDB_TABLE_MAX]; +/** File or DB stats of %DDB tables.*/ struct ddb_stat ddb_stats_table[DDB_TABLE_MAX]; +/** Last key on iterator. */ static struct Ddb *ddb_iterator_key = NULL; +/** Last content on iterator. */ static struct Ddb **ddb_iterator_content = NULL; +/** Position of hash on iterator. */ static int ddb_iterator_hash_pos = 0; +/** Length of hash on iterator. */ static int ddb_iterator_hash_len = 0; +static void ddb_table_init(unsigned char table); static int ddb_add_key(unsigned char table, char *key, char *content); static int ddb_del_key(unsigned char table, char *key); +/** Verify if a table is resident. + * @param[in] table Table of the %DDB Distributed DataBase. + * @return Non-zero if a table is resident; zero is not resident. + */ int ddb_table_is_resident(unsigned char table) { return ddb_resident_table[table] ? 1 : 0; @@ -88,8 +111,10 @@ } */ -/** - * +/** Copy a malloc in the memory. + * @param[in] buf Buffer + * @param[in] len Length + * @param[in] p Pointer */ static void DdbCopyMalloc(char *buf, int len, char **p) @@ -104,15 +129,19 @@ } if (!p2) { - p2 = MyMalloc(len + 1); /* El '\0' final */ + p2 = MyMalloc(len + 1); /* The '\0' */ *p = p2; } memcpy(p2, buf, len); p2[len] = '\0'; } -/** - * +/** Calculates the hash. + * @param[in] table Table of the %DDB Distributed DataBase. + * @param[in] id ID number in the table. + * @param[in] mask Mask of the server. + * @param[in] key Key of the registry. + * @param[in] content Content of the registry. */ static void ddb_hash_calculate(unsigned char table, unsigned int id, char *mask, char *key, char *content) @@ -134,11 +163,14 @@ strncpy((char *)buffer, buf, sizeof(buffer) - 1); + /* TODO */ +#if 0 /* Parece que no es necesario, comprobarlo */ while ((p2 = strchr((char *)buffer, '\n'))) *p2 = '\0'; while ((p2 = strchr((char *)buffer, '\r'))) *p2 = '\0'; +#endif k[0] = k[1] = 0; x[0] = ddb_hashtable_hi[table]; @@ -154,8 +186,7 @@ ddb_hashtable_lo[table] = x[1]; } -/** initialize Distributed DataBase - * +/** Initialize %DDB Distributed DataBases. */ void ddb_init(void) @@ -168,33 +199,92 @@ memset(ddb_resident_table, 0, sizeof(ddb_resident_table)); /* - * Las longitudes DEBEN ser potencias de 2, - * y no deben ser superiores a HASHSIZE, ya que ello - * solo desperdiciaria memoria. + * The lengths MUST be powers of 2 and do not have + * to be superior to HASHSIZE. */ ddb_resident_table[DDB_ILINEDB] = 256; ddb_resident_table[DDB_NICKDB] = 32768; ddb_resident_table[DDB_CONFIGDB] = 256; for (table = DDB_INIT; table <= DDB_END; table++) - { - ddb_drop_memory(table, 0); - ddb_db_read(NULL, table, 0, 0); -/* ddb_hash_read(table); */ - } + ddb_table_init(table); /* - * La operacion anterior puede ser una operacion larga. - * Resincronizamos tiempo. + * The previous operation it can be a long operation. + * Updates time. */ CurrentTime = time(NULL); } -/** - * +/** Initialize a table of %DDB. + * @param[in] table + */ +static void ddb_table_init(unsigned char table) +{ + unsigned int hi, lo; + + /* First drop table */ + ddb_drop_memory(table, 0); + + /* Read the table on file or database */ + ddb_db_read(NULL, table, 0, 0); + + /* Read hashes */ + ddb_db_hash_read(table, &hi, &lo); + + /* Compare memory hashes with local hashes */ + sendto_opmask_butone(0, SNO_OLDSNO, "Lo: %d Hashtable_Lo: %d Hi: %d Hashtable_Hi %d", + lo, ddb_hashtable_lo[table], hi, ddb_hashtable_hi[table]); + +#if 0 + if ((ddb_hashtable_hi[table] != hi) || (ddb_hashtable_lo[table] != lo)) + { + struct DLink *lp; + char buf[1024]; + + log_write(LS_DDB, L_INFO, 0, "WARNING - Table '%c' is corrupt. Droping table...", table); + ddb_db_drop(table); + + ircd_snprintf(0, buf, sizeof(buf), "Table '%c' is corrupt. Reloading via remote burst...", table); + ddb_splithubs_butone(NULL, buf); + + log_write(LS_DDB, L_INFO, 0, "Solicit a copy of table '%s' to neighboring nodes", table); + + /* Solicit a copy to only hubs*/ + for (lp = cli_serv(&me)->down; lp; lp = lp->next) + { + if (IsHub(lp->value.cptr)) + sendcmdto_one(&me, CMD_DB, lp->value.cptr, "%C 0 J %u %c", + lp->value.cptr, ddb_id_table[table], table); + } + } + else +#endif + { + ddb_db_hash_write(table); + + if (ddb_resident_table[table]) + { + ddb_del_key(table, "*"); + log_write(LS_DDB, L_INFO, 0, "Loading Table '%c' finished: S=%u R=%u", + table, ddb_id_table[table], ddb_count_table[table]); + } + else if (ddb_count_table[table]) + log_write(LS_DDB, L_INFO, 0, "Loading Table '%c' finished: S=%u NoResident", + table, ddb_id_table[table]); + } +} + +/** Add a new register from the network or reading when ircd is starting. + * @param[in] cptr %Server sending a new register. If is NULL, it is own server during ircd start. + * @param[in] table Table of the %DDB Distributed DataBases. + * @param[in] id Identify number of the register. + * @param[in] mask Servermask of the register. + * @param[in] key Key of the register. + * @param[in] content Content of the key. */ void -ddb_new_register(struct Client *cptr, unsigned char table, char *mask, unsigned int id, char *key, char *content) +ddb_new_register(struct Client *cptr, unsigned char table, unsigned int id, char *mask, char *key, char *content) { static char *keytemp = NULL; static int key_len = 0; @@ -204,30 +294,27 @@ ddb_hash_calculate(table, id, mask, key, content); - /* Al iniciar, cptr no existe y por lo tanto no se escribe */ + /* In the ircd starting, cptr is NULL and it not writing on file or database */ if (cptr) { - ddb_db_write(table, mask, id, key, content); - ddb_hash_write(table); + ddb_db_write(table, id, mask, key, content); + ddb_db_hash_write(table); } ddb_id_table[table] = id; - /* Solo ponemos en memoria registros cuya mascara - * concuerda con el servidor. - * Y por supuesto, que sean residentes - */ + /* If the table is not resident, do not save in memory */ if (!ddb_resident_table[table]) return; - /* Usamos collapse+match por un bug en lastNNServer del find_match_server */ + /* If a mask is not concerned with me, do not save in memory */ + /* For lastNNServer bug (find_match_server) it use collapse + match */ collapse(mask); if (!match(mask, cli_name(&me))) { - int i = 0; +/* int i = 0; */ int update = 0; - /* pasamos el key en minusculas */ if ((strlen(key) + 1 > key_len) || (!keytemp)) { key_len = strlen(key) + 1; @@ -238,17 +325,21 @@ assert(0 != keytemp); } strcpy(keytemp, key); + +/* while (keytemp[i]) { -/* keytemp[i] = ToLower(keytemp[i]); */ + keytemp[i] = ToLower(keytemp[i]); i++; } +*/ if (content) update = ddb_add_key(table, keytemp, content); else ddb_del_key(table, keytemp); + /* TODO */ /* Ejecutamos los eventos */ /* if (!cptr && ddb_events_table[table]) */ if (ddb_events_table[table]) @@ -257,8 +348,11 @@ } -/** - * +/** Add or update an register on the memory. + * @param[in] table Table of the %DDB Distributed DataBases. + * @param[in] key Key of the register. + * @param[in] content Content of the key. + * @return 1 is an update, 0 is a new register. */ static int ddb_add_key(unsigned char table, char *key, char *content) @@ -281,7 +375,6 @@ strcpy(k, key); strcpy(c, content); - /* paso a minusculas */ /* while (c[i] != 0) { @@ -290,23 +383,25 @@ } */ - ddb->key = k; - ddb->content = c; - ddb->next = NULL; + ddb_key(ddb) = k; + ddb_content(ddb) = c; + ddb_next(ddb) = NULL; - hashi = ddb_hash_register(ddb->key, ddb_resident_table[table]); + hashi = ddb_hash_register(ddb_key(ddb), ddb_resident_table[table]); - Debug((DEBUG_INFO, "Inserto T='%c' K='%s' C='%s' H=%u",table, ddb->key, ddb->content, hashi)); + Debug((DEBUG_INFO, "Add DDB: T='%c' K='%s' C='%s' H=%u", table, ddb_key(ddb), ddb_content(ddb), hashi)); - ddb->next = ddb_data_table[table][hashi]; + ddb_next(ddb) = ddb_data_table[table][hashi]; ddb_data_table[table][hashi] = ddb; ddb_count_table[table]++; - return delete; + return delete; } -/** - * +/** Delete an register from memory. + * @param[in] table Table of the %DDB Distributed DataBases. + * @param[in] key Key of the register. + * @return 1 on success; 0 do not delete. */ static int ddb_del_key(unsigned char table, char *key) @@ -322,8 +417,8 @@ for (ddb = *ddb3; ddb; ddb = ddb2) { - ddb2 = ddb->next; - if (!strcmp(ddb->key, key)) + ddb2 = ddb_next(ddb); + if (!strcmp(ddb_key(ddb), key)) { *ddb3 = ddb2; delete = 1; @@ -331,30 +426,31 @@ ddb_count_table[table]--; break; } - ddb3 = &(ddb->next); + ddb3 = &(ddb_next(ddb)); } return delete; } -/** - * +/** Deletes a table. + * @param[in] table Table of the %DDB Distributed DataBases. */ void ddb_drop(unsigned char table) { - /* Borramos el fichero de la tabla */ + /* Delete file or database of the table */ ddb_db_drop(table); - /* Borramos la tabla en la memoria */ + /* Delete table from memory */ ddb_drop_memory(table, 0); - - ddb_hash_write(table); - ddb_corrupt_table[table] = 0; + + /* Write hash on file or database */ + ddb_db_hash_write(table); } -/** - * +/** Deletes a table from memory. + * @param[in] table Table of the %DDB Distributed DataBases. + * @param[in] events Non-zero impliques events. */ void ddb_drop_memory(unsigned char table, int events) @@ -371,10 +467,10 @@ { for (ddb = ddb_data_table[table][i]; ddb; ddb = ddb2) { - ddb2 = ddb->next; + ddb2 = ddb_next(ddb); if (events && ddb_events_table[table]) - ddb_events_table[table](ddb->key, NULL, 0); + ddb_events_table[table](ddb_key(ddb), NULL, 0); DdbFree(ddb); } @@ -395,19 +491,35 @@ ddb_id_table[table] = 0; ddb_hashtable_hi[table] = 0; ddb_hashtable_lo[table] = 0; -/* - tabla_corrupta[tabla] = 0; -*/ } -/** - * +/** Packing the table. + * @param[in] table Table of the %DDB Distributed DataBases. + * @param[in] id Identify number of the register. + * @param[in] content Content of the key. + */ +void +ddb_compact(unsigned char table, unsigned int id, char *content) +{ + log_write(LS_DDB, L_INFO, 0, "Packing table '%c'", table); + ddb_id_table[table] = id; + ddb_db_compact(table); + + ddb_hash_calculate(table, id, "*", "*", content); + ddb_db_write(table, id, "*", "*", content); + ddb_db_hash_write(table); +} + +/** Sending the %DDB burst tables. + * @param[in] cptr %Server sending the petition. */ void ddb_burst(struct Client *cptr) { int i; + sendto_opmask_butone(0, SNO_NETWORK, "Bursting DDB tables"); + sendcmdto_one(&me, CMD_DB, cptr, "* 0 J %u n", ddb_id_table[DDB_NICKDB]); @@ -419,8 +531,8 @@ } } -/** - * +/** Initializes %DDB iterator. + * @return ddb_iterator_key pointer. */ static struct Ddb * ddb_iterator_init(void) @@ -429,16 +541,13 @@ if (ddb_iterator_key) { - ddb_iterator_key = ddb_iterator_key->next; + ddb_iterator_key = ddb_next(ddb_iterator_key); if (ddb_iterator_key) { return ddb_iterator_key; } } - /* - * Indica el PROXIMO valor a utilizar. - */ while (ddb_iterator_hash_pos < ddb_iterator_hash_len) { ddb = ddb_iterator_content[ddb_iterator_hash_pos++]; @@ -456,8 +565,9 @@ return NULL; } -/** - * +/** Initializes iterator for a table. + * @param[in] table Table of the %DDB Distributed DataBase. + * @return First active register on a table. */ struct Ddb * ddb_iterator_first(unsigned char table) @@ -473,9 +583,9 @@ return ddb_iterator_init(); } - -/** - * + +/** Next iterator. + * @return Next active register on a table. */ struct Ddb * ddb_iterator_next(void) @@ -487,15 +597,17 @@ return ddb_iterator_init(); } -/** - * +/** Find a register by the key (internal). + * @param[in] table Table of the %DDB Distributed DataBases. + * @param[in] key Key of the register. + * @return Pointer of the register. */ static struct Ddb *ddb_find_registry_table(unsigned char table, char *key) { struct Ddb *ddb; static char *k = 0; static int k_len = 0; - int i, hashi; + int i = 0, hashi; if ((strlen(key) + 1 > k_len) || (!k)) { @@ -507,30 +619,33 @@ return 0; } strcpy(k, key); - /* paso a minusculas */ - i = 0; + +/* while (k[i]) { -/* k[i] = ToLower(k[i]); */ + k[i] = ToLower(k[i]); i++; } +*/ hashi = ddb_hash_register(k, ddb_resident_table[table]); - for (ddb = ddb_data_table[table][hashi]; ddb; ddb = ddb->next) + for (ddb = ddb_data_table[table][hashi]; ddb; ddb = ddb_next(ddb)) { -/* if (!strcmp(ddb->key, k)) */ - if (!ircd_strcmp(ddb->key, k)) +/* if (!strcmp(ddb_key(ddb), k)) */ + if (!ircd_strcmp(ddb_key(ddb), k)) { - assert(0 != ddb->content); + assert(0 != ddb_content(ddb)); return ddb; } } return NULL; } -/** - * +/** Find a register by the key. + * @param[in] table Table of the %DDB Distributed DataBases. + * @param[in] key Key of the register. + * @return Pointer of the register. */ struct Ddb *ddb_find_key(unsigned char table, char *key) { @@ -547,24 +662,25 @@ if (!ddb) return NULL; - /* Lo que sigue lo sustituye */ - key_init = ddb->key; + key_init = ddb_key(ddb); key_end = key_init + strlen(key_init); - content_init = ddb->content; + content_init = ddb_content(ddb); content_end = content_init + strlen(content_init); DdbCopyMalloc(key_init, key_end - key_init, - &ddb_buf_cache[ddb_buf_cache_i].key); + &ddb_buf_cache[ddb_buf_cache_i].ddb_key); DdbCopyMalloc(content_init, content_end - content_init, - &ddb_buf_cache[ddb_buf_cache_i].content); + &ddb_buf_cache[ddb_buf_cache_i].ddb_content); if (++ddb_buf_cache_i >= DDB_BUF_CACHE) ddb_buf_cache_i = 0; return ddb; } -/** - * +/** Get nick!user@host of the virtual bot. + * @param[in] bot Key of the register. + * @return nick!user@host of the virtual bot if exists and + * if not exists, return my servername. */ char * ddb_get_botname(char *bot) @@ -573,21 +689,19 @@ ddb = ddb_find_key(DDB_CONFIGDB, DDB_NICKSERV); if (ddb) - return ddb->content; + return ddb_content(ddb); else return cli_name(&me); } -/** - * +/** When IRCD is reloading, it is executing. */ void ddb_reload(void) { - sendto_opmask_butone(0, SNO_OLDSNO, "Reload Distributed DataBase..."); log_write(LS_DDB, L_INFO, 0, "Reload Distributed DataBase..."); - ddb_init(); + /* ddb_init(); */ } @@ -641,6 +755,8 @@ server_die(exitmsg); } +/** Finalizes the %DDB subsystem. + */ void ddb_end(void) { Index: ircd-ircdev/ircd/ddb_db_native.c diff -u ircd-ircdev/ircd/ddb_db_native.c:1.3 ircd-ircdev/ircd/ddb_db_native.c:1.4 --- ircd-ircdev/ircd/ddb_db_native.c:1.3 Sat May 7 15:23:40 2005 +++ ircd-ircdev/ircd/ddb_db_native.c Mon May 16 03:17:27 2005 @@ -3,7 +3,7 @@ * * Copyright (C) 2002-2005 IRC-Dev Development Team <de...@ir...> * Copyright (C) 2004-2005 Toni Garcia (zoltan) <zo...@ir...> - * Copyright (C) 1999-2003 Jesus Cea Avion <jc...@ar...> + * Copyright (C) 1999-2003 Jesus Cea Avion <jc...@ar...> Esnet IRC Network * * 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 @@ -21,8 +21,8 @@ * */ /** @file - * @brief Native DataBase implementation of Distributed DataBase. - * @version $Id: ddb_db_native.c,v 1.3 2005/05/07 22:23:40 zolty Exp $ + * @brief Native DataBase implementation of Distributed DataBases. + * @version $Id: ddb_db_native.c,v 1.4 2005/05/16 10:17:27 zolty Exp $ */ #include "config.h" @@ -32,8 +32,10 @@ #include "ircd_features.h" #include "ircd_log.h" #include "ircd_snprintf.h" +#include "ircd_string.h" #include "msg.h" #include "numnicks.h" +#include "s_debug.h" #include "send.h" /* #include <assert.h> -- Now using assert in ircd_log.h */ @@ -42,22 +44,30 @@ #include <string.h> #include <unistd.h> #include <sys/mman.h> + /* -#include <stdlib.h> -#include <sys/stat.h> -*/ + * ddb_db_native + */ +struct ddb_memory_table { + struct ddb_stat file_stat; + char *position; /* Posicion */ + char *point_r; /* Lectura */ +}; static int ddb_read(struct ddb_memory_table *map_table, char *buf); static int ddb_seek(struct ddb_memory_table *map_table, char *buf, unsigned int id); static void get_ddb_stat(int fd, struct ddb_stat *ddbstat); +static char *check_corrupt_table(unsigned char table, struct ddb_stat *ddbstat); -/** - * + +/** Initialize database gestion module of + * %DDB Distributed DataBases. */ void ddb_db_init(void) { char path[1024]; + unsigned char table; int fd; int temp; @@ -71,32 +81,50 @@ ddb_die("Error when creating %s directory", feature_str(FEAT_DDBPATH)); } #endif - /* Verificar archivo hashes */ + + /* Verify if hashes file is exist. */ ircd_snprintf(0, path, sizeof(path), "%s/hashes", feature_str(FEAT_DDBPATH)); alarm(3); fd = open(path, O_WRONLY, S_IRUSR | S_IWUSR); if (fd == -1) { - unsigned char tabletemp; fd = open(path, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); if (fd == -1) - ddb_die("Error when creating hashes file"); + ddb_die("Error when creating hashes file (OPEN)"); - for (tabletemp = DDB_INIT; tabletemp <= DDB_END; tabletemp++) + for (table = DDB_INIT; table <= DDB_END; table++) { - ircd_snprintf(0, path, sizeof(path), "%c AAAAAAAAAAAA\n", tabletemp); + ircd_snprintf(0, path, sizeof(path), "%c AAAAAAAAAAAA\n", table); write(fd, path, 15); } } close(fd); alarm(0); - /* Verificar archivos de las tablas */ - + /* Verify if tables file is exist. */ + for (table = DDB_INIT; table <= DDB_END; table++) + { + ircd_snprintf(0, path, sizeof(path), "%s/table.%c", + feature_str(FEAT_DDBPATH), table); + alarm(3); + fd = open(path, O_WRONLY, S_IRUSR | S_IWUSR); + if (fd == -1) + { + fd = open(path, O_CREAT, S_IRUSR | S_IWUSR); + if (fd == -1) + ddb_die("Error when creating table '%c' (OPEN)", table); + } + close(fd); + alarm(0); + } } -/** - * +/** Read the table. + * @param[in] cptr %Server if is exists, it sends to server. + * @param[in] table Table of the %DDB Distributed DataBase. + * @param[in] id ID number in the table. + * @param[in] count Number of registers to be read. + * @return 1 No data pending, 0 have data pending, -1 error. */ int ddb_db_read(struct Client *cptr, unsigned char table, unsigned int id, int count) @@ -122,15 +150,13 @@ MAP_SHARED | MAP_NORESERVE, fd, 0); if (fd == -1) -/* ddb_die("Error when reading table '%c' (OPEN)", table); */ - return -1; + ddb_die("Error when reading table '%c' (OPEN)", table); if ((map_table.file_stat.size != 0) && (map_table.position == MAP_FAILED)) ddb_die("Error when reading table '%c' (MMAP)", table); close(fd); alarm(0); -/* map_table->point_r = map_table->point_w = map_table->position; */ map_table.point_r = map_table.position; cont = ddb_seek(&map_table, buf, id); @@ -140,7 +166,7 @@ return -1; } - /* Leer */ + /* Read registers */ do { char *mask, *key, *content; @@ -165,8 +191,8 @@ *content++ = '\0'; if (!cptr) - /* Inicio del ircd */ - ddb_new_register(NULL, table, mask, cid, key, content); + /* IRCD starting */ + ddb_new_register(NULL, table, cid, mask, key, content); else { /* Burst */ @@ -187,34 +213,40 @@ } while(ddb_read(&map_table, buf) != -1); - /* CERRAR FICHERO */ + /* Close mmap file */ munmap(map_table.position, map_table.file_stat.size); return int_return; } -/** - * +/** Write the table. + * @param[in] table Table of the %DDB Distributed DataBase. + * @param[in] id ID number in the table. + * @param[in] mask Mask of the server. + * @param[in] key Key of the registry. + * @param[in] content Content of the registry. */ void -ddb_db_write(unsigned char table, char *mask, unsigned int id, char *key, char *content) +ddb_db_write(unsigned char table, unsigned int id, char *mask, char *key, char *content) { struct ddb_stat ddbstat; char path[1024]; + char *corrupt; int fd, offset; ircd_snprintf(0, path, sizeof(path), "%s/table.%c", feature_str(FEAT_DDBPATH), table); alarm(3); - fd = open(path, O_CREAT | O_APPEND | O_WRONLY, S_IRUSR | S_IWUSR); + fd = open(path, O_WRONLY | O_APPEND, S_IRUSR | S_IWUSR); if (fd == -1) ddb_die("Error when saving new key in table '%c' (OPEN)", table); get_ddb_stat(fd, &ddbstat); - /* TODO: Comprobar corrupcion - * comprueba_corrupcion(table, &ddbstat); - */ + corrupt = check_corrupt_table(table, &ddbstat); + if (corrupt) + ddb_die("A nonauthorized modification is detect in table '%c' [%s]", + table, corrupt); offset = lseek(fd, 0 , SEEK_CUR); if (offset < 0) @@ -233,8 +265,8 @@ alarm(0); } -/** - * +/** Delete a table. + * @param[in] table Table of the %DDB Distributed DataBase. */ void ddb_db_drop(unsigned char table) @@ -257,20 +289,21 @@ alarm(0); } -/** - * +/** Pack the table. + * @param[in] table Table of the %DDB Distributed DataBase. */ void -ddb_db_compact(unsigned char table, char *mask, unsigned int id, char *comment) +ddb_db_compact(unsigned char table) { - } -/** - * +/** Read the hashes. + * @param[in] table Table of the %DDB Distributed DataBase. + * @param[out] hi Hi hash. + * @param[out] lo Lo hash. */ void -ddb_hash_read(unsigned char table, unsigned int *hi, unsigned int *lo) +ddb_db_hash_read(unsigned char table, unsigned int *hi, unsigned int *lo) { char path[1024]; char c; @@ -278,6 +311,7 @@ ircd_snprintf(0, path, sizeof(path), "%s/hashes", feature_str(FEAT_DDBPATH)); + alarm(3); fd = open(path, O_RDONLY, S_IRUSR | S_IWUSR); if (fd == -1) { @@ -300,11 +334,11 @@ *lo = base64toint(path + 6); } -/** - * +/** Write the hash. + * @param[in] table Table of the %DDB Distributed DataBase. */ void -ddb_hash_write(unsigned char table) +ddb_db_hash_write(unsigned char table) { char path[1024]; char hash[20]; @@ -329,8 +363,7 @@ } -/** - * +/** Executes when finalizes the %DDB subsystem. */ void ddb_db_end(void) @@ -338,8 +371,9 @@ /* Backup copy? */ } -/** - * +/** Read the table. + * @param[in,out] map_table Structure ddb_memory_table. + * @param[in] buf Buffer. */ static int ddb_read(struct ddb_memory_table *map_table, char *buf) @@ -366,8 +400,10 @@ return -1; } -/** - * +/** Seek the table. + * @param[in,out] memory_table Structure ddb_memory_table. + * @param[in] buf Buffer. + * @param[in] id ID number in the table. */ static int ddb_seek(struct ddb_memory_table *map_table, char *buf, unsigned int id) @@ -411,8 +447,9 @@ return ddb_read(map_table, buf); } -/** - * +/** Fstat wrapper. + * @param[in] fd File Descriptor. + * @param[out] ddbstat Structure ddb_stat. */ static void get_ddb_stat(int fd, struct ddb_stat *ddbstat) @@ -427,3 +464,58 @@ ddbstat->size = st.st_size; ddbstat->mtime = st.st_mtime; } + +/** Checking if a table is corrupt + * @param[in] table Table of the %DDB Distributed DataBase. + * @param[in] ddbstat Structure ddb_stat + * @return If is NULL, the table is not corrupt else, return the reason message. + */ +static char * +check_corrupt_table(unsigned char table, struct ddb_stat *ddbstat) +{ + char *msg = NULL; + + /* TODO */ + return msg; + if (memcmp(&ddbstat, &ddb_stats_table[table], sizeof(ddbstat))) + { + char buf[1024]; + char *space = ""; + + if (ddbstat->dev != ddb_stats_table[table].dev) + { + ircd_snprintf(0, buf, sizeof(buf), "DEVICE %llu<>%llu", + ddbstat->dev, ddb_stats_table[table].dev); + space = " "; + Debug((DEBUG_INFO, "check_corrupt1: %s", buf)); + } + + if (ddbstat->ino != ddb_stats_table[table].ino) + { + ircd_snprintf(0, buf + strlen(buf), sizeof(buf), "%sINODE %llu<>%llu", + space, ddbstat->ino, ddb_stats_table[table].ino); + space = " "; + Debug((DEBUG_INFO, "check_corrupt2: %s", buf)); + } + + if (ddbstat->size != ddb_stats_table[table].size) + { + ircd_snprintf(0, buf + strlen(buf), sizeof(buf), "%sSIZE %llu<>%llu", + space, ddbstat->size, ddb_stats_table[table].size); + space = " "; + Debug((DEBUG_INFO, "check_corrupt3: %s", buf)); + } + + if (ddbstat->mtime != ddb_stats_table[table].mtime) + { + ircd_snprintf(0, buf + strlen(buf), sizeof(buf), "%sMTIME %llu<>%llu", + space, ddbstat->mtime, ddb_stats_table[table].mtime); + Debug((DEBUG_INFO, "check_corrupt4: %s", buf)); + } + Debug((DEBUG_INFO, "check_corrupt: %s", buf)); + ircd_strncpy(msg, buf, strlen(buf)); + } +/* TODO */ + return NULL; + return msg; +} Index: ircd-ircdev/ircd/ddb_db_template.c diff -u ircd-ircdev/ircd/ddb_db_template.c:1.1 ircd-ircdev/ircd/ddb_db_template.c:1.2 --- ircd-ircdev/ircd/ddb_db_template.c:1.1 Wed Mar 23 10:34:47 2005 +++ ircd-ircdev/ircd/ddb_db_template.c Mon May 16 03:17:27 2005 @@ -1,9 +1,8 @@ /* - * IRC-Dev IRCD - An advanced and innovative IRC Daemon, ircd/ddb_db_example.c + * IRC-Dev IRCD - An advanced and innovative IRC Daemon, ircd/ddb_db_template.c * * Copyright (C) 2002-2005 IRC-Dev Development Team <de...@ir...> * Copyright (C) 2004-2005 Toni Garcia (zoltan) <zo...@ir...> - * Copyright (C) 1999-2003 Jesus Cea Avion <jc...@ar...> * * 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 @@ -21,59 +20,150 @@ * */ /** @file - * @brief Implementation of Distributed DataBase. - * @version $Id: ddb_db_template.c,v 1.1 2005/03/23 18:34:47 zolty Exp $ + * @brief Template DataBase mplementation of Distributed DataBases. + * @version $Id: ddb_db_template.c,v 1.2 2005/05/16 10:17:27 zolty Exp $ */ #include "config.h" #include "ddb.h" +#include "client.h" +#include "ircd.h" +#include "ircd_log.h" +#include "ircd_snprintf.h" +#include "ircd_string.h" +#include "msg.h" #include "numnicks.h" +#include "send.h" -#include <fcntl.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/mman.h> -#include <sys/stat.h> -#include <unistd.h> +/* #include <assert.h> -- Now using assert in ircd_log.h */ -int -ddb_db_open(unsigned char table, unsigned int id, struct ddb_memory_table *mt) +/** Initialize database gestion module of + * %DDB Distributed DataBases. + */ +void +ddb_db_init(void) { - return 1; } - -void ddb_db_close(struct ddb_memory_table *mt) +/** Read the table. + * @param[in] cptr %Server if is exists, it sends to server. + * @param[in] table Table of the %DDB Distributed DataBase. + * @param[in] id ID number in the table. + * @param[in] count Number of registers to be read. + * @return 1 No data pending, 0 have data pending, -1 error. + */ +int +ddb_db_read(struct Client *cptr, unsigned char table, unsigned int id, int count) { -} + int int_return; -int ddb_db_read(struct ddb_memory_table *mt, char *mask, char *id, char *key, char *content) -{ - return 1; -} + int_return = 1; /* 1 = success */ + + /* Open file or database */ -void ddb_db_write(unsigned char table, char *mask, unsigned int id, char *key, char *content) + + /* Read registers */ + do + { + if (!cptr) + /* IRCD starting */ + ddb_new_register(NULL, table, mask, cid, key, content); + else + { + /* Burst */ + if (content) + sendcmdto_one(&me, CMD_DB, cptr, "%s %u %c %s :%s", + mask, cid, table, key, content); + else + sendcmdto_one(&me, CMD_DB, cptr, "%s %u %c %s", + mask, cid, table, key); + + if (!(--cont)) + { + int_return = 0; + break; + } + } + + } while(0) /* While read function */ + + /* Close File or Database */ + + return int_return; +} + +/** Write the table. + * @param[in] table Table of the %DDB Distributed DataBase. + * @param[in] id ID number in the table. + * @param[in] mask Mask of the server. + * @param[in] key Key of the registry. + * @param[in] content Content of the registry. + */ +void +ddb_db_write(unsigned char table, char *mask, unsigned int id, char *key, char *content) { + char buf[1024]; + + ircd_snprintf(0, buf, sizeof(buf), "%d %s %s%s%s\n", id, mask, key, + content ? " " : "", content ? content : ""); } -void ddb_db_drop(unsigned char table) +/** Delete a table. + * @param[in] table Table of the %DDB Distributed DataBase. + */ +void +ddb_db_drop(unsigned char table) { } +/** Pack the table. + * @param[in] table Table of the %DDB Distributed DataBase. + */ void ddb_db_compact(unsigned char table, char *mask, unsigned int id, char *comment) { - } +/** Read the hashes. + * @param[in] table Table of the %DDB Distributed DataBase. + * @param[out] hi Hi hash. + * @param[out] lo Lo hash. + */ +void +ddb_db_hash_read(unsigned char table, unsigned int *hi, unsigned int *lo) +{ + char buf[30]; + + /* Read buf + * buf = lala; + */ + buf[12] = '\0'; + c = buf[6]; + buf[6] = '\0'; + *hi = base64toint(buf); + buf[6] = c; + *lo = base64toint(buf + 6); +} -void ddb_hash_read(unsigned char table, unsigned int *hi, unsigned int *lo) +/** Write the hash. + * @param[in] table Table of the %DDB Distributed DataBase. + */ +void +ddb_db_hash_write(unsigned char table) { + char hash[20]; + + inttobase64(hash, ddb_hashtable_hi[table], 6); + inttobase64(hash + 6, ddb_hashtable_lo[table], 6); + ircd_snprintf(0, path, sizeof(path), "%c %s\n", table, hash); } -void ddb_hash_write(unsigned char table) +/** Executes whe finalizes the %DDB subsystem. + */ +void +ddb_db_end(void) { } + Index: ircd-ircdev/ircd/ddb_events.c diff -u ircd-ircdev/ircd/ddb_events.c:1.3 ircd-ircdev/ircd/ddb_events.c:1.4 --- ircd-ircdev/ircd/ddb_events.c:1.3 Sat May 7 15:23:40 2005 +++ ircd-ircdev/ircd/ddb_events.c Mon May 16 03:17:27 2005 @@ -20,8 +20,8 @@ * */ /** @file - * @brief Events of Distributed DataBase. - * @version $Id: ddb_events.c,v 1.3 2005/05/07 22:23:40 zolty Exp $ + * @brief Events of Distributed DataBases. + * @version $Id: ddb_events.c,v 1.4 2005/05/16 10:17:27 zolty Exp $ */ #include "config.h" @@ -39,14 +39,17 @@ #include <stdio.h> #include <string.h> - +/** It indicates events is initialized */ static int events_init = 0; +/** Events table engine */ +ddb_events_table_td ddb_events_table[DDB_TABLE_MAX]; + static void ddb_events_table_n(char *key, char *content, int update); static void ddb_events_table_z(char *key, char *content, int update); -ddb_events_table_td ddb_events_table[DDB_TABLE_MAX]; - +/** Initialize events module of %DDB Distributed DataBases. + */ void ddb_events_init(void) { @@ -60,7 +63,11 @@ events_init = 1; } - +/** Handle events on Nick Table. + * @param[in] key Key of registry. + * @param[in] content Content of registry. + * @param[in] update Update of registry or no. + */ static void ddb_events_table_n(char *key, char *content, int update) { @@ -86,20 +93,17 @@ send_umode_out(cptr, cptr, &oldflags, IsRegistered(cptr)); } - else + else if (content) { /* New Key or Update Key */ - char c = content[strlen(content) - 1]; int nick_suspend = 0; - int nick_forbid = 0; - if (c == '+') + if (content[strlen(content) - 1] == '+') nick_suspend = 1; - else if (c == '*') - nick_forbid = 1; - if (nick_forbid) + if (*content == '*') { + /* Forbid Nick */ sendcmdbotto_one(botname, CMD_NOTICE, cptr, "%C :*** Your nick %C has been forbided, cannot be used", cptr, cptr); nick_renames = 1; @@ -180,6 +184,11 @@ } } +/** Handle events on Config Table. + * @param[in] key Key of registry. + * @param[in] content Content of registry. + * @param[in] update Update of registry or no. + */ static void ddb_events_table_z(char *key, char *content, int update) { Index: ircd-ircdev/ircd/ircd_log.c diff -u ircd-ircdev/ircd/ircd_log.c:1.10 ircd-ircdev/ircd/ircd_log.c:1.11 --- ircd-ircdev/ircd/ircd_log.c:1.10 Sat May 7 15:23:40 2005 +++ ircd-ircdev/ircd/ircd_log.c Mon May 16 03:17:27 2005 @@ -22,7 +22,7 @@ */ /** @file * @brief IRC logging implementation. - * @version $Id: ircd_log.c,v 1.10 2005/05/07 22:23:40 zolty Exp $ + * @version $Id: ircd_log.c,v 1.11 2005/05/16 10:17:27 zolty Exp $ */ #include "config.h" @@ -157,7 +157,7 @@ S(WHO, -1, 0), S(NETWORK, -1, SNO_NETWORK), #ifdef DDB - S(DDB, -1, 0), + S(DDB, -1, SNO_NETWORK), #endif S(OPERKILL, -1, 0), S(SERVKILL, -1, 0), Index: ircd-ircdev/ircd/m_db.c diff -u ircd-ircdev/ircd/m_db.c:1.5 ircd-ircdev/ircd/m_db.c:1.6 --- ircd-ircdev/ircd/m_db.c:1.5 Sat May 7 15:23:40 2005 +++ ircd-ircdev/ircd/m_db.c Mon May 16 03:17:27 2005 @@ -22,17 +22,17 @@ */ /** @file * @brief Handlers for DB command. - * @version $Id: m_db.c,v 1.5 2005/05/07 22:23:40 zolty Exp $ + * @version $Id: m_db.c,v 1.6 2005/05/16 10:17:27 zolty Exp $ */ -/* TODO-ZOLTAN - * Traducidr los comentarios al ingles */ #include "config.h" #include "ddb.h" #include "client.h" #include "ircd.h" +#include "ircd_features.h" #include "ircd_log.h" #include "ircd_reply.h" +#include "ircd_snprintf.h" #include "list.h" #include "match.h" #include "msg.h" @@ -88,18 +88,18 @@ id = atoi(parv[2]); if (!id) { - /* No es un registro */ + /* It is not a register */ id = atoi(parv[4]); if (parc == 6) { table = *parv[5]; if ((table < DDB_INIT) || (table > DDB_END)) { - /* Se pide un HASH Global de todas las tablas */ + /* A global HASH of all the tables is requested */ if ((table == '*') && ((*parv[3] == 'Q') || (*parv[3] == 'R'))) table = '*'; #if 1 - /* COMPATIBILIDAD IRC-HISPANO */ + /* ESNET Compatibility */ else if (table == '2') table = DDB_NICKDB; #endif @@ -114,7 +114,7 @@ switch (*parv[3]) { - /* Peticion de Burst (quedan registros) */ + /* Burst command (Pending registers for send) */ case 'B': if (IsHub(cptr)) sendcmdto_one(&me, CMD_DB, cptr, "%s 0 J %u %c", parv[0], ddb_id_table[table], table); @@ -126,61 +126,60 @@ if (!IsHub(cptr)) break; - /* Enviamos el mensaje al resto de servidores */ + /* Send the message to the rest of servers */ for (lp = cli_serv(&me)->down; lp; lp = lp->next) { if (lp->value.cptr != cptr) { sendcmdto_one(&me, CMD_DB, lp->value.cptr, "%s 0 D %s %c", parv[1], parv[4], table); - /* TODO-ZOLTAN: Mirar si es necesario (IRC-Hispano) */ + /* TODO-ZOLTAN: Mirar si es necesario (ESNET) */ /* cli_serv(lp->value.cptr)->ddb_open &= ~ddb_mask); */ } } - - /* Usamos collapse+match por un bug en lastNNServer del find_match_server() */ + + /* For lastNNServer bug (find_match_server) it use collapse + match */ collapse(parv[1]); - /* Si no es para nosotros, lo ignoramos */ + /* If it is not for us, it ignored */ if (match(parv[1], cli_name(&me))) break; - /* Borramos la tabla en memoria y en disco */ + /* Drop the table on memory and disk */ ddb_drop(table); - /* Desconectamos con todos los hubs menos el que nos envia la orden */ - log_write(LS_DDB, L_INFO, 0, "DB Drop Table %c from %#C", table, cptr); - ircd_snprintf(0, ddb_buf, sizeof(ddb_buf), "DB DROP Table %c from %s", - table, cli_name(cptr)); + /* Disconnect with all hubs except which it sends to us */ + log_write(LS_DDB, L_INFO, 0, "DB Drop Table %c from %C", table, cptr); + ircd_snprintf(0, ddb_buf, sizeof(ddb_buf), "DB DROP Table %c from %C", + table, cptr); ddb_splithubs_butone(cptr, ddb_buf); - /* Mandamos la respuesta de conformidad */ + /* Send the conformity response */ sendcmdto_one(&me, CMD_DB, cptr, "%s 0 E %s %c", cli_name(cptr), parv[4], table); /* TODO-ZOLTAN: Creo que hay que mandar a todos */ cli_serv(cptr)->ddb_open &= ~ddb_mask; - /* Solicitamos de nuevo la tabla */ sendcmdto_one(&me, CMD_DB, cptr, "%s 0 J %u %c", cli_name(cptr), ddb_id_table[table], table); break; } - /* Respuesta de Drop */ + /* Drop response */ case 'E': - /* Si no es para nosotros, lo pasamos a otros */ + /* If it is not for us, passed it to others */ if ((acptr = find_match_server(parv[1])) && (!IsMe(acptr))) sendcmdto_one(sptr, CMD_DB, acptr, "%s 0 E %s %c", cli_name(acptr), parv[4], table); break; - /* Comprobacion de Hash automatico leaf <=> hub */ + /* Automatic verification of HASH leaf <=> Hub */ case 'H': { char *hash; unsigned int hash_lo, hash_hi; - if (IsHub(&me)) + if (feature_bool(FEAT_HUB)) return protocol_violation(cptr, "Don't HASH check to HUBs, table %c from %#C", table, cptr); hash = parv[4]; @@ -192,58 +191,59 @@ hash[6] = parv[4][6]; hash_hi = base64toint(hash + 6); + sendto_opmask_butone(0, SNO_OLDSNO, "Lo: %d Hashtable_Lo: %d Hi: %d Hashtable_Hi %d", + hash_lo, ddb_hashtable_lo[table], hash_hi, ddb_hashtable_hi[table]); +#if 0 if (!((hash_lo == ddb_hashtable_lo[table]) && (hash_hi == ddb_hashtable_hi[table]))) { - /* El HASH es incorrecto, a borrar */ - sendto_opmask_butone(0, SNO_OLDSNO, "DB HASH Check failed, droping table %c", table); + /* The HASH is incorrect, to erase */ log_write(LS_DDB, L_INFO, 0, "DB HASH Check failed, droping table %c", table); - /* Borramos la tabla en memoria y en disco*/ + /* Drop the table on memory and disk */ ddb_drop(table); - /* Solicitamos de nuevo la tabla */ sendcmdto_one(&me, CMD_DB, cptr, "%s 0 J %u %c", cli_name(cptr), ddb_id_table[table], table); } +#endif break; } /* Join */ case 'J': { - int burst; + int end_burst; if (id >= ddb_id_table[table]) { - /* Registros individuales */ + /* Individual registers*/ cli_serv(cptr)->ddb_open |= ddb_mask; break; } else if ((cli_serv(cptr)->ddb_open) & ddb_mask) { - /* Grifo abierto y registros antiguos. - * Ocurre si la copia de cptr de la DDB - * esta corrupta + /* Open faucet and old registers. + * It happens if the copy of cptr of the DDB + * is corrupt. */ (cli_serv(cptr)->ddb_open) &= ~ddb_mask; - /* Borramos su DDB para curarnos en salud */ + /* Drop your DDB */ sendcmdto_one(&me, CMD_DB, cptr, "%s 0 D DDB_CORRUPT %c", cli_name(cptr), table); break; } - /* En el Burst de tabla, se hacen rafagas de 1000 registros, - * se envia una en cada petición de JOIN. La funcion devuelve 1 - * si se han mandado todos los datos en el rafaga y 0 si aún hay - * datos pendientes. - * La comprobacion automatica de HASH solo se debe hacer a los - * leafs, NUNCA a HUBS, ya que si un HUB tiene la DB corrupta, - * toda la red se va a tomar por viento con un borrado masivo. + /* In the burst of table, bursts become of 1000 registers, is send + * one in each JOIN request. This function gives back 1 if all the + * data is sent and 0 if still there are pending data. + * The automatic HASH verification is due to do to leafs, NEVER to + * HUBS, since if a HUB has the corrupt DB, all the network is down + * by wind with a massive erasure. */ - burst = ddb_db_read(cptr, table, (id + 1), 1000); - if (burst == 1) + end_burst = ddb_db_read(cptr, table, (id + 1), 1000); + if (end_burst == 1) { cli_serv(cptr)->ddb_open |= ((unsigned int)1) << (table - DDB_INIT); if (IsHub(cptr)) @@ -254,26 +254,26 @@ sendcmdto_one(&me, CMD_DB, cptr, "%s 0 H %s %c", cli_name(cptr), ddb_buf, table); } - else if (burst == 0) + else if (end_burst == 0) sendcmdto_one(&me, CMD_DB, cptr, "%s 0 B %u %c", cli_name(cptr), ddb_id_table[table], table); break; } - /* Query de hash para comprobaciones desde un service */ + /* Hash Query command for verify from a service */ case 'Q': { if (!IsHub(cptr)) break; - /* Usamos collapse+match por un bug en lastNNServer del find_match_server() */ + /* For lastNNServer bug (find_match_server) it use collapse + match */ collapse(parv[1]); - /* Solo si es para nosotros si lo ignoramos */ + /* If it is not for us, passed it to others */ if (!match(parv[1], cli_name(&me))) { if (table == '*') { - /* HASH de todas las tablas */ + /* HASH of all the tables */ unsigned int hashes_hi = 0; unsigned int hashes_lo = 0; unsigned int id_tables = 1; @@ -297,7 +297,7 @@ } else { - /* Una tabla */ + /* One table */ inttobase64(ddb_buf, ddb_hashtable_hi[table], 6); inttobase64(ddb_buf + 6, ddb_hashtable_lo[table], 6); @@ -307,7 +307,7 @@ } } - /* Enviamos la petición a los demas */ + /* Send the petition to the others */ for (lp = cli_serv(&me)->down; lp; lp = lp->next) { if (lp->value.cptr != cptr) @@ -317,52 +317,44 @@ break; } - /* Respuesta de hash */ + /* Hash response */ case 'R': - /* Si no es para nosotros, lo pasamos a otros */ + /* If it is not for us, passed it to others */ if ((acptr = find_match_server(parv[1])) && (!IsMe(acptr))) sendcmdto_one(sptr, CMD_DB, acptr, "%s 0 R %s %c", cli_name(acptr), parv[4], table); break; - /* Registro nuevo, el parv[3] es la tabla */ + /* New register, parv[3] is the table */ default: { int delete; - /* Solo se aceptan registros procedentes de un HUB */ -/* Hablitarlo + /* Only accepted registers coming from a HUB */ if (!IsHub(cptr)) return 0; -*/ + table = *parv[3]; if (table < DDB_INIT || table > DDB_END) - { -#if 0 - /* COMPATIBILIDAD IRC-HISPANO */ - if (table == 'N') - table = DDB_NICKDB; -#endif return 0; - } id = atoi(parv[2]); - /* Rechazamos registros con ID inferior al nuestro */ + /* Rejected registers with ID lower to our */ if (id <= ddb_id_table[table]) return 0; if (parc == 5) - /* Borrado del registro */ + /* Delete register */ delete = 1; else if (parc > 5) - /* Insertado del registro */ + /* Add register */ delete = 0; else - /* No deberia ocurrir */ return protocol_violation(sptr, "DB Incorrect parameters"); ddb_mask = ((unsigned int) 1) << (table - DDB_INIT); - /* Propagamos a nuestros servidores hijos */ + + /* Propagated to our child servers */ for (lp = cli_serv(&me)->down; lp; lp = lp->next) { if ((lp->value.cptr != cptr) && @@ -378,11 +370,9 @@ } if (strcmp(parv[4], "*")) - ddb_new_register(cptr, table, parv[1], id, parv[4], (!delete ? parv[5] : NULL)); -/* + ddb_new_register(cptr, table, id, parv[1], parv[4], (!delete ? parv[5] : NULL)); else - ddb_compact(table, parv[1], id, parv[5]); -*/ + ddb_compact(table, id, parv[5]); break; } Index: ircd-ircdev/ircd/m_dbq.c diff -u ircd-ircdev/ircd/m_dbq.c:1.3 ircd-ircdev/ircd/m_dbq.c:1.4 --- ircd-ircdev/ircd/m_dbq.c:1.3 Wed Mar 23 10:34:51 2005 +++ ircd-ircdev/ircd/m_dbq.c Mon May 16 03:17:27 2005 @@ -21,7 +21,7 @@ */ /** @file * @brief Handlers for DBQ command. - * @version $Id: m_dbq.c,v 1.3 2005/03/23 18:34:51 zolty Exp $ + * @version $Id: m_dbq.c,v 1.4 2005/05/16 10:17:27 zolty Exp $ */ #include "config.h" @@ -77,7 +77,7 @@ if (parc == 3) { - server = NULL; /* no nos indican server */ + server = NULL; table = *parv[parc - 2]; key = parv[parc - 1]; } @@ -96,15 +96,14 @@ /* NOT BROADCAST */ if (!(acptr = find_match_server(server))) { - /* joer, el server de destino no existe */ send_reply(sptr, ERR_NOSUCHSERVER, server); return 0; } - if (!IsMe(acptr)) /* no es para mi, a rutar */ + if (!IsMe(acptr)) { sendcmdto_one(acptr, CMD_DBQ, sptr, "%s %c %s", server, table, key); - return 0; /* ok, rutado, fin del trabajo */ + return 0; } } } @@ -129,11 +128,11 @@ sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :DBQ OK Table='%c' Key='%s' Content='%... [truncated message content] |