Exemple #1
0
void print_fun(FILE *out, ChordServer *srv, char *fun_name, chordID *id)
{
	fprintf(out, "%s: ", fun_name);
	print_chordID(out, &srv->node.id);
	fprintf(out, " > ");
	print_chordID(out, id);
	print_current_time(out, " @ ", "");
}
Exemple #2
0
void print_two_chordIDs(FILE *out, char *prefix, chordID *id1,
						char *middle, chordID *id2,
						char *suffix)
{
	assert(prefix && id1 && middle && id2 && suffix);
	fprintf(out, "%s", prefix);
	print_chordID(out, id1);
	fprintf(out, "%s", middle);
	print_chordID(out, id2);
	fprintf(out, "%s", suffix);
}
Exemple #3
0
/* this function unpacks the CHORD_FINGERS_REPL message 
 * and prints its content
 *
 * the function returns TRUE if the successor of the Chord node
 * has not been visited so far, and FALSE otherwise.
 * the functions also returns the successor address and port
 * number in succ_addr and succ_port variables
 */
static int unpack_client_traceroute_repl(char *buf, int n, int orig_ttl,
					 ulong chordsrv_addr, 
					 ushort chordsrv_port)
{
  chordID id;
  char    type;
  ulong   addr;
  ushort  port; 
  ulong   rtt_avg, rtt_dev;
  int     len;
  uchar   ttl, hops;
  struct  in_addr ia;

  len = unpack(buf, "cccx", &type, &ttl, &hops, &id);

  assert(type == CHORD_TRACEROUTE_REPL);

  if (orig_ttl == 1) {
    /* print the last link of the traceroute path */
    len += unpack(buf + len, "xls", &id, &addr, &port);
    
    printf("First hop: (");
    print_chordID(&id);
    ia.s_addr = htonl(addr);
    printf("), (%s:%d))\n", inet_ntoa(ia), port);
    return TRUE;
  } 

  if (ttl)
    /* the last hop has been already returned in the previous call */ 
    return FALSE;

  /* print the last link of the traceroute path */
  len += unpack(buf + len, "xlsll", &id, &addr, &port, &rtt_avg, &rtt_dev);
  
  printf("\n(");
  print_chordID(&id);
  ia.s_addr = htonl(addr);
  printf("), (%s:%d)) --> \n", inet_ntoa(ia), port);
  
  len += unpack(buf + len, "xls", &id, &addr, &port);
  printf("   (");
  print_chordID(&id);
  ia.s_addr = htonl(addr);
  printf("), (%s:%d))\n", inet_ntoa(ia), port);
  
  printf("        rtt_avg = %5.2f ms, rtt_stdev = %5.2f ms\n",
	 (float)rtt_avg/1000., (float)rtt_dev/1000.);
  return TRUE;
}
Exemple #4
0
int process_addr_discover_reply(Header *header, ChordPacketArgs *args,
								AddrDiscoverReply *msg, Node *from)
{
	ChordServer *srv = args->srv;
	LOG_PROCESS(&from->id, &from->addr, from->port);

	if (!verify_ticket(srv->ticket_salt, srv->ticket_salt_len,
					   srv->ticket_hash_len, msg->ticket.data, msg->ticket.len,
					   "c6s", CHORD_ADDR_DISCOVER, &from->addr, from->port))
		return CHORD_INVALID_TICKET;

	if (IN6_IS_ADDR_UNSPECIFIED(&srv->node.addr)) {
		v6_addr_set(&srv->node.addr, msg->addr.data);
		get_address_id(&srv->node.id, &srv->node.addr, srv->node.port);
		chord_update_range(srv, &srv->node.id, &srv->node.id);

		StartLog(INFO);
		PartialLog("address: [%s]:%d, ", v6addr_to_str(&srv->node.addr), srv->node.port);
		PartialLog("node id: ");
		print_chordID(clog_file_logger()->fp, &srv->node.id);
		EndLog();
		
		Info("Stabilizing every %u.%u seconds", STABILIZE_PERIOD / 1000000UL, STABILIZE_PERIOD % 1000000UL);

		event_del(srv->discover_addr_event);
		
		struct timeval timeout;
		timeout.tv_sec = STABILIZE_PERIOD / 1000000UL;
		timeout.tv_usec = STABILIZE_PERIOD % 1000000UL;
		event_add(srv->stab_event, &timeout);
	}
	return CHORD_NO_ERROR;
}
Exemple #5
0
void print_node(FILE *out, Node *node)
{
	fprintf(out, "[");
	print_chordID(out, &node->id);

	char *addr_str = v6addr_to_str(&node->addr);
	fprintf(out, ", %s, %d]", addr_str, node->port);
}
Exemple #6
0
void print_send(FILE *out, ChordServer *srv, char *send_type, chordID *id, in6_addr *addr, ushort port)
{
	//int i = TYPE_LEN - strlen(send_type);

	//fprintf(out, "[%s]", send_type);
	//if (i > 0) for (; i; i--) fprintf(out, " ");

	fprintf(out, "(");
	print_chordID(out, id);
	fprintf(out, ") ");
	
	print_node(out, &srv->node);
	if (addr == NULL)
		fprintf(out, " -----> <,>");
	else
		fprintf(out, " -----> <%s, %d>", v6addr_to_str(addr), port);
	print_current_time(out, " Time:", "");
}
Exemple #7
0
void print_process(FILE *out, ChordServer *srv, char *process_type, chordID *id, in6_addr *addr,
				   ushort port)
{
#define TYPE_LEN 16
	//int i = TYPE_LEN - strlen(process_type);

	//fprintf(out, "[%s]", process_type);
	//if (i > 0) for (; i; i--) fprintf(out, " ");

	fprintf(out, "(");
	if (id)
		print_chordID(out, id);
	else
		fprintf(out, "null");
	fprintf(out, ") ");
	print_node(out, &srv->node);
	if (addr == NULL)
		fprintf(out, " <----- <,>");
	else
		fprintf(out, " <----- <%s, %d>", v6addr_to_str(addr), port);
	print_current_time(out, " Time:", "");
}