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

Add a config option to allow local peers #1370

Merged
merged 6 commits into from
Nov 23, 2018
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 rai/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,16 @@ class network_message_visitor : public rai::message_visitor

void rai::network::receive_action (rai::udp_data * data_a)
{
if (!rai::reserved_address (data_a->endpoint, false) && data_a->endpoint != endpoint ())
auto allowed_sender (true);
if (data_a->endpoint == endpoint ())
{
allowed_sender = false;
}
else if (rai::reserved_address (data_a->endpoint, false) && !node.config.allow_local_peers)
{
allowed_sender = false;
}
if (allowed_sender)
{
network_message_visitor visitor (node, data_a->endpoint);
rai::message_parser parser (node.block_uniquer, node.vote_uniquer, visitor, node.work);
Expand Down
5 changes: 5 additions & 0 deletions rai/node/nodeconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ bootstrap_connections (4),
bootstrap_connections_max (64),
callback_port (0),
lmdb_max_dbs (128),
allow_local_peers (false),
block_processor_batch_max_time (std::chrono::milliseconds (5000))
{
const char * epoch_message ("epoch v1 block");
Expand Down Expand Up @@ -106,6 +107,7 @@ void rai::node_config::serialize_json (boost::property_tree::ptree & tree_a) con
tree_a.put ("callback_target", callback_target);
tree_a.put ("lmdb_max_dbs", lmdb_max_dbs);
tree_a.put ("block_processor_batch_max_time", block_processor_batch_max_time.count ());
tree_a.put ("allow_local_peers", allow_local_peers);
}

bool rai::node_config::upgrade_json (unsigned version_a, boost::property_tree::ptree & tree_a)
Expand Down Expand Up @@ -193,6 +195,9 @@ bool rai::node_config::upgrade_json (unsigned version_a, boost::property_tree::p
tree_a.put ("block_processor_batch_max_time", block_processor_batch_max_time.count ());
result = true;
case 15:
tree_a.put ("allow_local_peers", allow_local_peers);
result = true;
case 16:
break;
default:
throw std::runtime_error ("Unknown node_config version");
Expand Down
3 changes: 2 additions & 1 deletion rai/node/nodeconfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ class node_config
uint16_t callback_port;
std::string callback_target;
int lmdb_max_dbs;
bool allow_local_peers;
rai::stat_config stat_config;
rai::uint256_union epoch_block_link;
rai::account epoch_block_signer;
std::chrono::milliseconds block_processor_batch_max_time;
static std::chrono::seconds constexpr keepalive_period = std::chrono::seconds (60);
static std::chrono::seconds constexpr keepalive_cutoff = keepalive_period * 5;
static std::chrono::minutes constexpr wallet_backup_interval = std::chrono::minutes (5);
static constexpr int json_version = 15;
static constexpr int json_version = 16;
};
}