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(); }
/* Check that the remote IP is actually remote. It must be to ensure * that test packets will pass through our device. */ static void check_remote_address(struct config *config, struct wire_client_netdev *netdev) { if (is_ip_local(&config->live_remote_ip)) { die("error: live_remote_ip %s is not remote\n", config->live_remote_ip_string); } }
void ExternalIPCounter::CountIP( const SockAddr& addr, const SockAddr& voter, int weight ) { // Don't let local peers vote on our IP address if (is_ip_local(voter)) return; // Accept an empty voter address. if ( ! voter.is_addr_any() ) { // TODO: we should support IPv6 voters as well // If voter is in bloom filter, return uint32 vaddr = voter.get_addr4(); sha1_hash key = _sha_callback((const byte*)&vaddr, 4); if (_voterFilter.test(key)) return; _voterFilter.add(key); } CountIP(addr, weight); }