qBittorrent
BitTorrent::PeerInfo Class Reference

#include <peerinfo.h>

Public Member Functions

 PeerInfo ()=default
 
 PeerInfo (const Torrent *torrent, const lt::peer_info &nativeInfo)
 
bool fromDHT () const
 
bool fromPeX () const
 
bool fromLSD () const
 
bool isInteresting () const
 
bool isChocked () const
 
bool isRemoteInterested () const
 
bool isRemoteChocked () const
 
bool isSupportsExtensions () const
 
bool isLocalConnection () const
 
bool isHandshake () const
 
bool isConnecting () const
 
bool isOnParole () const
 
bool isSeed () const
 
bool optimisticUnchoke () const
 
bool isSnubbed () const
 
bool isUploadOnly () const
 
bool isEndgameMode () const
 
bool isHolepunched () const
 
bool useI2PSocket () const
 
bool useUTPSocket () const
 
bool useSSLSocket () const
 
bool isRC4Encrypted () const
 
bool isPlaintextEncrypted () const
 
PeerAddress address () const
 
QString client () const
 
qreal progress () const
 
int payloadUpSpeed () const
 
int payloadDownSpeed () const
 
qlonglong totalUpload () const
 
qlonglong totalDownload () const
 
QBitArray pieces () const
 
QString connectionType () const
 
qreal relevance () const
 
QString flags () const
 
QString flagsDescription () const
 
QString country () const
 
int downloadingPieceIndex () const
 

Private Member Functions

void calcRelevance (const Torrent *torrent)
 
void determineFlags ()
 

Private Attributes

lt::peer_info m_nativeInfo = {}
 
qreal m_relevance = 0
 
QString m_flags
 
QString m_flagsDescription
 
QString m_country
 

Detailed Description

Definition at line 42 of file peerinfo.h.

Constructor & Destructor Documentation

◆ PeerInfo() [1/2]

BitTorrent::PeerInfo::PeerInfo ( )
default

◆ PeerInfo() [2/2]

PeerInfo::PeerInfo ( const Torrent torrent,
const lt::peer_info &  nativeInfo 
)

Definition at line 40 of file peerinfo.cpp.

41  : m_nativeInfo(nativeInfo)
42 {
43  calcRelevance(torrent);
45 }
lt::peer_info m_nativeInfo
Definition: peerinfo.h:98
void calcRelevance(const Torrent *torrent)
Definition: peerinfo.cpp:229

References calcRelevance(), and determineFlags().

Here is the call graph for this function:

Member Function Documentation

◆ address()

PeerAddress PeerInfo::address ( ) const

Definition at line 169 of file peerinfo.cpp.

170 {
171  // fast path for platforms which boost.asio internal struct maps to `sockaddr`
172  return {QHostAddress(m_nativeInfo.ip.data()), m_nativeInfo.ip.port()};
173  // slow path for the others
174  //return {QHostAddress(QString::fromStdString(m_nativeInfo.ip.address().to_string()))
175  // , m_nativeInfo.ip.port()};
176 }

References m_nativeInfo.

Referenced by country(), and PeerListWidget::updatePeer().

Here is the caller graph for this function:

◆ calcRelevance()

void PeerInfo::calcRelevance ( const Torrent torrent)
private

Definition at line 229 of file peerinfo.cpp.

230 {
231  const QBitArray allPieces = torrent->pieces();
232  const QBitArray peerPieces = pieces();
233 
234  int localMissing = 0;
235  int remoteHaves = 0;
236 
237  for (int i = 0; i < allPieces.size(); ++i)
238  {
239  if (!allPieces[i])
240  {
241  ++localMissing;
242  if (peerPieces[i])
243  ++remoteHaves;
244  }
245  }
246 
247  if (localMissing == 0)
248  m_relevance = 0.0;
249  else
250  m_relevance = static_cast<qreal>(remoteHaves) / localMissing;
251 }
QBitArray pieces() const
Definition: peerinfo.cpp:208
virtual QBitArray pieces() const =0

References m_relevance, pieces(), and BitTorrent::Torrent::pieces().

Referenced by PeerInfo().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ client()

QString PeerInfo::client ( ) const

Definition at line 178 of file peerinfo.cpp.

179 {
180  return QString::fromStdString(m_nativeInfo.client);
181 }

References m_nativeInfo.

