Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion include/bitcoin/node/sessions/session_outbound.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

namespace libbitcoin {
namespace node {

class BCN_API session_outbound
: public session_peer<network::session_outbound>
{
Expand All @@ -33,13 +33,22 @@ class BCN_API session_outbound
using base = session_peer<network::session_outbound>;
using base::base;

/// Start connections, reduced when current (call from network strand).
void start(network::result_handler&& handler) NOEXCEPT override;

protected:
/// Outbound connections require the configured node services.
uint64_t services_required() const NOEXCEPT override
{
return system::bit_or(base::services_required(),
node_settings().services_required());
}

private:
void handle_started(const code& ec,
const network::result_handler& handler) NOEXCEPT;
bool handle_chase(const code& ec, event_value value) NOEXCEPT;
void update_connections() NOEXCEPT;
};

} // namespace node
Expand Down
1 change: 1 addition & 0 deletions include/bitcoin/node/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class BCN_API settings
double minimum_fee_rate;
double minimum_bump_rate;
uint64_t batch_signatures;
uint16_t current_connections;
uint16_t announcement_cache;
uint16_t fee_estimate_horizon;
uint32_t maximum_height;
Expand Down
6 changes: 5 additions & 1 deletion src/protocols/protocol_observer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,11 @@ bool protocol_observer::handle_broadcast_terminator(const code& ec,
if (stopped(ec))
return false;

if (!message->targets(identifier(), outbound(), opposite()))
using target = network::diagnostics::target;
const auto slotted = (group() == target::outbound) &&
is_terminal(message->slots());

if (!slotted && !message->targets(identifier(), outbound(), opposite()))
return true;

message->stopped();
Expand Down
80 changes: 80 additions & 0 deletions src/sessions/session_outbound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,88 @@
*/
#include <bitcoin/node/sessions/session_outbound.hpp>

#include <bitcoin/node/chase.hpp>
#include <bitcoin/node/define.hpp>

namespace libbitcoin {
namespace node {

#define CLASS session_outbound

using namespace system;
using namespace std::placeholders;

BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)

// Start/stop sequence.
// ----------------------------------------------------------------------------

void session_outbound::start(network::result_handler&& handler) NOEXCEPT
{
BC_ASSERT(stranded());

update_connections();
base::start(BIND(handle_started, _1, std::move(handler)));
}

void session_outbound::handle_started(const code& ec,
const network::result_handler& handler) NOEXCEPT
{
BC_ASSERT(stranded());

if (ec || stopped() || is_zero(node_settings().current_connections))
{
handler(ec);
return;
}

subscribe_chase(BIND(handle_chase, _1, _2));
update_connections();
handler(ec);
}

// Currency.
// ----------------------------------------------------------------------------

bool session_outbound::handle_chase(const code&, event_value value) NOEXCEPT
{
BC_ASSERT(stranded());

if (stopped())
return false;

switch (to_chase(value))
{
case chase::block:
case chase::stale:
{
update_connections();
break;
}
case chase::stop:
{
return false;
}
default:
{
break;
}
}

return true;
}

// Outbound is reduced when current, when inbound is enabled (delay_inbound).
void session_outbound::update_connections() NOEXCEPT
{
BC_ASSERT(stranded());

const auto reduced = node_settings().current_connections;
const auto configured = network_settings().outbound.connections;
set_connections((is_recent() && to_bool(reduced)) ? reduced : configured);
}

BC_POP_WARNING()

} // namespace node
} // namespace libbitcoin
1 change: 1 addition & 0 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ settings::settings() NOEXCEPT
minimum_fee_rate{ 0.0 },
minimum_bump_rate{ 0.0 },
allowed_deviation{ 1.5 },
current_connections{ 10 },
announcement_cache{ 42 },
fee_estimate_horizon{ 0 },
////snapshot_bytes{ 200'000'000'000 },
Expand Down
1 change: 1 addition & 0 deletions test/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ BOOST_AUTO_TEST_CASE(settings__node__default_context__expected)
BOOST_REQUIRE_EQUAL(node.minimum_bump_rate, 0.0);
BOOST_REQUIRE_EQUAL(node.allowed_deviation, 1.5);
BOOST_REQUIRE_EQUAL(node.batch_signatures, 0_u64);
BOOST_REQUIRE_EQUAL(node.current_connections, 10_u16);
BOOST_REQUIRE_EQUAL(node.announcement_cache, 42_u16);
BOOST_REQUIRE_EQUAL(node.fee_estimate_horizon, 0u);
BOOST_REQUIRE_EQUAL(node.maximum_height, 0_u32);
Expand Down
Loading