forked from premiere/premiere-libtorrent
extend dht_observer to support IPv6 external addresses
This commit is contained in:
parent
11fa4f3e47
commit
356d2506bd
|
@ -61,6 +61,8 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
namespace libtorrent
|
||||
{
|
||||
enum address_type { ipv4, ipv6, num_address_type };
|
||||
|
||||
#if defined TORRENT_BUILD_SIMULATOR
|
||||
typedef sim::asio::ip::address address;
|
||||
typedef sim::asio::ip::address_v4 address_v4;
|
||||
|
|
|
@ -604,7 +604,7 @@ namespace libtorrent
|
|||
// implements dht_observer
|
||||
virtual void set_external_address(address const& ip
|
||||
, address const& source) TORRENT_OVERRIDE;
|
||||
virtual address external_address() TORRENT_OVERRIDE;
|
||||
virtual address external_address(address_type at) TORRENT_OVERRIDE;
|
||||
virtual void get_peers(sha1_hash const& ih) TORRENT_OVERRIDE;
|
||||
virtual void announce(sha1_hash const& ih, address const& addr, int port) TORRENT_OVERRIDE;
|
||||
virtual void outgoing_get_peers(sha1_hash const& target
|
||||
|
|
|
@ -68,7 +68,7 @@ namespace libtorrent { namespace dht
|
|||
{
|
||||
virtual void set_external_address(address const& addr
|
||||
, address const& source) = 0;
|
||||
virtual address external_address() = 0;
|
||||
virtual address external_address(address_type at) = 0;
|
||||
virtual void get_peers(sha1_hash const& ih) = 0;
|
||||
virtual void outgoing_get_peers(sha1_hash const& target
|
||||
, sha1_hash const& sent_target, udp::endpoint const& ep) = 0;
|
||||
|
|
|
@ -73,14 +73,14 @@ namespace {
|
|||
|
||||
void nop() {}
|
||||
|
||||
node_id calculate_node_id(node_id const& nid, dht_observer* observer)
|
||||
node_id calculate_node_id(node_id const& nid, dht_observer* observer, address_type at)
|
||||
{
|
||||
address external_address;
|
||||
if (observer) external_address = observer->external_address();
|
||||
if (observer) external_address = observer->external_address(at);
|
||||
|
||||
// if we don't have an observer, don't pretend that external_address is valid
|
||||
// generating an ID based on 0.0.0.0 would be terrible. random is better
|
||||
if (!observer || external_address == address())
|
||||
if (!observer || external_address.is_unspecified())
|
||||
{
|
||||
return generate_random_id();
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ node::node(udp_socket_interface* sock
|
|||
, struct counters& cnt
|
||||
, dht_storage_constructor_type storage_constructor)
|
||||
: m_settings(settings)
|
||||
, m_id(calculate_node_id(nid, observer))
|
||||
, m_id(calculate_node_id(nid, observer, ipv4))
|
||||
, m_table(m_id, 8, settings, observer)
|
||||
, m_rpc(m_id, m_settings, m_table, sock, observer)
|
||||
, m_observer(observer)
|
||||
|
|
|
@ -6779,9 +6779,12 @@ namespace aux {
|
|||
set_external_address(ip, source_dht, source);
|
||||
}
|
||||
|
||||
address session_impl::external_address()
|
||||
address session_impl::external_address(address_type at)
|
||||
{
|
||||
if (at == ipv4)
|
||||
return m_external_ip.external_address(address_v4());
|
||||
else
|
||||
return m_external_ip.external_address(address_v6());
|
||||
}
|
||||
|
||||
void session_impl::get_peers(sha1_hash const& ih)
|
||||
|
|
|
@ -476,7 +476,7 @@ struct obs : dht::dht_observer
|
|||
, address const& source) TORRENT_OVERRIDE
|
||||
{}
|
||||
|
||||
virtual address external_address() TORRENT_OVERRIDE
|
||||
virtual address external_address(address_type at) TORRENT_OVERRIDE
|
||||
{
|
||||
return address_v4::from_string("236.0.0.1");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue