response_object["response"]["peers"]=peers_array;// If the queried node has peers for the infohash, they are returned in a key "values" as a list of strings. Each string containing "compact" format peer information for a single peer
}
// Generate and include a token value in the response
autosecret=generate_secret(16);
std::stringtoken=generate_token(node.get_id(),data_hash,secret);// The reason for concatenating the node ID and info hash is to ensure that the generated token is unique and specific to the peer making the request. This helps prevent replay attacks, where an attacker intercepts and reuses a token generated for another peer.
// If ipc_mode is false, it means the "put" message is being processed from other nodes. In this case, the key-value pair is stored in the node's own key-value store using the node.store(key, value) function.
if(ipc_mode==false){// For Processing Put Requests from Other Nodes:
assert(request_object["args"].is_object());
autoparams_object=request_object["args"];
assert(params_object["key"].is_string());
std::stringkey=params_object["key"];
assert(params_object["value"].is_string());
std::stringvalue=params_object["value"];
// Add the key-value pair to the key-value store
code=(node.store(key,value)==false)
?static_cast<int>(KadResultCode::StoreFailed)
:static_cast<int>(KadResultCode::Success);
if(code==0){
// Map keys to search terms for efficient search operations
node.map(key,value);
}
if(method=="put"&&ipc_mode==false){// For Processing Put Requests from Other Nodes - If ipc_mode is false, it means the "put" message is being processed from other nodes. In this case, the key-value pair is stored in the node's own key-value store using the node.store(key, value) function.
// On the other hand, if ipc_mode is true, it means the "put" message is being sent from the local IPC client. In this case, the node.send_put(key, value) function is called to send the put message to the closest nodes in the routing table. Additionally, you can add a line of code to store the key-value pair in the local node's own hash table as well
assert(request_object["args"].is_object());
autoparams_object=request_object["args"];
assert(params_object["key"].is_string());
std::stringkey=params_object["key"];
assert(params_object["value"].is_string());
std::stringvalue=params_object["value"];
// Send put messages to the closest nodes in your routing table (IPC mode)
intput_messages_sent=node.send_put(key,value);
code=(put_messages_sent<=0)
?static_cast<int>(KadResultCode::StoreFailed)
:static_cast<int>(KadResultCode::Success);
std::cout<<"Number of nodes you've sent a put message to: "<<put_messages_sent<<"\n";
// Store the key-value pair in your own node as well
if(node.store(key,value)){
// Add the key-value pair to the key-value store
code=(node.store(key,value)==false)
?static_cast<int>(KadResultCode::StoreFailed)
:static_cast<int>(KadResultCode::Success);
// Map keys to search terms for efficient search operations
if(method=="set" &&ipc_mode){// modify/update data
if((method=="set"||method=="put")&&ipc_mode){// For Sending Put Requests to Other Nodes - If ipc_mode is true, it means the "put" message is being sent from the local IPC client. In this case, the node.send_put(key, value) function is called to send the put message to the closest nodes in the routing table. Additionally, you can add a line of code to store the key-value pair in the local node's own hash table as well