コード例 #1
0
/**
 * Check if there's a handler for this message and call it, else
 * discard message.
 *
 * @param in The input message.
 * @param out The output message.
 */
bool sac_process_message(meta_message_ptr& in, meta_message_ptr& out)
{
	// discard messages that this MIHF broadcasted to itself
	// discard messages that are not destined to this MIHF or if
	// multicast messages are not supported
	if(in->source() == mihfid) {
		ODTONE_LOG(1, "(sac) Discarding message! Reason: ",
					  "message was broadcasted to itself");
		return false;
	}

	if(!utils::this_mihf_is_destination(in) && !utils::is_multicast(in)) {
		ODTONE_LOG(1, "(sac) Discarding message! Reason: ",
					  "this is not the message destination");
		return false;
	}

	/** __no__ authentication at this point */

	uint mid = in->mid();

	//
	// no thread safety because insertion should __only__ be made
	// on MIHF initialization
	//
	std::map<uint, handler_t>::iterator it;
	it = _callbacks.find(mid);

	if(it != _callbacks.end()) {
		handler_t process_message = it->second;

		bool rsp;

		try {

			rsp = process_message(in, out);

		} catch(mih::bad_tlv) {
			ODTONE_LOG(1, "Discarding malformed message.");
			return false;
		}

		// set ip and port of response message
		out->ip(in->ip());
		out->scope(in->scope());
		out->port(in->port());

		// response message must have the same tid
		out->tid(in->tid());

		return rsp;
	} else {
		ODTONE_LOG(1, "(sac) (warning) message with mid: ", mid,
		    " unknown, discarding.");
	}

	return false;
}
コード例 #2
0
bool sac_process_message(meta_message_ptr& in, meta_message_ptr& out)
{
	// discard messages that this MIHF broadcasted to itself
	if (in->source() == mihfid)
		return false;

	/** __no__ authentication at this point */

	uint mid = in->mid();

	//
	// no thread safety because insertion should __only__ be made
	// on MIHF initialization
	//
	std::map<uint, handler_t>::iterator it;
	it = _callbacks.find(mid);

	if(it != _callbacks.end()) {
		handler_t process_message = it->second;

		bool rsp = process_message(in, out);

		// set ip and port of response message
		out->ip(in->ip());
		out->port(in->port());

		// response message must have the same tid
		out->tid(in->tid());

		return rsp;
	} else {
		log(1, "(sac) (warning) message with mid: ", mid,
		    " unknown, discarding.");
	}

	return false;
}
コード例 #3
0
ファイル: service_management.cpp プロジェクト: ATNoG/ODTONE
/**
 * Parse all capabilities from MIH Capability Discover message and stores
 * them.
 *
 * @param in input message.
 * @param out output message.
 */
void service_management::get_capabilities(meta_message_ptr& in,
										  meta_message_ptr& out)
{
	address_entry mihf_info;
	mihf_info.ip = in->ip();
	mihf_info.port = in->port();

	if(in->opcode() == mih::operation::request) {
		*in >> mih::request(mih::request::capability_discover)
				& mih::tlv_net_type_addr_list(mihf_info.capabilities_list_net_type_addr)
				& mih::tlv_event_list(mihf_info.capabilities_event_list)
				& mih::tlv_command_list(mihf_info.capabilities_cmd_list)
				& mih::tlv_query_type_list(mihf_info.capabilities_query_type)
				& mih::tlv_transport_option_list(mihf_info.capabilities_trans_list)
				& mih::tlv_mbb_ho_supp_list(mihf_info.capabilities_mbb_ho_supp);
	} else if(in->opcode() == mih::operation::response) {
コード例 #4
0
ファイル: transaction.hpp プロジェクト: ATNoG/EMICOM
	/**
	 * Run Acknowledge Responder State Machine transaction.
	 */
	void ack_responder()
		{
			switch(ack_rsp_state)
			{
			case ACK_RSP_INIT:
				goto _rsp_init_lbl_;
			case ACK_RSP_RETURN_ACK:
				goto _rsp_return_ack_lbl_;
			case ACK_RSP_PIGGYBACKING:
				goto _rsp_piggybacking_lbl_;
			case ACK_RSP_RETURN_DUPLICATE:
				goto _rsp_return_duplicate_lbl_;
			}

		  _rsp_init_lbl_:
			{
				ack->ackreq(false);
				ack->ackrsp(true);
				ack->opcode((mih::operation::type)opcode);
				ack->tid(tid);
				ack->mid(in->mid());
				ack->source(my_mihf_id);
				ack->destination(peer_mihf_id);
				ack->ip(in->ip());
				ack->port(in->port());

				if (msg_out_avail)
					goto _rsp_piggybacking_lbl_;
				else
				{			
					_netsap.send(ack);
					msg_in_avail = false;
					goto _rsp_return_ack_lbl_;
				}
					

				return;
			}

		  _rsp_return_ack_lbl_:
			{
				ack_rsp_state = ACK_RSP_RETURN_ACK;
				if(msg_in_avail)
				{					
					_netsap.send(ack);
					msg_in_avail = false;
				}
				else if (msg_out_avail)
					goto _rsp_piggybacking_lbl_;

				return;
			}

		  _rsp_piggybacking_lbl_:
			{
				ack_rsp_state = ACK_RSP_PIGGYBACKING;

				out->ackrsp(true);
				dup = out;

				if (msg_in_avail)
					goto _rsp_return_duplicate_lbl_;

				return;
			}

		  _rsp_return_duplicate_lbl_:
			{
				ack_rsp_state = ACK_RSP_RETURN_DUPLICATE;
				if (msg_in_avail) {
					_netsap.send(dup);
					msg_in_avail = false;
				}
			}
		}