NSIS-ka
A free C++ implementation of NSIS protocols

Changeset 4462


Ignore:
Timestamp:
Sep 23, 2009, 6:13:13 PM (8 years ago)
Author:
stud-lenk
Message:

Change multicast_peer to use NLI instead of SII as key for the hash_map.

Location:
ntlp/branches/20090723-multicast/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • ntlp/branches/20090723-multicast/src/ntlp_statemodule_data.cpp

    r4452 r4462  
    149149 
    150150  bool more_peers = false;
    151   hash_map<uint32, multicast_peerstatus>::const_iterator mcast_peer_it = r_entry->get_multicast_peers()->begin();
     151  mcast_peer_list_t::const_iterator mcast_peer_it = r_entry->get_multicast_peers()->begin();
    152152  do {
    153153    appladdress* peer= new appladdress;
     
    155155    peer->set_protocol(param.udp);
    156156 
    157     const nli* peer_nli = r_entry->is_multicast_QNode() ? param.rt.findNLI(mcast_peer_it->first) : r_entry->get_peer_nli();
     157    const nli* peer_nli = r_entry->is_multicast_QNode() ? &mcast_peer_it->first : r_entry->get_peer_nli();
     158    assert(peer_nli);
    158159
    159160    // set destination address
     
    235236 
    236237  bool more_peers = false;
    237   hash_map<uint32, multicast_peerstatus>::const_iterator mcast_peer_it = r_entry->get_multicast_peers()->begin();
     238  mcast_peer_list_t::const_iterator mcast_peer_it = r_entry->get_multicast_peers()->begin();
    238239  do {
    239     const nli* peer_nli = r_entry->is_multicast_QNode() ? param.rt.findNLI(mcast_peer_it->first) : r_entry->get_peer_nli();
     240    const nli* peer_nli = r_entry->is_multicast_QNode() ? &mcast_peer_it->first : r_entry->get_peer_nli();
     241    assert(peer_nli);
    240242    appladdress* peer= param.rt.lookup_ma_peeraddress(peer_nli);
    241243
  • ntlp/branches/20090723-multicast/src/ntlp_statemodule_querier.cpp

    r4426 r4462  
    358358  // usually this one here will not happen, because the parsing method will throw an error
    359359  // earlier
    360   if (!incoming_pdu->get_nli())
     360  const nli* peer_nli = incoming_pdu->get_nli();
     361  if (!peer_nli)
    361362  {
    362363      ERRCLog(param.name, "No NLI in Response present. Sending back error message.");
     
    401402    r_entry->set_querycookie(NULL);
    402403
    403     const nli* peer_nli = incoming_pdu->get_nli();
    404     // create/reuse and store SII handle for this peer
    405     uint32 sii_handle = param.rt.generate_sii_handle(peer_nli);
    406404    if (r_key && r_key->mr && r_key->mr->is_multicast_target() && r_entry->is_multicast_QNode())
    407405    {
    408406      // multicast specific handling of responses
    409       if (peer_nli) {
    410         r_entry->trim_peer_rs_validity_time(peer_nli->get_rs_validity_time());
    411         DLog(param.name, "This peer's RS-Validity time: " << peer_nli->get_rs_validity_time() << "ms");
    412         DLog(param.name, "Using lowest peer RS-Validity time: " << r_entry->get_min_peer_rs_validity_time() << "ms");
    413       } else {
    414         ERRCLog(param.name, "incoming_pdu has no NLI. There is something really wrong!");
    415       }
    416       r_entry->add_multicast_peer(sii_handle);
    417       DLog(param.name, "Saved NLI in list of multicast peers, SII handle = " << sii_handle);
     407      r_entry->trim_peer_rs_validity_time(peer_nli->get_rs_validity_time());
     408      DLog(param.name, "This peer's RS-Validity time: " << peer_nli->get_rs_validity_time() << "ms");
     409      DLog(param.name, "Using lowest peer RS-Validity time: " << r_entry->get_min_peer_rs_validity_time() << "ms");
     410      r_entry->add_multicast_peer(peer_nli);
    418411      r_entry->set_peer_nli(NULL);
    419412      r_entry->set_sii_handle(0);
     
    444437      // delete old NLI use new one (new one is present due to checked precondition above)
    445438      r_entry->set_peer_nli(peer_nli);
    446       r_entry->set_sii_handle(sii_handle);
    447       DLog(param.name, "Installed NLI in routing state, SII handle = " << sii_handle);
     439
     440      // create/reuse and store SII handle for this peer
     441      r_entry->set_sii_handle(param.rt.generate_sii_handle(peer_nli));
     442
     443      DLog(param.name, "Installed NLI in routing state, SII handle = " << r_entry->get_sii_handle());
    448444    }
    449445
     
    556552
    557553  if (r_entry->is_multicast_QNode()) {
     554    const nli* peer_nli = incoming_pdu->get_nli();
     555    assert(peer_nli);
     556
     557    // trim the locally stored peer's routing state validity time if needed
     558    r_entry->trim_peer_rs_validity_time(peer_nli->get_rs_validity_time());
     559   
    558560    // Add peer to list of multicast peers
    559     uint32 sii_handle = param.rt.generate_sii_handle(incoming_pdu->get_nli());
    560     if (incoming_pdu->get_nli())
    561       r_entry->trim_peer_rs_validity_time(incoming_pdu->get_nli()->get_rs_validity_time());
    562     r_entry->add_multicast_peer(sii_handle);
     561    r_entry->add_multicast_peer(peer_nli);
    563562     
     563    // Calculate remaining time for other responses
    564564    uint32 remaining_responses_time = r_entry->get_remaining_response_time();
    565565    DLog(param.name, "Remaining time for other responses: " << remaining_responses_time << " ms");
     
    569569                        << r_entry->get_min_peer_rs_validity_time() << " ms");
    570570      remaining_responses_time = r_entry->get_min_peer_rs_validity_time();
    571       // TODO MULTICAST: shorten running timer for to_Refresh_QNode
     571      // TODO MULTICAST: shorten running timer Refresh_QNode
    572572    }
    573573    if (remaining_responses_time == 0) {
     
    734734  }
    735735
     736  const nli* peer_nli = incoming_pdu->get_nli();
     737  assert(peer_nli);
     738
    736739  uint32 refresh_timeout;
    737740  if (r_entry->is_multicast_QNode())
    738   { // if multicast: add peer and/or mark peer as active
    739     uint32 sii_handle = param.rt.generate_sii_handle(incoming_pdu->get_nli());
    740     if (incoming_pdu->get_nli())
    741       r_entry->trim_peer_rs_validity_time(incoming_pdu->get_nli()->get_rs_validity_time());
    742     r_entry->add_multicast_peer(sii_handle);
     741  { // if multicast:
     742   
     743    // trim the locally stored peer's routing state validity time if needed
     744    r_entry->trim_peer_rs_validity_time(peer_nli->get_rs_validity_time());
     745
     746    // add/update peer in multicast peer list
     747    r_entry->add_multicast_peer(peer_nli);
    743748    refresh_timeout = r_entry->get_min_peer_rs_validity_time();
    744749  }
     
    746751  { // if unicast:
    747752    // update RS_Validity Time (we update the whole NLI)
    748     if (incoming_pdu->get_nli()) {
    749       r_entry->set_peer_nli(incoming_pdu->get_nli());
    750     }
     753    r_entry->set_peer_nli(incoming_pdu->get_nli());
    751754    refresh_timeout = r_entry->get_peer_nli()->get_rs_validity_time();
    752755  }
  • ntlp/branches/20090723-multicast/src/pdu/nli.h

    r4245 r4462  
    173173}; // end class nli
    174174
     175/// a comparison function for hash map on the NLI used as key for
     176/// Message Association table and routingentry.multicast_peers table
     177/// only peer_identity and if_address should be used for this
     178struct eqnli
     179{
     180  bool operator()(const nli& nliobj1, const nli& nliobj2) const
     181  {
     182    return (nliobj1.get_pi() != NULL && nliobj2.get_pi() != NULL) ?
     183            ((*nliobj1.get_pi() == *nliobj2.get_pi()) && nliobj1.get_if_address() == nliobj2.get_if_address()) :
     184            (nliobj1.get_if_address() == nliobj2.get_if_address());
     185  }
     186};
     187
     188/// a hash function operating on the nli
     189struct hash_nli {
     190  size_t operator()(const nli nliobj)  const {
     191    const peer_identity* pi_p= nliobj.get_pi();
     192    return pi_p!=0 ? pi_p->get_hash() ^ nliobj.get_if_address().get_hash() : nliobj.get_if_address().get_hash();
     193  }
     194};
     195
    175196
    176197inline
  • ntlp/branches/20090723-multicast/src/routingentry.cpp

    r4455 r4462  
    7070
    7171  if (is_multicast_QNode()) {
    72     os << " multicast peers:" << multicast_peer.size();
    73     hash_map<uint32, multicast_peerstatus>::const_iterator mcast_peer_it;
    74     for (mcast_peer_it = multicast_peer.begin(); mcast_peer_it != multicast_peer.end(); mcast_peer_it++) {
    75       os << std::endl << "  Multicast peer with SII " << mcast_peer_it->first
     72    os << " multicast peers:" << multicast_peers.size();
     73    mcast_peer_list_t::const_iterator mcast_peer_it;
     74    for (mcast_peer_it = multicast_peers.begin(); mcast_peer_it != multicast_peers.end(); mcast_peer_it++) {
     75      os << std::endl << "  Multicast peer " << mcast_peer_it->first.get_if_address()
    7676                      << ": " << mcast_peer_it->second.response_miss_allow_count << " missing responses allowed";
    7777    }
     
    8989
    9090void
    91 routingentry::add_multicast_peer(const uint32 sii_handle)
     91routingentry::add_multicast_peer(const nli* peer)
    9292{
    9393  if (!is_multicast_QNode()) { ERRCLog("add_multicast_peer()", "Not a multicast QNode -- skipping"); return; }
    94   if (sii_handle == 0) { ERRCLog("add_multicast_peer()", "Trying to add invalid SII 0 -- skipping"); return; }
    95   hash_map<uint32, multicast_peerstatus>::iterator it;
    96   it = multicast_peer.find(sii_handle);
    97   if (it == multicast_peer.end()) {
     94  assert(peer);
     95  mcast_peer_list_t::iterator it;
     96  it = multicast_peers.find(*peer);
     97  if (it == multicast_peers.end()) {
    9898    // This multicast peer is a new one, so add it to the list
    9999    multicast_peerstatus status;
    100100    status.response_miss_allow_count = get_max_response_miss_count();
    101     multicast_peer[sii_handle] = status;
    102     DLog("MulticastQN", "Multicast peer with SII " << sii_handle << " added and marked active (allowed to miss "
     101    multicast_peers[*peer] = status;
     102    DLog("MulticastQN", "Multicast peer " << peer->get_if_address() << " added and marked active (allowed to miss "
    103103                        << status.response_miss_allow_count << " responses)");
    104104  } else {
    105105    // this is a known multicast peer -- just re-activate it
    106106    it->second.response_miss_allow_count = get_max_response_miss_count();
    107     DLog("MulticastQN", "Multicast peer with SII " << sii_handle << " marked active");
     107    DLog("MulticastQN", "Multicast peer " << peer->get_if_address() << " marked active");
    108108  }
    109109}
     
    112112routingentry::expire_multicast_peers()
    113113{
    114   if (!is_multicast_QNode()) { ERRCLog("expire_multicast_peers()", "Not a multicast QNode"); return; }
    115   hash_map<uint32, multicast_peerstatus>::iterator it;
    116   for (it=multicast_peer.begin(); it != multicast_peer.end(); it++)
     114  if (!is_multicast_QNode()) { ERRCLog("expire_multicast_peers()", "Not a multicast QNode -- skipping"); return; }
     115  mcast_peer_list_t::iterator it;
     116  for (it=multicast_peers.begin(); it != multicast_peers.end(); it++)
    117117  {
    118118    it->second.response_miss_allow_count--;
     
    130130
    131131  unsigned int purged_peer_count = 0;
    132   hash_map<uint32, multicast_peerstatus>::iterator it;
    133   for (it=multicast_peer.begin(); it != multicast_peer.end(); it++)
     132  mcast_peer_list_t::iterator it = multicast_peers.begin();
     133  while (it != multicast_peers.end())
    134134  {
    135135    if (it->second.response_miss_allow_count <= 0) {
     136      // erase_candidate is needed because otherwise `it' is invalid after multicast_peers.erase()
     137      mcast_peer_list_t::iterator erase_candidate = it++;
    136138      purged_peer_count++;
    137       multicast_peer.erase(it);
    138       DLog("MulticastQN", "Multicast peer with SII " << it->first << " purged");
     139      DLog("MulticastQN", "Multicast peer " << erase_candidate->first.get_if_address() << " purged");
     140      multicast_peers.erase(erase_candidate);
    139141
    140142      // TODO MULTICAST:
     
    142144
    143145    } else {
    144       DLog("MulticastQN", "Multicast peer with SII " << it->first << " is allowed to miss "
     146      DLog("MulticastQN", "Multicast peer " << it->first.get_if_address() << " is allowed to miss "
    145147                          << it->second.response_miss_allow_count << " responses without being purged");
     148      it++;
    146149    }
    147150  }
    148   DLog("MulticastQN", "purge_multicast_peers(): " << purged_peer_count << " peers removed from list of multicast peers");
     151  if (purged_peer_count > 0)
     152    DLog("MulticastQN", "purge_multicast_peers(): " << purged_peer_count << " peers removed from list of multicast peers");
    149153
    150154  // ensure later timer events on mcast_collect get ignored:
  • ntlp/branches/20090723-multicast/src/routingentry.h

    r4452 r4462  
    122122  uint32 response_miss_allow_count;
    123123};
     124
     125typedef hash_map<nli, multicast_peerstatus, hash_nli, eqnli> mcast_peer_list_t;
    124126
    125127/// an entry for the routing data vector
     
    326328        void set_multicast_querier(bool new_mq = true) { is_multicast_querier = is_querying_node() ? new_mq : false; }
    327329        bool is_multicast_QNode() const;
    328         void add_multicast_peer(const uint32 sii_handle);
     330        void add_multicast_peer(const nli* nli);
    329331        void expire_multicast_peers();
    330332        void purge_multicast_peers();
     
    344346
    345347        // return a const pointer to the hash_map of multicast peers
    346         const hash_map<uint32, multicast_peerstatus>* get_multicast_peers() const { return &multicast_peer; }
     348        const mcast_peer_list_t* get_multicast_peers() const { return &multicast_peers; }
    347349
    348350  /// enqueued DATA PAYLOAD
     
    369371  // key for each multicast_peerstatus: sii_handle
    370372  bool is_multicast_querier;
    371   hash_map<uint32, multicast_peerstatus> multicast_peer;
     373  mcast_peer_list_t multicast_peers;
    372374
    373375  // The local address that was used as source to create this entry
  • ntlp/branches/20090723-multicast/src/routingtable.h

    r4313 r4462  
    104104};
    105105
    106 /// a comparison function for Message Association table key (NLI)
    107 /// only peer_identity and if_address should be used for this
    108 struct eqnli
    109 {
    110   bool operator()(const nli& nliobj1, const nli& nliobj2) const
    111   {
    112     return (nliobj1.get_pi() != NULL && nliobj2.get_pi() != NULL) ?
    113             ((*nliobj1.get_pi() == *nliobj2.get_pi()) && nliobj1.get_if_address() == nliobj2.get_if_address()) :
    114             (nliobj1.get_if_address() == nliobj2.get_if_address());
    115   }
    116 };
    117 
    118 /// a hash function operating on the routing key
    119 struct hash_nli {
    120   size_t operator()(const nli nliobj)  const {
    121     const peer_identity* pi_p= nliobj.get_pi();
    122     return pi_p!=0 ? pi_p->get_hash() ^ nliobj.get_if_address().get_hash() : nliobj.get_if_address().get_hash();
    123   }
    124 };
    125 
    126106
    127107typedef enum ma_state_enum {
Note: See TracChangeset for help on using the changeset viewer.