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

0001 /*
0002     SPDX-FileCopyrightText: 2005 Joris Guisson <joris.guisson@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 #ifndef DHTANNOUNCETASK_H
0007 #define DHTANNOUNCETASK_H
0008 
0009 #include "kbucket.h"
0010 #include "task.h"
0011 
0012 namespace dht
0013 {
0014 class Database;
0015 
0016 class KBucketEntryAndToken : public KBucketEntry
0017 {
0018     QByteArray token;
0019 
0020 public:
0021     KBucketEntryAndToken()
0022     {
0023     }
0024     KBucketEntryAndToken(const KBucketEntry &e, const QByteArray &token)
0025         : KBucketEntry(e)
0026         , token(token)
0027     {
0028     }
0029     ~KBucketEntryAndToken() override
0030     {
0031     }
0032 
0033     const QByteArray &getToken() const
0034     {
0035         return token;
0036     }
0037 };
0038 
0039 /**
0040     @author Joris Guisson <joris.guisson@gmail.com>
0041 */
0042 class AnnounceTask : public Task
0043 {
0044 public:
0045     AnnounceTask(Database *db, RPCServer *rpc, Node *node, const dht::Key &info_hash, bt::Uint16 port, QObject *parent);
0046     ~AnnounceTask() override;
0047 
0048     void callFinished(RPCCall *c, RPCMsg::Ptr rsp) override;
0049     void callTimeout(RPCCall *c) override;
0050     void update() override;
0051 
0052     /**
0053      * Take one item from the returned values.
0054      * Returns false if there is no item to take.
0055      * @param item The item
0056      * @return false if no item to take, true else
0057      */
0058     bool takeItem(DBItem &item);
0059 
0060 private:
0061     void handleNodes(const QByteArray &nodes, int ip_version);
0062 
0063 private:
0064     dht::Key info_hash;
0065     bt::Uint16 port;
0066     std::set<KBucketEntryAndToken> answered; // nodes which have answered with values
0067     KBucketEntrySet answered_visited; // nodes which have answered with values which have been visited
0068     Database *db;
0069     DBItemList returned_items;
0070 };
0071 
0072 }
0073 
0074 #endif