Referenced by PeerListWidget::updatePeer().

Here is the caller graph for this function:

◆ connectionType()

QString PeerInfo::connectionType ( ) const

Definition at line 219 of file peerinfo.cpp.

220 {
221  if (m_nativeInfo.flags & lt::peer_info::utp_socket)
222  return QString::fromUtf8(C_UTP);
223 
224  return (m_nativeInfo.connection_type == lt::peer_info::standard_bittorrent)
225  ? QLatin1String {"BT"}
226  : QLatin1String {"Web"};
227 }
const char C_UTP[]

References C_UTP, and m_nativeInfo.

Referenced by PeerListWidget::updatePeer().

Here is the caller graph for this function:

◆ country()

QString PeerInfo::country ( ) const

Definition at line 62 of file peerinfo.cpp.

63 {
64  if (m_country.isEmpty())
66  return m_country;
67 }
PeerAddress address() const
Definition: peerinfo.cpp:169
static GeoIPManager * instance()
QString lookup(const QHostAddress &hostAddr) const

References address(), Net::GeoIPManager::instance(), Net::GeoIPManager::lookup(), and m_country.

Referenced by PeerListWidget::updatePeer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ determineFlags()

void PeerInfo::determineFlags ( )
private

Definition at line 258 of file peerinfo.cpp.

259 {
260  const auto updateFlags = [this](const QChar specifier, const QString &explanation)
261  {
262  m_flags += (specifier + QLatin1Char(' '));
263  m_flagsDescription += QString::fromLatin1("%1 = %2\n").arg(specifier, explanation);
264  };
265 
266  if (isInteresting())
267  {
268  if (isRemoteChocked())
269  {
270  // d = Your client wants to download, but peer doesn't want to send (interested and choked)
271  updateFlags(QLatin1Char('d'), tr("Interested (local) and choked (peer)"));
272  }
273  else
274  {
275  // D = Currently downloading (interested and not choked)
276  updateFlags(QLatin1Char('D'), tr("Interested (local) and unchoked (peer)"));
277  }
278  }
279 
280  if (isRemoteInterested())
281  {
282  if (isChocked())
283  {
284  // u = Peer wants your client to upload, but your client doesn't want to (interested and choked)
285  updateFlags(QLatin1Char('u'), tr("Interested (peer) and choked (local)"));
286  }
287  else
288  {
289  // U = Currently uploading (interested and not choked)
290  updateFlags(QLatin1Char('U'), tr("Interested (peer) and unchoked (local)"));
291  }
292  }
293 
294  // K = Peer is unchoking your client, but your client is not interested
295  if (!isRemoteChocked() && !isInteresting())
296  updateFlags(QLatin1Char('K'), tr("Not interested (local) and unchoked (peer)"));
297 
298  // ? = Your client unchoked the peer but the peer is not interested
299  if (!isChocked() && !isRemoteInterested())
300  updateFlags(QLatin1Char('?'), tr("Not interested (peer) and unchoked (local)"));
301 
302  // O = Optimistic unchoke
303  if (optimisticUnchoke())
304  updateFlags(QLatin1Char('O'), tr("Optimistic unchoke"));
305 
306  // S = Peer is snubbed
307  if (isSnubbed())
308  updateFlags(QLatin1Char('S'), tr("Peer snubbed"));
309 
310  // I = Peer is an incoming connection
311  if (!isLocalConnection())
312  updateFlags(QLatin1Char('I'), tr("Incoming connection"));
313 
314  // H = Peer was obtained through DHT
315  if (fromDHT())
316  updateFlags(QLatin1Char('H'), tr("Peer from DHT"));
317 
318  // X = Peer was included in peerlists obtained through Peer Exchange (PEX)
319  if (fromPeX())
320  updateFlags(QLatin1Char('X'), tr("Peer from PEX"));
321 
322  // L = Peer is local
323  if (fromLSD())
324  updateFlags(QLatin1Char('L'), tr("Peer from LSD"));
325 
326  // E = Peer is using Protocol Encryption (all traffic)
327  if (isRC4Encrypted())
328  updateFlags(QLatin1Char('E'), tr("Encrypted traffic"));
329 
330  // e = Peer is using Protocol Encryption (handshake)
331  if (isPlaintextEncrypted())
332  updateFlags(QLatin1Char('e'), tr("Encrypted handshake"));
333 
334  // P = Peer is using uTorrent uTP
335  if (useUTPSocket())
336  updateFlags(QLatin1Char('P'), QString::fromUtf8(C_UTP));
337 
338  m_flags.chop(1);
339  m_flagsDescription.chop(1);
340 }
bool useUTPSocket() const
Definition: peerinfo.cpp:149
bool isRemoteInterested() const
Definition: peerinfo.cpp:79
bool isLocalConnection() const
Definition: peerinfo.cpp:94
bool fromPeX() const
Definition: peerinfo.cpp:52
bool isInteresting() const
Definition: peerinfo.cpp:69
bool isRC4Encrypted() const
Definition: peerinfo.cpp:159
bool isSnubbed() const
Definition: peerinfo.cpp:124
bool fromLSD() const
Definition: peerinfo.cpp:57
bool isPlaintextEncrypted() const
Definition: peerinfo.cpp:164
bool fromDHT() const
Definition: peerinfo.cpp:47
bool isRemoteChocked() const
Definition: peerinfo.cpp:84
bool optimisticUnchoke() const
Definition: peerinfo.cpp:119
bool isChocked() const
Definition: peerinfo.cpp:74
QString m_flagsDescription
Definition: peerinfo.h:101

