Skip to content

Commit

Permalink
more of the routing should be complete..
Browse files Browse the repository at this point in the history
git-svn-id: https://subversion.cs.uiuc.edu/svn/bang/eoh2009@146 69d76c3e-0761-0410-948c-9895a8bb34fc
  • Loading branch information
nbysani2 committed Mar 11, 2009
1 parent ae341dd commit 642e9d0
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 11 deletions.
15 changes: 8 additions & 7 deletions src/base/bang-module-api.c
Expand Up @@ -9,6 +9,7 @@
#include"bang-module-api.h"
#include"bang-com.h"
#include"bang-routing.h"
#include"bang-utils.h"
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
Expand Down Expand Up @@ -81,18 +82,18 @@ void BANG_get_me_peers(BANG_module_info *info) {
/* This does not use routing...! */
uuid_t *valid_routes = get_valid_routes(info);

int i = 0;
int **peers_to_bug = BANG_not_route_get_peer_id(valid_routes);
BANG_linked_list *peers_to_bug = BANG_not_route_get_peer_id(valid_routes);
int *cur;

BANG_request *req = new_BANG_request(BANG_MODULE_PEER_REQUEST,NULL,0);
/* TODO: Put the module info inside the data... */
for (; peers_to_bug[i]; ++i) {
BANG_request_peer_id(*(peers_to_bug[i]),req);
free(peers_to_bug[i]);
peers_to_bug[i] = NULL;

while ((cur = BANG_linked_list_pop(peers_to_bug)) != NULL) {
BANG_request_peer_id(*cur,req);
free(cur);
}
free(peers_to_bug);

free_BANG_linked_list(peers_to_bug,NULL);
free(valid_routes);
}

Expand Down
49 changes: 47 additions & 2 deletions src/base/bang-routing.c
Expand Up @@ -16,6 +16,11 @@ enum remote_route {
LOCAL
};

typedef struct {
BANG_linked_list *not_peers_list;
uuid_t *routes;
} not_peers_struct;

typedef struct {
int peer_id;
char *module_name;
Expand Down Expand Up @@ -52,6 +57,7 @@ static peer_or_module *new_pom_peer_route(int peer_id, char *module_name, unsign
static BANG_request* create_request(enum BANG_request_types request, uuid_t authority, uuid_t peer);
static BANG_request* create_request_with_message(enum BANG_request_types request, char *message);
static BANG_request* create_request_with_job(enum BANG_request_types request, uuid_t authority, uuid_t peer, BANG_job *job);
static void find_not_peers(const void *info_about_peers, void *store_not_peers);

static BANG_rw_syncro *routes_lock = NULL;
static BANG_hashmap *routes = NULL;
Expand Down Expand Up @@ -378,11 +384,50 @@ int BANG_route_get_peer_id(uuid_t peer) {
}
}

static int check_route_match(const void *route_of_peer, void *routes_to_find) {
uuid_t *route_to_check = (void*) route_of_peer;
uuid_t *routes_check_against = routes_to_find;
int i;

for (i = 0; !uuid_is_null(routes_check_against[i]); ++i) {
if (uuid_compare(*route_to_check,routes_check_against[i]) == 0)
return 0;
}

return 1;
}

static void find_not_peers(const void *info_about_peers, void *store_not_peers) {
peer_to_uuids *ptu = (void*) info_about_peers;
not_peers_struct *not_peers = store_not_peers;
int *found_peer_id;

BANG_read_lock(ptu->lck);

if (BANG_linked_list_conditional_iterate(ptu->routes,&check_route_match,not_peers->routes)) {
found_peer_id = malloc(sizeof(int));
*found_peer_id = ptu->peer_id;
BANG_linked_list_push(not_peers->not_peers_list,found_peer_id);
}

BANG_read_unlock(ptu->lck);
}

/* TODO: THIS IS IMPORTANT! */
int** BANG_not_route_get_peer_id(uuid_t *peers) {
BANG_linked_list* BANG_not_route_get_peer_id(uuid_t *peers) {
assert(peers != NULL);

return NULL;
not_peers_struct not_peers;
not_peers.not_peers_list = new_BANG_linked_list();
not_peers.routes = peers;

BANG_read_lock(routes_lock);

BANG_linked_list_iterate(peers_list,&find_not_peers,&not_peers);

BANG_read_lock(routes_lock);

return not_peers.not_peers_list;
}

/* TODO: THIS IS IMPORTANT! */
Expand Down
4 changes: 2 additions & 2 deletions src/base/bang-routing.h
Expand Up @@ -73,12 +73,12 @@ int BANG_route_get_peer_id(uuid_t peer);
/**
* \param uuids The routes to peers, null terminated.
*
* \return NULL terminated array of peer ids.
* \return An allocated linked list of allocted ints.
*
* \brief Returns peer_ids not on the list.
* memory: You must take care of it.
*/
int** BANG_not_route_get_peer_id(uuid_t *peers);
BANG_linked_list* BANG_not_route_get_peer_id(uuid_t *peers);

/**
* \param peer A running module peer.
Expand Down

0 comments on commit 642e9d0

Please sign in to comment.