Skip to content

Commit

Permalink
Created a remove_mapping function.
Browse files Browse the repository at this point in the history
git-svn-id: https://subversion.cs.uiuc.edu/svn/bang/eoh2009@58 69d76c3e-0761-0410-948c-9895a8bb34fc
  • Loading branch information
nbysani2 committed Jan 26, 2009
1 parent 28da66d commit 1a2bcf2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
39 changes: 32 additions & 7 deletions src/base/bang-routing.c
Expand Up @@ -14,9 +14,10 @@
#include<uuid/uuid.h>

#define CREATE_MAPPINGS "CREATE TABLE mappings(route_uuid blob unique primary key, remote integer, peer_id int, module blob, name text, version blob)"
#define INSERT_STATEMENT "INSERT INTO mappings(route_uuid,remote,module,peer_id,name,text) VALUES (?,?,?,?,?)"
#define SELECT_STATEMENT "SELECT remote,module,peer_id,name,version FROM mappings WHERE ? = route_uuid"
#define INSERT_MAPPING "INSERT INTO mappings(route_uuid,remote,module,peer_id,name,text) VALUES (?,?,?,?,?)"
#define SELECT_MAPPING "SELECT remote,module,peer_id,name,version FROM mappings WHERE ? = route_uuid"
#define SELECT_UUID "SELECT route_uuid WHERE ? = peer_id"
#define REMOVE_MAPPING "DELETE FROM mappings WHERE ? = route_uuid"

#define CREATE_PEER_LIST "CREATE TABLE peers(id int)"
#define INSERT_PEER "INSERT INTO peers(id) VALUES (?)"
Expand All @@ -41,6 +42,8 @@ static void mem_append(void *dst, void *src, int length, int *pos);

static void insert_mapping(uuid_t uuid, int remote, BANG_module *module, int peer_id, char *module_name, unsigned char *module_version);

static void remove_mapping(uuid_t uuid);

static sqlite3_stmt* prepare_select_statement(uuid_t uuid);

static BANG_linked_list* select_routes_from_id(int id);
Expand Down Expand Up @@ -304,6 +307,12 @@ void BANG_register_peer_route(uuid_t uuid, int peer, char *module_name, unsigned
insert_mapping(uuid,REMOTE_ROUTE,NULL,peer,module_name,module_version);
}

void BANG_deregister_route(uuid_t uuid) {
assert(!uuid_is_null(uuid));

remove_mapping(uuid);
}

void BANG_route_close() {
#ifdef BDEBUG_1
fprintf(stderr,"BANG route closing.\n");
Expand Down Expand Up @@ -377,9 +386,9 @@ static void insert_mapping(uuid_t uuid, int remote, BANG_module *module, int pee
sqlite3_stmt *insert;

#ifdef NEW_SQLITE
sqlite3_prepare_v2(db,INSERT_STATMENT,-1,&insert,NULL);
sqlite3_prepare_v2(db,INSERT_MAPPING,-1,&insert,NULL);
#else
sqlite3_prepare(db,INSERT_STATEMENT,-1,&insert,NULL);
sqlite3_prepare(db,INSERT_MAPPING,-1,&insert,NULL);
#endif
sqlite3_bind_blob(insert,1,uuid,sizeof(uuid_t),SQLITE_STATIC);
sqlite3_bind_int(insert,2,remote);
Expand All @@ -392,15 +401,31 @@ static void insert_mapping(uuid_t uuid, int remote, BANG_module *module, int pee
sqlite3_finalize(insert);
}

static void remove_mapping(uuid_t uuid) {
assert(!uuid_is_null(uuid));

sqlite3_stmt *remove;

#ifdef NEW_SQLITE
sqlite3_prepare_v2(db,REMOVE_MAPPING,-1,&remove,NULL);
#else
sqlite3_prepare(db,REMOVE_MAPPING,-1,&remove,NULL);
#endif

sqlite3_bind_blob(remove,1,uuid,sizeof(uuid_t),SQLITE_STATIC);
sqlite3_step(remove);
sqlite3_finalize(remove);
}

static sqlite3_stmt* prepare_select_statement(uuid_t uuid) {
assert(!uuid_is_null(uuid));

sqlite3_stmt *get_peer_route;
/* God dammit, ews needs to update sqlite */
#ifdef NEW_SQLITE
sqlite3_prepare_v2(db,SELECT_STATEMENT,-1,&get_peer_route,NULL);
sqlite3_prepare_v2(db,SELECT_MAPPING,-1,&get_peer_route,NULL);
#else
sqlite3_prepare(db,SELECT_STATEMENT,90,&get_peer_route,NULL);
sqlite3_prepare(db,SELECT_MAPPING,-1,&get_peer_route,NULL);
#endif

sqlite3_bind_blob(get_peer_route,1,uuid,sizeof(uuid_t),SQLITE_STATIC);
Expand Down Expand Up @@ -563,14 +588,14 @@ static void catch_peer_removed(int signal, int num_peers, void **p) {
lst = select_routes_from_id(*(peers[i]));

while ((route = BANG_linked_list_pop(lst)) != NULL) {
/* TODO: tell them that route is being removed. */
route_list = select_route(*route);

while ((remote_route = BANG_linked_list_pop(route_list)) != NULL) {
BANG_route_remove_peer(*remote_route,*route);
free(remote_route);
}

BANG_deregister_route(*route);
free(route);
}

Expand Down
7 changes: 7 additions & 0 deletions src/base/bang-routing.h
Expand Up @@ -114,6 +114,13 @@ void BANG_register_module_route(BANG_module *module);
*/
void BANG_register_peer_route(uuid_t uuid, int peer, char *module_name, unsigned char* module_version);

/**
* \param uuid The identifier to deregister.
*
* \brief Deregisters a uuid.
*/
void BANG_deregister_route(uuid_t uid);

/**
* \brief Starts the routing part of the library.
*/
Expand Down

0 comments on commit 1a2bcf2

Please sign in to comment.