mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-01 21:28:07 -06:00
Move error logging of adding peers to the proper place
This commit is contained in:
@@ -30,7 +30,9 @@
|
||||
|
||||
#include <QString>
|
||||
|
||||
BitTorrent::PeerAddress BitTorrent::PeerAddress::parse(const QString &address)
|
||||
using namespace BitTorrent;
|
||||
|
||||
PeerAddress PeerAddress::parse(const QString &address)
|
||||
{
|
||||
QVector<QStringRef> ipPort;
|
||||
|
||||
@@ -55,3 +57,14 @@ BitTorrent::PeerAddress BitTorrent::PeerAddress::parse(const QString &address)
|
||||
|
||||
return {ip, port};
|
||||
}
|
||||
|
||||
QString PeerAddress::toString() const
|
||||
{
|
||||
if (ip.isNull())
|
||||
return {};
|
||||
|
||||
const QString ipStr = (ip.protocol() == QAbstractSocket::IPv6Protocol)
|
||||
? ('[' + ip.toString() + ']')
|
||||
: ip.toString();
|
||||
return (ipStr + ':' + QString::number(port));
|
||||
}
|
||||
|
||||
@@ -40,5 +40,6 @@ namespace BitTorrent
|
||||
ushort port = 0;
|
||||
|
||||
static PeerAddress parse(const QString &address);
|
||||
QString toString() const;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -537,11 +537,28 @@ void TorrentHandle::removeUrlSeeds(const QVector<QUrl> &urlSeeds)
|
||||
bool TorrentHandle::connectPeer(const PeerAddress &peerAddress)
|
||||
{
|
||||
lt::error_code ec;
|
||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
||||
const lt::address addr = lt::address::from_string(peerAddress.ip.toString().toStdString(), ec);
|
||||
#else
|
||||
const lt::address addr = lt::make_address(peerAddress.ip.toString().toStdString(), ec);
|
||||
#endif
|
||||
if (ec) return false;
|
||||
|
||||
const boost::asio::ip::tcp::endpoint ep(addr, peerAddress.port);
|
||||
m_nativeHandle.connect_peer(ep);
|
||||
const lt::tcp::endpoint endpoint(addr, peerAddress.port);
|
||||
try {
|
||||
m_nativeHandle.connect_peer(endpoint);
|
||||
}
|
||||
#if (LIBTORRENT_VERSION_NUM < 10200)
|
||||
catch (const boost::system::system_error &err) {
|
||||
#else
|
||||
catch (const lt::system_error &err) {
|
||||
#endif
|
||||
LogMsg(tr("Failed to add peer \"%1\" to torrent \"%2\". Reason: %3")
|
||||
.arg(peerAddress.toString(), name(), QString::fromLocal8Bit(err.what())), Log::WARNING);
|
||||
return false;
|
||||
}
|
||||
|
||||
LogMsg(tr("Peer \"%1\" is added to torrent \"%2\"").arg(peerAddress.toString(), name()));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user