【发布时间】:2019-02-20 06:50:35
【问题描述】:
我正在尝试使用 dht 来通过 libtorrent 保存可变数据。据我了解,正确的方法是使用 session 中的 dht_put_item 方法。问题是我需要传递一个回调函数,我不知道我做错了什么......我的代码如下所示
namespace lt = libtorrent;
//The callback function
void cb(lt::entry& cdentry, boost::array<char,64>& cbarray, boost::uint64_t& cbint, std::string const& cbstring){
//My stuff here
}
void main(){
//The session
lt::session ses;
//The data I want to insert into DHT
std::string cadenaStr = "519d818411de49652b4aaf34850321de28bb2dce";
//Now I create the keys
unsigned char seed[32];
unsigned char public_key[32];
unsigned char private_key[64];
unsigned char signature[32];
ed25519_create_seed(seed);
ed25519_create_keypair(public_key, private_key, seed);
ed25519_sign(signature, cadenaStr.c_str(), sizeof(cadenaStr.c_str()), public_key, private_key);
//How can I use this?, where is the data supposed to go? :|
ses.dht_put_item(public_key, cb, false);
}
在 libtorrent/session_handler.hpp 这个方法被定义为
void dht_put_item(boost::array<char, 32> key
, boost::function<void(entry&, boost::array<char,64>&
, boost::uint64_t&, std::string const&)> cb
, std::string salt = std::string());
谁能告诉我我做错了什么。
谢谢!
【问题讨论】:
标签: c++ dht libtorrent