@@ -42,12 +42,30 @@ BC_PUSH_WARNING(NO_VALUE_OR_CONST_REF_SHARED_PTR)
4242BC_PUSH_WARNING (SMART_PTR_NOT_NEEDED)
4343BC_PUSH_WARNING (NO_THROW_IN_NOEXCEPT)
4444
45+ size_t get_target_connections (const network::settings& network) NOEXCEPT
46+ {
47+ // Only divide among manual and target outbound, but will also use inbound.
48+ const auto outgoing = ceilinged_add (network.outbound .connections ,
49+ network.manual .peers .size ());
50+
51+ // Only divide by inbound config if there are no outgoing connections.
52+ return is_zero (outgoing) ? network.inbound .connections : outgoing;
53+ }
54+
55+ size_t get_step (size_t connections, size_t maximum_concurrency) NOEXCEPT
56+ {
57+ constexpr auto max = messages::peer::max_inventory;
58+ const auto span = ceilinged_multiply (max, connections);
59+ return std::min (maximum_concurrency, span);
60+ }
61+
4562chaser_check::chaser_check (full_node& node) NOEXCEPT
4663 : chaser(node),
64+ allowed_deviation_ (node.node_settings().allowed_deviation),
4765 maximum_concurrency_(node.node_settings().maximum_concurrency_()),
4866 maximum_height_(node.node_settings().maximum_height_()),
49- connections_(node.network_settings().outbound.connections ),
50- allowed_deviation_(node.node_settings().allowed_deviation )
67+ connections_(get_target_connections( node.network_settings()) ),
68+ step_(get_step(connections_, maximum_concurrency_) )
5169{
5270}
5371
@@ -515,18 +533,13 @@ size_t chaser_check::set_unassociated() NOEXCEPT
515533
516534size_t chaser_check::get_inventory_size () const NOEXCEPT
517535{
518- // Either condition means blocks shouldn't be getting downloaded (yet).
519- const size_t peers = network_settings ().outbound .connections ;
520- if (is_zero (peers) || !is_current (false ))
536+ if (is_zero (connections_) || !is_current (false ))
521537 return zero;
522538
523539 const auto & query = archive ();
524540 const auto fork = query.get_fork ();
525-
526- const auto span = ceilinged_multiply (messages::peer::max_inventory, peers);
527- const auto step = std::min (maximum_concurrency_, span);
528- const auto inventory = query.get_unassociated_count_above (fork, step);
529- return ceilinged_divide (inventory, peers);
541+ const auto inventory = query.get_unassociated_count_above (fork, step_);
542+ return ceilinged_divide (inventory, connections_);
530543}
531544
532545BC_POP_WARNING ()
0 commit comments