Changeset - c6a12058c9da
[Not reviewed]
default
0 6 0
Nathan Brink (binki) - 15 years ago 2010-06-29 23:58:06
ohnobinki@ohnopublishing.net
- Fix up the client making outbound connections. It can now send a sort of ping request but not handle responses yet.
6 files changed with 109 insertions and 17 deletions:
0 comments (0 inline, 0 general)
src/common/protocol.c
Show inline comments
 
@@ -18,6 +18,7 @@
 
*/
 

	
 
#include "protocol.h"
 
#include "remoteio.h"
 

	
 
#include <malloc.h>
 
#include <stdio.h>
 
@@ -44,6 +45,42 @@ int distren_request_new(struct distren_r
 
  return 0;
 
}
 

	
 
int distren_request_send(struct remoteio *rem, struct distren_request *req, void *data)
 
{
 
  void *packet;
 
  void *packet_ptr;
 
  size_t len;
 
  size_t byteswritten;
 
  int write_err;
 

	
 
  if(req->magic != DISTREN_REQUEST_MAGIC)
 
    fprintf(stderr, "distren_request_send got a bad req\n");
 

	
 
  len = sizeof(struct distren_request) + req->len;
 

	
 
  packet = malloc(len);
 
  if(!packet)
 
    {
 
      fprintf(stderr, "Error allocating memory for packet\n");
 
      return 1;
 
    }
 
  memcpy(packet, req, sizeof(struct distren_request));
 
  memcpy(packet + sizeof(struct distren_request), data, req->len);
 

	
 
  write_err = 0;
 
  packet_ptr = packet;
 
  while(len
 
	&& !write_err)
 
    {
 
      write_err = remoteio_write(rem, packet_ptr, len, &byteswritten);
 
      len -= byteswritten;
 
      packet_ptr += byteswritten;
 
    }
 
  free(packet);
 

	
 
  return 0;
 
}
 

	
 
int distren_request_new_fromdata(struct distren_request **req, void *data, size_t len)
 
{
 
  struct distren_request *newreq;
src/common/protocol.h
Show inline comments
 
@@ -39,8 +39,12 @@
 
 */
 
enum distren_request_type
 
  {
 
    DISTREN_REQUEST_VERSION = 1, /*< identifies the version of software being
 
				   used by the sender and tells if it is a client or server */
 
    /**
 
       identifies the version of software being
 
       used by the sender and tells if it is a client or server.
 
       Just send PACKAGE_STRING.
 
    */
 
    DISTREN_REQUEST_VERSION = 1,
 
    DISTREN_REQUEST_PING = 2,
 
    DISTREN_REQUEST_PONG = 3,
 
    DISTREN_REQUEST_DISCONNECT = 4,
 
@@ -68,16 +72,17 @@ enum distren_request_type
 
slave is repoting on a frame it's actually assigned to */
 
    DISTREN_REQUEST_PROGRESS = 10, /*< tells another server of the progress of the first server's work at rendering */
 
    DISTREN_REQUEST_GETWORK = 11,
 
    DISTREN_REQUEST_GETVERSION = 12, /* returns version of software that slave
 
should be running */
 
    DISTREN_REQUEST_GETRENDERPOWER = 13, /* returns the render power of a
 
slave */
 
    DISTREN_REQUEST_GETVERSION = 12, /*< returns version of software that slave should be running */
 
    DISTREN_REQUEST_GETRENDERPOWER = 13, /* returns the render power of a slave */
 
    DISTREN_REQUEST_SETRENDERPOWER = 14, /* sets renderpower in server
 
database */
 
    DISTREN_REQUEST_RESETFRAME = 15, /* sets a frame back to unassigned,
 
    /**
 
       sets a frame back to unassigned,
 
happens if the slave quits for some reason. server code should only allow
 
resetting of a frame assigned to the slave calling the request (see php
 
code)*/ 
 
       code)
 
    */ 
 
    DISTREN_REQUEST_RESETFRAME = 15,
 

	
 
  };
 

	
 
@@ -94,6 +99,19 @@ struct distren_request
 
 */
 
int distren_request_new(struct distren_request **req, uint32_t len, enum distren_request_type type);
 

	
 
struct remoteio;
 
/**
 
   Takes a struct distren_request and its associated data, allocates
 
   a new block of data to hold the whole packet, and packets the req
 
   header and data together.
 

	
 
   @param rem A remoteio handle to ship this packet off to
 
   @param req Something you initialized with distren_request_new(). You are responsible for distren_request_free()ing this yourself.
 
   @param data A chunk of data the size of req->len. You are responsible for free()ing this yourself.
 
   @return 0 on success and 1 on failure.
 
 */
 
int distren_request_send(struct remoteio *rem, struct distren_request *req, void *data);
 

	
 
