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
5 changes: 4 additions & 1 deletion include/bitcoin/network/net.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ class BCT_API net

DELETE_COPY_MOVE(net);

/// Construct an instance.
/// Construct an instance from config.
net(const configuration& config, const logger& log) NOEXCEPT;

/// Construct an instance from settings (deprecated).
net(const settings& settings, const logger& log) NOEXCEPT;

/// Calls close().
Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/network/protocols/protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class BCT_API protocol
virtual uint64_t nonce() const NOEXCEPT;

/// Network settings.
virtual const network::settings& settings() const NOEXCEPT;
virtual const network::settings& network_settings() const NOEXCEPT;

/// Channel identifier (for broadcast identification).
virtual uint64_t identifier() const NOEXCEPT;
Expand Down
10 changes: 5 additions & 5 deletions include/bitcoin/network/protocols/protocol_rpc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
namespace libbitcoin {
namespace network {

template <typename Interface>
template <typename Channel>
class protocol_rpc
: public protocol
{
public:
typedef std::shared_ptr<protocol_rpc<Interface>> ptr;
using channel_t = channel_rpc<Interface>;
typedef std::shared_ptr<protocol_rpc<Channel>> ptr;
using channel_t = Channel;
using options_t = channel_t::options_t;

protected:
Expand Down Expand Up @@ -65,8 +65,8 @@ class protocol_rpc
} // namespace network
} // namespace libbitcoin

#define TEMPLATE template <typename Interface>
#define CLASS protocol_rpc<Interface>
#define TEMPLATE template <typename Channel>
#define CLASS protocol_rpc<Channel>

#include <bitcoin/network/impl/protocols/protocol_rpc.ipp>

Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/network/sessions/session.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class BCT_API session
/// -----------------------------------------------------------------------

/// Access network configuration settings.
const network::settings& settings() const NOEXCEPT;
const network::settings& network_settings() const NOEXCEPT;

/// Arbitrary identifier of the session (for net subscriber).
uint64_t identifier() const NOEXCEPT;
Expand Down
13 changes: 13 additions & 0 deletions include/bitcoin/network/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,19 @@ struct BCT_API settings
const messages::peer::address_item& item) const NOEXCEPT;
};

/// Network configuration, thread safe.
class BCT_API configuration
{
public:
inline configuration(system::chain::selection context) NOEXCEPT
: network(context)
{
}

/// Settings.
network::settings network;
};

} // namespace network
} // namespace libbitcoin

Expand Down
16 changes: 8 additions & 8 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ connectors_ptr net::create_connectors(size_t count) NOEXCEPT
const auto connects = to_shared<connectors>();
connects->reserve(count);

const auto maximum = settings_.outbound.maximum_request;
const auto maximum = network_settings().outbound.maximum_request;
for (size_t connect{}; connect < count; ++connect)
connects->push_back(create_connector(maximum));

Expand All @@ -92,15 +92,15 @@ connectors_ptr net::create_connectors(size_t count) NOEXCEPT
connector::ptr net::create_connector(size_t maximum) NOEXCEPT
{
return emplace_shared<connector>(log, strand(), service(),
settings_.connect_timeout(), maximum, connect_suspended_);
network_settings().connect_timeout(), maximum, connect_suspended_);
}

// seed
connector::ptr net::create_connector() NOEXCEPT
{
return emplace_shared<connector>(log, strand(), service(),
settings_.outbound.seeding_timeout(),
settings_.outbound.maximum_request, connect_suspended_);
network_settings().outbound.seeding_timeout(),
network_settings().outbound.maximum_request, connect_suspended_);
}

// Start sequence.
Expand Down Expand Up @@ -168,7 +168,7 @@ void net::do_run(const result_handler& handler) NOEXCEPT
}

// Start manual connections.
for (const auto& peer: settings_.manual.peers)
for (const auto& peer: network_settings().manual.peers)
do_connect(peer);

