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
12 changes: 9 additions & 3 deletions include/bitcoin/network/net.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,15 @@ class BCT_API net

/// Suspensions.
/// -----------------------------------------------------------------------
/// Service connections are managed independently from P2P.

/// Network connections are suspended (incoming and/or outgoing).
/// P2P connections are suspended (incoming and/or outgoing).
virtual bool suspended() const NOEXCEPT;

/// Suspend all connections.
/// Suspend all P2P connections.
virtual void suspend(const code& ec) NOEXCEPT;

/// Resume all connection.
/// Resume all P2P connection.
virtual void resume() NOEXCEPT;

/// Properties.
Expand Down Expand Up @@ -217,6 +218,8 @@ class BCT_API net
friend class session;

/// I/O factories.
virtual acceptor::ptr create_service(
const socket::context& context={}) NOEXCEPT;
virtual acceptor::ptr create_acceptor(
const socket::context& context={}) NOEXCEPT;
virtual connector::ptr create_seed_connector() NOEXCEPT;
Expand Down Expand Up @@ -265,6 +268,8 @@ class BCT_API net

private:
// Suspensions.
void suspend_services() NOEXCEPT;
void resume_services() NOEXCEPT;
void suspend_acceptors() NOEXCEPT;
void resume_acceptors() NOEXCEPT;
void suspend_connectors() NOEXCEPT;
Expand Down Expand Up @@ -310,6 +315,7 @@ class BCT_API net
const settings& settings_;
std::atomic_bool closed_{ false };
std::atomic_bool accept_suspended_{ false };
std::atomic_bool service_suspended_{ false };
std::atomic_bool connect_suspended_{ false };
std::atomic<size_t> total_channel_count_{};
std::atomic<size_t> inbound_channel_count_{};
Expand Down
4 changes: 4 additions & 0 deletions include/bitcoin/network/sessions/session.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ class BCT_API session
/// Factories.
/// -----------------------------------------------------------------------

/// Create a channel acceptor (service).
virtual acceptor::ptr create_service(
const socket::context& context={}) NOEXCEPT;

/// Create a channel acceptor (inbound).
virtual acceptor::ptr create_acceptor(
const socket::context& context={}) NOEXCEPT;
Expand Down
29 changes: 28 additions & 1 deletion src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,23 @@ net::~net() NOEXCEPT
// I/O factories.
// ----------------------------------------------------------------------------

// inbound/server
// server
// TODO: could move this to server by extending context.
acceptor::ptr net::create_service(const socket::context& context) NOEXCEPT
{
const auto& settings = network_settings();
socket::parameters params
{
.connect_timeout = settings.connect_timeout(),
.maximum_request = settings.inbound.maximum_request,
.context = context
};

return emplace_shared<acceptor>(log, strand(), service(),
service_suspended_, std::move(params));
}

// inbound
acceptor::ptr net::create_acceptor(const socket::context& context) NOEXCEPT
{
const auto& settings = network_settings();
Expand Down Expand Up @@ -275,6 +291,17 @@ bool net::closed() const NOEXCEPT

// Suspensions.
// ----------------------------------------------------------------------------
// Service connections are managed independently from P2P.

void net::suspend_services() NOEXCEPT
{
service_suspended_.store(true);
}

void net::resume_services() NOEXCEPT
{
service_suspended_.store(false);
}

void net::suspend(const code&) NOEXCEPT
{
Expand Down
8 changes: 7 additions & 1 deletion src/sessions/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,13 @@ void session::unsubscribe_close() NOEXCEPT
// Factories.
// ----------------------------------------------------------------------------

// inbound/server
// server
acceptor::ptr session::create_service(const socket::context& context) NOEXCEPT
{
return network_.create_service(context);
}

// inbound
acceptor::ptr session::create_acceptor(const socket::context& context) NOEXCEPT
{
return network_.create_acceptor(context);
Expand Down
2 changes: 1 addition & 1 deletion src/sessions/session_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ code session_server::do_accept(const config::authorities& binds,

for (const auto& bind: binds)
{
const auto acceptor = create_acceptor(context);
const auto acceptor = create_service(context);

// Require that all acceptors at least start.
if (const auto ec = acceptor->start(bind))
Expand Down
Loading