References C_UTP, fromDHT(), fromLSD(), fromPeX(), isChocked(), isInteresting(), isLocalConnection(), isPlaintextEncrypted(), isRC4Encrypted(), isRemoteChocked(), isRemoteInterested(), isSnubbed(), m_flags, m_flagsDescription, optimisticUnchoke(), and useUTPSocket().

Referenced by PeerInfo().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ downloadingPieceIndex()

int PeerInfo::downloadingPieceIndex ( ) const

Definition at line 352 of file peerinfo.cpp.

353 {
354  return static_cast<int>(m_nativeInfo.downloading_piece_index);
355 }

References m_nativeInfo.

Referenced by PeerListWidget::updatePeer().

Here is the caller graph for this function:

◆ flags()

QString PeerInfo::flags ( ) const

Definition at line 342 of file peerinfo.cpp.

343 {
344  return m_flags;
345 }

References m_flags.

Referenced by PeerListWidget::updatePeer().

Here is the caller graph for this function:

◆ flagsDescription()

QString PeerInfo::flagsDescription ( ) const

Definition at line 347 of file peerinfo.cpp.

348 {
349  return m_flagsDescription;
350 }

References m_flagsDescription.

Referenced by PeerListWidget::updatePeer().

Here is the caller graph for this function:

◆ fromDHT()

bool PeerInfo::fromDHT ( ) const

Definition at line 47 of file peerinfo.cpp.

48 {
49  return static_cast<bool>(m_nativeInfo.source & lt::peer_info::dht);
50 }

References m_nativeInfo.

Referenced by determineFlags().

Here is the caller graph for this function:

◆ fromLSD()

bool PeerInfo::fromLSD ( ) const

Definition at line 57 of file peerinfo.cpp.

58 {
59  return static_cast<bool>(m_nativeInfo.source & lt::peer_info::lsd);
60 }

References m_nativeInfo.

Referenced by determineFlags().

Here is the caller graph for this function:

◆ fromPeX()

bool PeerInfo::fromPeX ( ) const

Definition at line 52 of file peerinfo.cpp.

53 {
54  return static_cast<bool>(m_nativeInfo.source & lt::peer_info::pex);
55 }

References m_nativeInfo.

Referenced by determineFlags().

Here is the caller graph for this function:

◆ isChocked()

bool PeerInfo::isChocked ( ) const

Definition at line 74 of file peerinfo.cpp.

75 {
76  return static_cast<bool>(m_nativeInfo.flags & lt::peer_info::choked);
77 }

References m_nativeInfo.

Referenced by determineFlags().

Here is the caller graph for this function:

◆ isConnecting()

bool PeerInfo::isConnecting ( ) const

Definition at line 104 of file peerinfo.cpp.

105 {
106  return static_cast<bool>(m_nativeInfo.flags & lt::peer_info::connecting);
107 }

References m_nativeInfo.

◆ isEndgameMode()

bool PeerInfo::isEndgameMode ( ) const

Definition at line 134 of file peerinfo.cpp.

135 {
136  return static_cast<bool>(m_nativeInfo.flags & lt::peer_info::endgame_mode);
137 }