// Start inbound connections.
Expand Down Expand Up @@ -581,7 +581,7 @@ bool net::store_nonce(const channel_peer& channel) NOEXCEPT
{
BC_ASSERT(stranded());

if (settings_.inbound.enable_loopback || channel.inbound())
if (network_settings().inbound.enable_loopback || channel.inbound())
return true;

if (!nonces_.insert(channel.nonce()).second)
Expand All @@ -597,7 +597,7 @@ bool net::unstore_nonce(const channel_peer& channel) NOEXCEPT
{
BC_ASSERT(stranded());

if (settings_.inbound.enable_loopback || channel.inbound())
if (network_settings().inbound.enable_loopback || channel.inbound())
return true;

if (!to_bool(nonces_.erase(channel.nonce())))
Expand All @@ -613,7 +613,7 @@ bool net::is_loopback(const channel_peer& channel) const NOEXCEPT
{
BC_ASSERT(stranded());

if (settings_.inbound.enable_loopback || !channel.inbound())
if (network_settings().inbound.enable_loopback || !channel.inbound())
return false;

return to_bool(nonces_.count(channel.peer_version()->nonce));
Expand Down
4 changes: 2 additions & 2 deletions src/protocols/protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ uint64_t protocol::nonce() const NOEXCEPT
return channel_->nonce();
}

const network::settings& protocol::settings() const NOEXCEPT
const network::settings& protocol::network_settings() const NOEXCEPT
{
return session_->settings();
return session_->network_settings();
}

uint64_t protocol::identifier() const NOEXCEPT
Expand Down
4 changes: 2 additions & 2 deletions src/protocols/protocol_address_in_209.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void protocol_address_in_209::start() NOEXCEPT
address::cptr protocol_address_in_209::filter(
const address_items& items) const NOEXCEPT
{
const size_t cap = settings().outbound.host_pool_capacity;
const size_t cap = network_settings().outbound.host_pool_capacity;
const size_t gap = cap - address_count();

// Take at least the gap or what we can get.
Expand All @@ -96,7 +96,7 @@ address::cptr protocol_address_in_209::filter(
addresses.resize(select);
std::erase_if(addresses, [&](const auto& address) NOEXCEPT
{
return settings().excluded(address);
return network_settings().excluded(address);
});

return message;
Expand Down
2 changes: 1 addition & 1 deletion src/protocols/protocol_address_out_209.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void protocol_address_out_209::start() NOEXCEPT
return;

// Advertise self if configured for inbound and with self address(es).
if (settings().inbound.advertise())
if (network_settings().inbound.advertise())
{
SEND(selfs(), handle_send, _1);
}
Expand Down
4 changes: 2 additions & 2 deletions src/protocols/protocol_peer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ void protocol_peer::set_negotiated_version(uint32_t value) NOEXCEPT
address protocol_peer::selfs() const NOEXCEPT
{
const auto time_now = unix_time();
const auto services = settings().services_maximum;
const auto& selfs = settings().inbound.selfs;
const auto services = network_settings().services_maximum;
const auto& selfs = network_settings().inbound.selfs;

address message{};
message.addresses.reserve(selfs.size());
Expand Down
2 changes: 1 addition & 1 deletion src/protocols/protocol_ping_106.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protocol_ping_106::protocol_ping_106(const session::ptr& session,
const channel::ptr& channel) NOEXCEPT
: protocol_peer(session, channel),
timer_(std::make_shared<deadline>(session->log, channel->strand(),
session->settings().channel_heartbeat())),
session->network_settings().channel_heartbeat())),
tracker<protocol_ping_106>(session->log)
{
}
Expand Down
8 changes: 4 additions & 4 deletions src/protocols/protocol_seed_209.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protocol_seed_209::protocol_seed_209(const session::ptr& session,
const channel::ptr& channel) NOEXCEPT
: protocol_peer(session, channel),
timer_(std::make_shared<deadline>(session->log, channel->strand(),
session->settings().outbound.seeding_timeout())),
session->network_settings().outbound.seeding_timeout())),
tracker<protocol_seed_209>(session->log)
{
}
Expand Down Expand Up @@ -117,7 +117,7 @@ void protocol_seed_209::handle_send_get_address(const code& ec) NOEXCEPT
address::cptr protocol_seed_209::filter(
const address_items& items) const NOEXCEPT
{
const size_t cap = settings().outbound.host_pool_capacity;
const size_t cap = network_settings().outbound.host_pool_capacity;
const size_t gap = cap - address_count();

// Take at least the gap or what we can get.
Expand All @@ -138,7 +138,7 @@ address::cptr protocol_seed_209::filter(
addresses.resize(select);
std::erase_if(addresses, [&](const auto& address) NOEXCEPT
{
return settings().excluded(address);
return network_settings().excluded(address);
});

return message;
Expand Down Expand Up @@ -208,7 +208,7 @@ bool protocol_seed_209::handle_receive_get_address(const code& ec,
return false;

// Advertise self if configured for inbound and with self address(es).
if (settings().inbound.advertise())
if (network_settings().inbound.advertise())
{
SEND(selfs(), handle_send_address, _1);
return true;
Expand Down
20 changes: 10 additions & 10 deletions src/protocols/protocol_version_106.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ using namespace std::placeholders;
protocol_version_106::protocol_version_106(const session::ptr& session,
const channel::ptr& channel) NOEXCEPT
: protocol_version_106(session, channel,
session->settings().services_minimum,
session->settings().services_maximum)
session->network_settings().services_minimum,
session->network_settings().services_maximum)
{
}

Expand All @@ -57,14 +57,14 @@ protocol_version_106::protocol_version_106(const session::ptr& session,
uint64_t maximum_services) NOEXCEPT
: protocol_peer(session, channel),
inbound_(channel->inbound()),
minimum_version_(session->settings().protocol_minimum),
maximum_version_(session->settings().protocol_maximum),
minimum_version_(session->network_settings().protocol_minimum),
maximum_version_(session->network_settings().protocol_maximum),
minimum_services_(minimum_services),
maximum_services_(maximum_services),
invalid_services_(session->settings().invalid_services),
maximum_skew_minutes_(session->settings().maximum_skew_minutes),
invalid_services_(session->network_settings().invalid_services),
maximum_skew_minutes_(session->network_settings().maximum_skew_minutes),
timer_(std::make_shared<deadline>(session->log, channel->strand(),
session->settings().channel_handshake())),
session->network_settings().channel_handshake())),
tracker<protocol_version_106>(session->log)
{
}
Expand Down Expand Up @@ -110,12 +110,12 @@ messages::peer::version protocol_version_106::version_factory(
{
timestamp,
maximum_services_,
settings().inbound.first_self().to_ip_address(),
settings().inbound.first_self().port(),
network_settings().inbound.first_self().to_ip_address(),
network_settings().inbound.first_self().port(),
},

nonce(),
settings().user_agent,
network_settings().user_agent,
possible_narrow_cast<uint32_t>(start_height()),
relay
};
Expand Down
6 changes: 3 additions & 3 deletions src/protocols/protocol_version_70001.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ using namespace network::messages::peer;
protocol_version_70001::protocol_version_70001(const session::ptr& session,
const channel::ptr& channel) NOEXCEPT
: protocol_version_70001(session, channel,
session->settings().services_minimum,
session->settings().services_maximum,
session->settings().enable_relay)
session->network_settings().services_minimum,
session->network_settings().services_maximum,
session->network_settings().enable_relay)
{
}

Expand Down
6 changes: 3 additions & 3 deletions src/protocols/protocol_version_70002.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ using namespace std::placeholders;
protocol_version_70002::protocol_version_70002(const session::ptr& session,
const channel::ptr& channel) NOEXCEPT
: protocol_version_70002(session, channel,
session->settings().services_minimum,
session->settings().services_maximum,
session->settings().enable_relay)
session->network_settings().services_minimum,
session->network_settings().services_maximum,
session->network_settings().enable_relay)
{
}

Expand Down
8 changes: 4 additions & 4 deletions src/protocols/protocol_version_70016.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ using namespace std::placeholders;
protocol_version_70016::protocol_version_70016(const session::ptr& session,
const channel::ptr& channel) NOEXCEPT
: protocol_version_70016(session, channel,
session->settings().services_minimum,
session->settings().services_maximum,
session->settings().enable_relay,
session->settings().enable_reject)
session->network_settings().services_minimum,
session->network_settings().services_maximum,
session->network_settings().enable_relay,
session->network_settings().enable_reject)
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/sessions/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ void session::do_handle_channel_stopped(const code& ec,
void session::defer(result_handler&& handler) NOEXCEPT
{
BC_ASSERT(stranded());
defer(settings().retry_timeout(), std::move(handler));
defer(network_settings().retry_timeout(), std::move(handler));
}

void session::defer(const steady_clock::duration& timeout,
Expand Down Expand Up @@ -387,7 +387,7 @@ asio::strand& session::strand() NOEXCEPT
return network_.strand();
}

const network::settings& session::settings() const NOEXCEPT
const network::settings& session::network_settings() const NOEXCEPT
{
return network_.network_settings();
}
Expand Down
Loading
Loading