Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various minor coding style updates #1863

Merged
merged 4 commits into from Mar 26, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 4 additions & 8 deletions nano/lib/numbers.hpp
Expand Up @@ -38,11 +38,9 @@ nano::uint128_t const Gxrb_ratio = nano::uint128_t ("100000000000000000000000000
nano::uint128_t const Mxrb_ratio = nano::uint128_t ("1000000000000000000000000000000"); // 10^30
nano::uint128_t const kxrb_ratio = nano::uint128_t ("1000000000000000000000000000"); // 10^27
nano::uint128_t const xrb_ratio = nano::uint128_t ("1000000000000000000000000"); // 10^24
nano::uint128_t const mxrb_ratio = nano::uint128_t ("1000000000000000000000"); // 10^21
nano::uint128_t const uxrb_ratio = nano::uint128_t ("1000000000000000000"); // 10^18
nano::uint128_t const raw_ratio = nano::uint128_t ("1"); // 10^0

union uint128_union
union uint128_union final
{
public:
uint128_union () = default;
Expand All @@ -52,7 +50,6 @@ union uint128_union
*/
uint128_union (std::string const &);
uint128_union (uint64_t);
uint128_union (nano::uint128_union const &) = default;
uint128_union (nano::uint128_t const &);
bool operator== (nano::uint128_union const &) const;
bool operator!= (nano::uint128_union const &) const;
Expand All @@ -77,7 +74,7 @@ union uint128_union
// Balances are 128 bit.
using amount = uint128_union;
class raw_key;
union uint256_union
union uint256_union final
{
uint256_union () = default;
/**
Expand Down Expand Up @@ -116,17 +113,16 @@ using account = uint256_union;
using public_key = uint256_union;
using private_key = uint256_union;
using secret_key = uint256_union;
class raw_key
class raw_key final
{
public:
raw_key () = default;
~raw_key ();
void decrypt (nano::uint256_union const &, nano::raw_key const &, uint128_union const &);
bool operator== (nano::raw_key const &) const;
bool operator!= (nano::raw_key const &) const;
nano::uint256_union data;
};
union uint512_union
union uint512_union final
{
uint512_union () = default;
uint512_union (nano::uint256_union const &, nano::uint256_union const &);
Expand Down
2 changes: 1 addition & 1 deletion nano/lib/plat/darwin/thread_role.cpp
@@ -1,7 +1,7 @@
#include <nano/lib/utility.hpp>
#include <pthread.h>

void nano::thread_role::set_os_name (std::string thread_name)
void nano::thread_role::set_os_name (std::string const & thread_name)
{
pthread_setname_np (thread_name.c_str ());
}
2 changes: 1 addition & 1 deletion nano/lib/plat/freebsd/thread_role.cpp
Expand Up @@ -2,7 +2,7 @@
#include <pthread.h>
#include <pthread_np.h>

void nano::thread_role::set_os_name (std::string thread_name)
void nano::thread_role::set_os_name (std::string const & thread_name)
{
pthread_set_name_np (pthread_self (), thread_name.c_str ());
}
2 changes: 1 addition & 1 deletion nano/lib/plat/linux/thread_role.cpp
@@ -1,7 +1,7 @@
#include <nano/lib/utility.hpp>
#include <pthread.h>

void nano::thread_role::set_os_name (std::string thread_name)
void nano::thread_role::set_os_name (std::string const & thread_name)
{
pthread_setname_np (pthread_self (), thread_name.c_str ());
}
10 changes: 5 additions & 5 deletions nano/lib/plat/windows/priority.cpp
@@ -1,8 +1,8 @@
#include <nano/lib/utility.hpp>

#include <windows.h>

void nano::work_thread_reprioritize ()
namespace nano
{
auto SUCCESS (SetThreadPriority (GetCurrentThread (), THREAD_MODE_BACKGROUND_BEGIN));
void work_thread_reprioritize ()
{
SetThreadPriority (GetCurrentThread (), THREAD_MODE_BACKGROUND_BEGIN);
}
}
9 changes: 3 additions & 6 deletions nano/lib/plat/windows/thread_role.cpp
Expand Up @@ -3,13 +3,10 @@
#include <nano/lib/utility.hpp>
#include <processthreadsapi.h>

typedef HRESULT (*SetThreadDescription_t) (HANDLE, PCWSTR);

void nano::thread_role::set_os_name (std::string thread_name)
void nano::thread_role::set_os_name (std::string const & thread_name)
{
SetThreadDescription_t SetThreadDescription_local;

SetThreadDescription_local = (SetThreadDescription_t)GetProcAddress (GetModuleHandle (TEXT ("kernel32.dll")), "SetThreadDescription");
using SetThreadDescription_t = HRESULT (*) (HANDLE, PCWSTR);
SetThreadDescription_t SetThreadDescription_local = (SetThreadDescription_t)GetProcAddress (GetModuleHandle (TEXT ("kernel32.dll")), "SetThreadDescription");
if (SetThreadDescription_local)
{
std::wstring thread_name_wide (thread_name.begin (), thread_name.end ());
Expand Down
3 changes: 0 additions & 3 deletions nano/lib/utility.cpp
Expand Up @@ -96,9 +96,6 @@ namespace thread_role
case nano::thread_role::name::signature_checking:
thread_role_name_string = "Signature check";
break;
case nano::thread_role::name::slow_db_upgrade:
thread_role_name_string = "Slow db upgrade";
break;
}

/*
Expand Down
7 changes: 3 additions & 4 deletions nano/lib/utility.hpp
Expand Up @@ -84,8 +84,7 @@ namespace thread_role
wallet_actions,
bootstrap_initiator,
voting,
signature_checking,
slow_db_upgrade,
signature_checking
};
/*
* Get/Set the identifier for the current thread
Expand All @@ -101,7 +100,7 @@ namespace thread_role
/*
* Internal only, should not be called directly
*/
void set_os_name (std::string);
void set_os_name (std::string const &);
}

namespace thread_attributes
Expand All @@ -110,7 +109,7 @@ namespace thread_attributes
}

template <typename... T>
class observer_set
class observer_set final
{
public:
void add (std::function<void(T...)> const & observer_a)
Expand Down
4 changes: 2 additions & 2 deletions nano/lib/work.hpp
Expand Up @@ -18,14 +18,14 @@ bool work_validate (nano::block_hash const &, uint64_t, uint64_t * = nullptr);
bool work_validate (nano::block const &, uint64_t * = nullptr);
uint64_t work_value (nano::block_hash const &, uint64_t);
class opencl_work;
class work_item
class work_item final
{
public:
nano::uint256_union item;
std::function<void(boost::optional<uint64_t> const &)> callback;
uint64_t difficulty;
};
class work_pool
class work_pool final
{
public:
work_pool (unsigned, std::function<boost::optional<uint64_t> (nano::uint256_union const &, uint64_t)> = nullptr);
Expand Down
4 changes: 2 additions & 2 deletions nano/node/blockprocessor.hpp
Expand Up @@ -27,10 +27,10 @@ class rolled_hash
* Processing blocks is a potentially long IO operation.
* This class isolates block insertion from other operations like servicing network operations
*/
class block_processor
class block_processor final
{
public:
block_processor (nano::node &);
explicit block_processor (nano::node &);
~block_processor ();
void stop ();
void flush ();
Expand Down
11 changes: 1 addition & 10 deletions nano/node/bootstrap.cpp
Expand Up @@ -842,20 +842,11 @@ void nano::bulk_pull_account_client::receive_pending ()
});
}

nano::pull_info::pull_info () :
account (0),
end (0),
count (0),
attempts (0)
{
}

nano::pull_info::pull_info (nano::account const & account_a, nano::block_hash const & head_a, nano::block_hash const & end_a, count_t count_a) :
account (account_a),
head (head_a),
end (end_a),
count (count_a),
attempts (0)
count (count_a)
{
}

Expand Down
54 changes: 27 additions & 27 deletions nano/node/bootstrap.hpp
Expand Up @@ -28,10 +28,10 @@ enum class sync_result
error,
fork
};
class socket : public std::enable_shared_from_this<nano::socket>
class socket final : public std::enable_shared_from_this<nano::socket>
{
public:
socket (std::shared_ptr<nano::node>);
explicit socket (std::shared_ptr<nano::node>);
void async_connect (nano::tcp_endpoint const &, std::function<void(boost::system::error_code const &)>);
void async_read (std::shared_ptr<std::vector<uint8_t>>, size_t, std::function<void(boost::system::error_code const &, size_t)>);
void async_write (std::shared_ptr<std::vector<uint8_t>>, std::function<void(boost::system::error_code const &, size_t)>);
Expand All @@ -53,14 +53,14 @@ class bootstrap_client;
class pull_info
{
public:
typedef nano::bulk_pull::count_t count_t;
pull_info ();
using count_t = nano::bulk_pull::count_t;
pull_info () = default;
pull_info (nano::account const &, nano::block_hash const &, nano::block_hash const &, count_t = 0);
nano::account account;
nano::block_hash head;
nano::block_hash end;
count_t count;
unsigned attempts;
nano::account account{ 0 };
nano::block_hash head{ 0 };
nano::block_hash end{ 0 };
count_t count{ 0 };
unsigned attempts{ 0 };
};
enum class bootstrap_mode
{
Expand All @@ -71,10 +71,10 @@ enum class bootstrap_mode
class frontier_req_client;
class bulk_push_client;
class bulk_pull_account_client;
class bootstrap_attempt : public std::enable_shared_from_this<bootstrap_attempt>
class bootstrap_attempt final : public std::enable_shared_from_this<bootstrap_attempt>
{
public:
bootstrap_attempt (std::shared_ptr<nano::node> node_a);
explicit bootstrap_attempt (std::shared_ptr<nano::node> node_a);
~bootstrap_attempt ();
void run ();
std::shared_ptr<nano::bootstrap_client> connection (std::unique_lock<std::mutex> &);
Expand Down Expand Up @@ -135,10 +135,10 @@ class bootstrap_attempt : public std::enable_shared_from_this<bootstrap_attempt>
// Wallet lazy bootstrap
std::deque<nano::account> wallet_accounts;
};
class frontier_req_client : public std::enable_shared_from_this<nano::frontier_req_client>
class frontier_req_client final : public std::enable_shared_from_this<nano::frontier_req_client>
{
public:
frontier_req_client (std::shared_ptr<nano::bootstrap_client>);
explicit frontier_req_client (std::shared_ptr<nano::bootstrap_client>);
~frontier_req_client ();
void run ();
void receive_frontier ();
Expand All @@ -158,7 +158,7 @@ class frontier_req_client : public std::enable_shared_from_this<nano::frontier_r
std::deque<std::pair<nano::account, nano::block_hash>> accounts;
static size_t constexpr size_frontier = sizeof (nano::account) + sizeof (nano::block_hash);
};
class bulk_pull_client : public std::enable_shared_from_this<nano::bulk_pull_client>
class bulk_pull_client final : public std::enable_shared_from_this<nano::bulk_pull_client>
{
public:
bulk_pull_client (std::shared_ptr<nano::bootstrap_client>, nano::pull_info const &);
Expand All @@ -175,7 +175,7 @@ class bulk_pull_client : public std::enable_shared_from_this<nano::bulk_pull_cli
uint64_t total_blocks;
uint64_t unexpected_count;
};
class bootstrap_client : public std::enable_shared_from_this<bootstrap_client>
class bootstrap_client final : public std::enable_shared_from_this<bootstrap_client>
{
public:
bootstrap_client (std::shared_ptr<nano::node>, std::shared_ptr<nano::bootstrap_attempt>, std::shared_ptr<nano::transport::channel_tcp>);
Expand All @@ -193,10 +193,10 @@ class bootstrap_client : public std::enable_shared_from_this<bootstrap_client>
std::atomic<bool> pending_stop;
std::atomic<bool> hard_stop;
};
class bulk_push_client : public std::enable_shared_from_this<nano::bulk_push_client>
class bulk_push_client final : public std::enable_shared_from_this<nano::bulk_push_client>
{
public:
bulk_push_client (std::shared_ptr<nano::bootstrap_client> const &);
explicit bulk_push_client (std::shared_ptr<nano::bootstrap_client> const &);
~bulk_push_client ();
void start ();
void push (nano::transaction const &);
Expand All @@ -206,7 +206,7 @@ class bulk_push_client : public std::enable_shared_from_this<nano::bulk_push_cli
std::promise<bool> promise;
std::pair<nano::block_hash, nano::block_hash> current_target;
};
class bulk_pull_account_client : public std::enable_shared_from_this<nano::bulk_pull_account_client>
class bulk_pull_account_client final : public std::enable_shared_from_this<nano::bulk_pull_account_client>
{
public:
bulk_pull_account_client (std::shared_ptr<nano::bootstrap_client>, nano::account const &);
Expand All @@ -217,10 +217,10 @@ class bulk_pull_account_client : public std::enable_shared_from_this<nano::bulk_
nano::account account;
uint64_t total_blocks;
};
class bootstrap_initiator
class bootstrap_initiator final
{
public:
bootstrap_initiator (nano::node &);
explicit bootstrap_initiator (nano::node &);
~bootstrap_initiator ();
void bootstrap (nano::endpoint const &, bool add_to_peers = true);
void bootstrap ();
Expand Down Expand Up @@ -248,7 +248,7 @@ class bootstrap_initiator
std::unique_ptr<seq_con_info_component> collect_seq_con_info (bootstrap_initiator & bootstrap_initiator, const std::string & name);

class bootstrap_server;
class bootstrap_listener
class bootstrap_listener final
{
public:
bootstrap_listener (boost::asio::io_context &, uint16_t, nano::node &);
Expand All @@ -272,7 +272,7 @@ class bootstrap_listener
std::unique_ptr<seq_con_info_component> collect_seq_con_info (bootstrap_listener & bootstrap_listener, const std::string & name);

class message;
class bootstrap_server : public std::enable_shared_from_this<nano::bootstrap_server>
class bootstrap_server final : public std::enable_shared_from_this<nano::bootstrap_server>
{
public:
bootstrap_server (std::shared_ptr<nano::socket>, std::shared_ptr<nano::node>);
Expand All @@ -294,7 +294,7 @@ class bootstrap_server : public std::enable_shared_from_this<nano::bootstrap_ser
std::queue<std::unique_ptr<nano::message>> requests;
};
class bulk_pull;
class bulk_pull_server : public std::enable_shared_from_this<nano::bulk_pull_server>
class bulk_pull_server final : public std::enable_shared_from_this<nano::bulk_pull_server>
{
public:
bulk_pull_server (std::shared_ptr<nano::bootstrap_server> const &, std::unique_ptr<nano::bulk_pull>);
Expand All @@ -313,7 +313,7 @@ class bulk_pull_server : public std::enable_shared_from_this<nano::bulk_pull_ser
nano::bulk_pull::count_t sent_count;
};
class bulk_pull_account;
class bulk_pull_account_server : public std::enable_shared_from_this<nano::bulk_pull_account_server>
class bulk_pull_account_server final : public std::enable_shared_from_this<nano::bulk_pull_account_server>
{
public:
bulk_pull_account_server (std::shared_ptr<nano::bootstrap_server> const &, std::unique_ptr<nano::bulk_pull_account>);
Expand All @@ -333,18 +333,18 @@ class bulk_pull_account_server : public std::enable_shared_from_this<nano::bulk_
bool pending_include_address;
bool invalid_request;
};
class bulk_push_server : public std::enable_shared_from_this<nano::bulk_push_server>
class bulk_push_server final : public std::enable_shared_from_this<nano::bulk_push_server>
{
public:
bulk_push_server (std::shared_ptr<nano::bootstrap_server> const &);
explicit bulk_push_server (std::shared_ptr<nano::bootstrap_server> const &);
void receive ();
void received_type ();
void received_block (boost::system::error_code const &, size_t, nano::block_type);
std::shared_ptr<std::vector<uint8_t>> receive_buffer;
std::shared_ptr<nano::bootstrap_server> connection;
};
class frontier_req;
class frontier_req_server : public std::enable_shared_from_this<nano::frontier_req_server>
class frontier_req_server final : public std::enable_shared_from_this<nano::frontier_req_server>
{
public:
frontier_req_server (std::shared_ptr<nano::bootstrap_server> const &, std::unique_ptr<nano::frontier_req>);
Expand Down