// Check if there's a handler for this message and call it, else // discard message. void sac_dispatch::operator()(meta_message_ptr& in) { /** __no__ authentication at this point */ uint mid = in->mid(); log(1, "(sac) dispatching message with mid: ", 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; meta_message_ptr out(new meta_message); out->tid(in->tid()); // send response if it was generated if (process_message(in, out)) _transmit(out); } else { log(1, "(sac) (warning) message with mid: ", mid, " unknown, discarding."); } }
/** * 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; }
/** * Create a new destination transaction for the incoming message. * * @param m The input message. */ void message_in::new_dst_transaction(meta_message_ptr& m) { dst_transaction_ptr t(new dst_transaction_t(process_message, _netsap)); t->in = m; t->mid = m->mid(); t->msg_in_avail = true; t->run(); if (t->transaction_status == ONGOING) _tpool.add(t); }
/** * Create a new source transaction for the outgoing message. * * @param m The output message. */ void message_out::new_src_transaction(meta_message_ptr& m) { src_transaction_ptr t(new src_transaction_t(process_message, _netsap)); _tid++; if (_tid == 0) // don't send a message with a _tid = 1; // transaction id of 0 _lpool.set_remote_tid(m->destination().to_string(), m->tid(), _tid); m->tid(_tid); t->out = m; t->mid = m->mid(); t->msg_out_avail = true; t->run(); if (t->transaction_status == ONGOING) _tpool.add(t); }
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; }
/** * Check if there is a handler for this message and call it, else * discard message. * * @param in The input message. */ void sac_dispatch::operator()(meta_message_ptr& in) { /** __no__ authentication at this point */ uint mid = in->mid(); ODTONE_LOG(1, "(sac) dispatching message with mid: ", 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; meta_message_ptr out(new meta_message); out->tid(in->tid()); // send response if it was generated try { if (process_message(in, out)) _transmit(out); } catch(mih::bad_tlv) { ODTONE_LOG(1, "Discarding malformed message."); } catch(unknown_link_sap) { ODTONE_LOG(1, "Received message from an unknown Link SAP. Discarding message."); } catch(unknown_mih_user) { ODTONE_LOG(1, "Received message from an unknown MIH-User. Discarding message."); } } else { ODTONE_LOG(1, "(sac) (warning) message with mid: ", mid, " unknown, discarding."); } }
/** * 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; } } }