File indexing completed on 2025-01-05 04:37:23

0001 /*
0002     SPDX-FileCopyrightText: 2009 Joris Guisson <joris.guisson@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef BT_UTMETADATA_H
0008 #define BT_UTMETADATA_H
0009 
0010 #include <peer/peerprotocolextension.h>
0011 
0012 namespace bt
0013 {
0014 class MetadataDownload;
0015 class BDictNode;
0016 class Peer;
0017 class Torrent;
0018 
0019 /**
0020     Handles ut_metadata extension
0021 */
0022 class KTORRENT_EXPORT UTMetaData : public PeerProtocolExtension
0023 {
0024 public:
0025     UTMetaData(const Torrent &tor, bt::Uint32 id, Peer *peer);
0026     ~UTMetaData() override;
0027 
0028     /**
0029         Handle a metadata packet
0030     */
0031     void handlePacket(const bt::Uint8 *packet, Uint32 size) override;
0032 
0033     /**
0034         Set the reported metadata size
0035     */
0036     void setReportedMetadataSize(Uint32 metadata_size);
0037 
0038 private:
0039     void request(BDictNode *dict);
0040     void reject(BDictNode *dict);
0041     void data(BDictNode *dict, const QByteArray &piece_data);
0042     void sendReject(int piece);
0043     void sendData(int piece, int total_size, const QByteArray &data);
0044     void startDownload();
0045 
0046 private:
0047     const Torrent &tor;
0048     Uint32 reported_metadata_size;
0049     MetadataDownload *download;
0050 };
0051 
0052 }
0053 
0054 #endif // BT_UTMETADATA_H