Skip to content

document rate-limiting of local peers #8356

@milahu

Description

@milahu

currently the docs say

upload_rate_limit and download_rate_limit sets the session-global limits of upload and download rate limits, in bytes per second. By default peers on the local network are not rate limited.

but they offer no solution...

use case:
simulate traffic between libtorrent instances running on localhost

this paragraph was removed 9 years ago in 116802f

These rate limits are only used for local peers (peers within the same subnet as the client itself) and it is only used when ignore_limits_on_local_network is set to true (which it is by default). These rate limits default to unthrottled, but can be useful in case you want to treat local peers preferentially, but not quite unthrottled.

but meanwhile, ignore_limits_on_local_network has been deprecated
in favor of set_peer_class_filter

ignore_limits_on_local_network

rate-limiting of local peers with ignore_limits_on_local_network

import libtorrent as lt

settings = lt.default_settings()

settings["upload_rate_limit"] = 1024**2
settings["download_rate_limit"] = 1024**2

# also apply upload_rate_limit and download_rate_limit
# to peers on the local network
# NOTE ignore_limits_on_local_network is deprecated
# in favor of set_peer_class_filter
settings["ignore_limits_on_local_network"] = False

ses = lt.session(settings)

set_peer_class_filter

// if set to true, upload, download and unchoke limits are ignored for
// peers on the local network. This option is *DEPRECATED*, please use
// set_peer_class_filter() instead.
ignore_limits_on_local_network TORRENT_DEPRECATED_ENUM,

rate-limiting of local peers with set_peer_class_filter

based on libtorrent/bindings/python/test.py

import libtorrent as lt

settings = lt.default_settings()

settings["upload_rate_limit"] = 1024**2
settings["download_rate_limit"] = 1024**2

ses = lt.session(settings)

# also apply upload_rate_limit and download_rate_limit
# to peers on the local network
# based on libtorrent/bindings/python/test.py

# settings = ses.get_settings()

# if settings.get("ignore_limits_on_local_network") == False:

# define limits for the default global class
pci = ses.get_peer_class(lt.session.global_peer_class_id)
pci["upload_limit"] = settings["upload_rate_limit"]
pci["download_limit"] = settings["download_rate_limit"]
ses.set_peer_class(lt.session.global_peer_class_id, pci)

# force all peers into class 0
pcf = lt.peer_class_type_filter()
# all TCP peers
pcf.add(lt.peer_class_type_filter.tcp_socket, lt.session.global_peer_class_id)
# all UDP peers
pcf.add(lt.peer_class_type_filter.utp_socket, lt.session.global_peer_class_id)
ses.set_peer_class_type_filter(pcf)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions