-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Conversation
src/p2p/net_node.inl
Outdated
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
} | ||
--count; | ||
} | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
"opertations" in the last commit message. |
"opertations" fixed! |
This is working as intended on my system. |
|
||
if (out_connections.size() == 0) | ||
return; | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Something bludgeoned indentation :/ |
del_connection(conn); | ||
close(*i); | ||
connections.erase(i); | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
src/common/rpc_client.h
Outdated
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 ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove whitespace after !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
src/common/rpc_client.h
Outdated
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 ? |
There was a problem hiding this comment.
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]); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this newline
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did this change?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
More testing showed that this was indeed working correctly. No changes needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed
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)
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.