mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-11 07:18:08 +00:00
Merge pull request #10963 from glassez/peeraddress
Extract PeerAddress class into separate file
This commit is contained in:
commit
431ab095e8
@ -7,6 +7,7 @@ bittorrent/cachestatus.h
|
||||
bittorrent/downloadpriority.h
|
||||
bittorrent/infohash.h
|
||||
bittorrent/magneturi.h
|
||||
bittorrent/peeraddress.h
|
||||
bittorrent/peerinfo.h
|
||||
bittorrent/private/bandwidthscheduler.h
|
||||
bittorrent/private/filterparserthread.h
|
||||
@ -81,6 +82,7 @@ unicodestrings.h
|
||||
bittorrent/downloadpriority.cpp
|
||||
bittorrent/infohash.cpp
|
||||
bittorrent/magneturi.cpp
|
||||
bittorrent/peeraddress.cpp
|
||||
bittorrent/peerinfo.cpp
|
||||
bittorrent/private/bandwidthscheduler.cpp
|
||||
bittorrent/private/filterparserthread.cpp
|
||||
|
@ -6,6 +6,7 @@ HEADERS += \
|
||||
$$PWD/bittorrent/downloadpriority.h \
|
||||
$$PWD/bittorrent/infohash.h \
|
||||
$$PWD/bittorrent/magneturi.h \
|
||||
$$PWD/bittorrent/peeraddress.h \
|
||||
$$PWD/bittorrent/peerinfo.h \
|
||||
$$PWD/bittorrent/private/bandwidthscheduler.h \
|
||||
$$PWD/bittorrent/private/filterparserthread.h \
|
||||
@ -80,6 +81,7 @@ SOURCES += \
|
||||
$$PWD/bittorrent/downloadpriority.cpp \
|
||||
$$PWD/bittorrent/infohash.cpp \
|
||||
$$PWD/bittorrent/magneturi.cpp \
|
||||
$$PWD/bittorrent/peeraddress.cpp \
|
||||
$$PWD/bittorrent/peerinfo.cpp \
|
||||
$$PWD/bittorrent/private/bandwidthscheduler.cpp \
|
||||
$$PWD/bittorrent/private/filterparserthread.cpp \
|
||||
|
58
src/base/bittorrent/peeraddress.cpp
Normal file
58
src/base/bittorrent/peeraddress.cpp
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Bittorrent Client using Qt and libtorrent.
|
||||
* Copyright (C) 2019 Vladimir Golovnev <glassez@yandex.ru>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give permission to
|
||||
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
||||
* modified versions of it that use the same license as the "OpenSSL" library),
|
||||
* and distribute the linked executables. You must obey the GNU General Public
|
||||
* License in all respects for all of the code used other than "OpenSSL". If you
|
||||
* modify file(s), you may extend this exception to your version of the file(s),
|
||||
* but you are not obligated to do so. If you do not wish to do so, delete this
|
||||
* exception statement from your version.
|
||||
*/
|
||||
|
||||
#include "peeraddress.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
BitTorrent::PeerAddress BitTorrent::PeerAddress::parse(QString peerAddressStr)
|
||||
{
|
||||
PeerAddress addr;
|
||||
QStringList ipPort;
|
||||
|
||||
if ((peerAddressStr[0] == '[') && (peerAddressStr.indexOf("]:") != -1)) // IPv6
|
||||
ipPort = peerAddressStr.remove(QChar('[')).split("]:");
|
||||
else if (peerAddressStr.indexOf(':') != -1) // IPv4
|
||||
ipPort = peerAddressStr.split(':');
|
||||
else
|
||||
return addr;
|
||||
|
||||
QHostAddress ip(ipPort[0]);
|
||||
if (ip.isNull())
|
||||
return addr;
|
||||
|
||||
bool ok;
|
||||
int port = ipPort[1].toInt(&ok);
|
||||
if (!ok || (port < 1) || (port > 65535))
|
||||
return addr;
|
||||
|
||||
addr.ip = ip;
|
||||
addr.port = port;
|
||||
return addr;
|
||||
}
|
44
src/base/bittorrent/peeraddress.h
Normal file
44
src/base/bittorrent/peeraddress.h
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Bittorrent Client using Qt and libtorrent.
|
||||
* Copyright (C) 2019 Vladimir Golovnev <glassez@yandex.ru>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give permission to
|
||||
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
||||
* modified versions of it that use the same license as the "OpenSSL" library),
|
||||
* and distribute the linked executables. You must obey the GNU General Public
|
||||
* License in all respects for all of the code used other than "OpenSSL". If you
|
||||
* modify file(s), you may extend this exception to your version of the file(s),
|
||||
* but you are not obligated to do so. If you do not wish to do so, delete this
|
||||
* exception statement from your version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QHostAddress>
|
||||
|
||||
class QString;
|
||||
|
||||
namespace BitTorrent
|
||||
{
|
||||
struct PeerAddress
|
||||
{
|
||||
QHostAddress ip;
|
||||
ushort port = 0;
|
||||
|
||||
static PeerAddress parse(QString peerAddressStr);
|
||||
};
|
||||
}
|
@ -34,24 +34,10 @@
|
||||
#include "base/net/geoipmanager.h"
|
||||
#include "base/unicodestrings.h"
|
||||
#include "base/utils/string.h"
|
||||
#include "peeraddress.h"
|
||||
|
||||
using namespace BitTorrent;
|
||||
|
||||
// PeerAddress
|
||||
|
||||
PeerAddress::PeerAddress()
|
||||
: port(0)
|
||||
{
|
||||
}
|
||||
|
||||
PeerAddress::PeerAddress(const QHostAddress &ip, ushort port)
|
||||
: ip(ip)
|
||||
, port(port)
|
||||
{
|
||||
}
|
||||
|
||||
// PeerInfo
|
||||
|
||||
PeerInfo::PeerInfo(const TorrentHandle *torrent, const lt::peer_info &nativeInfo)
|
||||
: m_nativeInfo(nativeInfo)
|
||||
{
|
||||
@ -183,8 +169,8 @@ bool PeerInfo::isPlaintextEncrypted() const
|
||||
|
||||
PeerAddress PeerInfo::address() const
|
||||
{
|
||||
return PeerAddress(QHostAddress(QString::fromStdString(m_nativeInfo.ip.address().to_string())),
|
||||
m_nativeInfo.ip.port());
|
||||
return {QHostAddress(QString::fromStdString(m_nativeInfo.ip.address().to_string()))
|
||||
, m_nativeInfo.ip.port()};
|
||||
}
|
||||
|
||||
QString PeerInfo::client() const
|
||||
|
@ -39,15 +39,7 @@ class QBitArray;
|
||||
namespace BitTorrent
|
||||
{
|
||||
class TorrentHandle;
|
||||
|
||||
struct PeerAddress
|
||||
{
|
||||
QHostAddress ip;
|
||||
ushort port;
|
||||
|
||||
PeerAddress();
|
||||
PeerAddress(const QHostAddress &ip, ushort port);
|
||||
};
|
||||
struct PeerAddress;
|
||||
|
||||
class PeerInfo
|
||||
{
|
||||
|
@ -65,6 +65,7 @@
|
||||
#include "base/utils/fs.h"
|
||||
#include "base/utils/string.h"
|
||||
#include "downloadpriority.h"
|
||||
#include "peeraddress.h"
|
||||
#include "peerinfo.h"
|
||||
#include "session.h"
|
||||
#include "trackerentry.h"
|
||||
|
@ -40,6 +40,7 @@
|
||||
#include <QTableView>
|
||||
#include <QWheelEvent>
|
||||
|
||||
#include "base/bittorrent/peeraddress.h"
|
||||
#include "base/bittorrent/peerinfo.h"
|
||||
#include "base/bittorrent/session.h"
|
||||
#include "base/bittorrent/torrenthandle.h"
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include <QHostAddress>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "base/bittorrent/peeraddress.h"
|
||||
#include "base/global.h"
|
||||
#include "ui_peersadditiondialog.h"
|
||||
|
||||
@ -63,7 +64,7 @@ void PeersAdditionDialog::validateInput()
|
||||
return;
|
||||
}
|
||||
for (const QString &peer : asConst(m_ui->textEditPeers->toPlainText().trimmed().split('\n'))) {
|
||||
BitTorrent::PeerAddress addr = parsePeer(peer);
|
||||
const BitTorrent::PeerAddress addr = BitTorrent::PeerAddress::parse(peer);
|
||||
if (!addr.ip.isNull()) {
|
||||
m_peersList.append(addr);
|
||||
}
|
||||
@ -77,29 +78,3 @@ void PeersAdditionDialog::validateInput()
|
||||
}
|
||||
accept();
|
||||
}
|
||||
|
||||
BitTorrent::PeerAddress PeersAdditionDialog::parsePeer(QString peer)
|
||||
{
|
||||
BitTorrent::PeerAddress addr;
|
||||
QStringList ipPort;
|
||||
|
||||
if ((peer[0] == '[') && (peer.indexOf("]:") != -1)) // IPv6
|
||||
ipPort = peer.remove(QChar('[')).split("]:");
|
||||
else if (peer.indexOf(':') != -1) // IPv4
|
||||
ipPort = peer.split(':');
|
||||
else
|
||||
return addr;
|
||||
|
||||
QHostAddress ip(ipPort[0]);
|
||||
if (ip.isNull())
|
||||
return addr;
|
||||
|
||||
bool ok;
|
||||
int port = ipPort[1].toInt(&ok);
|
||||
if (!ok || (port < 1) || (port > 65535))
|
||||
return addr;
|
||||
|
||||
addr.ip = ip;
|
||||
addr.port = port;
|
||||
return addr;
|
||||
}
|
||||
|
@ -53,8 +53,6 @@ protected slots:
|
||||
void validateInput();
|
||||
|
||||
private:
|
||||
BitTorrent::PeerAddress parsePeer(QString peer);
|
||||
|
||||
Ui::PeersAdditionDialog *m_ui;
|
||||
QList<BitTorrent::PeerAddress> m_peersList;
|
||||
};
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include <QMetaObject>
|
||||
#include <QThread>
|
||||
|
||||
#include "base/bittorrent/peeraddress.h"
|
||||
#include "base/bittorrent/peerinfo.h"
|
||||
#include "base/bittorrent/session.h"
|
||||
#include "base/bittorrent/torrenthandle.h"
|
||||
|
Loading…
Reference in New Issue
Block a user