开发者

libtorrent dht peer request?

Ive been playing around with the pyth开发者_运维百科on bindings for libtorrent/rasterbar. What I wanted to do was generate a new 'node-id' and reannounce it to the other nodes.

I read that a 'bencoded dicionary' needs to be created and I assume announced using something like force_dht_reannounce, is this correct?


You can force libtorrent to use a specific node ID for the DHT by crafting a session-state file, and feed it to the session::load_state() function. Once you do this, you also need to restart the DHT by calling session::stop_dht() followed by session::start_dht().

The relevant parts of the session state you need to craft have the following format (bencoded):

  {
    "dht state": {
      "node-id": "<20-byte binary node-ID>"
    }
  }

If you want to keep the rest of the session state, it might be a good idea to first call session::save_state() and then simply insert/overwrite the node-id field.

Something like this:

state = ses.save_state()
state["dht state"]["node-id"] = "<...>";
ses.load_state(state)
ses.stop_dht()
ses.start_dht()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