From b56937f5fa451b55b8e983c1eceb0371a7d441d3 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 2 Dec 2018 14:03:15 +0800 Subject: [PATCH] Use QHostAddress for storing IP --- src/base/bittorrent/tracker.cpp | 6 +++--- src/base/bittorrent/tracker.h | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/base/bittorrent/tracker.cpp b/src/base/bittorrent/tracker.cpp index 601f06c38..dbb8bb7db 100644 --- a/src/base/bittorrent/tracker.cpp +++ b/src/base/bittorrent/tracker.cpp @@ -60,7 +60,7 @@ bool Peer::operator==(const Peer &other) const QString Peer::uid() const { - return ip + ':' + QString::number(port); + return ip.toString() + ':' + QString::number(port); } libtorrent::entry Peer::toEntry(bool noPeerId) const @@ -68,7 +68,7 @@ libtorrent::entry Peer::toEntry(bool noPeerId) const libtorrent::entry::dictionary_type peerMap; if (!noPeerId) peerMap["id"] = libtorrent::entry(peerId.toStdString()); - peerMap["ip"] = libtorrent::entry(ip.toStdString()); + peerMap["ip"] = libtorrent::entry(ip.toString().toStdString()); peerMap["port"] = libtorrent::entry(port); return libtorrent::entry(peerMap); @@ -148,7 +148,7 @@ void Tracker::respondToAnnounceRequest() TrackerAnnounceRequest annonceReq; // IP - annonceReq.peer.ip = m_env.clientAddress.toString(); + annonceReq.peer.ip = m_env.clientAddress; // 1. Get info_hash if (!queryParams.contains("info_hash")) { diff --git a/src/base/bittorrent/tracker.h b/src/base/bittorrent/tracker.h index 4ddcc7397..05aaebc0d 100644 --- a/src/base/bittorrent/tracker.h +++ b/src/base/bittorrent/tracker.h @@ -32,6 +32,7 @@ #include #include +#include #include "base/http/irequesthandler.h" #include "base/http/responsebuilder.h" @@ -51,7 +52,7 @@ namespace BitTorrent { struct Peer { - QString ip; + QHostAddress ip; QByteArray peerId; int port;