Mercurial > hg > waaad
changeset 133:776a136f5a1f
Started reorganization of the code
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Tue, 19 Aug 2008 14:17:54 +0900 |
parents | 9dfac05e0e48 |
children | b39966808cfb |
files | waaad/Makefile.am waaad/session.c waaad/tests/Makefile.am waaad/utils.c waaad/utils.h waaad/waaad-internal.h |
diffstat | 6 files changed, 172 insertions(+), 56 deletions(-) [+] |
line wrap: on
line diff
--- a/waaad/Makefile.am Tue Aug 19 14:17:34 2008 +0900 +++ b/waaad/Makefile.am Tue Aug 19 14:17:54 2008 +0900 @@ -21,13 +21,16 @@ # This is the list of sources for "waaad" : waaad_SOURCES = waaad-internal.h main.c \ + utils.h utils.c \ conf.h conf.c conf-gram.y conf-token.l \ hgversion.h log.h log.c \ extensions.h extensions.c \ dictionary.h dictionary.c \ dict-base.h dict-base.c \ - peer.h peer.c peer-thctl.c peer-listener.c \ + peer.h peer.c \ + peer-internal.h peer-thctl.c peer-listener.c \ peer-psm.c peer-send.c peer-recv.c \ + peer-tcp.c peer-sctp.c peer-events.c \ message.h message.c \ queues.h queues.c \ routing.h routing.c \
--- a/waaad/session.c Tue Aug 19 14:17:34 2008 +0900 +++ b/waaad/session.c Tue Aug 19 14:17:54 2008 +0900 @@ -168,50 +168,6 @@ /********************************************************************************************************/ -/* Hash function -- credits to Austin Appleby, thank you ^^ */ -/* See http://murmurhash.googlepages.com for more information on this function */ - -/* Our sid is always aligned properly, so we use the simple MurmurHash2 function */ -#define _HASH_MIX(h,k,m) { k *= m; k ^= k >> r; k *= m; h *= m; h ^= k; } -static uint32_t _hash ( char * sid, size_t len ) -{ - uint32_t hash = len; - char * data = sid; - - const unsigned int m = 0x5bd1e995; - const int r = 24; - - /* Check the alignment is really correct -- otherwise we have to switch to the other version */ - assert(((long)sid & 3) == 0); - - while(len >= 4) - { - /* Mix 4 bytes at a time into the hash */ - uint32_t k = *(uint32_t *)data; /* We don't care about the byte order */ - - _HASH_MIX(hash, k, m); - - data += 4; - len -= 4; - } - - /* Handle the last few bytes of the input */ - switch(len) { - case 3: hash ^= data[2] << 16; - case 2: hash ^= data[1] << 8; - case 1: hash ^= data[0]; - hash *= m; - } - - /* Do a few final mixes of the hash to ensure the last few - bytes are well-incorporated. */ - hash ^= hash >> 13; - hash *= m; - hash ^= hash >> 15; - - return hash; -} -/********************************************************************************************************/ /* Function to compare a (hash, sid, len) with a sess_id_element. */ static __inline__ int cmp_si(uint32_t hash1, char * sid1, size_t sid1len, _sess_id_t * si2) @@ -399,7 +355,7 @@ } /* Compute the hash value of this string */ - hash = _hash(sid, len); + hash = uti_hash(sid, len); /* Lock the hash table line */ ret = pthread_mutex_lock( H_LOCK(hash) );
--- a/waaad/tests/Makefile.am Tue Aug 19 14:17:34 2008 +0900 +++ b/waaad/tests/Makefile.am Tue Aug 19 14:17:54 2008 +0900 @@ -14,12 +14,16 @@ # List of daemon's source files, without the "main" function WAAADSOURCES = ../waaad-internal.h \ + ../utils.h ../utils.c \ ../conf.h ../conf.c ../conf-gram.y ../conf-token.l \ - ../log.h ../log.c \ + ../hgversion.h ../log.h ../log.c \ ../extensions.h ../extensions.c \ ../dictionary.h ../dictionary.c \ ../dict-base.h ../dict-base.c \ ../peer.h ../peer.c \ + ../peer-internal.h ../peer-thctl.c ../peer-listener.c \ + ../peer-psm.c ../peer-send.c ../peer-recv.c \ + ../peer-tcp.c ../peer-sctp.c ../peer-events.c \ ../message.h ../message.c \ ../queues.h ../queues.c \ ../routing.h ../routing.c \
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/waaad/utils.c Tue Aug 19 14:17:54 2008 +0900 @@ -0,0 +1,96 @@ +/********************************************************************************************************* +* Software License Agreement (BSD License) * +* Author: Sebastien Decugis <sdecugis@nict.go.jp> * +* * +* Copyright (c) 2008, WIDE Project and NICT * +* All rights reserved. * +* * +* Redistribution and use of this software in source and binary forms, with or without modification, are * +* permitted provided that the following conditions are met: * +* * +* * Redistributions of source code must retain the above * +* copyright notice, this list of conditions and the * +* following disclaimer. * +* * +* * Redistributions in binary form must reproduce the above * +* copyright notice, this list of conditions and the * +* following disclaimer in the documentation and/or other * +* materials provided with the distribution. * +* * +* * Neither the name of the WIDE Project or NICT nor the * +* names of its contributors may be used to endorse or * +* promote products derived from this software without * +* specific prior written permission of WIDE Project and * +* NICT. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * +* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * +* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * +* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * +*********************************************************************************************************/ + +/* Useful functions. + * + * See utils.h for more information on the functions and types involved. + */ + +#include <pthread.h> +#include <errno.h> +#include <assert.h> +#include <time.h> +#include <string.h> +#include <stdio.h> + +#include "waaad-internal.h" + + +/********************************************************************************************************/ +/* Hash function -- credits to Austin Appleby, thank you ^^ */ +/* See http://murmurhash.googlepages.com for more information on this function */ + +/* the strings are always aligned properly, so we use the simple MurmurHash2 function */ +#define _HASH_MIX(h,k,m) { k *= m; k ^= k >> r; k *= m; h *= m; h ^= k; } +uint32_t uti_hash ( char * string, size_t len ) +{ + uint32_t hash = len; + char * data = string; + + const unsigned int m = 0x5bd1e995; + const int r = 24; + + /* Check the alignment is really correct -- otherwise we have to switch to the other version */ + assert(((long)string & 3) == 0); + + while(len >= 4) + { + /* Mix 4 bytes at a time into the hash */ + uint32_t k = *(uint32_t *)data; /* We don't care about the byte order */ + + _HASH_MIX(hash, k, m); + + data += 4; + len -= 4; + } + + /* Handle the last few bytes of the input */ + switch(len) { + case 3: hash ^= data[2] << 16; + case 2: hash ^= data[1] << 8; + case 1: hash ^= data[0]; + hash *= m; + } + + /* Do a few final mixes of the hash to ensure the last few + bytes are well-incorporated. */ + hash ^= hash >> 13; + hash *= m; + hash ^= hash >> 15; + + return hash; +} +/********************************************************************************************************/ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/waaad/utils.h Tue Aug 19 14:17:54 2008 +0900 @@ -0,0 +1,60 @@ +/********************************************************************************************************* +* Software License Agreement (BSD License) * +* Author: Sebastien Decugis <sdecugis@nict.go.jp> * +* * +* Copyright (c) 2008, WIDE Project and NICT * +* All rights reserved. * +* * +* Redistribution and use of this software in source and binary forms, with or without modification, are * +* permitted provided that the following conditions are met: * +* * +* * Redistributions of source code must retain the above * +* copyright notice, this list of conditions and the * +* following disclaimer. * +* * +* * Redistributions in binary form must reproduce the above * +* copyright notice, this list of conditions and the * +* following disclaimer in the documentation and/or other * +* materials provided with the distribution. * +* * +* * Neither the name of the WIDE Project or NICT nor the * +* names of its contributors may be used to endorse or * +* promote products derived from this software without * +* specific prior written permission of WIDE Project and * +* NICT. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * +* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * +* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * +* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * +*********************************************************************************************************/ + +/* Useful functions. + * + * This file provides some general-purpose functions that are useful in several modules. + */ + +#ifndef _UTILS_H +#define _UTILS_H + +/* Some aliases to socket addresses structures */ +#ifndef sSA_ALIASES +#define sSS struct sockaddr_storage +#define sSA struct sockaddr +#define sSA4 struct sockaddr_in +#define sSA6 struct sockaddr_in6 +#define sSA_ALIASES +#endif /* sSA_ALIASES */ + + +/* Compute a hash value of a string (session id, diameter id, ...) */ +uint32_t uti_hash ( char * string, size_t len ); + + + + +#endif /* _UTILS_H */
--- a/waaad/waaad-internal.h Tue Aug 19 14:17:34 2008 +0900 +++ b/waaad/waaad-internal.h Tue Aug 19 14:17:54 2008 +0900 @@ -41,15 +41,6 @@ #ifndef _WAAAD_INTERNAL_H #define _WAAAD_INTERNAL_H -/* Some aliases to socket addresses structures */ -#ifndef sSA_ALIASES -#define sSS struct sockaddr_storage -#define sSA struct sockaddr -#define sSA4 struct sockaddr_in -#define sSA6 struct sockaddr_in6 -#define sSA_ALIASES -#endif /* sSA_ALIASES */ - /* Configuration generated by the configure script. Contains host-specific environment information */ #include "config.h" @@ -122,5 +113,11 @@ */ #include "security.h" +/* Useful functions. +Some functions that may be useful in several modules +uti_* functions. +*/ +#include "utils.h" + #endif /* _WAAAD_INTERNAL_H */