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
RPC: allow binding of restricted port in addition to core port #2836
RPC: allow binding of restricted port in addition to core port #2836
Conversation
{ | ||
throw std::runtime_error("Failed to initialize core rpc server."); | ||
throw std::runtime_error("Failed to initialize " + m_description + " rpc server."); |
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 wasn't able to use the <<
syntax here as it returned an error during compilation related to invalid operands to binary expression ('const char *' and 'const std::string'...)
Trying to figure out why (and will replace this once I do figure that out) but just making note of it if anyone knows offhand (still learning C++ so this isn't immediately obvious to me).
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.
<< is when the object is something which has this operator, such as a stringtream. operator+ is the right thing to use here.
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.
Looks good in general, just a couple minor questions.
src/daemon/daemon.cpp
Outdated
const auto restricted_rpc_port = command_line::get_arg(vm, testnet ? cryptonote::core_rpc_server::arg_testnet_rpc_restricted_bind_port : cryptonote::core_rpc_server::arg_rpc_restricted_bind_port); | ||
rpcs.emplace_back(new t_rpc{vm, core, p2p, restricted, testnet, main_rpc_port, "core"}); | ||
|
||
if(restricted_rpc_port.size()) |
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 should probably be somhting like "if (command_line::is_arg_defaulted(vm, ...))" and have the get_arg inside the if.
src/daemon/daemon.cpp
Outdated
|
||
std::unique_ptr<daemonize::t_command_server> rpc_commands; | ||
for(const auto& rpc: mp_internals->rpcs) | ||
rpc->run(); |
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.
Logically, it seems odd to call run on a const object. I'd make it non const, it's less surprising I think ?
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.
Sounds good, yeah agreed I'll switch those instances of it to remove that.
src/daemon/rpc.h
Outdated
, const bool restricted | ||
, const bool testnet | ||
, const std::string port | ||
, const std::string description |
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.
Maybe forgot a & ? (unless you know what you're doing with copy elision, I'm not very familiar with those)
I've pushed up some changes via https://github.com/Timo614/monero/commit/a45022eda85a048707910e14185fb1b5328d2a11 which I squashed and force pushed up here to one commit.
|
Going to push up one more change to just rename a variable I introduced in https://github.com/Timo614/monero/commit/a45022eda85a048707910e14185fb1b5328d2a11 from Edit: should be set now. |
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.
Nice trick that emplace_back, I should start using it too...
IMO we've got a useless proliferation of duplicate options, for testnet vs mainnet. It's not as if we allow a single daemon to operate on both simultaneously (do we?) There should be just one |
Edit: Removed, originally attempted to include the changes to merge the testnet parameters here but it's not worth including in this pull request / outside of scope and the comments I had added just muddy the conversation so nuking them. |
I'd rather the testnet arguments merge be in a totally separate patch (PR or not at your convenience, I don't really care, just a separate patch as it's logically separate). |
BTW, I think fluffypony had a preference for separating the arguments, so I'll go ping him to see this. |
I pushed up https://github.com/Timo614/monero/commit/7c1a19a77f9fb73db75466e4cd758b158fcf7437 Which reverts https://github.com/Timo614/monero/commit/6201ccd55871d0558990c2c5a11566660774ba08
If we decide to combine the testnet and regular arguments I'll nix the testnet one I added here and save any additional changes to combine the testnet and regular versions to outside of this branch in its own patch (the behavior of the
|
I ended up squashing this -- it's back to the code it was at previously where there's the two RPC arguments (one for testnet and one for the normal use case). Can swing back and remove the testnet one for this particular use case if we decide to combine them or can just do that in a subsequent patch and deprecate that command in a similar way (or just delete it then if we haven't released a new version yet / wouldn't break backwards compatibility). |
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
23b6f68 RPC: allow binding of restricted port in addition to core port (Tim L)
This branch adds two new configuration options
--rpc-restricted-bind-port
and--testnet-rpc-restricted-bind-port
which allow for a second port to be opened to handle RPC requests.Let me know if this direction is unwise. I spent some time looking over the code and this was the approach that seemed most sensible to me but I'm still learning C++ so completely understand if I've done something asinine. Currently the login is the same across both but if there's value that could be split into a separate set of configuration arguments as well.
I was able to test this by using the
/getinfo
call across both and confirmed that/get_peer_list
only works for the unrestricted.It's currently possible for someone to both set the core RPC port as restricted via
--restricted-rpc
and enable the restricted RPC port -- if it's worth it I can add something quickly to prevent that though.ref: #835