diff --git a/src/base/bang-module-registry.c b/src/base/bang-module-registry.c index d8b571a..d000401 100644 --- a/src/base/bang-module-registry.c +++ b/src/base/bang-module-registry.c @@ -1,12 +1,46 @@ #include"bang-module.h" +#include"bang-utils.h" +#include"string.h" + +static BANG_hashmap *modules = NULL; + +typedef struct { + BANG_module *module; + char started; +} module_wrapper_t; + +typedef struct { + char *name; + unsigned char *version; +} module_wrapper_key_t; + +static unsigned int hash_module_wrapper_key_t(const void *data) { + const module_wrapper_key_t *module_key = data; + + unsigned int hashcode; + + hashcode = strlen(module_key->name); + hashcode |= module_key->name[hashcode/4] << 24; + hashcode |= module_key->name[hashcode/2] << 12; + hashcode |= module_key->version[0] << 4; + hashcode |= module_key->version[1] << 8; + + return hashcode; +} + +static int compare_module_wrapper_key_t(const void *d1, const void *d2) { + const module_wrapper_key_t *mk1 = d1; + const module_wrapper_key_t *mk2 = d2; + + return BANG_version_cmp(mk1->version, mk2->version) + + strcmp(mk1->name, mk2->name); +} void BANG_new_module(char *path, char **module_name, unsigned char **module_version) { - BANG_module* new_mod = BANG_load_module(path); - + *module_name = new_mod->info->module_name; *module_version = new_mod->info->module_version; - } BANG_module* BANG_get_module(char *module_name, unsigned char *module_version) { @@ -29,3 +63,10 @@ void BANG_module_inform_new_peer(char *module_name, unsigned char *module_versio new_peer = 0; // TODO: gotta call this, but need the params - BANG_module_new_peer(const BANG_module *module, uuid_t peer, uuid_t new_peer); } + +void BANG_module_registry_init() { + modules = new_BANG_hashmap(&hash_module_wrapper_key_t,&compare_module_wrapper_key_t); +} + +void BANG_module_registry_close() { +} diff --git a/src/base/bang-module-registry.h b/src/base/bang-module-registry.h index 430c97e..c738b89 100644 --- a/src/base/bang-module-registry.h +++ b/src/base/bang-module-registry.h @@ -51,4 +51,8 @@ int BANG_start_module(char *module_name, unsigned char *module_version); * \brief If the given module is running, tells it about the new peer. */ void BANG_module_inform_new_peer(char *module_name, unsigned char *module_version, uuid_t new_peer); + +void BANG_module_registry_init(); +void BANG_module_registry_close(); + #endif diff --git a/src/base/bang-routing.c b/src/base/bang-routing.c index 424d88c..b62b157 100644 --- a/src/base/bang-routing.c +++ b/src/base/bang-routing.c @@ -50,7 +50,7 @@ static int add_uuid_to_peer(const void *p, void *peer_uuid); static int remove_uuid_from_peer(const void *p, void *r); static void free_peer_to_uuids(void *old); static peer_to_uuids* new_peer_to_uuids(int peer_id); -static int uuid_hashcode(const void *uuid); +static unsigned int uuid_hashcode(const void *uuid); static int uuid_ptr_compare(const void *uuid1, const void *uuid2); static peer_or_module *new_pom_module_route(BANG_module *module); static peer_or_module *new_pom_peer_route(int peer_id, char *module_name, unsigned char *module_version); @@ -185,10 +185,11 @@ static peer_to_uuids* new_peer_to_uuids(int peer_id) { return new; } -static int uuid_hashcode(const void *uuid) { +static unsigned int uuid_hashcode(const void *uuid) { assert(uuid != NULL); - int hc = (*((uuid_t*)uuid)[0] << 2) & (*((uuid_t*)uuid)[15]); + unsigned int hc = (*((uuid_t*)uuid)[0] << 8) | (*((uuid_t*)uuid)[15]); + hc |= (*((uuid_t*)uuid)[3] << 16) | (*((uuid_t*)uuid)[7]) << 24; return hc; } diff --git a/src/base/bang-utils.h b/src/base/bang-utils.h index d7f27f5..defa8ca 100644 --- a/src/base/bang-utils.h +++ b/src/base/bang-utils.h @@ -52,7 +52,7 @@ typedef struct { BANG_linked_list *free_space; } BANG_set; -typedef int (*BANG_hashcode) (const void *); +typedef unsigned int (*BANG_hashcode) (const void *); typedef int (*BANG_compare) (const void*,const void*); typedef struct { @@ -190,8 +190,18 @@ void BANG_linked_list_enumerate(BANG_linked_list *lst, void (*it_callback) (cons */ int BANG_linked_list_conditional_iterate(BANG_linked_list *lst, int (*it_callback) (const void*,void*), void *data); +/** + * \brief Allocates and returns a BANG set. + * + * \return A newly intialized BANG set. + */ BANG_set* new_BANG_set(); +/** + * \param set The set to get rid of. + * + * \brief Dealloctes a BANG set. + */ void free_BANG_set(BANG_set *set); int BANG_set_add(BANG_set *s, void *data);