KanoopTorrentQt 0.1.0
Qt6 wrapper library for libtorrent-rasterbar
Loading...
Searching...
No Matches
peerinfo.h
1#ifndef PEERINFO_H
2#define PEERINFO_H
3
4#include <Kanoop/torrent/kanooptorrent.h>
5#include <QHostAddress>
6#include <QString>
7
8/**
9 * @brief Snapshot of a connected peer's state.
10 *
11 * PeerInfo is a lightweight value class populated by Torrent::peers().
12 * Each instance captures a point-in-time view of one peer connection
13 * including transfer rates, identification, and capability flags.
14 */
15class LIBKANOOPTORRENT_EXPORT PeerInfo
16{
17public:
18 /**
19 * @brief Capability and state flags for a peer connection.
20 *
21 * These flags can be combined with bitwise OR.
22 */
23 enum Flag {
24 NoFlags = 0x0000,
25 Interesting = 0x0001, ///< We are interested in pieces this peer has.
26 Choked = 0x0002, ///< We are choking this peer (not uploading to it).
27 RemoteChoked = 0x0004, ///< This peer is choking us (not uploading to us).
28 Seed = 0x0008, ///< Peer has the complete torrent.
29 Encrypted = 0x0010, ///< Connection is encrypted (RC4 or AES).
30 Incoming = 0x0020, ///< Peer initiated the connection.
31 Snubbed = 0x0040, ///< Peer has not sent data for a long time.
32 UploadOnly = 0x0080, ///< Peer is in upload-only mode (e.g. super-seeding).
33 };
34 Q_DECLARE_FLAGS(Flags, Flag)
35
36 PeerInfo() = default;
37
38 // ── Identity ────────────────────────────────────────────────────────
39
40 /** @brief Peer's IP address. */
41 QHostAddress address() const { return _address; }
42 void setAddress(const QHostAddress& value) { _address = value; }
43
44 /** @brief Peer's TCP port. */
45 quint16 port() const { return _port; }
46 void setPort(quint16 value) { _port = value; }
47
48 /**
49 * @brief Peer's client identification string (e.g. "qBittorrent 4.6.2").
50 *
51 * Derived from the peer's extension handshake or peer ID encoding.
52 */
53 QString client() const { return _client; }
54 void setClient(const QString& value) { _client = value; }
55
56 // ── Transfer ────────────────────────────────────────────────────────
57
58 /** @brief Current download rate from this peer in bytes/sec. */
59 qint64 downloadRate() const { return _downloadRate; }
60 void setDownloadRate(qint64 value) { _downloadRate = value; }
61
62 /** @brief Current upload rate to this peer in bytes/sec. */
63 qint64 uploadRate() const { return _uploadRate; }
64 void setUploadRate(qint64 value) { _uploadRate = value; }
65
66 /** @brief Total bytes downloaded from this peer. */
67 qint64 totalDownload() const { return _totalDownload; }
68 void setTotalDownload(qint64 value) { _totalDownload = value; }
69
70 /** @brief Total bytes uploaded to this peer. */
71 qint64 totalUpload() const { return _totalUpload; }
72 void setTotalUpload(qint64 value) { _totalUpload = value; }
73
74 // ── Progress ────────────────────────────────────────────────────────
75
76 /** @brief Peer's download progress as a ratio from 0.0 to 1.0. */
77 double progress() const { return _progress; }
78 void setProgress(double value) { _progress = value; }
79
80 // ── Flags ───────────────────────────────────────────────────────────
81
82 /** @brief Capability and state flags for this connection. */
83 Flags flags() const { return _flags; }
84 void setFlags(Flags value) { _flags = value; }
85
86private:
87 QHostAddress _address;
88 quint16 _port = 0;
89 QString _client;
90 qint64 _downloadRate = 0;
91 qint64 _uploadRate = 0;
92 qint64 _totalDownload = 0;
93 qint64 _totalUpload = 0;
94 double _progress = 0.0;
95 Flags _flags = NoFlags;
96};
97
98Q_DECLARE_OPERATORS_FOR_FLAGS(PeerInfo::Flags)
99
100#endif // PEERINFO_H
Snapshot of a connected peer's state.
Definition peerinfo.h:16
qint64 downloadRate() const
Current download rate from this peer in bytes/sec.
Definition peerinfo.h:59
double progress() const
Peer's download progress as a ratio from 0.0 to 1.0.
Definition peerinfo.h:77
qint64 uploadRate() const
Current upload rate to this peer in bytes/sec.
Definition peerinfo.h:63
QString client() const
Peer's client identification string (e.g.
Definition peerinfo.h:53
quint16 port() const
Peer's TCP port.
Definition peerinfo.h:45
QHostAddress address() const
Peer's IP address.
Definition peerinfo.h:41
qint64 totalDownload() const
Total bytes downloaded from this peer.
Definition peerinfo.h:67
Flags flags() const
Capability and state flags for this connection.
Definition peerinfo.h:83
Flag
Capability and state flags for a peer connection.
Definition peerinfo.h:23
qint64 totalUpload() const
Total bytes uploaded to this peer.
Definition peerinfo.h:71