Skip to content

Commit

Permalink
Some type updates.
Browse files Browse the repository at this point in the history
git-svn-id: https://subversion.cs.uiuc.edu/svn/bang/eoh2009@111 69d76c3e-0761-0410-948c-9895a8bb34fc
  • Loading branch information
btowal2 committed Mar 7, 2009
1 parent 0055c3e commit 15db4ef
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 41 deletions.
31 changes: 25 additions & 6 deletions src/base/bang-types.h
Expand Up @@ -230,6 +230,7 @@ enum BANG_headers {
*/
BANG_HELLO = 0,
/**
* BANG_DEBUG_REQUEST (corresponding request type)
* sends a debug message that should be printed out on the remote
* end.
* message:
Expand Down Expand Up @@ -273,10 +274,22 @@ enum BANG_headers {
* Send a job to a uuid. The read thread passes the data
* off to a router after constructing a job.
* message:
* -BANG_SEND_JOB
* -uuid (16 bytes)
* -BANG_SEND_JOB (unsigned 4 bytes)
* -Authority (16 bytes)
* -Peer (16 bytes)
* -Job_number (4 bytes)
* -Job_length (unsigned 4 bytes)
* -Job data (...)
*/
BANG_SEND_JOB,
/**
* Requests a job from a uuid.
* message:
* -BANG_REQUEST_JOB (unsigned 4 bytes)
* -Authority (16 bytes)
* -Peer (16 bytes)
*/
BANG_REQUEST_JOB,
/**
* tells the remote end that version is wrong, and that
* they are hanging up
Expand Down Expand Up @@ -329,12 +342,12 @@ enum BANG_request_types {
BANG_MODULE_PEER_REQUEST,
/**
* BANG_request.type == BANG_SEND_JOB_REQUEST
* BAND_request.request:
* | uuid_t auth | uuid_t peer |
* BANG_request.request:
* c
* | job_number | job_length | job data |
*
* do:
* -send Out everything appended to a header.
* -send out everything appended to a header.
*
*/
BANG_SEND_JOB_REQUEST,
Expand All @@ -350,7 +363,13 @@ enum BANG_request_types {
*/
BANG_SEND_FINISHED_JOB_REQUEST,
/**
* haha!
* BANG_request.type == BANG_SEND_REQUEST_JOB_REQUEST
* BANG_request.request:
* | uuid_t auth | uuid_t peer |
*
* do:
* -send formatted data appended to a header.
*
*/
BANG_SEND_REQUEST_JOB_REQUEST,
BANG_SEND_AVAILABLE_JOB_REQUEST,
Expand Down
128 changes: 93 additions & 35 deletions src/base/bang-write-thread.c
Expand Up @@ -22,10 +22,12 @@ static unsigned int write_message(BANG_peer *self, void *message, unsigned int l
* it may be possible that modules don't fit in memory though this seems
* _very_ unlikely.
*/

static void write_module(BANG_peer *self, BANG_request *request);

static void write_module_exists(BANG_peer *self, BANG_request *request);

//Does the actual writing
static unsigned int write_message(BANG_peer *self, void *message, unsigned int length) {
unsigned int written = 0;
int write_return = 0;
Expand All @@ -45,6 +47,7 @@ static unsigned int write_message(BANG_peer *self, void *message, unsigned int l
return written;
}

//----------------------Actions performed on requests--------------------------.
static char write_bye(BANG_peer *self) {
BANG_header header = BANG_BYE;

Expand All @@ -53,6 +56,68 @@ static char write_bye(BANG_peer *self) {
return 0;
}


static char write_debug(BANG_peer *self, BANG_request *request) {
BANG_header header = BANG_DEBUG_MESSAGE;

unsigned int ret = write_message(self,&header,LENGTH_OF_HEADER);

if (ret < LENGTH_OF_HEADER)
return 0;

ret = write_message(self,&(request->length),LENGTH_OF_LENGTHS);

if (ret < LENGTH_OF_LENGTHS)
return 0;

write_message(self,request->request,request->length);

if (ret < request->length)
return 0;
else
return 1;

}

static void write_module_exists(BANG_peer *self, BANG_request *request) {
BANG_header header = BANG_EXISTS_MODULE;
write_message(self,&header,LENGTH_OF_HEADER);
write_message(self,request->request,request->length);
}





static void write_send_job(BANG_peer *self, BANG_request *request) {
BANG_header header = BANG_SEND_JOB;
write_message(self,&header,LENGTH_OF_HEADER);
write_message(self,request->request,request->length);
}

static void write_finished_job() {
BANG_header header = ;
write_message(self,&header,LENGTH_OF_HEADER);

}

static void write_request_job() {
BANG_header header = BANG_REQUEST_JOB;
write_message(self,&header,LENGTH_OF_HEADER);

}

static void write_available_job() {
BANG_header header = ;
write_message(self,&header,LENGTH_OF_HEADER);

}






static void write_module(BANG_peer *self, BANG_request *request) {
FILE *fd = fopen((char*)request->request,"r");
if (fd == NULL) {
Expand Down Expand Up @@ -83,34 +148,10 @@ static void write_module(BANG_peer *self, BANG_request *request) {
fclose(fd);
}

static char write_debug(BANG_peer *self, BANG_request *request) {
BANG_header header = BANG_DEBUG_MESSAGE;
//----------------------Actions performed on requests--------------------------'

unsigned int ret = write_message(self,&header,LENGTH_OF_HEADER);

if (ret < LENGTH_OF_HEADER)
return 0;

ret = write_message(self,&(request->length),LENGTH_OF_LENGTHS);

if (ret < LENGTH_OF_LENGTHS)
return 0;

write_message(self,request->request,request->length);

if (ret < request->length)
return 0;
else
return 1;

}

static void write_module_exists(BANG_peer *self, BANG_request *request) {
BANG_header header = BANG_EXISTS_MODULE;
write_message(self,&header,LENGTH_OF_HEADER);
write_message(self,request->request,request->length);
}

//-------------------------Request processing----------------------------------.
void* BANG_write_peer_thread(void *self_info) {
BANG_peer *self = (BANG_peer*)self_info;
BANG_request *current;
Expand All @@ -126,32 +167,48 @@ void* BANG_write_peer_thread(void *self_info) {
switch (current->type) {
case BANG_CLOSE_REQUEST:
sending = write_bye(self);
break;
break;

case BANG_SUDDEN_CLOSE_REQUEST:
sending = 0;
break;
break;

case BANG_DEBUG_REQUEST:
/* TODO: ADD ERROR CHECKING!
* possibly put in own method */
sending = write_debug(self,current);
break;

case BANG_SEND_MODULE_REQUEST:
write_module(self,current->request);
break;
break;

case BANG_MODULE_PEER_REQUEST:
write_module_exists(self,current->request);
break;
break;
//-----------------------------------------------------------------.
case BANG_SEND_JOB_REQUEST:
write_send_job();
break;

case BANG_SEND_FINISHED_JOB_REQUEST:
write_finished_job();
break;

case BANG_SEND_REQUEST_JOB_REQUEST:
write_request_job();
break;

case BANG_SEND_AVAILABLE_JOB_REQUEST:
write_available_job();
break;
//-----------------------------------------------------------------'
case BANG_SEND_MODULE_REQUEST:
write_module(self,current->request);
break;

default:
/*ERROR!*/
#ifdef BDEBUG_1
fprintf(stderr,"BANG ERROR:\t%d is not a request type that we take care of!\n",current->type);
#endif
break;
break;
}

free_BANG_request(current);
Expand All @@ -162,3 +219,4 @@ void* BANG_write_peer_thread(void *self_info) {
#endif
return NULL;
}
//-------------------------Request processing----------------------------------'

0 comments on commit 15db4ef

Please sign in to comment.