Commits

Ziling Zhao committed 8dc169c

indentation fix

Comments (0)

Files changed (3)

 /*
-**
-** $Id: chimera.c,v 1.49 2006/09/07 04:12:07 krishnap Exp $
-**
-** Matthew Allen
-** description: 
-*/
+ **
+ ** $Id: chimera.c,v 1.49 2006/09/07 04:12:07 krishnap Exp $
+ **
+ ** Matthew Allen
+ ** description: 
+ */
 
 #include <stdio.h>
 #include <unistd.h>
 int chimera_encodehosts (void *logs, char *s, int size, ChimeraHost ** host)
 {
 
-    int i, j;
+	int i, j;
 
-    s[0] = 0;
-    for (i = 0; host[i] != NULL; i++)
+	s[0] = 0;
+	for (i = 0; host[i] != NULL; i++)
 	{
-	    j = strlen (s);
-	    host_encode (s + j, size - j, host[i]);
-	    if (LOGS)
-	      log_message (logs, LOG_DEBUG, "ENCODED %d = %s\n", i, s + j);
-	    strcat (s, "\n");	/* add a spacer */
+		j = strlen (s);
+		host_encode (s + j, size - j, host[i]);
+		if (LOGS)
+			log_message (logs, LOG_DEBUG, "ENCODED %d = %s\n", i, s + j);
+		strcat (s, "\n");	/* add a spacer */
 	}
 
-    return (strlen (s) + 1);
+	return (strlen (s) + 1);
 
 }
 
 ChimeraHost **chimera_decodehosts (ChimeraState * state, char *s)
 {
 
-    ChimeraHost **host;
-    int hostnum;
-    int i, j, k;
+	ChimeraHost **host;
+	int hostnum;
+	int i, j, k;
 
-    for (i = 0, hostnum = 0; i < strlen (s); i++)
+	for (i = 0, hostnum = 0; i < strlen (s); i++)
 	{
-	    if (s[i] == '\n')
-		hostnum++;
+		if (s[i] == '\n')
+			hostnum++;
 	}
 
-    host = (ChimeraHost **) malloc (sizeof (ChimeraHost *) * (hostnum + 1));
-    //memset(host, 0, (sizeof(ChimeraHost *) * (hostnum + 1)));
+	host = (ChimeraHost **) malloc (sizeof (ChimeraHost *) * (hostnum + 1));
+	//memset(host, 0, (sizeof(ChimeraHost *) * (hostnum + 1)));
 
-    /* gets the number of hosts in the lists and goes through them 1 by 1 */
-    for (i = 0, j = 0, k = 0; i < (int) hostnum; i++)
+	/* gets the number of hosts in the lists and goes through them 1 by 1 */
+	for (i = 0, j = 0, k = 0; i < (int) hostnum; i++)
 	{
-	    while (s[k] != '\n')
+		while (s[k] != '\n')
 		{
-		    k++;
+			k++;
 		}
-	    s[k] = 0;
-	    /* once you've found the seperater, decode the host and send it an update */
-	    host[i] = host_decode (state, s + j);
-	    k++;
-	    j = k;
+		s[k] = 0;
+		/* once you've found the seperater, decode the host and send it an update */
+		host[i] = host_decode (state, s + j);
+		k++;
+		j = k;
 	}
-    host[i] = NULL;
+	host[i] = NULL;
 
-    return (host);
+	return (host);
 
 }
 
  */
 void chimera_send_rowinfo (ChimeraState * state, Message * message)
 {
-    int32_t size;
-    ChimeraHost **rowinfo;
-    char s[NETWORK_PACK_SIZE];
-    ChimeraHost *host;
-    Message *msg;
-    ChimeraGlobal *chglob = (ChimeraGlobal *) state->chimera;
-
-    host = host_decode (state, message->payload);
-
-    /* send one row of our routing table back to joiner #host# */
-    rowinfo = route_row_lookup (state, host->key);
-    size = chimera_encodehosts (state->log, s, NETWORK_PACK_SIZE, rowinfo);
-    msg = message_create (host->key, CHIMERA_PIGGY, size, s);
-    if (!message_send (state, host, msg, TRUE)) {
-      if (LOGS)
-	log_message (state->log, LOG_ERROR,
-		     "Sending row information to node: %s:%d failed\n",
-		     host->name, host->port);
-    }
-    free (rowinfo);
-    message_free (msg);
+	int32_t size;
+	ChimeraHost **rowinfo;
+	char s[NETWORK_PACK_SIZE];
+	ChimeraHost *host;
+	Message *msg;
+	ChimeraGlobal *chglob = (ChimeraGlobal *) state->chimera;
+
+	host = host_decode (state, message->payload);
+
+	/* send one row of our routing table back to joiner #host# */
+	rowinfo = route_row_lookup (state, host->key);
+	size = chimera_encodehosts (state->log, s, NETWORK_PACK_SIZE, rowinfo);
+	msg = message_create (host->key, CHIMERA_PIGGY, size, s);
+	if (!message_send (state, host, msg, TRUE)) {
+		if (LOGS)
+			log_message (state->log, LOG_ERROR,
+					"Sending row information to node: %s:%d failed\n",
+					host->name, host->port);
+	}
+	free (rowinfo);
+	message_free (msg);
 }
 
 /** chimera_join_complete:
-** internal function that is called at the destination of a JOIN message. This
-** call encodes the leaf set of the current host and sends it to the joiner.
-** 
-*/
+ ** internal function that is called at the destination of a JOIN message. This
+ ** call encodes the leaf set of the current host and sends it to the joiner.
+ ** 
+ */
 
 void chimera_join_complete (ChimeraState * state, ChimeraHost * host)
 {
 
-    char s[NETWORK_PACK_SIZE];
-    Message *m;
-    ChimeraHost **leafset;
-    ChimeraGlobal *chglob = (ChimeraGlobal *) (state->chimera);
+	char s[NETWORK_PACK_SIZE];
+	Message *m;
+	ChimeraHost **leafset;
+	ChimeraGlobal *chglob = (ChimeraGlobal *) (state->chimera);
 
-    /* copy myself into the reply */
-    host_encode (s, NETWORK_PACK_SIZE, chglob->me);
-    strcat (s, "\n");		/* add a spacer */
+	/* copy myself into the reply */
+	host_encode (s, NETWORK_PACK_SIZE, chglob->me);
+	strcat (s, "\n");		/* add a spacer */
 
-    /* check to see if the node has just left the network or not */
-    if ((dtime () - host->failuretime) < GRACEPERIOD)
+	/* check to see if the node has just left the network or not */
+	if ((dtime () - host->failuretime) < GRACEPERIOD)
 	{
-	    if (LOGS)
-	      log_message (state->log, LOG_WARN,
-			   "JOIN request from node: %s:%d rejected ,elapsed time since failure = %f sec\n",
-			   host->name, host->port,
-			   dtime () - host->failuretime);
+		if (LOGS)
+			log_message (state->log, LOG_WARN,
+					"JOIN request from node: %s:%d rejected ,elapsed time since failure = %f sec\n",
+					host->name, host->port,
+					dtime () - host->failuretime);
 
-	    m = message_create (host->key, CHIMERA_JOIN_NACK, strlen (s) + 1,
+		m = message_create (host->key, CHIMERA_JOIN_NACK, strlen (s) + 1,
 				s);
-	    if (!message_send (state, host, m, TRUE))
-	      if (LOGS)
-		log_message (state->log, LOG_WARN,
-			     "message_send NACK failed!\n");
-	    message_free (m);
-	    return;
+		if (!message_send (state, host, m, TRUE))
+			if (LOGS)
+				log_message (state->log, LOG_WARN,
+						"message_send NACK failed!\n");
+		message_free (m);
+		return;
 	}
 
-    /* copy my leaf set into the reply */
-    leafset = route_neighbors (state, LEAFSET_SIZE);
-    chimera_encodehosts (state->log, s + strlen (s),
-			 NETWORK_PACK_SIZE - strlen (s), leafset);
-    free (leafset);
+	/* copy my leaf set into the reply */
+	leafset = route_neighbors (state, LEAFSET_SIZE);
+	chimera_encodehosts (state->log, s + strlen (s),
+			NETWORK_PACK_SIZE - strlen (s), leafset);
+	free (leafset);
 
-    m = message_create (host->key, CHIMERA_JOIN_ACK, strlen (s) + 1, s);
-    if (!message_send (state, host, m, TRUE))
+	m = message_create (host->key, CHIMERA_JOIN_ACK, strlen (s) + 1, s);
+	if (!message_send (state, host, m, TRUE))
 	{
-	    if (LOGS)
-	      log_message (state->log, LOG_WARN, "message_send ACK failed!\n");
+		if (LOGS)
+			log_message (state->log, LOG_WARN, "message_send ACK failed!\n");
 	}
-    message_free (m);
+	message_free (m);
 }
 
 /**
 void *chimera_check_leafset (void *chstate)
 {
 
-    char s[NETWORK_PACK_SIZE];
-    Message *m;
-    ChimeraHost **leafset;
-    ChimeraHost **table;
-    int i, count = 0;
-    ChimeraState *state = (ChimeraState *) chstate;
-    ChimeraGlobal *chglob = (ChimeraGlobal *) state->chimera;
+	char s[NETWORK_PACK_SIZE];
+	Message *m;
+	ChimeraHost **leafset;
+	ChimeraHost **table;
+	int i, count = 0;
+	ChimeraState *state = (ChimeraState *) chstate;
+	ChimeraGlobal *chglob = (ChimeraGlobal *) state->chimera;
 
 
-    while (1)
+	while (1)
 	{
 
-	    leafset = route_neighbors (state, LEAFSET_SIZE);
-	    for (i = 0; leafset[i] != NULL; i++)
+		leafset = route_neighbors (state, LEAFSET_SIZE);
+		for (i = 0; leafset[i] != NULL; i++)
 		{
-		    if (chimera_ping (state, leafset[i]) == 1)
+			if (chimera_ping (state, leafset[i]) == 1)
 			{
-			    leafset[i]->failuretime = dtime ();
-			    if (LOGS)
-			      log_message (state->log, LOG_WARN,
-					   "message send to host: %s:%d failed at time: %f!\n",
-					   leafset[i]->name, leafset[i]->port,
-					   leafset[i]->failuretime);
-			    if (leafset[i]->success_avg < BAD_LINK)
+				leafset[i]->failuretime = dtime ();
+				if (LOGS)
+					log_message (state->log, LOG_WARN,
+							"message send to host: %s:%d failed at time: %f!\n",
+							leafset[i]->name, leafset[i]->port,
+							leafset[i]->failuretime);
+				if (leafset[i]->success_avg < BAD_LINK)
 				{
-				  if (LOGS)				  
-				    printf ("Deleting %s:%d \n",
-					    leafset[i]->name,
-					    leafset[i]->port);
-				  route_update (state, leafset[i], 0);
+					if (LOGS)				  
+						printf ("Deleting %s:%d \n",
+								leafset[i]->name,
+								leafset[i]->port);
+					route_update (state, leafset[i], 0);
 				}
 			}
-		    host_release (state, leafset[i]);
+			host_release (state, leafset[i]);
 		}
-	    free (leafset);
+		free (leafset);
 
-	    table = route_get_table (state);
-	    for (i = 0; table[i] != NULL; i++)
+		table = route_get_table (state);
+		for (i = 0; table[i] != NULL; i++)
 		{
-		    if (chimera_ping (state, table[i]) == 1)
+			if (chimera_ping (state, table[i]) == 1)
 			{
-			    table[i]->failuretime = dtime ();
-			    if (LOGS)
-			      log_message (state->log, LOG_WARN,
-					   "message send to host: %s:%d failed at time: %f!\n",
-					   table[i]->name, table[i]->port,
-					   table[i]->failuretime);
-			    if (table[i]->success_avg < BAD_LINK)
+				table[i]->failuretime = dtime ();
+				if (LOGS)
+					log_message (state->log, LOG_WARN,
+							"message send to host: %s:%d failed at time: %f!\n",
+							table[i]->name, table[i]->port,
+							table[i]->failuretime);
+				if (table[i]->success_avg < BAD_LINK)
 				{
-				    route_update (state, table[i], 0);
+					route_update (state, table[i], 0);
 				}
 			}
-		    host_release (state, table[i]);
+			host_release (state, table[i]);
 		}
-	    free (table);
+		free (table);
 
-	    /* send leafset exchange data every  3 times that pings the leafset */
-	    if (count == 2)
+		/* send leafset exchange data every  3 times that pings the leafset */
+		if (count == 2)
 		{
-		    count = 0;
-		    leafset = route_neighbors (state, LEAFSET_SIZE);
-		    host_encode (s, NETWORK_PACK_SIZE, chglob->me);
-		    strcat (s, "\n");	/* add a spacer */
-		    chimera_encodehosts (state->log, s + strlen (s),
-					 NETWORK_PACK_SIZE - strlen (s),
-					 leafset);
-
-		    for (i = 0; leafset[i] != NULL; i++)
+			count = 0;
+			leafset = route_neighbors (state, LEAFSET_SIZE);
+			host_encode (s, NETWORK_PACK_SIZE, chglob->me);
+			strcat (s, "\n");	/* add a spacer */
+			chimera_encodehosts (state->log, s + strlen (s),
+					NETWORK_PACK_SIZE - strlen (s),
+					leafset);
+
+			for (i = 0; leafset[i] != NULL; i++)
 			{
-			    m = message_create (leafset[i]->key,
+				m = message_create (leafset[i]->key,
 						CHIMERA_PIGGY, strlen (s) + 1,
 						s);
-			    if (!message_send (state, leafset[i], m, TRUE))
+				if (!message_send (state, leafset[i], m, TRUE))
 				{
-				  if (LOGS)
-				    log_message (state->log, LOG_WARN,
-						 "sending leafset update to %s:%d failed!\n",
-						 leafset[i]->name,
-						 leafset[i]->port);
-				    if (leafset[i]->success_avg < BAD_LINK)
+					if (LOGS)
+						log_message (state->log, LOG_WARN,
+								"sending leafset update to %s:%d failed!\n",
+								leafset[i]->name,
+								leafset[i]->port);
+					if (leafset[i]->success_avg < BAD_LINK)
 					{
-					    route_update (state, leafset[i],
-							  0);
+						route_update (state, leafset[i],
+								0);
 					}
 				}
-			    message_free (m);
-			    host_release (state, leafset[i]);
+				message_free (m);
+				host_release (state, leafset[i]);
 			}
 
-		    free (leafset);
+			free (leafset);
 
 		}
-	    else
-		count++;
+		else
+			count++;
 
-	    sleep (LEAFSET_CHECK_PERIOD);
+		sleep (LEAFSET_CHECK_PERIOD);
 	}
 }
 
 int chimera_check_leafset_init (ChimeraState * state)
 {
 
-    pthread_attr_t attr;
-    pthread_t tid;
-    ChimeraGlobal *chglob = (ChimeraGlobal *) state->chimera;
+	pthread_attr_t attr;
+	pthread_t tid;
+	ChimeraGlobal *chglob = (ChimeraGlobal *) state->chimera;
 
-    if (pthread_attr_init (&attr) != 0)
+	if (pthread_attr_init (&attr) != 0)
 	{
-	    if (LOGS)
-	      log_message (state->log, LOG_ERROR,
-			   "(CHIMERA)pthread_attr_init: %s", strerror (errno));
-	    return (0);
+		if (LOGS)
+			log_message (state->log, LOG_ERROR,
+					"(CHIMERA)pthread_attr_init: %s", strerror (errno));
+		return (0);
 	}
-    if (pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM) != 0)
+	if (pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM) != 0)
 	{
-	    if (LOGS)
-	      log_message (state->log, LOG_ERROR,
-			   "(CHIMERA)pthread_attr_setscope: %s",
-			   strerror (errno));
-	    goto out;
+		if (LOGS)
+			log_message (state->log, LOG_ERROR,
+					"(CHIMERA)pthread_attr_setscope: %s",
+					strerror (errno));
+		goto out;
 	}