References m_nativeInfo.

◆ isHandshake()

bool PeerInfo::isHandshake ( ) const

Definition at line 99 of file peerinfo.cpp.

100 {
101  return static_cast<bool>(m_nativeInfo.flags & lt::peer_info::handshake);
102 }

References m_nativeInfo.

◆ isHolepunched()

bool PeerInfo::isHolepunched ( ) const

Definition at line 139 of file peerinfo.cpp.

140 {
141  return static_cast<bool>(m_nativeInfo.flags & lt::peer_info::holepunched);
142 }

References m_nativeInfo.

◆ isInteresting()

bool PeerInfo::isInteresting ( ) const

Definition at line 69 of file peerinfo.cpp.

70 {
71  return static_cast<bool>(m_nativeInfo.flags & lt::peer_info::interesting);
72 }

References nova3.sgmllib3::interesting, and m_nativeInfo.

Referenced by determineFlags().

Here is the caller graph for this function:

◆ isLocalConnection()

bool PeerInfo::isLocalConnection ( ) const

Definition at line 94 of file peerinfo.cpp.

95 {
96  return static_cast<bool>(m_nativeInfo.flags & lt::peer_info::local_connection);
97 }

References m_nativeInfo.

Referenced by determineFlags().

Here is the caller graph for this function:

◆ isOnParole()

bool PeerInfo::isOnParole ( ) const

Definition at line 109 of file peerinfo.cpp.

110 {
111  return static_cast<bool>(m_nativeInfo.flags & lt::peer_info::on_parole);
112 }

References m_nativeInfo.

◆ isPlaintextEncrypted()

bool PeerInfo::isPlaintextEncrypted ( ) const

Definition at line 164 of file peerinfo.cpp.

165 {
166  return static_cast<bool>(m_nativeInfo.flags & lt::peer_info::plaintext_encrypted);
167 }

References m_nativeInfo.

Referenced by determineFlags().

Here is the caller graph for this function:

◆ isRC4Encrypted()

bool PeerInfo::isRC4Encrypted ( ) const

Definition at line 159 of file peerinfo.cpp.

160 {
161  return static_cast<bool>(m_nativeInfo.flags & lt::peer_info::rc4_encrypted);
162 }

References m_nativeInfo.

Referenced by determineFlags().

Here is the caller graph for this function:

◆ isRemoteChocked()

bool PeerInfo::isRemoteChocked ( ) const

Definition at line 84 of file peerinfo.cpp.

85 {
86  return static_cast<bool>(m_nativeInfo.flags & lt::peer_info::remote_choked);
87 }

References m_nativeInfo.

Referenced by determineFlags().

Here is the caller graph for this function:

◆ isRemoteInterested()

bool PeerInfo::isRemoteInterested ( ) const

Definition at line 79 of file peerinfo.cpp.

80 {
81  return static_cast<bool>(m_nativeInfo.flags & lt::peer_info::remote_interested);
82 }

References m_nativeInfo.

Referenced by determineFlags().

Here is the caller graph for this function:

◆ isSeed()

bool PeerInfo::isSeed ( ) const

Definition at line 114 of file peerinfo.cpp.

115 {
116  return static_cast<bool>(m_nativeInfo.flags & lt::peer_info::seed);
117 }

References m_nativeInfo.

◆ isSnubbed()

bool PeerInfo::isSnubbed ( ) const

Definition at line 124 of file peerinfo.cpp.

125 {
126  return static_cast<bool>(m_nativeInfo.flags & lt::peer_info::snubbed);
127 }

References m_nativeInfo.

Referenced by determineFlags().

Here is the caller graph for this function:

◆ isSupportsExtensions()

bool PeerInfo::isSupportsExtensions ( ) const

Definition at line 89 of file peerinfo.cpp.

90 {
91  return static_cast<bool>(m_nativeInfo.flags & lt::peer_info::supports_extensions);
92 }

References m_nativeInfo.

◆ isUploadOnly()

bool PeerInfo::isUploadOnly ( ) const

Definition at line 129 of file peerinfo.cpp.

130 {
131  return static_cast<bool>(m_nativeInfo.flags & lt::peer_info::upload_only);
132 }

References m_nativeInfo.

◆ optimisticUnchoke()

bool PeerInfo::optimisticUnchoke ( ) const

