void ExternalIPCounter::CountIP( const SockAddr& addr, int weight ) { // ignore anyone who claims our external IP is // INADDR_ANY or on a local network if(addr.is_addr_any() || is_ip_local(addr)) return; // timestamp the first time we get a vote if(! _HeatStarted) _HeatStarted = time(NULL); // attempt to insert this vote std::pair<candidate_map::iterator, bool> inserted = _map.insert(std::make_pair(addr, weight)); // if the new IP wasn't inserted, it's already in there // increase the vote counter if (!inserted.second) inserted.first->second += weight; // if the IP vout count exceeds the current leader, replace it if(addr.isv4() && (_winnerV4 == _map.end() || inserted.first->second > _winnerV4->second)) _winnerV4 = inserted.first; if(addr.isv6() && (_winnerV6 == _map.end() || inserted.first->second > _winnerV6->second)) _winnerV6 = inserted.first; _TotalVotes += weight; Rotate(); }