Пример #1
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;
}
Пример #2
0
int process_fs_reply(Header *header, ChordPacketArgs *args,
					 FindSuccessorReply *msg, Node *from)
{
	ChordServer *srv = args->srv;
	int fnew;
	chordID id;

	if (IN6_IS_ADDR_UNSPECIFIED(&srv->node.addr))
		return CHORD_ADDR_UNDISCOVERED;

	in6_addr addr;
	memcpy(addr.s6_addr, msg->addr.data, 16);

	get_address_id(&id, &addr, msg->port);

	if (!verify_ticket(srv->ticket_salt, srv->ticket_salt_len,
					   srv->ticket_hash_len, msg->ticket.data, msg->ticket.len,
					   "c", CHORD_FS))
		return CHORD_INVALID_TICKET;

	if (v6_addr_equals(&srv->node.addr, &addr) && srv->node.port == msg->port)
		return CHORD_NO_ERROR;
	
	LOG_PROCESS(&id, &from->addr, from->port);

	insert_finger(srv, &id, &addr, msg->port, &fnew);
	if (fnew)
		send_ping(srv, &addr, msg->port, get_current_time());

	return CHORD_NO_ERROR;
}
Пример #3
0
/*!
  The function evaluates the up-call ticket, retrieves the appropriate
  broker handle, and passes on the request to __handle_MB_call(), if
  successful.

  \param socket the connection socket.
 */
static void __verify_MB_call(int socket)
{
    comm_ticket ticket;
    CONST CMPIBroker *broker;

    TRACE_VERBOSE(("entered function."));
    TRACE_NORMAL(("handling incoming broker service request."));

    io_read_fixed_length(socket, &ticket, sizeof(comm_ticket));
    broker = verify_ticket(&ticket);

    if (broker == NULL) {

        TRACE_CRITICAL(("ticket invalid, could not obtain a broker"
                        " handle."));
        // return bad status.
        close(socket);

    } else
        __handle_MB_call(socket, broker);

    TRACE_VERBOSE(("leaving function."));
}
Пример #4
0
int process_pong(Header *header, ChordPacketArgs *args, Pong *msg, Node *from)
{
	ChordServer *srv = args->srv;
	Finger *f, *pred, *newpred;
	ulong	 new_rtt;
	int		 fnew;

	if (IN6_IS_ADDR_UNSPECIFIED(&srv->node.addr))
		return CHORD_ADDR_UNDISCOVERED;

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

	f = insert_finger(srv, &from->id, &from->addr, from->port, &fnew);
	if (!f)
		return CHORD_FINGER_ERROR;

	LOG_PROCESS(&from->id, &from->addr, from->port);

	f->npings = 0;
	new_rtt = get_current_time() - msg->time; /* takes care of overlow */
	update_rtt(&f->rtt_avg, &f->rtt_dev, (long)new_rtt);

	pred = pred_finger(srv);
	activate_finger(srv, f); /* there is a two-way connectivity to this node */
	newpred = pred_finger(srv); /* check whether pred has changed, i.e.,
								 * f has became the new pred
								 */
	assert(newpred || (pred == newpred));

	if (pred != newpred)
		chord_update_range(srv, &newpred->node.id, &srv->node.id);

	return CHORD_NO_ERROR;
}