Multicast code cleanup.

This commit is contained in:
Adam Ierymenko 2014-11-24 10:05:16 -08:00
parent acac88cf77
commit d772639cc6
2 changed files with 14 additions and 14 deletions

View File

@ -304,6 +304,7 @@ void Multicaster::send(
// supernode. Our supernode then takes care of relaying it down to <1.0.0 // supernode. Our supernode then takes care of relaying it down to <1.0.0
// nodes. This code can go away (along with support for P5_MULTICAST_FRAME) // nodes. This code can go away (along with support for P5_MULTICAST_FRAME)
// once there are no more such nodes on the network. // once there are no more such nodes on the network.
#if 0
{ {
SharedPtr<Peer> sn(RR->topology->getBestSupernode()); SharedPtr<Peer> sn(RR->topology->getBestSupernode());
if (sn) { if (sn) {
@ -342,32 +343,31 @@ void Multicaster::send(
sn->send(RR,outp.data(),outp.size(),now); sn->send(RR,outp.data(),outp.size(),now);
} }
} }
#endif
} }
void Multicaster::clean(uint64_t now) void Multicaster::clean(uint64_t now)
{ {
Mutex::Lock _l(_groups_m); Mutex::Lock _l(_groups_m);
for(std::map< std::pair<uint64_t,MulticastGroup>,MulticastGroupStatus >::iterator mm(_groups.begin());mm!=_groups.end();) { for(std::map< std::pair<uint64_t,MulticastGroup>,MulticastGroupStatus >::iterator mm(_groups.begin());mm!=_groups.end();) {
// Remove expired outgoing multicasts from multicast TX queue
for(std::list<OutboundMulticast>::iterator tx(mm->second.txQueue.begin());tx!=mm->second.txQueue.end();) { for(std::list<OutboundMulticast>::iterator tx(mm->second.txQueue.begin());tx!=mm->second.txQueue.end();) {
if ((tx->expired(now))||(tx->atLimit())) if ((tx->expired(now))||(tx->atLimit()))
mm->second.txQueue.erase(tx++); mm->second.txQueue.erase(tx++);
else ++tx; else ++tx;
} }
// Remove expired members from membership list, and update rank unsigned long count = 0;
// so that remaining members can be sorted in ascending order of {
// transmit priority. std::vector<MulticastGroupMember>::iterator reader(mm->second.members.begin());
std::vector<MulticastGroupMember>::iterator reader(mm->second.members.begin()); std::vector<MulticastGroupMember>::iterator writer(reader);
std::vector<MulticastGroupMember>::iterator writer(reader); while (reader != mm->second.members.end()) {
unsigned int count = 0; if ((now - reader->timestamp) < ZT_MULTICAST_LIKE_EXPIRE) {
while (reader != mm->second.members.end()) { *writer = *reader;
if ((now - reader->timestamp) < ZT_MULTICAST_LIKE_EXPIRE) { ++writer;
*writer = *reader; ++count;
++writer; }
++count; ++reader;
} }
++reader;
} }
if (count) { if (count) {

View File

@ -133,7 +133,7 @@ public:
*/ */
inline bool sendIfNew(const RuntimeEnvironment *RR,const Address &toAddr) inline bool sendIfNew(const RuntimeEnvironment *RR,const Address &toAddr)
{ {
for(std::vector<Address>::iterator a(_alreadySentTo.begin());a!=_alreadySentTo.end();++a) { for(std::vector<Address>::const_iterator a(_alreadySentTo.begin());a!=_alreadySentTo.end();++a) {
if (*a == toAddr) if (*a == toAddr)
return false; return false;
} }