diff --git a/ChangeLog b/ChangeLog index d7c7f4a74..b31aba9ce 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * peer_blocked_alert now derives from peer_alert * transitioned exception types to system_error * made alerts move-only * move files one-by-one when moving storage for a torrent diff --git a/bindings/python/src/alert.cpp b/bindings/python/src/alert.cpp index 2fe8c3725..9137c8aac 100644 --- a/bindings/python/src/alert.cpp +++ b/bindings/python/src/alert.cpp @@ -534,10 +534,19 @@ void bind_alert() #endif ; - class_, noncopyable>( + class_, noncopyable>( "peer_blocked_alert", no_init) - .add_property("ip", make_getter(&peer_blocked_alert::ip - , return_value_policy())) + .add_property("reason", &peer_blocked_alert::reason) + ; + + enum_("reason_t") + .value("ip_filter", peer_blocked_alert::reason_t::ip_filter) + .value("port_filter", peer_blocked_alert::reason_t::port_filter) + .value("i2p_mixed", peer_blocked_alert::reason_t::i2p_mixed) + .value("privileged_ports", peer_blocked_alert::reason_t::privileged_ports) + .value("utp_disabled", peer_blocked_alert::reason_t::utp_disabled) + .value("tcp_disabled", peer_blocked_alert::reason_t::tcp_disabled) + .value("invalid_local_interface", peer_blocked_alert::reason_t::invalid_local_interface) ; class_, noncopyable>( @@ -830,4 +839,5 @@ void bind_alert() .def("num_peers", &dht_get_peers_reply_alert::num_peers) .def("peers", peers) ; + } diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index 65e57eebd..b82522c70 100644 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -1467,20 +1467,17 @@ namespace libtorrent // * the port filter // * the peer has a low port and ``no_connect_privileged_ports`` is enabled // * the protocol of the peer is blocked (uTP/TCP blocking) - struct TORRENT_EXPORT peer_blocked_alert final : torrent_alert + struct TORRENT_EXPORT peer_blocked_alert final : peer_alert { // internal peer_blocked_alert(aux::stack_allocator& alloc, torrent_handle const& h - , address const& i, int r); + , tcp::endpoint const& ep, int r); TORRENT_DEFINE_ALERT(peer_blocked_alert, 54) static const int static_category = alert::ip_block_notification; virtual std::string message() const override; - // the address that was blocked. - address ip; - enum reason_t { ip_filter, @@ -1492,6 +1489,8 @@ namespace libtorrent invalid_local_interface }; + // the reason for the peer being blocked. Is one of the values from the + // reason_t enum. int reason; }; diff --git a/src/alert.cpp b/src/alert.cpp index cef787fcd..408c3f3be 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -1023,10 +1023,8 @@ namespace libtorrent { } peer_blocked_alert::peer_blocked_alert(aux::stack_allocator& alloc - , torrent_handle const& h, address const& i - , int r) - : torrent_alert(alloc, h) - , ip(i) + , torrent_handle const& h, tcp::endpoint const& ep, int r) + : peer_alert(alloc, h, ep, peer_id(0)) , reason(r) {} @@ -1034,7 +1032,7 @@ namespace libtorrent { { error_code ec; char ret[600]; - char const* reason_str[] = + static char const* reason_str[] = { "ip_filter", "port_filter", @@ -1045,9 +1043,8 @@ namespace libtorrent { "invalid_local_interface" }; - std::snprintf(ret, sizeof(ret), "%s: blocked peer: %s [%s]" - , torrent_alert::message().c_str(), ip.to_string(ec).c_str() - , reason_str[reason]); + std::snprintf(ret, sizeof(ret), "%s: blocked peer [%s]" + , peer_alert::message().c_str(), reason_str[reason]); return ret; } diff --git a/src/session_impl.cpp b/src/session_impl.cpp index f7acbf611..3a100dff5 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -2666,7 +2666,7 @@ namespace aux { #endif if (m_alerts.should_post()) m_alerts.emplace_alert(torrent_handle() - , endp.address(), peer_blocked_alert::utp_disabled); + , endp, peer_blocked_alert::utp_disabled); return; } @@ -2678,7 +2678,7 @@ namespace aux { #endif if (m_alerts.should_post()) m_alerts.emplace_alert(torrent_handle() - , endp.address(), peer_blocked_alert::tcp_disabled); + , endp, peer_blocked_alert::tcp_disabled); return; } @@ -2714,7 +2714,7 @@ namespace aux { #endif if (m_alerts.should_post()) m_alerts.emplace_alert(torrent_handle() - , endp.address(), peer_blocked_alert::invalid_local_interface); + , endp, peer_blocked_alert::invalid_local_interface); return; } } @@ -2738,7 +2738,7 @@ namespace aux { #endif if (m_alerts.should_post()) m_alerts.emplace_alert(torrent_handle() - , endp.address(), peer_blocked_alert::ip_filter); + , endp, peer_blocked_alert::ip_filter); return; } diff --git a/src/torrent.cpp b/src/torrent.cpp index 827028173..737765203 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -3599,7 +3599,7 @@ namespace libtorrent #endif if (m_ses.alerts().should_post()) m_ses.alerts().emplace_alert(get_handle() - , host.address(), peer_blocked_alert::ip_filter); + , host, peer_blocked_alert::ip_filter); return; } @@ -6197,7 +6197,7 @@ namespace libtorrent { if (m_ses.alerts().should_post()) m_ses.alerts().emplace_alert(get_handle() - , a.address(), peer_blocked_alert::ip_filter); + , a, peer_blocked_alert::ip_filter); return; } @@ -6275,7 +6275,7 @@ namespace libtorrent { if (m_ses.alerts().should_post()) m_ses.alerts().emplace_alert(get_handle() - , a.address(), peer_blocked_alert::ip_filter); + , a, peer_blocked_alert::ip_filter); return; } @@ -7313,7 +7313,7 @@ namespace libtorrent { if (m_ses.alerts().should_post()) m_ses.alerts().emplace_alert(get_handle() - , p->remote().address(), peer_blocked_alert::ip_filter); + , p->remote(), peer_blocked_alert::ip_filter); p->disconnect(errors::banned_by_ip_filter, op_bittorrent); return false; } @@ -10576,7 +10576,7 @@ namespace libtorrent { if (alerts().should_post()) alerts().emplace_alert(get_handle() - , adr.address(), peer_blocked_alert::ip_filter); + , adr, peer_blocked_alert::ip_filter); #ifndef TORRENT_DISABLE_EXTENSIONS notify_extension_add_peer(adr, source, torrent_plugin::filtered); @@ -10588,7 +10588,7 @@ namespace libtorrent { if (alerts().should_post()) alerts().emplace_alert(get_handle() - , adr.address(), peer_blocked_alert::port_filter); + , adr, peer_blocked_alert::port_filter); #ifndef TORRENT_DISABLE_EXTENSIONS notify_extension_add_peer(adr, source, torrent_plugin::filtered); #endif @@ -10602,7 +10602,7 @@ namespace libtorrent { if (alerts().should_post()) alerts().emplace_alert(get_handle() - , adr.address(), peer_blocked_alert::i2p_mixed); + , adr, peer_blocked_alert::i2p_mixed); return NULL; } #endif @@ -10611,7 +10611,7 @@ namespace libtorrent { if (alerts().should_post()) alerts().emplace_alert(get_handle() - , adr.address(), peer_blocked_alert::privileged_ports); + , adr, peer_blocked_alert::privileged_ports); #ifndef TORRENT_DISABLE_EXTENSIONS notify_extension_add_peer(adr, source, torrent_plugin::filtered); #endif @@ -10739,7 +10739,8 @@ namespace libtorrent { for (std::vector
::iterator i = banned.begin() , end(banned.end()); i != end; ++i) - alerts().emplace_alert(get_handle(), *i + alerts().emplace_alert(get_handle() + , tcp::endpoint(*i, 0) , peer_blocked_alert::ip_filter); } @@ -10759,7 +10760,8 @@ namespace libtorrent { for (std::vector
::iterator i = banned.begin() , end(banned.end()); i != end; ++i) - alerts().emplace_alert(get_handle(), *i + alerts().emplace_alert(get_handle() + , tcp::endpoint(*i, 0) , peer_blocked_alert::port_filter); }