【问题标题】:libtorrent disable dht and lsd in the sessionlibtorrent 在会话中禁用 dht 和 lsd
【发布时间】:2019-12-07 13:31:05
【问题描述】:

我们正在创建这样的 libtorrent 会话:

ses_settings = lt.session_settings() 
ses_settings.ignore_limits_on_local_network = False
ses_settings.announce_to_all_trackers = True
ses_settings.ssl_listen = 0 
ses = lt.session()
ses.listen_on(LISTEN_ON_RANGE_START, LISTEN_ON_RANGE_END)
ses.set_settings(ses_settings)
ses.set_download_rate_limit(download_rate)
ses.set_upload_rate_limit(upload_rate)

类似于 ssl_listen,我们想在 libtorrent 会话中禁用 DHT、LSD、UPnP、NAT-PMP。有什么办法吗?

在 libtorrent 手册页中也提到:

Configuration options can be updated after the session is started by calling apply_settings(). Some settings are best set before starting the session though, like listen_interfaces, to avoid race conditions. If you start the session with the default settings and then immediately change them, there will still be a window where the default settings apply.

Changing the settings may trigger listen sockets to close and re-open and NAT-PMP, UPnP updates to be sent. For this reason, it's typically a good idea to batch settings updates into a single call.

如何在一次调用中进行批量设置更新?

基本上我们想要更改这些默认设置字段:enable_lsd, enable_dht, enable_upnp, enable_natpmp,然后使用这些设置创建一个会话对象。

【问题讨论】:

  • 请注意,您通常不需要在会话级别禁用它,您可以通过torrent_flags_t为单个种子禁用它。

标签: bittorrent libtorrent libtorrent-rasterbar


【解决方案1】:

会话中的session_settings 类型和set_settings() 函数已被弃用(并且已经有一段时间了)。在线参考文档 (https://libtorrent.org) 是最新的稳定版本,因此您不会在那里找到它们的文档。

改为在会话中使用 settings_packapply_settings()。或者更好的是,将您的设置包传递给会话构造函数。

在 C++ 接口中,settings_pack 是一个具有相当简单接口的类,但在 python 绑定中它只是一个普通的字典。

要在 python 中设置设置包,请执行以下操作:

sett = {'enable_lsd': False,
  'enable_dht': False,
  'enable_upnp': False,
  'enable_natpmp': False,
  'listen_interfaces': '0.0.0.0:%s' % LISTEN_ON_RANGE_START,
  'download_rate_limit': download_rate,
  'upload_rate_limit': upload_rate,
  'announce_to_all_tracker': True}
ses = lt.session(sett)
# ...

您可以在reference documentation 中找到所有可用的设置。

【讨论】:

  • 这是很棒的信息。谢谢@Arvid
猜你喜欢
  • 2020-04-07
  • 1970-01-01
  • 1970-01-01
  • 2020-01-13
  • 1970-01-01
  • 2015-10-13
  • 2015-12-06
  • 2015-10-07
  • 1970-01-01
相关资源
最近更新 更多