query_object["args"]["ephemeral_port"]=get_port();// for testing on local network. This cannot be removed since the two primary sockets used in the protocol have different ports with the "ephemeral_port" being the actual port
intmy_port=get_port();
if(my_port!=NEROSHOP_P2P_DEFAULT_PORT){
query_object["args"]["port"]=my_port;// for testing on local network. This cannot be removed since the two primary sockets used in the protocol have different ports with the "port" being the actual port
// announce_peer is called by a client to announce that it is downloading a file with a specific infohash and is now a potential peer for that file. This is typically called when a client starts downloading a file or completes downloading a file and wants to start seeding it.
// When a client calls announce_peer, it sends an announce_peer query to the DHT network, which contains the client's node ID, the infohash of the file, and the client's IP address and port number. If the query is successful, the DHT network will store the client's IP address and port number in the list of peers for the specified infohash.
// Other clients who are also downloading or seeding the same file can then query the DHT network for a list of peers for that infohash. The DHT network will respond with a list of IP addresses and port numbers of all the peers who have announced themselves for that infohash. The requesting client can then use this list to connect to other peers and start downloading or uploading data.
query_object["args"]["port"]=port;// the port of the peer that is announcing itself
query_object["args"]["token"]=token;
query_object["args"]["implied_port"]=(port!=0);//implied_port; // optional // set to 1 if the port number is included in the peer list, and 0 otherwise. // refers to the port of the peer that is announcing itself, not the port of the node that receives the announcement // the value of implied_port should be set based on whether the port number is included in the peer list or not, and it should not be set to this->port.
////std::vector<Node*> lookup(const std::string& key); // In Kademlia, the primary purpose of the lookup function is to find the nodes responsible for storing a particular key in the DHT, rather than retrieving the actual value of the key. The lookup function helps in locating the nodes that are likely to have the key or be able to provide information about it.
boolping(conststd::string&address,intport);// A simple query to check if a node is online and responsive.
std::vector<Node*>find_node(conststd::string&target_id,intcount)const;// override; // A query to find the contact information for a specific node in the DHT. // Finds the node closest to the target_id
std::vector<Peer>get_peers(conststd::string&info_hash)const;// A query to get a list of peers for a specific torrent or infohash.
voidannounce_peer(conststd::string&info_hash,intport,conststd::string&token);// A query to announce that a peer has joined a specific torrent or infohash.
std::stringget(conststd::string&key)const;// A query to get a specific value stored in the DHT. // Retrieves the value associated with the key from the DHT
std::stringfind_value(conststd::string&key)const;
intremove(conststd::string&key);// Remove a key-value pair from the DHT