Definition at line 119 of file peerinfo.cpp.

120 {
121  return static_cast<bool>(m_nativeInfo.flags & lt::peer_info::optimistic_unchoke);
122 }

References m_nativeInfo.

Referenced by determineFlags().

Here is the caller graph for this function:

◆ payloadDownSpeed()

int PeerInfo::payloadDownSpeed ( ) const

Definition at line 193 of file peerinfo.cpp.

194 {
195  return m_nativeInfo.payload_down_speed;
196 }

References m_nativeInfo.

Referenced by PeerListWidget::updatePeer().

Here is the caller graph for this function:

◆ payloadUpSpeed()

int PeerInfo::payloadUpSpeed ( ) const

Definition at line 188 of file peerinfo.cpp.

189 {
190  return m_nativeInfo.payload_up_speed;
191 }

References m_nativeInfo.

Referenced by PeerListWidget::updatePeer().

Here is the caller graph for this function:

◆ pieces()

QBitArray PeerInfo::pieces ( ) const

Definition at line 208 of file peerinfo.cpp.

209 {
210  QBitArray result(m_nativeInfo.pieces.size());
211  for (int i = 0; i < result.size(); ++i)
212  {
213  if (m_nativeInfo.pieces[lt::piece_index_t {i}])
214  result.setBit(i, true);
215  }
216  return result;
217 }

References m_nativeInfo.

Referenced by calcRelevance().

Here is the caller graph for this function:

◆ progress()

qreal PeerInfo::progress ( ) const

Definition at line 183 of file peerinfo.cpp.

184 {
185  return m_nativeInfo.progress;
186 }

References m_nativeInfo.

Referenced by PeerListWidget::updatePeer().

Here is the caller graph for this function:

◆ relevance()

qreal PeerInfo::relevance ( ) const

Definition at line 253 of file peerinfo.cpp.

254 {
255  return m_relevance;
256 }

References m_relevance.

Referenced by PeerListWidget::updatePeer().

Here is the caller graph for this function:

◆ totalDownload()

qlonglong PeerInfo::totalDownload ( ) const

Definition at line 203 of file peerinfo.cpp.

204 {
205  return m_nativeInfo.total_download;
206 }

References m_nativeInfo.

Referenced by PeerListWidget::updatePeer().

Here is the caller graph for this function:

◆ totalUpload()

qlonglong PeerInfo::totalUpload ( ) const

Definition at line 198 of file peerinfo.cpp.

199 {
200  return m_nativeInfo.total_upload;
201 }

References m_nativeInfo.

Referenced by PeerListWidget::updatePeer().

Here is the caller graph for this function:

◆ useI2PSocket()

bool PeerInfo::useI2PSocket ( ) const

Definition at line 144 of file peerinfo.cpp.

145 {
146  return static_cast<bool>(m_nativeInfo.flags & lt::peer_info::i2p_socket);
147 }

References m_nativeInfo.

◆ useSSLSocket()

bool PeerInfo::useSSLSocket ( ) const

Definition at line 154 of file peerinfo.cpp.

155 {
156  return static_cast<bool>(m_nativeInfo.flags & lt::peer_info::ssl_socket);
157 }

References m_nativeInfo.

◆ useUTPSocket()

bool PeerInfo::useUTPSocket ( ) const

Definition at line 149 of file peerinfo.cpp.

150 {
151  return static_cast<bool>(m_nativeInfo.flags & lt::peer_info::utp_socket);
152 }

References m_nativeInfo.

Referenced by determineFlags().

Here is the caller graph for this function:

Member Data Documentation

◆ m_country

QString BitTorrent::PeerInfo::m_country
mutableprivate

Definition at line 103 of file peerinfo.h.

Referenced by country().

◆ m_flags

QString BitTorrent::PeerInfo::m_flags
private

Definition at line 100 of file peerinfo.h.

Referenced by determineFlags(), and flags().

◆ m_flagsDescription

QString BitTorrent::PeerInfo::m_flagsDescription
private

Definition at line 101 of file peerinfo.h.

Referenced by determineFlags(), and flagsDescription().

◆ m_nativeInfo

◆ m_relevance

qreal BitTorrent::PeerInfo::m_relevance = 0
private

Definition at line 99 of file peerinfo.h.

Referenced by calcRelevance(), and relevance().


The documentation for this class was generated from the following files: