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

RPC: allow binding of restricted port in addition to core port #2836

Merged
merged 1 commit into from Dec 2, 2017
Merged

RPC: allow binding of restricted port in addition to core port #2836

merged 1 commit into from Dec 2, 2017

Conversation

Timo614
Copy link
Contributor

@Timo614 Timo614 commented Nov 17, 2017

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

{
throw std::runtime_error("Failed to initialize core rpc server.");
throw std::runtime_error("Failed to initialize " + m_description + " rpc server.");
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 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).

Copy link
Collaborator

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.

@Timo614 Timo614 changed the title RPC: allow binding of restricted API in addition to core API RPC: allow binding of restricted port in addition to core port Nov 17, 2017
Copy link
Collaborator

@moneromooo-monero moneromooo-monero left a 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.

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())
Copy link
Collaborator

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.


std::unique_ptr<daemonize::t_command_server> rpc_commands;
for(const auto& rpc: mp_internals->rpcs)
rpc->run();
Copy link
Collaborator

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 ?

Copy link
Contributor Author

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
Copy link
Collaborator

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)

@Timo614
Copy link
Contributor Author

Timo614 commented Nov 17, 2017

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.

  • Added the & to the method signatures for port and description to pass by reference
  • Switched the iteration of the rpcs to remove the const declaration
  • Used is_arg_defaulted for confirming whether the restricted port was requested

@Timo614
Copy link
Contributor Author

Timo614 commented Nov 17, 2017

Going to push up one more change to just rename a variable I introduced in https://github.com/Timo614/monero/commit/a45022eda85a048707910e14185fb1b5328d2a11 from restricted_rpc_arg to restricted_rpc_port_arg as there's another --restricted-rpc arg and I want to reduce confusion that naming may cause.

Edit: should be set now.

Copy link
Collaborator

@moneromooo-monero moneromooo-monero left a 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...

@hyc
Copy link
Collaborator

hyc commented Nov 17, 2017

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 --testnet option, which completely changes the daemon's operating context, and thus all of the other parameters, in one fell swoop.

@Timo614
Copy link
Contributor Author

Timo614 commented Nov 17, 2017

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.

@moneromooo-monero
Copy link
Collaborator

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).

@moneromooo-monero
Copy link
Collaborator

BTW, I think fluffypony had a preference for separating the arguments, so I'll go ping him to see this.

@Timo614
Copy link
Contributor Author

Timo614 commented Nov 17, 2017

I pushed up https://github.com/Timo614/monero/commit/7c1a19a77f9fb73db75466e4cd758b158fcf7437

Which reverts https://github.com/Timo614/monero/commit/6201ccd55871d0558990c2c5a11566660774ba08

I'll hold off on squashing it for now.

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 --rpc-bind-port and --rpc-restricted-bind-port will diverge in that case for testnet but only until the additional PR is merged so not terrible).

Alternatively I can just squash now and we can revisit this in a separate issue later (it'll add the new --testnet-rpc-restricted-bind-port command here but it can be deprecated in the same fashion as the --testnet-rpc-bind-port when we file those changes).

@Timo614
Copy link
Contributor Author

Timo614 commented Nov 17, 2017

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).

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 23b6f68 into monero-project:master Dec 2, 2017
fluffypony added a commit that referenced this pull request Dec 2, 2017
23b6f68 RPC: allow binding of restricted port in addition to core port (Tim L)
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.

None yet

4 participants