From 10a00fc62be80692125051f09ae838b2460e34a2 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 19 Feb 2011 21:20:03 +0000 Subject: [PATCH] fixed extended handshake error handling to be more robust and fix extension message precedence over plugins --- src/bt_peer_connection.cpp | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index c5763fd13..d6f050765 100644 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -1578,6 +1578,7 @@ namespace libtorrent , ((error >= 0 && error < 4)?err_msg[error]:"unknown message id")); #endif // #error deal with holepunch errors + (void)error; } break; #if defined TORRENT_VERBOSE_LOGGING default: @@ -1672,9 +1673,23 @@ namespace libtorrent return; } + if (extended_id == share_mode_msg) + { + if (!packet_finished()) return; + bool sm = detail::read_uint8(recv_buffer.begin); +#ifdef TORRENT_VERBOSE_LOGGING + peer_log("<== SHARE_MODE [ %s ]", (sm?"true":"false")); +#endif + set_share_mode(sm); + return; + } + if (extended_id == holepunch_msg) { if (!packet_finished()) return; +#ifdef TORRENT_VERBOSE_LOGGING + peer_log("<== HOLEPUNCH"); +#endif on_holepunch(); return; } @@ -1695,20 +1710,6 @@ namespace libtorrent } #endif - if (extended_id == upload_only_msg) - { - if (!packet_finished()) return; - set_upload_only(detail::read_uint8(recv_buffer.begin)); - return; - } - - if (extended_id == share_mode_msg) - { - if (!packet_finished()) return; - set_share_mode(detail::read_uint8(recv_buffer.begin)); - return; - } - disconnect(errors::invalid_message, 2); return; } @@ -1725,8 +1726,8 @@ namespace libtorrent lazy_entry root; error_code ec; int pos; - lazy_bdecode(recv_buffer.begin + 2, recv_buffer.end, root, ec, &pos); - if (root.type() != lazy_entry::dict_t) + int ret = lazy_bdecode(recv_buffer.begin + 2, recv_buffer.end, root, ec, &pos); + if (ret != 0 || ec || root.type() != lazy_entry::dict_t) { #ifdef TORRENT_VERBOSE_LOGGING peer_log("*** invalid extended handshake: %s pos: %d"