-    if (pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED) != 0)
+	if (pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED) != 0)
 	{
-	    if (LOGS)
-	      log_message (state->log, LOG_ERROR,
-			   "(CHIMERA)pthread_attr_setdetachstate: %s",
-			   strerror (errno));
-	    goto out;
+		if (LOGS)
+			log_message (state->log, LOG_ERROR,
+					"(CHIMERA)pthread_attr_setdetachstate: %s",
+					strerror (errno));
+		goto out;
 	}
 
-    if (pthread_create (&tid, &attr, chimera_check_leafset, (void *) state) !=
-	0)
+	if (pthread_create (&tid, &attr, chimera_check_leafset, (void *) state) !=
+			0)
 	{
-	    if (LOGS)
-	      log_message (state->log, 
-			   LOG_ERROR, "(CHIMERA)pthread_create: %s",
-			   strerror (errno));
-	    goto out;
+		if (LOGS)
+			log_message (state->log, 
+					LOG_ERROR, "(CHIMERA)pthread_create: %s",
+					strerror (errno));
+		goto out;
 	}
 
-    return (1);
+	return (1);
 
-  out:
-    pthread_attr_destroy (&attr);
-    return (0);
+out:
+	pthread_attr_destroy (&attr);
+	return (0);
 }
 
 /**
 void chimera_join_denied (ChimeraState * state, Message * message)
 {
 
-    ChimeraHost *host;
-    ChimeraGlobal *chglob = (ChimeraGlobal *) state->chimera;
+	ChimeraHost *host;
+	ChimeraGlobal *chglob = (ChimeraGlobal *) state->chimera;
 
-    host = host_decode (state, message->payload);
+	host = host_decode (state, message->payload);
 
-    if (LOGS)
-      log_message (state->log, LOG_WARN, 
-		   "JOIN request rejected from %s:%d !\n",
-		   host->name, host->port);
+	if (LOGS)
+		log_message (state->log, LOG_WARN, 
+				"JOIN request rejected from %s:%d !\n",
+				host->name, host->port);
 
-    sleep (GRACEPERIOD);
+	sleep (GRACEPERIOD);
 
-    if (LOGS)
-      log_message (state->log, LOG_WARN, 
-		   "Re-sending JOIN message to %s:%d !\n",
-		   chglob->bootstrap->name, chglob->bootstrap->port);
-    chimera_join (state, chglob->bootstrap);
+	if (LOGS)
+		log_message (state->log, LOG_WARN, 
+				"Re-sending JOIN message to %s:%d !\n",
+				chglob->bootstrap->name, chglob->bootstrap->port);
+	chimera_join (state, chglob->bootstrap);
 
 }
 
  */
 
 void chimera_route (ChimeraState * state, Key * key, Message * message,
-		    ChimeraHost * host)
+		ChimeraHost * host)
 {
 
-    ChimeraHost **tmp;
-    //ChimeraHost **piggy;
-    Message *real;
-    uint32_t size;
-    char s[NETWORK_PACK_SIZE];
-    ChimeraGlobal *chglob = (ChimeraGlobal *) state->chimera;
+	ChimeraHost **tmp;
+	//ChimeraHost **piggy;
+	Message *real;
+	uint32_t size;
+	char s[NETWORK_PACK_SIZE];
+	ChimeraGlobal *chglob = (ChimeraGlobal *) state->chimera;
 
-    real = message;
+	real = message;
 
-    tmp = route_lookup (state, *key, 1, 0);
+	tmp = route_lookup (state, *key, 1, 0);
 
-    /* this is to avoid sending JOIN request to the node that
-     ** its information is already in the routing table  ****/
+	/* this is to avoid sending JOIN request to the node that
+	 ** its information is already in the routing table  ****/
 
-    if ((tmp[0] != NULL) && (message->type == CHIMERA_JOIN)
+	if ((tmp[0] != NULL) && (message->type == CHIMERA_JOIN)
 			&& (key_equal (tmp[0]->key, *key)))
 	{
-	    free (tmp);
-	    tmp = route_lookup (state, *key, 2, 0);
-	    if (tmp[1] != NULL && key_equal (tmp[0]->key, *key))
-		tmp[0] = tmp[1];
+		free (tmp);
+		tmp = route_lookup (state, *key, 2, 0);
+		if (tmp[1] != NULL && key_equal (tmp[0]->key, *key))
+			tmp[0] = tmp[1];
 	}
-    if (host == NULL && tmp[0] != chglob->me)
+	if (host == NULL && tmp[0] != chglob->me)
 	{
-	    host = tmp[0];
+		host = tmp[0];
 	}
-    if (tmp[0] == chglob->me)
+	if (tmp[0] == chglob->me)
 	{
-	    host = NULL;
+		host = NULL;
 	}
-    free (tmp);
-    tmp = NULL;
+	free (tmp);
+	tmp = NULL;
 
-    /* if I am the only host or the closest host is me, deliver the message */
-    if (host == NULL)
+	/* if I am the only host or the closest host is me, deliver the message */
+	if (host == NULL)
 	{
-	    if (chglob->deliver != NULL)
+		if (chglob->deliver != NULL)
 		{
-		    chglob->deliver (key, real);
+			chglob->deliver (key, real);
 		}
-	    if (message->type == CHIMERA_JOIN)
+		if (message->type == CHIMERA_JOIN)
 		{
-		    host = host_decode (state, message->payload);
-		    chimera_join_complete (state, host);
+			host = host_decode (state, message->payload);
+			chimera_join_complete (state, host);
 		}
 	}
 
-    /* otherwise, route it */
-    else
+	/* otherwise, route it */
+	else
 	{
-	    if (chglob->forward != NULL)
+		if (chglob->forward != NULL)
 		{
-		    chglob->forward (&key, &real, &host);
+			chglob->forward (&key, &real, &host);
 		}
-	    message = real;
+		message = real;
 
-	    while (!message_send (state, host, message, TRUE))
+		while (!message_send (state, host, message, TRUE))
 		{
 
-		    host->failuretime = dtime ();
-		    if (LOGS)
-		      log_message (state->log, LOG_WARN,
-				   "message send to host: %s:%d at time: %f failed!\n",
-				   host->name, host->port, host->failuretime);
-
-		    /* remove the faulty node from the routing table */
-		    if (host->success_avg < BAD_LINK)
-			route_update (state, host, 0);
-
-		    if (tmp != NULL)
-			free (tmp);
-		    tmp = route_lookup (state, *key, 1, 0);
-		    host = tmp[0];
-		    if (LOGS)
-		      log_message (state->log, LOG_WARN,
-				   "rerouting through %s:%d!\n", host->name,
-				   host->port);
+			host->failuretime = dtime ();
+			if (LOGS)
+				log_message (state->log, LOG_WARN,
+						"message send to host: %s:%d at time: %f failed!\n",
+						host->name, host->port, host->failuretime);
+
+			/* remove the faulty node from the routing table */
+			if (host->success_avg < BAD_LINK)
+				route_update (state, host, 0);
+
+			if (tmp != NULL)
+				free (tmp);
+			tmp = route_lookup (state, *key, 1, 0);
+			host = tmp[0];
+			if (LOGS)
+				log_message (state->log, LOG_WARN,
+						"rerouting through %s:%d!\n", host->name,
+						host->port);
 		}
 
-	    /* in each hop in the way to the key root nodes
-	       send their routing info to the joining node  */
+		/* in each hop in the way to the key root nodes
+		   send their routing info to the joining node  */
 
-	    if (message->type == CHIMERA_JOIN)
-		chimera_send_rowinfo (state, message);
+		if (message->type == CHIMERA_JOIN)
+			chimera_send_rowinfo (state, message);
 
-	    if (tmp != NULL)
-		free (tmp);
+		if (tmp != NULL)
+			free (tmp);
 	}
 
 }
 void chimera_join_acknowledged (ChimeraState * state, Message * message)
 {
 
-    ChimeraHost **host;
-    Message *m;
-    char s[256];
-    int i;
-    ChimeraGlobal *chglob = (ChimeraGlobal *) state->chimera;
+	ChimeraHost **host;
+	Message *m;
+	char s[256];
+	int i;
+	ChimeraGlobal *chglob = (ChimeraGlobal *) state->chimera;
 
-    host_encode (s, 256, chglob->me);
-    host = chimera_decodehosts (state, message->payload);
+	host_encode (s, 256, chglob->me);
+	host = chimera_decodehosts (state, message->payload);
 
-    /* announce my arrival to the nodes in my leafset */
-    for (i = 0; host[i] != NULL; i++)
+	/* announce my arrival to the nodes in my leafset */
+	for (i = 0; host[i] != NULL; i++)
 	{
-	    route_update (state, host[i], 1);
-	    m = message_create (host[i]->key, CHIMERA_UPDATE, strlen (s) + 1,
+		route_update (state, host[i], 1);
+		m = message_create (host[i]->key, CHIMERA_UPDATE, strlen (s) + 1,
 				s);
-	    if (!message_send (state, host[i], m, TRUE))
+		if (!message_send (state, host[i], m, TRUE))
 		{
-		  if (LOGS)
-		    log_message (state->log, LOG_WARN,
-				 "chimera_join_acknowledge: failed to update %s:%d\n",
-				 host[i]->name, host[i]->port);
+			if (LOGS)
+				log_message (state->log, LOG_WARN,
+						"chimera_join_acknowledge: failed to update %s:%d\n",
+						host[i]->name, host[i]->port);
 		}
-	    message_free (m);
+		message_free (m);
 	}
-    free (host);
+	free (host);
 
-    /* announce my arival to the nodes in my routing table */
-    host = route_get_table (state);
-    for (i = 0; host[i] != NULL; i++)
+	/* announce my arival to the nodes in my routing table */
+	host = route_get_table (state);
+	for (i = 0; host[i] != NULL; i++)
 	{
-	    m = message_create (host[i]->key, CHIMERA_UPDATE, strlen (s) + 1,
+		m = message_create (host[i]->key, CHIMERA_UPDATE, strlen (s) + 1,
 				s);
-	    if (!message_send (state, host[i], m, TRUE))
+		if (!message_send (state, host[i], m, TRUE))
 		{
-		  if (LOGS)
-		    log_message (state->log, LOG_WARN,
-				 "chimera_join_acknowledge: failed to update %s:%d\n",
-				 host[i]->name, host[i]->port);
+			if (LOGS)
+				log_message (state->log, LOG_WARN,
+						"chimera_join_acknowledge: failed to update %s:%d\n",
+						host[i]->name, host[i]->port);
 		}
-	    message_free (m);
+		message_free (m);
 	}
-    free (host);
+	free (host);
 
-    /* signal the chimera_join function, which is blocked awaying completion */
-    sema_v (chglob->join);
+	/* signal the chimera_join function, which is blocked awaying completion */
+	sema_v (chglob->join);
 
-    /* initialize the thread for leafset check and exchange */
-    if (!(chimera_check_leafset_init (state)))
+	/* initialize the thread for leafset check and exchange */
+	if (!(chimera_check_leafset_init (state)))
 	{
-	    if (LOGS)
-	      log_message (state->log, LOG_ERROR,
-			   "chimera_check_leafset_init FAILED \n");
-	    return;
+		if (LOGS)
+			log_message (state->log, LOG_ERROR,
+					"chimera_check_leafset_init FAILED \n");
+		return;
 	}
 }
 
  */
 void chimera_message (ChimeraState * state, Message * message)
 {
-    ChimeraGlobal *chglob = (ChimeraGlobal *) state->chimera;
-    chimera_route (state, &message->dest, message, NULL);
+	ChimeraGlobal *chglob = (ChimeraGlobal *) state->chimera;
+	chimera_route (state, &message->dest, message, NULL);
 }
 
 void chimera_register (ChimeraState * state, int type, int ack)
 {
-    if (type < 10)
+	if (type < 10)
 	{
-	    if (LOGS)
-	      log_message (state->log, LOG_ERROR,
-			 "chimera_register: message integer types < 10 are reserved for system\n");
-	    exit (1);
+		if (LOGS)
+			log_message (state->log, LOG_ERROR,
+					"chimera_register: message integer types < 10 are reserved for system\n");
+		exit (1);
 	}
 
-    if (ack != 1 && ack != 2)
+	if (ack != 1 && ack != 2)
 	{
-	    if (LOGS)
-	      log_message (state->log, LOG_ERROR,
-			   "chimera_register: message property ack must be either 1 or 2 unrecognized ack value %i\n",
-			 ack);
-	    exit (1);
+		if (LOGS)
+			log_message (state->log, LOG_ERROR,
+					"chimera_register: message property ack must be either 1 or 2 unrecognized ack value %i\n",
+					ack);
+		exit (1);
 	}
 
-    message_handler (state, type, chimera_message, ack);
+	message_handler (state, type, chimera_message, ack);
 
 }
 
 void chimera_update_message (ChimeraState * state, Message * message)
 {
 
-    ChimeraHost *host;
-    ChimeraGlobal *chglob = (ChimeraGlobal *) state->chimera;
+	ChimeraHost *host;
+	ChimeraGlobal *chglob = (ChimeraGlobal *) state->chimera;
 
-    host = host_decode (state, message->payload);
-    route_update (state, host, 1);
+	host = host_decode (state, message->payload);
+	route_update (state, host, 1);
 
 }
 
 void chimera_piggy_message (ChimeraState * state, Message * message)
 {
 
-    ChimeraHost **piggy;
-    ChimeraHost **tmp;
-    int i;
-    ChimeraGlobal *chglob = (ChimeraGlobal *) state->chimera;
+	ChimeraHost **piggy;
+	ChimeraHost **tmp;
+	int i;
+	ChimeraGlobal *chglob = (ChimeraGlobal *) state->chimera;
 
-    piggy = chimera_decodehosts (state, message->payload);
+	piggy = chimera_decodehosts (state, message->payload);
 
-    for (i = 0; piggy[i] != NULL; i++)
+	for (i = 0; piggy[i] != NULL; i++)
 	{
 
-	    if ((dtime () - piggy[i]->failuretime) > GRACEPERIOD)
+		if ((dtime () - piggy[i]->failuretime) > GRACEPERIOD)
 		{
-		    route_update (state, piggy[i], 1);
+			route_update (state, piggy[i], 1);
 		}
 
-	    else if (LOGS)
-		log_message (state->log, LOG_WARN,
-			     "refused to add:%s to routing table\n",
-			     get_key_string (&piggy[i]->key));
+		else if (LOGS)
+			log_message (state->log, LOG_WARN,
+					"refused to add:%s to routing table\n",
+					get_key_string (&piggy[i]->key));
 	}
-    free (piggy);
+	free (piggy);
 }
 
 
 void chimera_setkey (ChimeraState * state, Key key)
 {
 
-    ChimeraGlobal *chglob = (ChimeraGlobal *) state->chimera;
+	ChimeraGlobal *chglob = (ChimeraGlobal *) state->chimera;
 
-    key_assign (&(chglob->me->key), key);
-    route_keyupdate (state->route, chglob->me);
+	key_assign (&(chglob->me->key), key);
+	route_keyupdate (state->route, chglob->me);
 
 }
 
 int chimera_ping (ChimeraState * state, ChimeraHost * host)
 {
 
-    char name[256];
-    Message *message;
-    ChimeraGlobal *chglob = (ChimeraGlobal *) state->chimera;
+	char name[256];
+	Message *message;
+	ChimeraGlobal *chglob = (ChimeraGlobal *) state->chimera;
 
-    host_encode (name, 256, chglob->me);
+	host_encode (name, 256, chglob->me);
 
-    if (host == NULL)
+	if (host == NULL)
 	{
-	    return -1;
+		return -1;
 	}
 
-    message =
-	message_create (chglob->me->key, CHIMERA_PING, strlen (name) + 1,
-			name);
+	message =
+		message_create (chglob->me->key, CHIMERA_PING, strlen (name) + 1,
+				name);
 
-    if (!message_send (state, host, message, FALSE))
+	if (!message_send (state, host, message, FALSE))
 	{
-	    if (LOGS)
-	      log_message (state->log, LOG_WARN, "failed to ping host %s:%d\n",
-			   host->name, host->port);
-	    message_free (message);
-	    return 1;
+		if (LOGS)
+			log_message (state->log, LOG_WARN, "failed to ping host %s:%d\n",
+					host->name, host->port);
+		message_free (message);
+		return 1;
 	}
 
-    message_free (message);
-    return 0;
+	message_free (message);
+	return 0;
 }
 
 void chimera_ping_reply (ChimeraState * state, Message * message)
 {
 
-    ChimeraHost *host;
-    ChimeraGlobal *chglob = (ChimeraGlobal *) state->chimera;
+	ChimeraHost *host;
+	ChimeraGlobal *chglob = (ChimeraGlobal *) state->chimera;
 
 
-    host = host_decode (state, message->payload);
+	host = host_decode (state, message->payload);
 
-    // log_message(state->log,LOG_WARN, "received a PING message from %s:%d !\n",host->name,host->port ); 
+	// log_message(state->log,LOG_WARN, "received a PING message from %s:%d !\n",host->name,host->port ); 
 
 }
 
  ** chimera_init:
  ** Initializes Chimera on port port and returns the ChimeraState * which 
  ** contains global state of different chimera modules.
-*/
+ */
 
 ChimeraState *chimera_init (int port)
 {
 
-    char name[256];
-    struct hostent *he;
-    ChimeraState *state;
-    ChimeraGlobal *cg;
-    //  mtrace();
-    state = (ChimeraState *) malloc (sizeof (ChimeraState));
-    cg = (ChimeraGlobal *) malloc (sizeof (ChimeraGlobal));
-    state->chimera = (void *) cg;
-
-    state->log = log_init ();
-    log_direct (state->log, LOG_ERROR, stderr);
-    key_init ();
-
-    state->message = message_init ((void *) state, port);
-    if (state->message == NULL)
+	char name[256];
+	struct hostent *he;
+	ChimeraState *state;
+	ChimeraGlobal *cg;
+	//  mtrace();
+	state = (ChimeraState *) malloc (sizeof (ChimeraState));
+	cg = (ChimeraGlobal *) malloc (sizeof (ChimeraGlobal));
+	state->chimera = (void *) cg;
+
+	state->log = log_init ();
+	log_direct (state->log, LOG_ERROR, stderr);
+	key_init ();
+
+	state->message = message_init ((void *) state, port);
+	if (state->message == NULL)
 	{
-	    return (NULL);
+		return (NULL);
 	}
 
-    state->host = host_init (state->log, 64);
-    if (state->host == NULL)
+	state->host = host_init (state->log, 64);
+	if (state->host == NULL)
 	{
-	    return (NULL);
+		return (NULL);
 	}
 
-    if (gethostname (name, 256) != 0)
+	if (gethostname (name, 256) != 0)
 	{
-	    if (LOGS)
-	      log_message (state->log, LOG_ERROR,
-			   "chimera_init: gethostname: %s\n", 
-			   strerror (errno));
-	    return (NULL);
+		if (LOGS)
+			log_message (state->log, LOG_ERROR,
+					"chimera_init: gethostname: %s\n", 
+					strerror (errno));
+		return (NULL);
 	}
-    if ((he = gethostbyname (name)) == NULL)
+	if ((he = gethostbyname (name)) == NULL)
 	{
-	    if (LOGS)
-	      log_message (state->log, LOG_ERROR,
-			   "chimera_init: gethostbyname: %s\n",
-			   strerror (errno));
-	    return (NULL);
+		if (LOGS)
+			log_message (state->log, LOG_ERROR,
+					"chimera_init: gethostbyname: %s\n",
+					strerror (errno));
+		return (NULL);
 	}
-    strcpy (name, he->h_name);
+	strcpy (name, he->h_name);
 
-    cg->me = host_get (state, name, port);
+	cg->me = host_get (state, name, port);
 
-    sprintf (name + strlen (name), ":%d", port);
-    key_makehash (state->log, &(cg->me->key), name);
-    cg->deliver = NULL;
-    cg->forward = NULL;
-    cg->update = NULL;
+	sprintf (name + strlen (name), ":%d", port);
+	key_makehash (state->log, &(cg->me->key), name);
+	cg->deliver = NULL;
+	cg->forward = NULL;
+	cg->update = NULL;
 
-    state->route = route_init (cg->me);
+	state->route = route_init (cg->me);
 
-    message_handler (state, CHIMERA_JOIN, chimera_message, 1);
-    message_handler (state, CHIMERA_JOIN_ACK, chimera_join_acknowledged, 1);
-    message_handler (state, CHIMERA_UPDATE, chimera_update_message, 1);
-    message_handler (state, CHIMERA_PIGGY, chimera_piggy_message, 1);
-    message_handler (state, CHIMERA_JOIN_NACK, chimera_join_denied, 1);
-    message_handler (state, CHIMERA_PING, chimera_ping_reply, 1);
+	message_handler (state, CHIMERA_JOIN, chimera_message, 1);
+	message_handler (state, CHIMERA_JOIN_ACK, chimera_join_acknowledged, 1);
+	message_handler (state, CHIMERA_UPDATE, chimera_update_message, 1);
+	message_handler (state, CHIMERA_PIGGY, chimera_piggy_message, 1);
+	message_handler (state, CHIMERA_JOIN_NACK, chimera_join_denied, 1);
+	message_handler (state, CHIMERA_PING, chimera_ping_reply, 1);
 
-    /* more message types can be defined here */
+	/* more message types can be defined here */
 
-    pthread_mutex_init (&cg->lock, NULL);
-    cg->join = sema_create (0);
+	pthread_mutex_init (&cg->lock, NULL);
+	cg->join = sema_create (0);
 
-    return (state);
+	return (state);
 }
 
 /** 
 void chimera_join (ChimeraState * state, ChimeraHost * bootstrap)
 {
 
-    char name[256];
-    Message *message;
-    ChimeraGlobal *chglob = (ChimeraGlobal *) state->chimera;
+	char name[256];
+	Message *message;
+	ChimeraGlobal *chglob = (ChimeraGlobal *) state->chimera;
 
-    host_encode (name, 256, chglob->me);
+	host_encode (name, 256, chglob->me);
 
-    if (bootstrap == NULL)
+	if (bootstrap == NULL)
 	{
-	    if (!(chimera_check_leafset_init (state)))
-	      if (LOGS)
-		log_message (state->log, LOG_ERROR,
-			     "chimera_check_leafset_init FAILED \n");
-	    return;
+		if (!(chimera_check_leafset_init (state)))
+			if (LOGS)
+				log_message (state->log, LOG_ERROR,
+						"chimera_check_leafset_init FAILED \n");
+		return;
 	}
 
-    chglob->bootstrap = host_get (state, bootstrap->name, bootstrap->port);
+	chglob->bootstrap = host_get (state, bootstrap->name, bootstrap->port);
 
-    message = message_create (chglob->me->key, CHIMERA_JOIN, strlen (name) + 1,
+	message = message_create (chglob->me->key, CHIMERA_JOIN, strlen (name) + 1,
 			name);
-    if (!message_send (state, bootstrap, message, TRUE))
+	if (!message_send (state, bootstrap, message, TRUE))
 	{
-	    if (LOGS)
-	      log_message (state->log, LOG_ERROR,
-			   "chimera_join: failed to contact bootstrap host %s:%d\n",
-			   bootstrap->name, bootstrap->port);
+		if (LOGS)
+			log_message (state->log, LOG_ERROR,
+					"chimera_join: failed to contact bootstrap host %s:%d\n",
+					bootstrap->name, bootstrap->port);
 	}
 
-    sema_p (chglob->join, 0.0);
-    message_free (message);
+	sema_p (chglob->join, 0.0);
+	message_free (message);
 }
 
 
  ** key. 
  */
 void chimera_send (ChimeraState * state, Key key, int32_t type, uint32_t size,
-		   char *data)
+		char *data)
 {
 
-    Message *message;
-    char s[NETWORK_PACK_SIZE];
-    uint32_t realsize;
-    ChimeraGlobal *chglob = (ChimeraGlobal *) state->chimera;
+	Message *message;
+	char s[NETWORK_PACK_SIZE];
+	uint32_t realsize;
+	ChimeraGlobal *chglob = (ChimeraGlobal *) state->chimera;
 
-    /*
-     * XXXPAT: this effectively does nothing right now, and it's unclear
-     * why it's necessary even if it worked.
-     */
+	/*
+	 * XXXPAT: this effectively does nothing right now, and it's unclear
+	 * why it's necessary even if it worked.
+	 */
 #if 0
-    realsize = htonl ((uint32_t) size);
-    memcpy (s, &realsize, sizeof (uint32_t));
-    memcpy (s + sizeof (uint32_t), data, size);
-    size += sizeof (uint32_t);
+	realsize = htonl ((uint32_t) size);
+	memcpy (s, &realsize, sizeof (uint32_t));
+	memcpy (s + sizeof (uint32_t), data, size);
+	size += sizeof (uint32_t);
 #endif
 
-    message = message_create (key, type, size, data);
-    chimera_message (state, message);
-    message_free (message);
+	message = message_create (key, type, size, data);
+	chimera_message (state, message);
+	message_free (message);
 }
 
 /** 
  */
 void chimera_forward (ChimeraState * state, chimera_forward_upcall_t func)
 {
-    ChimeraGlobal *chglob = (ChimeraGlobal *) state->chimera;
-    chglob->forward = func;
+	ChimeraGlobal *chglob = (ChimeraGlobal *) state->chimera;
+	chglob->forward = func;
 }
 
 /** 
  */
 void chimera_deliver (ChimeraState * state, chimera_deliver_upcall_t func)
 {
-    ChimeraGlobal *chglob = (ChimeraGlobal *) state->chimera;
-    chglob->deliver = func;
+	ChimeraGlobal *chglob = (ChimeraGlobal *) state->chimera;
+	chglob->deliver = func;
 }
 
 /** 
  */
 void chimera_update (ChimeraState * state, chimera_update_upcall_t func)
 {
-    ChimeraGlobal *chglob = (ChimeraGlobal *) state->chimera;
-    chglob->update = func;
+	ChimeraGlobal *chglob = (ChimeraGlobal *) state->chimera;
+	chglob->update = func;
 }
 
 
  ** called by route_update to upcall into the user's system 
  */
 void chimera_update_upcall (ChimeraState * state, Key * k, ChimeraHost * h,
-			    int joined)
+		int joined)
 {
-    ChimeraGlobal *chglob = (ChimeraGlobal *) state->chimera;
-    if (chglob->update != NULL)
+	ChimeraGlobal *chglob = (ChimeraGlobal *) state->chimera;
+	if (chglob->update != NULL)
 	{
-	    chglob->update (k, h, joined);
+		chglob->update (k, h, joined);
 	}
 }
 
 typedef struct
 {
-    ChimeraHost *host;
-    int refrence;
-    JRB node;
-    Dllist free;
+	ChimeraHost *host;
+	int refrence;
+	JRB node;
+	Dllist free;
 } CacheEntry;
 
 typedef struct
 {
-    JRB hosts;
-    Dllist free;
-    int size;
-    int max;
-    pthread_mutex_t lock;
+	JRB hosts;
+	Dllist free;
+	int size;
+	int max;
+	pthread_mutex_t lock;
 } HostGlobal;
 
 void cacheentry_free (CacheEntry * entry)
 {
-    if (entry == NULL);
-    free (entry->host->name);
-    free (entry->host);
-    free (entry);
+	if (entry == NULL);
+	free (entry->host->name);
+	free (entry->host);
+	free (entry);
 }
 
 /** host_encode:
 void host_encode (char *s, int len, ChimeraHost * host)
 {
 
-    snprintf (s, len, "%s:", get_key_string (&host->key));
-    snprintf (s + strlen (s), len - strlen (s), "%s:", host->name);
-    snprintf (s + strlen (s), len - strlen (s), "%d", host->port);
+	snprintf (s, len, "%s:", get_key_string (&host->key));
+	snprintf (s + strlen (s), len - strlen (s), "%s:", host->name);
+	snprintf (s + strlen (s), len - strlen (s), "%d", host->port);
 
 }
 
 ChimeraHost *host_decode (ChimeraState * state, char *s)
 {
 
-    char *key = NULL, *name = NULL, *port = NULL;
-    ChimeraHost *host;
-    int i;
-    Key k;
-    HostGlobal *hg = (HostGlobal *) state->host;
+	char *key = NULL, *name = NULL, *port = NULL;
+	ChimeraHost *host;
+	int i;
+	Key k;
+	HostGlobal *hg = (HostGlobal *) state->host;
 
 
-    /* hex representation of key in front bytes */
-    key = s;
+	/* hex representation of key in front bytes */
+	key = s;
 
-    /* next is the name of the host */
-    for (i = 0; s[i] != ':' && s[i] != 0; i++);
-    s[i] = 0;
-    name = s + (i + 1);
+	/* next is the name of the host */
+	for (i = 0; s[i] != ':' && s[i] != 0; i++);
+	s[i] = 0;
+	name = s + (i + 1);
 
-    /* then a human readable integer of the port */
-    for (i++; s[i] != ':' && s[i] != 0; i++);
-    s[i] = 0;
-    port = s + (i + 1);
+	/* then a human readable integer of the port */
+	for (i++; s[i] != ':' && s[i] != 0; i++);
+	s[i] = 0;
+	port = s + (i + 1);
 
-    /* allocate space, do the network stuff, and return the host */
-    sscanf (port, "%d", &i);
-    host = host_get (state, name, i);
+	/* allocate space, do the network stuff, and return the host */
+	sscanf (port, "%d", &i);
+	host = host_get (state, name, i);
 
-    str_to_key (key, &k);
+	str_to_key (key, &k);
 
-    if (key_equal_ui (host->key, 0))
-	key_assign (&(host->key), k);
+	if (key_equal_ui (host->key, 0))
+		key_assign (&(host->key), k);
 
-    return (host);
+	return (host);
 
 }
 
 ChimeraHost *host_get (ChimeraState * state, char *hostname, int port)
 {
 
-    JRB node;
-    Dllist dllnode;
-    uint32_t address;
-    CacheEntry *tmp, *entry;
-    unsigned char *ip;
-    char id[256];
-    int i;
-    HostGlobal *hg = (HostGlobal *) state->host;
-
-    /* create an id of the form ip:port */
-    memset (id, 0, 256);
-    address = network_address (state->network, hostname);
-    ip = (unsigned char *) &address;
-    for (i = 0; i < 4; i++)
-	sprintf (id + strlen (id), "%s%d", (i == 0) ? ("") : ("."),
-		 (int) ip[i]);
-    sprintf (id + strlen (id), ":%d", port);
-
-    pthread_mutex_lock (&hg->lock);
-    node = jrb_find_str (hg->hosts, id);
-
-    /* if the node is not in the cache, create an entry and allocate a host */
-    if (node == NULL)
+	JRB node;
+	Dllist dllnode;
+	uint32_t address;
+	CacheEntry *tmp, *entry;
+	unsigned char *ip;
+	char id[256];
+	int i;
+	HostGlobal *hg = (HostGlobal *) state->host;
+
+	/* create an id of the form ip:port */
+	memset (id, 0, 256);
+	address = network_address (state->network, hostname);
+	ip = (unsigned char *) &address;
+	for (i = 0; i < 4; i++)
+		sprintf (id + strlen (id), "%s%d", (i == 0) ? ("") : ("."),
+				(int) ip[i]);
+	sprintf (id + strlen (id), ":%d", port);
+
+	pthread_mutex_lock (&hg->lock);
+	node = jrb_find_str (hg->hosts, id);
+
+	/* if the node is not in the cache, create an entry and allocate a host */
+	if (node == NULL)
 	{
-	    entry = (CacheEntry *) malloc (sizeof (CacheEntry));
-	    entry->host = (ChimeraHost *) malloc (sizeof (ChimeraHost));
-	    entry->host->name = strdup (hostname);
-	    entry->host->port = port;
-	    entry->host->address = address;
-	    entry->host->failed = 0;
-	    entry->host->failuretime = 0;
-
-	    key_assign_ui (&(entry->host->key), 0);
-
-	    entry->host->success_win_index = 0;
-	    for (i = 0; i < SUCCESS_WINDOW / 2; i++)
-		entry->host->success_win[i] = 0;
-	    for (i = SUCCESS_WINDOW / 2; i < SUCCESS_WINDOW; i++)
-		entry->host->success_win[i] = 1;
-	    entry->host->success_avg = 0.5;
-	    entry->refrence = 1;
-	    jrb_insert_str (hg->hosts, strdup (id), new_jval_v (entry));
-
-	    entry->node = jrb_find_str (hg->hosts, id);
-	    hg->size++;
+		entry = (CacheEntry *) malloc (sizeof (CacheEntry));
+		entry->host = (ChimeraHost *) malloc (sizeof (ChimeraHost));
+		entry->host->name = strdup (hostname);
+		entry->host->port = port;
+		entry->host->address = address;
+		entry->host->failed = 0;
+		entry->host->failuretime = 0;
+
+		key_assign_ui (&(entry->host->key), 0);
+
+		entry->host->success_win_index = 0;
+		for (i = 0; i < SUCCESS_WINDOW / 2; i++)
+			entry->host->success_win[i] = 0;
+		for (i = SUCCESS_WINDOW / 2; i < SUCCESS_WINDOW; i++)
+			entry->host->success_win[i] = 1;
+		entry->host->success_avg = 0.5;
+		entry->refrence = 1;
+		jrb_insert_str (hg->hosts, strdup (id), new_jval_v (entry));
+
+		entry->node = jrb_find_str (hg->hosts, id);
+		hg->size++;
 	}
 
-    /* otherwise, increase the refrence count */
-    else
+	/* otherwise, increase the refrence count */
+	else
 	{
-	    entry = (CacheEntry *) node->val.v;
-	    /* if it was in the free list, remove it */
-	    if (entry->refrence == 0)
+		entry = (CacheEntry *) node->val.v;
+		/* if it was in the free list, remove it */
+		if (entry->refrence == 0)
 		{
-		    dll_delete_node (entry->free);
+			dll_delete_node (entry->free);
 		}
-	    entry->refrence++;
+		entry->refrence++;
 	}
 
-    /* if the cache was overfull, empty it as much as possible */
-    while (hg->size > hg->max && !jrb_empty (hg->free))
+	/* if the cache was overfull, empty it as much as possible */
+	while (hg->size > hg->max && !jrb_empty (hg->free))
 	{
-	    dllnode = dll_first (hg->free);
-	    tmp = (CacheEntry *) dllnode->val.v;
-	    dll_delete_node (dllnode);
-	    jrb_delete_node (tmp->node);
-	    cacheentry_free (tmp);
-	    hg->size--;
+		dllnode = dll_first (hg->free);
+		tmp = (CacheEntry *) dllnode->val.v;
+		dll_delete_node (dllnode);
+		jrb_delete_node (tmp->node);
+		cacheentry_free (tmp);
+		hg->size--;
 	}
-    pthread_mutex_unlock (&hg->lock);
-    return (entry->host);
+	pthread_mutex_unlock (&hg->lock);
+	return (entry->host);
 }
 
 /** host_release:
 void host_release (ChimeraState * state, ChimeraHost * host)
 {
 
-    JRB node;
-    Dllist dllnode;
-    CacheEntry *entry, *tmp;
-    unsigned char *ip;
-    char id[256];
-    int i;
-    HostGlobal *hg = (HostGlobal *) state->host;
-
-    /* create an id of the form ip:port */
-    memset (id, 0, 256);
-    ip = (unsigned char *) &host->address;
-    for (i = 0; i < 4; i++)
-	sprintf (id + strlen (id), "%s%d", (i == 0) ? ("") : ("."),
-		 (int) ip[i]);
-    sprintf (id + strlen (id), ":%d", host->port);
-
-    pthread_mutex_lock (&hg->lock);
-    node = jrb_find_str (hg->hosts, id);
-    if (node == NULL)
+	JRB node;
+	Dllist dllnode;
+	CacheEntry *entry, *tmp;
+	unsigned char *ip;
+	char id[256];
+	int i;
+	HostGlobal *hg = (HostGlobal *) state->host;
+
+	/* create an id of the form ip:port */
+	memset (id, 0, 256);
+	ip = (unsigned char *) &host->address;
+	for (i = 0; i < 4; i++)
+		sprintf (id + strlen (id), "%s%d", (i == 0) ? ("") : ("."),
+				(int) ip[i]);
+	sprintf (id + strlen (id), ":%d", host->port);
+
+	pthread_mutex_lock (&hg->lock);
+	node = jrb_find_str (hg->hosts, id);
+	if (node == NULL)
 	{
-	    pthread_mutex_unlock (&hg->lock);
-	    return;
+		pthread_mutex_unlock (&hg->lock);
+		return;
 	}
