Libtorrent 通过 IP 添加节点

Libtorrent add peer by IP

有没有一种直接的方法可以使用 Libtorrent 通过 IP 地址手动添加对等点?例如,如果您已经拥有具有所请求文件的对等点的 IP 地址并希望将它们添加到对等点列表中。

还没有尝试过,但我很确定 connect_peer 函数应该可以解决问题:

void connect_peer (tcp::endpoint const& adr, int source = 0
  , int flags = 0x1 + 0x4 + 0x8) const;

connect_peer() is a way to manually connect to peers that one believe is a part of the torrent. If the peer does not respond, or is not a member of this torrent, it will simply be disconnected. No harm can be done by using this other than an unnecessary connection attempt is made. If the torrent is uninitialized or in queued or checking mode, this will throw libtorrent_exception. The second (optional) argument will be bitwised ORed into the source mask of this peer. Typically this is one of the source flags in peer_info. i.e. tracker, pex, dht etc.

flags are the same flags that are passed along with the ut_pex extension.