/**
 
   initializes and allocates request based on raw input data
 
   which includes the headers of the request.
src/common/remoteio.c
Show inline comments
 
@@ -113,7 +113,7 @@ int remoteio_config(cfg_t *cfg, struct r
 
      method = cfg_getstr(cfg_aserver, "method");
 
      for(counter2 = 0; funcmap[counter2].name; counter2 ++)
 
	if(strcmp(method, funcmap[counter2].name) == 0)
 
	  aserver.method = REMOTEIO_METHOD_SSH;
 
	  aserver.method = funcmap[counter2].method;
 
      if(aserver.method == REMOTEIO_METHOD_MAX)
 
	{
 
	  fprintf(stderr, "No such method as %s\n", method);
src/server/slave.c
Show inline comments
 
@@ -147,7 +147,7 @@ int main(int argc, char *argv[])
 
      fprintf(stderr, "Error connecting to server; exiting\n");
 
      return 1;
 
    }
 

	
 
  greet_server(comm_slave);
 

	
 
  // Variables needed for main loop
 
  int jobnum = 0;
 
@@ -203,7 +203,7 @@ int main(int argc, char *argv[])
 
    {
 

	
 
    // request work
 
    fprintf(stderr,"Requesting work...\n");
 
    fprintf(stderr, "Waiting...\n");
 
    haveWork = getwork(comm_slave, &jobnum, &framenum);
 

	
 
    /* If we got a frame */
 
@@ -301,10 +301,14 @@ int main(int argc, char *argv[])
 
        fprintf(stderr,"Nothing to do. Idling...\n");
 
      else
 
        fprintf(stderr,".");
 
      sleep(300); // Poll every 300 seconds @TODO: remove polling
 

	
 
      /**
 
	 to prevent infinite loops from burning CPU, we just sleep(1) ;-)
 
      */
 
      sleep(1);
 
    }
 

	
 
    // @TODO: If the server says that every frame for the last jobnum is finished, OR if the data is getting old
 
    /* @TODO: If the server says that every frame for the last jobnum is finished, OR if the data is getting old */
 
    if(1 == 0)
 
      {
 
        // Note: individual frames are already deleted after uploading,
src/server/slavefuncs.c
Show inline comments
 
@@ -867,11 +867,15 @@ int sendSignal(struct remoteio *rem, cha
 
   Sends the server an extended signal (request + data)
 
   ohnobinki: I have no clue how you really want to handle this. Please clarify/edit
 
*/
 
int sendExtSignal(struct remoteio *rem, char signal, char *data){
 
int sendExtSignal(struct remoteio *rem, char signal, char *data)
 
{
 
  size_t written;
 
  size_t towrite;
 
  char *ssignal;
 
  _distren_asprintf(&ssignal, "%c%s", signal, data); // Just append the data FIXME: We should do this differently
 
  /**
 
     Just append the data FIXME: We should do this differently
 
  */
 
  _distren_asprintf(&ssignal, "%c%s", signal, data);
 
  towrite = strlen(ssignal);
 
  while( towrite
 
          && !remoteio_write(rem, ssignal, towrite, &written))
 
@@ -924,10 +928,38 @@ void startframe(struct remoteio *rem, in
 

	
 
}
 

	
 
/**
 
   Greets the server.
 

	
 
   We send PACKAGE_STRING as our version ping thing.
 
 */
 
int greet_server(struct remoteio *rem)
 
{
 
  int err;
 
  struct distren_request *req;
 

	
 
  err = 0;
 

	
 
  fprintf(stderr, "Saying hello to the server ;-)...\n");
 

	
 
  err += distren_request_new(&req, strlen(PACKAGE_STRING), DISTREN_REQUEST_VERSION);
 
  err += distren_request_send(rem, req, PACKAGE_STRING);
 
  err += distren_request_free(req);
 

	
 
  return err;
 
}
 

	
 
/** retrieves job from server */
 
int getwork(struct remoteio *rem, int *jobnum, int *framenum){
 
int getwork(struct remoteio *rem, int *jobnum, int *framenum)
 
{
 
  struct distren_request *req;
 
  char* data;
 
  _distren_asprintf(&data, "%d%d", jobnum, framenum);
 
  int len; /*< asprintf() uses int, not size_t */
 
  len = _distren_asprintf(&data, "%d.%d", jobnum, framenum);
 

	
 
  //distren_request_new(&req, 
 

	
 

	
 
  sendExtSignal(rem, DISTREN_REQUEST_GETWORK, data);
 
  return 0;
 
}
src/server/slavefuncs.h
Show inline comments
 
@@ -58,6 +58,7 @@ void slaveTest();
 
void finishframe(struct remoteio *rem, int jobnum, int framenum);
 
void resetframe(struct remoteio *rem, int jobnum, int framenum);
 
void startframe(struct remoteio *rem, int jobnum, int framenum);
 
int greet_server(struct remoteio *rem);
 
int getwork(struct remoteio *rem, int *jobnum, int *framenum);
 
void setrenderpower(struct remoteio *rem, int renderpower);
 
int getrenderpower(struct remoteio *rem);
0 comments (0 inline, 0 general)