-    entry = (CacheEntry *) node->val.v;
-    entry->refrence--;
+	entry = (CacheEntry *) node->val.v;
+	entry->refrence--;
 
-    /* if we reduce the node to 0 refrences, put it in the cache */
-    if (entry->refrence == 0)
+	/* if we reduce the node to 0 refrences, put it in the cache */
+	if (entry->refrence == 0)
 	{
-	    dll_append (hg->free, new_jval_v (entry));
-	    entry->free = dll_last (hg->free);
+		dll_append (hg->free, new_jval_v (entry));
+		entry->free = dll_last (hg->free);
 	}
 
-    /* if the cache was overfull, empty it as much as possible */
-    while (hg->size > hg->max && !jrb_empty (hg->free))
+	/* if the cache was overfull, empty it as much as possible */
+	while (hg->size > hg->max && !jrb_empty (hg->free))
 	{
-	    dllnode = dll_first (hg->free);
-	    tmp = (CacheEntry *) dllnode->val.v;
-	    dll_delete_node (dllnode);
-	    jrb_delete_node (tmp->node);
-	    cacheentry_free (tmp);
-	    hg->size--;
+		dllnode = dll_first (hg->free);
+		tmp = (CacheEntry *) dllnode->val.v;
+		dll_delete_node (dllnode);
+		jrb_delete_node (tmp->node);
+		cacheentry_free (tmp);
+		hg->size--;
 	}
