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

Allow setting of max incoming connection count on command line and in config file #3163

Merged
merged 6 commits into from
Feb 16, 2018
Merged

Conversation

erikd
Copy link
Contributor

@erikd erikd commented Jan 20, 2018

With this patch, the maximum number of incoming peers can be set either on the command line (with --in-peers <n> or in the config file. I've tested this and even after 12 hours the number of incoming connections does not go over the specified number whereas previously I would see between 10 and 50 incoming connections after 12 hours.

However it is also supposed to be possible to modify the number of incoming connections on the fly via an RPC call and that is not currently working. However setting the number of outgoing peer connections via an RPC call isn't working either.

Therefore I'll leave this PR as is and fix the RPC call business in an upcoming PR.

RPC is now working as well.

@erikd erikd changed the title Allow setting of incoming connections on command line and config file Allow setting of max incoming connection count on command line and in config file Jan 21, 2018
@erikd erikd changed the title Allow setting of max incoming connection count on command line and in config file [Do not merge, still testing]: Allow setting of max incoming connection count on command line and in config file Jan 21, 2018
bool node_server<t_payload_net_handler>::set_max_in_peers(const boost::program_options::variables_map& vm, int64_t max)
{
if(max == -1) {
m_config.m_net_config.max_in_connection_count = P2P_DEFAULT_CONNECTIONS_COUNT;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That change causes a large change in the network, no ?
I think that if a new node comes online, it might not be able to connect to the network (or will take a while to find a node which doesn't have all its slots free). I would either consider the -1 default to mean no limit, or set a substantially larger limit than the out one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set to -1.

struct request
{
uint64_t in_peers;
BEGIN_KV_SERIALIZE_MAP()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to get proper indent on new code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}
--count;
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please factor with the existing function, should be pretty much all the same execpt the selection condition near the top.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I factored out the deletion of the connections, but my C++ is too rusty to factor it further.

@moneromooo-monero
Copy link
Collaborator

"opertations" in the last commit message.

@erikd
Copy link
Contributor Author

erikd commented Jan 22, 2018

"opertations" fixed!

@erikd erikd changed the title [Do not merge, still testing]: Allow setting of max incoming connection count on command line and in config file Allow setting of max incoming connection count on command line and in config file Jan 23, 2018
@erikd
Copy link
Contributor Author

erikd commented Jan 23, 2018

This is working as intended on my system.


if (out_connections.size() == 0)
return;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That whole part can be factored too, since the only difference is a boolean which can be passed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't t be better to change that to:

	if (out_connections.size() > 0)
		delete_connections(count, out_connections);

The early return without executing CRITICAL_REGION_END is a bit problematic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind. Now I get it. Will fix tomorrow.

@moneromooo-monero
Copy link
Collaborator

Something bludgeoned indentation :/

del_connection(conn);
close(*i);
connections.erase(i);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A recent PR modified this to delete from the end, please apply to this version too when you rebase.

This is needed so that a max_in_connection_count can be added.
This rename is needed so that delete_in_connections can be added.
Copy link
Contributor

@leonklingele leonklingele left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also revert trimming of trailing spaces.

if (!ok)
{
fail_msg_writer() << "Couldn't connect to daemon: " << m_http_client.get_host() << ":" << m_http_client.get_port();
return false;
}
else if (res.status != CORE_RPC_STATUS_OK) // TODO - handle CORE_RPC_STATUS_BUSY ?
ok = epee::net_utils::invoke_http_json_rpc("/json_rpc", method_name, req, res, m_http_client, t_http_connection::TIMEOUT());
if (! ok || res.status != CORE_RPC_STATUS_OK) // TODO - handle CORE_RPC_STATUS_BUSY ?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove whitespace after !

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

if (!ok)
{
fail_msg_writer() << "Couldn't connect to daemon: " << m_http_client.get_host() << ":" << m_http_client.get_port();
return false;
}
else if (res.status != CORE_RPC_STATUS_OK) // TODO - handle CORE_RPC_STATUS_BUSY ?
ok = epee::net_utils::invoke_http_json(relative_url, req, res, m_http_client, t_http_connection::TIMEOUT());
if (! ok || res.status != CORE_RPC_STATUS_OK) // TODO - handle CORE_RPC_STATUS_BUSY ?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove whitespace after !

try {
limit = std::stoi(args[0]);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this newline

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This matches the rest of the code in this file.

limit = std::stoi(args[0]);
}

catch(const std::exception& ex) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Add whitespace after catch
  • Move curly bracket to new line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This matches the rest of the code in this file.

if (args.empty()) return false;

unsigned int limit;
try {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move curly bracket to new line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This matches the rest of the code in this file.

@@ -1262,7 +1262,7 @@ bool t_rpc_command_executor::out_peers(uint64_t limit)

if (m_is_rpc)
{
if (!m_rpc_client->json_rpc_request(req, res, "out_peers", fail_message.c_str()))
if (!m_rpc_client->rpc_request(req, res, "/out_peers", fail_message.c_str()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did this change?

Copy link
Contributor Author

@erikd erikd Jan 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its not a JSON request. Calling it via json_rpc_request doesn't work (in fact never worked). Calling it via rpc_request does work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is an (unrelated) bugfix?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a separate commit that is part of this PR because it is related.

size_t count = 0;
m_net_server.get_config_object().foreach_connection([&](const p2p_connection_context& cntxt)
{
if(cntxt.m_is_income)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a space after if

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This matches the rest of the code in this file.

It was already possible to limit outgoing connections. One might want
to do this on home network connections with high bandwidth but low
usage caps.
Previously, the method name was printed as an exmpty string because
the input string had already been moved with `std::move`.
Previous code was unable to distingush between a connection error
and a communication error.
Original implementations could never have worked.
@erikd erikd changed the title Allow setting of max incoming connection count on command line and in config file [Do not merge, may be a problem with this] : Allow setting of max incoming connection count on command line and in config file Feb 3, 2018
@erikd
Copy link
Contributor Author

erikd commented Feb 3, 2018

I've noticed that if I set in_peers and start the daemon, the number of input peers climbs to the specified number, holds that value for a while and then the number slowly drops back to zero over a couple of days. I suspect that when an incoming connection is lost, the incoming connection count isn't being decremented so that a replacement connection isn't being allowed.

More testing showed that this was indeed working correctly. No changes needed.

@erikd erikd changed the title [Do not merge, may be a problem with this] : Allow setting of max incoming connection count on command line and in config file Allow setting of max incoming connection count on command line and in config file Feb 3, 2018
Copy link
Contributor

@fluffypony fluffypony left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed

@fluffypony fluffypony merged commit 628b78a into monero-project:master Feb 16, 2018
fluffypony added a commit that referenced this pull request Feb 16, 2018
628b78a Fix in_peers/out_peers RPC operations (Erik de Castro Lopo)
ece9bcf rpc_client: Fix error handling (Erik de Castro Lopo)
8f30350 Fix method name in invoke_http_json_rpc (Erik de Castro Lopo)
32c0f90 Allow the number of incoming connections to be limited (Erik de Castro Lopo)
d609a2c Rename delete_connections to delete_out_connections (Erik de Castro Lopo)
b927c0f Rename connections_count to max_out_connection_count (Erik de Castro Lopo)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants