qBittorrent
BitTorrent::PeerAddress Struct Reference

#include <peeraddress.h>

Public Member Functions

QString toString () const
 

Static Public Member Functions

static PeerAddress parse (QStringView address)
 

Public Attributes

QHostAddress ip
 
ushort port = 0
 

Detailed Description

Definition at line 37 of file peeraddress.h.

Member Function Documentation

◆ parse()

PeerAddress PeerAddress::parse ( QStringView  address)
static

Definition at line 35 of file peeraddress.cpp.

36 {
37  QList<QStringView> ipPort;
38 
39  if (address.startsWith(u'[') && address.contains(QLatin1String("]:")))
40  { // IPv6
41  ipPort = address.split(QString::fromLatin1("]:"));
42  ipPort[0] = ipPort[0].mid(1); // chop '['
43  }
44  else if (address.contains(u':'))
45  { // IPv4
46  ipPort = address.split(u':');
47  }
48  else
49  {
50  return {};
51  }
52 
53  const QHostAddress ip {ipPort[0].toString()};
54  if (ip.isNull())
55  return {};
56 
57  const ushort port {ipPort[1].toUShort()};
58  if (port == 0)
59  return {};
60 
61  return {ip, port};
62 }

References ip, and port.

Referenced by TorrentsController::addPeersAction(), TransferController::banPeersAction(), and PeersAdditionDialog::validateInput().

Here is the caller graph for this function:

◆ toString()

QString PeerAddress::toString ( ) const

Definition at line 64 of file peeraddress.cpp.

65 {
66  if (ip.isNull())
67  return {};
68 
69  const QString ipStr = (ip.protocol() == QAbstractSocket::IPv6Protocol)
70  ? ('[' + ip.toString() + ']')
71  : ip.toString();
72  return (ipStr + ':' + QString::number(port));
73 }

References ip, and port.

Referenced by BitTorrent::TorrentImpl::connectPeer().

Here is the caller graph for this function:

Member Data Documentation

◆ ip

◆ port

ushort BitTorrent::PeerAddress::port = 0

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