Commands for the peer rules of libtorrent-unused-peer-slots.patch and libtorrent-waiting-download-slots.patch: each
number and switch can be read and set from rtorrent.rc and over XML-RPC, and a change takes effect at the next
30-second tick, with no restart.

The idle-peer rule (libtorrent's idle_peer_rules; seconds unless said):
  throttle.idle_peers                       1    the rule on (1) or off (0)
  throttle.idle_peers.timeout               300  a peer idle this long is closed on the regular pass (30 to 86400)
  throttle.idle_peers.pass_interval         120  how often the regular pass runs (30 to 3600, a multiple of 30)
  throttle.idle_peers.refuse_time           1800 a closed peer is refused this long (0 to 86400; 0: not refused)
  throttle.idle_peers.starved               1    the faster pass while the download starves, on (1) or off (0)
  throttle.idle_peers.starved_timeout       90   a peer idle this long is closed on the starved pass (30 to 3600)
  throttle.idle_peers.starved_interval      30   how often starvation is checked (30 to 600, a multiple of 30)
  throttle.idle_peers.starved_ratio         10   starved: a check under this percent of the best check of the last
                                                 ten minutes (0 to 100; 0: no ratio test)
  throttle.idle_peers.starved_floor         2048 or under this many bytes a second (0: no floor)
The download slot rotation (libtorrent's choke_queue::rotate_*):
  throttle.download_slots.rotate            1    on (1) or off (0)
  throttle.download_slots.rotate_interval   30   how often (30 to 3600, a multiple of 30)
  throttle.download_slots.rotate_divisor    0    how many slots a time: one in this many (2 to 100), or 0 for
                                                 libtorrent's own rule (1 in 8, 1 in 10 from 31 slots)

Each has a .set (throttle.idle_peers.timeout.set = 600). A value out of range is refused with the range in the error,
and the number stays as it was. The getters and setters are marked safe, as the other throttle.* settings are. Needs
both libtorrent patches. Verified with tools/peer-rules-test.sh (every command against the built rtorrent: defaults,
a set read back, refusals) and tools/rtorrent-test.sh.
diff --git a/src/command_throttle.cc b/src/command_throttle.cc
index 50e23fe..71cb776 100644
--- a/src/command_throttle.cc
+++ b/src/command_throttle.cc
@@ -4,6 +4,8 @@
 #include <torrent/throttle.h>
 #include <torrent/rate.h>
 #include <torrent/download/resource_manager.h>
+#include <torrent/download/choke_queue.h>
+#include <torrent/peer/peer_list.h>
 
 #include "core/manager.h"
 #include "ui/root.h"
@@ -107,8 +109,64 @@ set_down_throttle_i64(ui::Root* root, int64_t rate) {
   root->set_down_throttle(throttle_rate_to_kb(rate));
 }
 
+// The peer rules' numbers (libtorrent's idle_peer_rules and choke_queue::rotate_*): a value outside uint32_t is refused
+// here, one outside a rule's own range by libtorrent's setter, with the range in its message.
+static uint32_t
+peer_rule_value(int64_t value) {
+  if (value < 0 || value > std::numeric_limits<uint32_t>::max())
+    throw torrent::input_error("Peer rule value must be between 0 and 4294967295.");
+
+  return static_cast<uint32_t>(value);
+}
+
+static void
+initialize_command_peer_rules() {
+  using rules = torrent::idle_peer_rules;
+  using queue = torrent::choke_queue;
+
+  // The idle-peer rule: a downloading torrent closes the peers that keep it waiting (0 off, 1 on).
+  CMD2_ANY         ("throttle.idle_peers",                      [](auto, auto) { return static_cast<int64_t>(rules::enabled()); });
+  CMD2_ANY_VALUE_V ("throttle.idle_peers.set",                  [](auto, auto v) { rules::set_enabled(v != 0); });
+  CMD2_ANY         ("throttle.idle_peers.timeout",              [](auto, auto) { return static_cast<int64_t>(rules::timeout()); });
+  CMD2_ANY_VALUE_V ("throttle.idle_peers.timeout.set",          [](auto, auto v) { rules::set_timeout(peer_rule_value(v)); });
+  CMD2_ANY         ("throttle.idle_peers.pass_interval",        [](auto, auto) { return static_cast<int64_t>(rules::pass_interval()); });
+  CMD2_ANY_VALUE_V ("throttle.idle_peers.pass_interval.set",    [](auto, auto v) { rules::set_pass_interval(peer_rule_value(v)); });
+  CMD2_ANY         ("throttle.idle_peers.refuse_time",          [](auto, auto) { return static_cast<int64_t>(rules::refuse_time()); });
+  CMD2_ANY_VALUE_V ("throttle.idle_peers.refuse_time.set",      [](auto, auto v) { rules::set_refuse_time(peer_rule_value(v)); });
+
+  // Its faster pass while the download starves (0 off, 1 on).
+  CMD2_ANY         ("throttle.idle_peers.starved",              [](auto, auto) { return static_cast<int64_t>(rules::starved()); });
+  CMD2_ANY_VALUE_V ("throttle.idle_peers.starved.set",          [](auto, auto v) { rules::set_starved(v != 0); });
+  CMD2_ANY         ("throttle.idle_peers.starved_timeout",      [](auto, auto) { return static_cast<int64_t>(rules::starved_timeout()); });
+  CMD2_ANY_VALUE_V ("throttle.idle_peers.starved_timeout.set",  [](auto, auto v) { rules::set_starved_timeout(peer_rule_value(v)); });
+  CMD2_ANY         ("throttle.idle_peers.starved_interval",     [](auto, auto) { return static_cast<int64_t>(rules::starved_interval()); });
+  CMD2_ANY_VALUE_V ("throttle.idle_peers.starved_interval.set", [](auto, auto v) { rules::set_starved_interval(peer_rule_value(v)); });
+  CMD2_ANY         ("throttle.idle_peers.starved_ratio",        [](auto, auto) { return static_cast<int64_t>(rules::starved_ratio()); });
+  CMD2_ANY_VALUE_V ("throttle.idle_peers.starved_ratio.set",    [](auto, auto v) { rules::set_starved_ratio(peer_rule_value(v)); });
+  CMD2_ANY         ("throttle.idle_peers.starved_floor",        [](auto, auto) { return static_cast<int64_t>(rules::starved_floor()); });
+  CMD2_ANY_VALUE_V ("throttle.idle_peers.starved_floor.set",    [](auto, auto v) { rules::set_starved_floor(peer_rule_value(v)); });
+
+  // The download slot rotation: a torrent whose download slots are all held gives its slowest to waiting peers.
+  CMD2_ANY         ("throttle.download_slots.rotate",              [](auto, auto) { return static_cast<int64_t>(queue::rotate_enabled()); });
+  CMD2_ANY_VALUE_V ("throttle.download_slots.rotate.set",          [](auto, auto v) { queue::set_rotate_enabled(v != 0); });
+  CMD2_ANY         ("throttle.download_slots.rotate_interval",     [](auto, auto) { return static_cast<int64_t>(queue::rotate_interval()); });
+  CMD2_ANY_VALUE_V ("throttle.download_slots.rotate_interval.set", [](auto, auto v) { queue::set_rotate_interval(peer_rule_value(v)); });
+  CMD2_ANY         ("throttle.download_slots.rotate_divisor",      [](auto, auto) { return static_cast<int64_t>(queue::rotate_divisor()); });
+  CMD2_ANY_VALUE_V ("throttle.download_slots.rotate_divisor.set",  [](auto, auto v) { queue::set_rotate_divisor(peer_rule_value(v)); });
+
+  for (auto name : {"throttle.idle_peers", "throttle.idle_peers.timeout", "throttle.idle_peers.pass_interval",
+                    "throttle.idle_peers.refuse_time", "throttle.idle_peers.starved", "throttle.idle_peers.starved_timeout",
+                    "throttle.idle_peers.starved_interval", "throttle.idle_peers.starved_ratio", "throttle.idle_peers.starved_floor",
+                    "throttle.download_slots.rotate", "throttle.download_slots.rotate_interval", "throttle.download_slots.rotate_divisor"}) {
+    rpc::rpc.mark_safe(name);
+    rpc::rpc.mark_safe(std::string(name) + ".set");
+  }
+}
+
 void
 initialize_command_throttle() {
+  initialize_command_peer_rules();
+
   CMD2_ANY         ("throttle.unchoked_uploads",       std::bind(&torrent::ResourceManager::currently_upload_unchoked, torrent::resource_manager()));
   CMD2_ANY         ("throttle.max_unchoked_uploads",   std::bind(&torrent::ResourceManager::max_upload_unchoked, torrent::resource_manager()));
   CMD2_ANY         ("throttle.unchoked_downloads",     std::bind(&torrent::ResourceManager::currently_download_unchoked, torrent::resource_manager()));
