Skip to content

Commit

Permalink
Wrote a bit of the route job function.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikhil Samith Bysani committed Jan 19, 2009
1 parent a9a6a50 commit ca13432
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 11 deletions.
1 change: 0 additions & 1 deletion src/base/bang-com.h
Expand Up @@ -80,7 +80,6 @@ void BANG_remove_peer(int peer_id);
*/
void BANG_add_peer(int socket);


/**
* \param peer_id The id of the peer thread.
*
Expand Down
2 changes: 1 addition & 1 deletion src/base/bang-module-api.c
Expand Up @@ -146,6 +146,6 @@ void BANG_send_job(BANG_module_info *info, BANG_job *job) {
get_uuid_from_id(route,job->peer,info);

if (!uuid_is_null(route)) {
BANG_route_job(route,job);
BANG_route_job(info->peers_info->uuids[info->my_id],route,job);
}
}
13 changes: 13 additions & 0 deletions src/base/bang-module-api.h
Expand Up @@ -34,6 +34,9 @@ typedef struct {
* though it is fairly transparent.
*/
typedef struct {
/**
* Infomation about the peers of this module.
*/
peers_information *peers_info;
/**
* The id of module running. Currently is always
Expand All @@ -42,8 +45,18 @@ typedef struct {
int my_id;
} BANG_module_info;

/**
* A job to be sent to be a peer, so that it the "data" can be worked
* on, and sent as a job back, with the "data" finished.
*/
typedef struct {
/**
* For the module's use as sendable data.
*/
void *data;
/**
* The size of the data
*/
unsigned int length;
/**
* For use by the module, if it wants
Expand Down
30 changes: 27 additions & 3 deletions src/base/bang-routing.c
@@ -1,9 +1,11 @@
#include"bang-com.h"
#include"bang-routing.h"
#include"bang-module.h"
#include"bang-module-api.h"
#include"bang-types.h"
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
/* I am really reeling in those external libraries! */
#include<sqlite3.h>
#include<uuid/uuid.h>
Expand All @@ -25,14 +27,36 @@ static sqlite3_stmt* prepare_select_statement(uuid_t uuid) {
return get_peer_route;
}

void BANG_route_job(uuid_t uuid, BANG_job *job) {
sqlite3_stmt *get_peer_route = prepare_select_statement(uuid);
void BANG_route_job(uuid_t authority, uuid_t peer, BANG_job *job) {
sqlite3_stmt *get_peer_route = prepare_select_statement(peer);

if (sqlite3_step(get_peer_route) == SQLITE_ROW) {
if (sqlite3_column_int(get_peer_route,1) == REMOTE_ROUTE) {
/* TODO: Make a request to peer. */
BANG_request request;
request.type = BANG_SEND_JOB_REQUEST;
/* We are being a little presumptuous, and constructing the actual message
* that the communications infrastructure will send...
*
* Probably should move this to bang-com.c
*/
request.length = LENGTH_OF_HEADER +sizeof(uuid_t) * 2 +
4 /* A MAGIC NUMBER! */ +
LENGTH_OF_LENGTHS +
job->length;
request.request = malloc(request.length);
unsigned int header = BANG_SEND_JOB;
memcpy(request.request,&header,LENGTH_OF_HEADER);
memcpy(request.request,authority,sizeof(uuid_t));
memcpy(request.request,peer,sizeof(uuid_t));
memcpy(request.request,&(job->job_number),4);
memcpy(request.request,job->data,job->length);

BANG_request_peer_id(sqlite3_column_int(get_peer_route,3),request);


} else {
const BANG_module *module = sqlite3_column_blob(get_peer_route,2);
/* const BANG_module *module = */sqlite3_column_blob(get_peer_route,2);
/* TODO: Callback peer with job */
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/base/bang-routing.h
Expand Up @@ -12,21 +12,23 @@
#include"bang-module.h"

/**
* \param uuid The module-peer to route to.
* \param authority The module-peer sending the job.
* \param peer The module-peer to route to.
* \param job The job to route to the module-peer.
*
* Gets a job to the a module, whever it may be as long
* as it is valid.
*/
void BANG_route_job(uuid_t uuid, BANG_job *job);
void BANG_route_job(uuid_t authority, uuid_t peer, BANG_job *job);

/**
* \param uuids A null termianted list of routes.
* \param authority The authority sending the job.
* \param peers A null termianted list of routes.
* \param job The job to route.
*
* \brief Routes the job to all peers in the uuid list.
*/
void BANG_route_job_to_uuids(uuid_t *uuids, BANG_job *job);
void BANG_route_job_to_uuids(uuid_t authority, uuid_t *peers, BANG_job *job);

/**
* \param uuid The route to send a finished job through.
Expand Down
4 changes: 2 additions & 2 deletions src/base/bang-types.h
Expand Up @@ -329,12 +329,12 @@ enum BANG_request_types {
*/
BANG_MODULE_PEER_REQUEST,
/**
* BANG_request.type == BANG_JOB_SEND_REQUEST
* BANG_request.type == BANG_SEND_JOB_REQUEST
* BAND_request.request:
* | uuid_t | job stuff ~ |
*
*/
BANG_JOB_SEND_REQUEST,
BANG_SEND_JOB_REQUEST,
/**
* do:
* -send BANG_SEND_MODULE
Expand Down

0 comments on commit ca13432

Please sign in to comment.