Skip to content

Commit

Permalink
Skeleton code for one of the routing functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikhil Samith Bysani committed Jan 18, 2009
1 parent c0e9e91 commit 527bdf5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/base/bang-module.h
Expand Up @@ -38,4 +38,6 @@ void* BANG_get_symbol(BANG_module *module, char *symbol);
*/
void BANG_run_module(BANG_module *module);

void BANG_module_callback_jobs_available(const BANG_module *module, uuid_t auth, uuid_t peer);

#endif
31 changes: 28 additions & 3 deletions src/base/bang-routing.c
@@ -1,10 +1,13 @@
#include"bang-routing.h"
#include"bang-module.h"
#include"bang-module-api.h"
#include"bang-types.h"
#include<stdlib.h>
/* I am really reeling in those external libraries! */
#include<sqlite3.h>
#include<uuid/uuid.h>

#define DB_CREATE_STR "CREATE TABLE mappings(route_uuid blob unique primary key, remote integer, id integer, callbacks blob, name text, version text)"
#define DB_SCHEMA "CREATE TABLE mappings(route_uuid blob unique primary key, remote integer, peer_id int, module blob, name text, version blob)"
#define REMOTE_ROUTE 2
#define LOCAL_ROUTE 1

Expand All @@ -20,8 +23,29 @@ void BANG_register_module_route(BANG_module *module) {
module->info->peers_info->validity[module->info->my_id] = 1;

sqlite3_stmt *insert_module;
sqlite3_prepare_v2(db,"INSERT INTO mappings (route_uuid,remote,callbacks,name,text) VALUES (?,1,?,?,?)",73,&insert_module,NULL);
sqlite3_prepare_v2(db,"INSERT INTO mappings (route_uuid,remote,module,name,text) VALUES (?,1,?,?,?)",80,&insert_module,NULL);
sqlite3_bind_blob(insert_module,1,module->info->peers_info->uuids[module->info->my_id],sizeof(uuid_t),SQLITE_STATIC);
/* Store the _pointer_ to the module. */
sqlite3_bind_blob(insert_module,2,module,sizeof(BANG_module*),SQLITE_STATIC);
sqlite3_bind_text(insert_module,3,module->module_name,-1,SQLITE_STATIC);
sqlite3_bind_blob(insert_module,4,module->module_version,LENGTH_OF_VERSION,SQLITE_STATIC);
sqlite3_step(insert_module);
sqlite3_finalize(insert_module);
}


void BANG_route_assertion_of_authority(uuid_t authority, uuid_t peer) {
sqlite3_stmt *get_peer_route;
sqlite3_prepare_v2(db,"SELECT remote,module,peer_id,name,version FROM mappings WHERE ? = route_uuid",90,&get_peer_route,NULL);
sqlite3_bind_blob(get_peer_route,1,peer,sizeof(uuid_t),SQLITE_STATIC);
if (sqlite3_step(get_peer_route) == SQLITE_ROW) {
if (sqlite3_column_int(get_peer_route,1) == REMOTE_ROUTE) {
/* TODO: Make a request to peer. */
} else {
const BANG_module *module = sqlite3_column_blob(get_peer_route,2);
BANG_module_callback_jobs_available(module,authority,peer);
}
}
}

void BANG_route_init() {
Expand All @@ -35,9 +59,10 @@ void BANG_route_close() {
#ifdef BDEBUG_1
fprintf(stderr,"BANG route closing.\n");
#endif
/* Keep the mappings database in memory. */
sqlite3_open_v2(":memory",&db,SQLITE_OPEN_READWRITE | SQLITE_OPEN_FULLMUTEX,NULL);
/*TODO: check for errors.
* Create database.
*/
sqlite3_exec(db,DB_CREATE_STR,NULL,NULL,NULL);
sqlite3_exec(db,DB_SCHEMA,NULL,NULL,NULL);
}

0 comments on commit 527bdf5

Please sign in to comment.