-    pthread_mutex_unlock (&hg->lock);
+	pthread_mutex_unlock (&hg->lock);
 }
 
 
 void host_update_stat (ChimeraHost * host, int success)
 {
 
-    int i;
-    float total = 0;
+	int i;
+	float total = 0;
 
-    host->success_win[host->success_win_index++ % SUCCESS_WINDOW] = success;
-    host->success_avg = 0;
+	host->success_win[host->success_win_index++ % SUCCESS_WINDOW] = success;
+	host->success_avg = 0;
 
-    // printf("SUCCESS_WIN["); 
-    for (i = 0; i < SUCCESS_WINDOW; i++)
+	// printf("SUCCESS_WIN["); 
+	for (i = 0; i < SUCCESS_WINDOW; i++)
 	{
-	    //  printf("%i ",host->success_win[i]);
-	    total += host->success_win[i];
-	    //   host->success_avg = host->success_win[i]/SUCCESS_WINDOW;
+		//  printf("%i ",host->success_win[i]);
+		total += host->success_win[i];
+		//   host->success_avg = host->success_win[i]/SUCCESS_WINDOW;
 	}
-    // printf("]   ");
-    host->success_avg = total / SUCCESS_WINDOW;
-    //  printf("Total: %f, avg: %f\n",total,host->success_avg);
+	// printf("]   ");
+	host->success_avg = total / SUCCESS_WINDOW;
+	//  printf("Total: %f, avg: %f\n",total,host->success_avg);
 
 }
 
 void *host_init (void *logs, int size)
 {
 
-    HostGlobal *hg;
-    hg = (HostGlobal *) malloc (sizeof (HostGlobal));
+	HostGlobal *hg;
+	hg = (HostGlobal *) malloc (sizeof (HostGlobal));
 
-    hg->hosts = make_jrb ();
-    hg->free = new_dllist ();
-    hg->size = 0;
-    hg->max = size;
+	hg->hosts = make_jrb ();
+	hg->free = new_dllist ();
+	hg->size = 0;
+	hg->max = size;
 
-    if (pthread_mutex_init (&hg->lock, NULL) != 0)
+	if (pthread_mutex_init (&hg->lock, NULL) != 0)
 	{
-	    if (LOGS)
-	      log_message (logs, LOG_ERROR, "pthread_mutex_init: %s",
-			   strerror (errno));
-	    return (NULL);
+		if (LOGS)
+			log_message (logs, LOG_ERROR, "pthread_mutex_init: %s",
+					strerror (errno));
+		return (NULL);
 	}
-    return ((void *) hg);
+	return ((void *) hg);
 }
 /*
-** $Id: network.c,v 1.30 2007/04/04 00:04:49 krishnap Exp $
-**
-** Matthew Allen
-** description: 
-*/
+ ** $Id: network.c,v 1.30 2007/04/04 00:04:49 krishnap Exp $
+ **
+ ** Matthew Allen
+ ** description: 
+ */
 
 #include <stdio.h>
 #include <unistd.h>
 
 typedef struct
 {
-    int sock;
-    JRB waiting;
-    uint32_t seqstart, seqend;
-    pthread_mutex_t lock;
+	int sock;
+	JRB waiting;
+	uint32_t seqstart, seqend;
+	pthread_mutex_t lock;
 	JRB retransmit;
 } NetworkGlobal;
 
 uint32_t network_address (void *networkglobal, char *hostname)
 {
 
-    int is_addr;
-    struct hostent *he;
-    uint32_t addr;
-    uint32_t local;
-    int i;
-    NetworkGlobal *netglob = (NetworkGlobal *) networkglobal;
+	int is_addr;
+	struct hostent *he;
+	uint32_t addr;
+	uint32_t local;
+	int i;
+	NetworkGlobal *netglob = (NetworkGlobal *) networkglobal;
 
 
-    /* apparently gethostbyname does not portably recognize ip addys */
+	/* apparently gethostbyname does not portably recognize ip addys */
 
 #ifdef SunOS
-    is_addr = inet_addr (hostname);
-    if (is_addr == -1)
-	is_addr = 0;
-    else
+	is_addr = inet_addr (hostname);
+	if (is_addr == -1)
+		is_addr = 0;
+	else
 	{
-	    memcpy (&addr, (struct in_addr *) &is_addr, sizeof (addr));
-	    is_addr = inet_addr ("127.0.0.1");
-	    memcpy (&local, (struct in_addr *) &is_addr, sizeof (addr));
-	    is_addr = 1;
+		memcpy (&addr, (struct in_addr *) &is_addr, sizeof (addr));
+		is_addr = inet_addr ("127.0.0.1");
+		memcpy (&local, (struct in_addr *) &is_addr, sizeof (addr));
+		is_addr = 1;
 	}
 #else
-    is_addr = inet_aton (hostname, (struct in_addr *) &addr);
-    inet_aton ("127.0.0.1", (struct in_addr *) &local);
+	is_addr = inet_aton (hostname, (struct in_addr *) &addr);
+	inet_aton ("127.0.0.1", (struct in_addr *) &local);
 #endif
 
-    pthread_mutex_lock (&(netglob->lock));
-    if (is_addr)
+	pthread_mutex_lock (&(netglob->lock));
+	if (is_addr)
 		he = gethostbyaddr ((char *) &addr, sizeof (addr), AF_INET);
-    else
+	else
 		he = gethostbyname (hostname);
 
-    if (he == NULL)
+	if (he == NULL)
 	{
-	    pthread_mutex_unlock (&(netglob->lock));
-	    return (0);
+		pthread_mutex_unlock (&(netglob->lock));
+		return (0);
 	}
 
-    /* make sure the machine is not returning localhost */
+	/* make sure the machine is not returning localhost */
 
-    addr = *(uint32_t *) he->h_addr_list[0];
-    for (i = 1; he->h_addr_list[i] != NULL && addr == local; i++)
-	addr = *(uint32_t *) he->h_addr_list[i];
-    pthread_mutex_unlock (&(netglob->lock));
+	addr = *(uint32_t *) he->h_addr_list[0];
+	for (i = 1; he->h_addr_list[i] != NULL && addr == local; i++)
+		addr = *(uint32_t *) he->h_addr_list[i];
+	pthread_mutex_unlock (&(netglob->lock));
 
-    return (addr);
+	return (addr);
 
 }
 
 
 void *network_init (void *logs, int port)
 {
-    int sd;
-    int ret;
-    struct sockaddr_in saddr;
-    int one;
-    NetworkGlobal *ng;
+	int sd;
+	int ret;
+	struct sockaddr_in saddr;
+	int one;
+	NetworkGlobal *ng;
 
-    ng = (NetworkGlobal *) malloc (sizeof (NetworkGlobal));
+	ng = (NetworkGlobal *) malloc (sizeof (NetworkGlobal));
 
-    /* create socket */
-    sd = socket (AF_INET, SOCK_DGRAM, 0);
-    if (sd < 0)
+	/* create socket */
+	sd = socket (AF_INET, SOCK_DGRAM, 0);
+	if (sd < 0)
 	{
-	    if (LOGS)
-	      log_message (logs, LOG_ERROR, "network: socket: %s\n",
-			   strerror (errno));
-	    return (NULL);
+		if (LOGS)
+			log_message (logs, LOG_ERROR, "network: socket: %s\n",
+					strerror (errno));
+		return (NULL);
 	}
-    if (setsockopt (sd, SOL_SOCKET, SO_REUSEADDR, (void *) &one, sizeof (one))
-	== -1)
+	if (setsockopt (sd, SOL_SOCKET, SO_REUSEADDR, (void *) &one, sizeof (one))
+			== -1)
 	{
-	    if (LOGS)
-	      log_message (logs, LOG_ERROR, "network: setsockopt: %s\n: ",
-			   strerror (errno));
-	    close (sd);
-	    return (NULL);
+		if (LOGS)
+			log_message (logs, LOG_ERROR, "network: setsockopt: %s\n: ",
+					strerror (errno));
+		close (sd);
+		return (NULL);
 	}
 
-    /* attach socket to #port#. */
-    saddr.sin_family = AF_INET;
-    saddr.sin_addr.s_addr = htonl (INADDR_ANY);
-    saddr.sin_port = htons ((short) port);
-    if (bind (sd, (struct sockaddr *) &saddr, sizeof (saddr)) < 0)
+	/* attach socket to #port#. */
+	saddr.sin_family = AF_INET;
+	saddr.sin_addr.s_addr = htonl (INADDR_ANY);
+	saddr.sin_port = htons ((short) port);
+	if (bind (sd, (struct sockaddr *) &saddr, sizeof (saddr)) < 0)
 	{
-	    if (LOGS)
-	      log_message (logs, LOG_ERROR, "network: bind: %s:\n",
-			   strerror (errno));
-	    close (sd);
-	    return (NULL);
+		if (LOGS)
+			log_message (logs, LOG_ERROR, "network: bind: %s:\n",
+					strerror (errno));
+		close (sd);
+		return (NULL);
 	}
 
-    if ((ret = pthread_mutex_init (&(ng->lock), NULL)) != 0)
+	if ((ret = pthread_mutex_init (&(ng->lock), NULL)) != 0)
 	{
-	    if (LOGS)
-	      log_message (logs, LOG_ERROR,
-			   "network: pthread_mutex_init: %s:\n",
-			   strerror (ret));
-	    close (sd);
-	    return (NULL);
+		if (LOGS)
+			log_message (logs, LOG_ERROR,
+					"network: pthread_mutex_init: %s:\n",
+					strerror (ret));
+		close (sd);
+		return (NULL);
 	}
 
-    ng->sock = sd;
-    ng->waiting = make_jrb();
-    ng->seqstart = 0;
-    ng->seqend = 0;
+	ng->sock = sd;
+	ng->waiting = make_jrb();
+	ng->seqstart = 0;
+	ng->seqend = 0;
 	ng->retransmit = make_jrb();
 
-    return ((void *) ng);
+	return ((void *) ng);
 }
 
 /** Never returns. Keep retransmitting the failed packets.
 		   network_resend(state, pqentry->desthost, pqentry->data, pqentry->datasize, 1, pqentry->seqnum); 
 		   jrb_delete_node(pqnode);
 		   }
-		 */
+		   */
 
 		sleep(RETRANSMIT_THREAD_SLEEP);
 	}
  */
 void *network_activate (void *state)
 {
-    fd_set fds, thisfds;
-    int ret, retack;
-    char data[SEND_SIZE];
-    struct sockaddr_in from;
-    int socklen = sizeof (from);
-    uint32_t ack, seq;
-    JRB node;
-    ChimeraState *chstate = (ChimeraState *) state;
-    NetworkGlobal *ng = (NetworkGlobal *) chstate->network;
-
-    FD_ZERO (&fds);
-    FD_SET (ng->sock, &fds);
-
-    while (1)
+	fd_set fds, thisfds;
+	int ret, retack;
+	char data[SEND_SIZE];
+	struct sockaddr_in from;
+	int socklen = sizeof (from);
+	uint32_t ack, seq;
+	JRB node;
+	ChimeraState *chstate = (ChimeraState *) state;
+	NetworkGlobal *ng = (NetworkGlobal *) chstate->network;
+
+	FD_ZERO (&fds);
+	FD_SET (ng->sock, &fds);
+
+	while (1)
 	{
-	    /* block until information becomes available */
-	    memcpy (&thisfds, &fds, sizeof (fd_set));
-	    ret = select (ng->sock + 1, &thisfds, NULL, NULL, NULL);
-	    if (ret < 0)
+		/* block until information becomes available */
+		memcpy (&thisfds, &fds, sizeof (fd_set));
+		ret = select (ng->sock + 1, &thisfds, NULL, NULL, NULL);
+		if (ret < 0)
 		{
-		  if (LOGS)
-		    log_message (chstate->log, LOG_ERROR,
-				 "network: select: %s\n", strerror (errno));
-		    continue;
+			if (LOGS)
+				log_message (chstate->log, LOG_ERROR,
+						"network: select: %s\n", strerror (errno));
+			continue;
 		}
 
-	    /* receive the new data */
-	    ret =
-		recvfrom (ng->sock, data, SEND_SIZE, 0,
-			  (struct sockaddr *) &from, &socklen);
-	    if (ret < 0)
+		/* receive the new data */
+		ret = recvfrom (ng->sock, data, SEND_SIZE, 0,
+					(struct sockaddr *) &from, &socklen);
+		if (ret < 0)
 		{
-		  if (LOGS)
-		    log_message (chstate->log, LOG_ERROR,
-				 "network: recvfrom: %s\n", strerror (errno));
-		    continue;
+			if (LOGS)
+				log_message (chstate->log, LOG_ERROR,
+						"network: recvfrom: %s\n", strerror (errno));
+			continue;
 		}
-	    memcpy (&ack, data, sizeof (uint32_t));
-	    ack = ntohl (ack);
-	    memcpy (&seq, data + sizeof (uint32_t),
-		    sizeof (uint32_t));
-	    seq = ntohl (seq);
-
-	    /* process acknowledgement */
-	    if (ack == 0)
+		memcpy (&ack, data, sizeof (uint32_t));
+		ack = ntohl (ack);
+		memcpy (&seq, data + sizeof (uint32_t),
+				sizeof (uint32_t));
+		seq = ntohl (seq);
+
+		/* process acknowledgement */
+		if (ack == 0)
 		{
-		  if (LOGS)
-		    log_message (chstate->log, LOG_NETWORKDEBUG,
-				 "network_activate: received ack seq=%d from %s:%d\n",
-				 seq, inet_ntoa (from.sin_addr),
-				 from.sin_port);
-
-		    pthread_mutex_lock (&(ng->lock));
-		    node = jrb_find_int (ng->waiting, seq);
-		    if (node != NULL)
+			if (LOGS)
+				log_message (chstate->log, LOG_NETWORKDEBUG,
+						"network_activate: received ack seq=%d from %s:%d\n",
+						seq, inet_ntoa (from.sin_addr),
+						from.sin_port);
+
+			pthread_mutex_lock (&(ng->lock));
+			node = jrb_find_int (ng->waiting, seq);
+			if (node != NULL)
 			{
 				AckEntry *entry = (AckEntry *)node->val.v;
 				entry->acked = 1;
 				entry->acktime = dtime();
-		//kpkp - enable
-		//		fprintf(stderr, "Received an ack for packet %d at time entry->acktime %f\n", seq, entry->acktime);
+				//kpkp - enable
+				//		fprintf(stderr, "Received an ack for packet %d at time entry->acktime %f\n", seq, entry->acktime);
 			}
-		    pthread_mutex_unlock (&(ng->lock));
+			pthread_mutex_unlock (&(ng->lock));
 		}
 
-	    /* process receive and send acknowledgement */
-	    else if (ack == 1)
+		/* process receive and send acknowledgement */
+		else if (ack == 1)
 		{
-		  if (LOGS)
-		    log_message (chstate->log, LOG_NETWORKDEBUG,
-				 "network_activate: received message seq=%d  data:%s\n",
-				 seq, data + (2 * sizeof (uint32_t)));
-		    ack = htonl (0);
-		    memcpy (data, &ack, sizeof (uint32_t));
-		    retack =
-			sendto (ng->sock, data, 2 * sizeof (uint32_t), 0,
-				(struct sockaddr *) &from, sizeof (from));
-		    if (retack < 0)
+			if (LOGS)
+				log_message (chstate->log, LOG_NETWORKDEBUG,
+						"network_activate: received message seq=%d  data:%s\n",
+						seq, data + (2 * sizeof (uint32_t)));
+			ack = htonl (0);
+			memcpy (data, &ack, sizeof (uint32_t));
+			retack =
+				sendto (ng->sock, data, 2 * sizeof (uint32_t), 0,
+						(struct sockaddr *) &from, sizeof (from));
+			if (retack < 0)
 			{
-			  if (LOGS)
-			    log_message (chstate->log, LOG_ERROR,
-					 "network: sendto: %s\n",
-					 strerror (errno));
-			  continue;
+				if (LOGS)
+					log_message (chstate->log, LOG_ERROR,
+							"network: sendto: %s\n",
+							strerror (errno));
+				continue;
 			}
-		    if (LOGS)
-		      log_message (chstate->log, LOG_NETWORKDEBUG,
-				   "network_activate: sent out ack for  message seq=%d\n",
-				   seq);
-		    message_received (state,
-				      data + (2 * sizeof (uint32_t)),
-				      ret - (2 * sizeof (uint32_t)));
+			if (LOGS)
+				log_message (chstate->log, LOG_NETWORKDEBUG,
+						"network_activate: sent out ack for  message seq=%d\n",
+						seq);
+			message_received (state,
+					data + (2 * sizeof (uint32_t)),
+					ret - (2 * sizeof (uint32_t)));
 		}
-	    else if (ack == 2)
+		else if (ack == 2)
 		{
-		    message_received (state,
-				      data + (2 * sizeof (uint32_t)),
-				      ret - (2 * sizeof (uint32_t)));
+			message_received (state,
+					data + (2 * sizeof (uint32_t)),
+					ret - (2 * sizeof (uint32_t)));
 		}
-	    else
+		else
 		{
-		  if (LOGS)
-		    log_message (chstate->log, LOG_ERROR,
-				 "network: received unrecognized message ack=%d seq=%d\n",
-				 ack, seq);
+			if (LOGS)
+				log_message (chstate->log, LOG_ERROR,
+						"network: received unrecognized message ack=%d seq=%d\n",
+						ack, seq);
 		}
 	}
 }
  ** Sends a message to host, updating the measurement info.
  */
 int network_send (void *state, ChimeraHost * host, char *data, uint32_t size,
-		  int32_t ack)
+		int32_t ack)
 {
-    struct sockaddr_in to;
-    int ret, retval;
-    uint32_t seq, seqnumbackup, ntype;
+	struct sockaddr_in to;
+	int ret, retval;
+	uint32_t seq, seqnumbackup, ntype;
 	int sizebackup;
-    char s[SEND_SIZE];
-    void *semaphore;
-    JRB node;
+	char s[SEND_SIZE];
+	void *semaphore;
+	JRB node;
 	JRB priqueue;
-    double start;
-    ChimeraState *chstate = (ChimeraState *) state;
-    NetworkGlobal *ng;
+	double start;
+	ChimeraState *chstate = (ChimeraState *) state;
+	NetworkGlobal *ng;
 
-    ng = (NetworkGlobal *) chstate->network;
+	ng = (NetworkGlobal *) chstate->network;
 
-    if (size > NETWORK_PACK_SIZE)
+	if (size > NETWORK_PACK_SIZE)
 	{
-	    if (LOGS)
-	      log_message (chstate->log, LOG_ERROR,
-			   "network_send: cannot send data over %lu bytes!\n",
-			   NETWORK_PACK_SIZE);
-	    return (0);
+		if (LOGS)
+			log_message (chstate->log, LOG_ERROR,
+					"network_send: cannot send data over %lu bytes!\n",
+					NETWORK_PACK_SIZE);
+		return (0);
 	}
-    if (ack != 1 && ack != 2)
+	if (ack != 1 && ack != 2)
 	{
-	    if (LOGS)
-	      log_message (chstate->log, LOG_ERROR,
-			   "network_send: FAILED, unexpected message ack property %i !\n", ack);
-	    return (0);
+		if (LOGS)
+			log_message (chstate->log, LOG_ERROR,
+					"network_send: FAILED, unexpected message ack property %i !\n", ack);
+		return (0);
 	}
-    memset (&to, 0, sizeof (to));
-    to.sin_family = AF_INET;
-    to.sin_addr.s_addr = host->address;
-    to.sin_port = htons ((short) host->port);
+	memset (&to, 0, sizeof (to));
+	to.sin_family = AF_INET;
+	to.sin_addr.s_addr = host->address;
+	to.sin_port = htons ((short) host->port);
 
-    AckEntry *ackentry = get_new_ackentry();
+	AckEntry *ackentry = get_new_ackentry();
 	sizebackup = size;
-    /* get sequence number and initialize acknowledgement indicator*/
+	/* get sequence number and initialize acknowledgement indicator*/
 	pthread_mutex_lock (&(ng->lock));
 	node = jrb_insert_int (ng->waiting, ng->seqend, new_jval_v(ackentry));
 	seqnumbackup = ng->seqend;
 	ng->seqend++;		/* needs to be fixed to modplus */
 	pthread_mutex_unlock (&(ng->lock));
 
-    /* create network header */
-    ntype = htonl (ack);
-    memcpy (s, &ntype, sizeof (uint32_t));
-    memcpy (s + sizeof (uint32_t), &seq, sizeof (uint32_t));
-    memcpy (s + (2 * sizeof (uint32_t)), data, size);
-    size += (2 * sizeof (uint32_t));
-
-    /* send data */
-    seq = ntohl (seq);
-    if (LOGS)
-      log_message (chstate->log, LOG_NETWORKDEBUG,
-		   "network_send: sending message seq=%d ack=%d to %s:%d  data:%s\n",
-		   seq, ack, host->name, host->port, data);
-    start = dtime ();
-
-    ret = sendto (ng->sock, s, size, 0, (struct sockaddr *) &to, sizeof (to));
-    if (LOGS)
-      log_message (chstate->log, LOG_NETWORKDEBUG,
-		   "network_send: sent message: %s\n", s);
-
-    if (ret < 0)
+	/* create network header */
+	ntype = htonl (ack);
+	memcpy (s, &ntype, sizeof (uint32_t));
+	memcpy (s + sizeof (uint32_t), &seq, sizeof (uint32_t));
+	memcpy (s + (2 * sizeof (uint32_t)), data, size);
+	size += (2 * sizeof (uint32_t));
+
+	/* send data */
+	seq = ntohl (seq);
+	if (LOGS)
+		log_message (chstate->log, LOG_NETWORKDEBUG,
+				"network_send: sending message seq=%d ack=%d to %s:%d  data:%s\n",
+				seq, ack, host->name, host->port, data);
+	start = dtime ();
+
+	ret = sendto (ng->sock, s, size, 0, (struct sockaddr *) &to, sizeof (to));
+	if (LOGS)
+		log_message (chstate->log, LOG_NETWORKDEBUG,
+				"network_send: sent message: %s\n", s);
+
+	if (ret < 0)
 	{
-	    if (LOGS)
-	      log_message (chstate->log, LOG_ERROR,
-			   "network_send: sendto: %s\n", strerror (errno));
-	    host_update_stat (host, 0);
-	    return (0);
+		if (LOGS)
+			log_message (chstate->log, LOG_ERROR,
+					"network_send: sendto: %s\n", strerror (errno));
+		host_update_stat (host, 0);
+		return (0);
 	}
 
-    if (ack == 1)
+	if (ack == 1)
 	{
 		// insert a record into the priority queue with the following information:
 		// key: starttime + next retransmit time
 		pthread_mutex_unlock (&(ng->lock));
 
 		//kpkp - enable
-	    // fprintf(stderr, "network_send: sent seq=%d; inserted entry into the retransmit priqueue with time %f\n", pqrecord->seqnum, start+1);
+		// fprintf(stderr, "network_send: sent seq=%d; inserted entry into the retransmit priqueue with time %f\n", pqrecord->seqnum, start+1);
 
-	    // wait for ack  
+		// wait for ack  
 		/* // This code is for the semaphore implmentation -- this should be deleted once 
-		   // the priority queue is well tested and stabilized
-
-	    if (LOGS)
-	      log_message (chstate->log, LOG_NETWORKDEBUG,
-			   "network_send: waiting for acknowledgement for seq=%d\n",
-			   seq);
-	    retval = sema_p (semaphore, TIMEOUT);
-	    if (LOGS) {
-	      if (retval != 0)
+		// the priority queue is well tested and stabilized
+
+		if (LOGS)
+		log_message (chstate->log, LOG_NETWORKDEBUG,
+		"network_send: waiting for acknowledgement for seq=%d\n",
+		seq);
+		retval = sema_p (semaphore, TIMEOUT);
+		if (LOGS) {
+		if (retval != 0)
 		log_message (chstate->log, LOG_NETWORKDEBUG,
-			     "network_send: acknowledgement timer seq=%d TIMEDOUT\n",
-			     seq);
-	      else
+		"network_send: acknowledgement timer seq=%d TIMEDOUT\n",
+		seq);
+		else
 		log_message (chstate->log, LOG_NETWORKDEBUG,
-			     "network_send: acknowledgement for seq=%d received\n",
-			     seq);
-	    }
-	    pthread_mutex_lock (&(ng->lock));
-	    sema_destroy (semaphore);
-	    jrb_delete_node (node);
-	    pthread_mutex_unlock (&(ng->lock));
-
-	    if (retval != 0)
+		"network_send: acknowledgement for seq=%d received\n",
+		seq);
+		}
+		pthread_mutex_lock (&(ng->lock));
+		sema_destroy (semaphore);
+		jrb_delete_node (node);
+		pthread_mutex_unlock (&(ng->lock));
+
+		if (retval != 0)
 		{
-		    host_update_stat (host, 0);
-		    return (0);
+		host_update_stat (host, 0);
+		return (0);
 		}
 
-	    /// update latency info 
-	    if (host->latency == 0.0)
+		/// update latency info 
+		if (host->latency == 0.0)
 		{
-		    host->latency = dtime () - start;
+		host->latency = dtime () - start;
 		}
-	    else
+		else
 		{
-		    host->latency =
-			(0.9 * host->latency) + (0.1 * (dtime () - start));
+		host->latency =
+		(0.9 * host->latency) + (0.1 * (dtime () - start));
 		}
 		*/
 	}
 
-    return (1);
+	return (1);
 }
 
 /**
  ** Resends a message to host
  */
 int network_resend (void *state, ChimeraHost *host, char *data, int size, 
-					int ack, uint32_t seqnum, double *transtime)
+		int ack, uint32_t seqnum, double *transtime)
 {
 	struct sockaddr_in to;
 	int ret, retval;
 	char s[SEND_SIZE];
 	double start;
-    ChimeraState *chstate = (ChimeraState *) state;
-    NetworkGlobal *ng = (NetworkGlobal *) chstate->network;
+	ChimeraState *chstate = (ChimeraState *) state;
+	NetworkGlobal *ng = (NetworkGlobal *) chstate->network;
 
 	memset (&to, 0, sizeof (to));
 	to.sin_family = AF_INET;
 		return (0);
 	}
 
-// kpkp
+	// kpkp
 	//fprintf(stderr, "network_resend: resending message seq=%d ack=%d to %s:%d  datalen:%d\n", seq, ack, host->name, host->port, strlen(data));
 	return (1);
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.