Skip to content

Commit

Permalink
working on running modules being able to pair up.
Browse files Browse the repository at this point in the history
git-svn-id: https://subversion.cs.uiuc.edu/svn/bang/eoh2009@149 69d76c3e-0761-0410-948c-9895a8bb34fc
  • Loading branch information
nbysani2 committed Mar 12, 2009
1 parent b4b88d5 commit 9c6e484
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 19 deletions.
5 changes: 3 additions & 2 deletions src/base/bang-module-api.c
Expand Up @@ -65,7 +65,7 @@ static uuid_t* get_valid_routes(BANG_module_info *info) {
}

void BANG_debug_on_all_peers(BANG_module_info *info, char *message) {
/* The first slot will be us, so skip that. */
/* The first slot will always be us, so skip that. */
fprintf(stderr,"%s",message);

int i = 1;
Expand Down Expand Up @@ -98,7 +98,8 @@ void BANG_get_me_peers(BANG_module_info *info) {
}

int BANG_number_of_active_peers(BANG_module_info *info) {
/* The way we store ids may change in the future, so this is a simple
/*
* The way we store ids may change in the future, so this is a simple
* wrapper function
*/
int i = 0,j = 0;
Expand Down
10 changes: 10 additions & 0 deletions src/base/bang-module-api.h
Expand Up @@ -34,6 +34,16 @@ typedef struct {
* though it is fairly transparent.
*/
typedef struct _BANG_module_info{
/**
* The name of the module.
*/
char *module_name;
int module_name_length;
/**
* 3 is a magic number ~
*/
unsigned char *module_version;
void *module_bang_name;
/**
* Infomation about the peers of this module.
*/
Expand Down
23 changes: 18 additions & 5 deletions src/base/bang-module.c
Expand Up @@ -103,16 +103,25 @@ static BANG_api* get_BANG_api() {
}

/**
* \param module Modules to derive info from.
* \param module_name The name of the module.
* \param module_version The version of the module.
*
* \return A newly allocated BANG_module_info.
*
* \brief Creates a BANG_module_info for use by a module.
*/
BANG_module_info* new_BANG_module_info() {
BANG_module_info* new_BANG_module_info(char* module_name, unsigned char* module_version) {
BANG_module_info *info = calloc(1,sizeof(BANG_module_info));

info->peers_info = calloc(1,sizeof(peers_information));
/* We aren't even a peer yet since we haven't been run/registered */
info->peers_info->peer_number = 0;
info->module_name = module_name;
info->module_name_length = strlen(module_name);
info->module_version = module_version;
info->module_bang_name = malloc(info->module_name_length + 4);
strcpy(info->module_bang_name, module_name);
memcpy(info->module_bang_name + info->module_name_length + 1,module_version,3);

info->my_id = 0;

Expand All @@ -128,6 +137,10 @@ BANG_module* BANG_load_module(char *path) {
*/

void *handle = dlopen(path,RTLD_NOW);

char *module_name;
unsigned char *module_version;

BANG_sigargs args;
args.args = dlerror();

Expand All @@ -145,7 +158,7 @@ BANG_module* BANG_load_module(char *path) {

BANG_module *module = (BANG_module*) calloc(1,sizeof(BANG_module));

module->module_name = dlsym(handle,"BANG_module_name");
module_name = dlsym(handle,"BANG_module_name");

/* Make sure the dlsym worked. */
if ((args.args = dlerror()) != NULL) {
Expand All @@ -159,7 +172,7 @@ BANG_module* BANG_load_module(char *path) {
return NULL;
}

module->module_version = dlsym(handle,"BANG_module_version");
module_version = dlsym(handle,"BANG_module_version");

/* Make sure the dlsym worked. */
if ((args.args = dlerror()) != NULL) {
Expand Down Expand Up @@ -210,7 +223,7 @@ BANG_module* BANG_load_module(char *path) {
module->path = path;

module->callbacks = module->module_init(get_BANG_api());
module->info = new_BANG_module_info();
module->info = new_BANG_module_info(module_name, module_version);

return module;
}
Expand Down
10 changes: 10 additions & 0 deletions src/base/bang-module.h
Expand Up @@ -95,4 +95,14 @@ void BANG_module_new_peer(const BANG_module *module, uuid_t peer, uuid_t new_pee
* \brief Informs the module that is losing a peer.
*/
void BANG_module_remove_peer(const BANG_module *module, uuid_t peer,uuid_t old_peer);

/**
* \param module_name The name of the module.
* \param module_version The version of the module.
*
* \return A newly allocated BANG_module_info.
*
* \brief Creates a BANG_module_info for use by a module.
*/
BANG_module_info* new_BANG_module_info(char* module_name, unsigned char* module_version);
#endif
11 changes: 5 additions & 6 deletions src/base/bang-scan.c
Expand Up @@ -20,6 +20,8 @@
#define BRDCSTPORT "4950"
#define SCAN_MSG_LEN 5

pthread_t scan_thread;

static void *get_in_addr(struct sockaddr *sa);
static int send_bang_reply(const char *reply_ip);

Expand Down Expand Up @@ -219,18 +221,15 @@ static void *scan_control(void *dontUse) {

return NULL;
}
//--------------------------------------------------------------------

//------------------Global--------------------------------------------

//Create working thread
void BANG_scan_init() {
pthread_create(&scanThread, NULL, scan_control, NULL);
pthread_create(&scan_thread, NULL, scan_control, NULL);
}

//Kill working thread
void BANG_scan_close() {
//DIE DIE DIE
pthread_kill(scanThread, SIGKILL); //If possible, change this to pthread_cancel()
pthread_join(scanThread, NULL);
pthread_kill(scan_thread, SIGKILL); //If possible, change this to pthread_cancel()
pthread_join(scan_thread, NULL);
}
8 changes: 2 additions & 6 deletions src/base/bang-types.h
Expand Up @@ -36,13 +36,9 @@ static const unsigned char BANG_LIBRARY_VERSION[3] = {
*/
typedef struct {
/**
* The name of the module.
* Information about the module.
* such as name, and its peers.
*/
char *module_name;
/**
* 3 is a magic number ~
*/
unsigned char *module_version;
BANG_module_info *info;
/**
* Callbacks to interact with the module.
Expand Down

0 comments on commit 9c6e484

Please sign in to comment.