more robust mechanism to determine external IP

This commit is contained in:
Arvid Norberg
2010-12-24 01:31:41 +00:00
parent 8cec51fc47
commit 451c583023
16 changed files with 360 additions and 39 deletions

View File

@@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/socket.hpp"
#include "libtorrent/socket_io.hpp"
#include "libtorrent/address.hpp"
#include "libtorrent/hasher.hpp" // for hasher
namespace libtorrent
{
@@ -92,5 +93,21 @@ namespace libtorrent
return print_endpoint(tcp::endpoint(ep.address(), ep.port()));
}
void hash_address(address const& ip, sha1_hash& h)
{
#if TORRENT_USE_IPV6
if (ip.is_v6())
{
address_v6::bytes_type b = ip.to_v6().to_bytes();
h = hasher((char*)&b[0], b.size()).final();
}
else
#endif
{
address_v4::bytes_type b = ip.to_v4().to_bytes();
h = hasher((char*)&b[0], b.size()).final();
}
}
}