diff --git a/ChangeLog b/ChangeLog index a50537d81..cfbab8b94 100644 --- a/ChangeLog +++ b/ChangeLog @@ -19,6 +19,7 @@ * fix uTP edge case where udp socket buffer fills up * fix nagle implementation in uTP + * support 'implied_port' in DHT announce_peer * don't use pool allocator for disk blocks (cache may now return pages to the kernel) 0.16.9 release diff --git a/include/libtorrent/kademlia/msg.hpp b/include/libtorrent/kademlia/msg.hpp index 5b160ef88..80e88a585 100644 --- a/include/libtorrent/kademlia/msg.hpp +++ b/include/libtorrent/kademlia/msg.hpp @@ -46,55 +46,6 @@ namespace libtorrent { namespace dht { typedef std::vector packet_t; -/* -namespace messages -{ - enum { ping = 0, find_node = 1, get_peers = 2, announce_peer = 3, error = 4 }; - char const* const ids[] = { "ping", "find_node", "get_peers", "announce_peer", "error" }; -} // namespace messages - -struct msg -{ - msg() - : reply(false) - , message_id(-1) - , port(0) - {} - - // true if this message is a reply - bool reply; - // the kind if message - int message_id; - // if this is a reply, a copy of the transaction id - // from the request. If it's a request, a transaction - // id that should be sent back in the reply - std::string transaction_id; - // the node id of the process sending the message - node_id id; - // the address of the process sending or receiving - // the message. - udp::endpoint addr; - // if this is a nodes response, these are the nodes - nodes_t nodes; - - peers_t peers; - - // similar to transaction_id but for write operations. - std::string write_token; - - // the info has for peer_requests, announce_peer - // and responses - node_id info_hash; - - // port for announce_peer messages - int port; - - // ERROR MESSAGES - int error_code; - std::string error_msg; -}; -*/ - typedef std::vector nodes_t; typedef std::vector peers_t; diff --git a/src/kademlia/node.cpp b/src/kademlia/node.cpp index 0418aa163..6b5ea70d2 100644 --- a/src/kademlia/node.cpp +++ b/src/kademlia/node.cpp @@ -703,10 +703,11 @@ void node_impl::incoming_request(msg const& m, entry& e) {"token", lazy_entry::string_t, 0, 0}, {"n", lazy_entry::string_t, 0, key_desc_t::optional}, {"seed", lazy_entry::int_t, 0, key_desc_t::optional}, + {"implied_port", lazy_entry::int_t, 0, key_desc_t::optional}, }; - lazy_entry const* msg_keys[5]; - if (!verify_message(arg_ent, msg_desc, msg_keys, 5, error_string, sizeof(error_string))) + lazy_entry const* msg_keys[6]; + if (!verify_message(arg_ent, msg_desc, msg_keys, 6, error_string, sizeof(error_string))) { #ifdef TORRENT_DHT_VERBOSE_LOGGING ++g_failed_announces; @@ -716,6 +717,12 @@ void node_impl::incoming_request(msg const& m, entry& e) } int port = int(msg_keys[1]->int_value()); + + // is the announcer asking to ignore the explicit + // listen port and instead use the source port of the packet? + if (msg_keys[5] && msg_keys[5]->int_value() != 0) + port = m.addr.port(); + if (port < 0 || port >= 65536) { #ifdef TORRENT_DHT_VERBOSE_LOGGING