-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 RPC/WS ports to server_info #4427
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,9 +65,11 @@ | |
#include <ripple/rpc/BookChanges.h> | ||
#include <ripple/rpc/DeliveredAmount.h> | ||
#include <ripple/rpc/impl/RPCHelpers.h> | ||
#include <ripple/rpc/impl/ServerHandlerImp.h> | ||
#include <boost/asio/ip/host_name.hpp> | ||
#include <boost/asio/steady_timer.hpp> | ||
|
||
#include <algorithm> | ||
#include <mutex> | ||
#include <string> | ||
#include <tuple> | ||
|
@@ -2661,6 +2663,51 @@ NetworkOPsImp::getServerInfo(bool human, bool admin, bool counters) | |
info["reporting"] = app_.getReportingETL().getInfo(); | ||
} | ||
|
||
// This array must be sorted in increasing order. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm assuming this is because of Is there a way to static assert that it is sorted? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great question, and a good idea. Since we're running C++20, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great idea. Thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice job with the |
||
static constexpr std::array<std::string_view, 7> protocols{ | ||
"http", "https", "peer", "ws", "ws2", "wss", "wss2"}; | ||
static_assert(std::is_sorted(std::begin(protocols), std::end(protocols))); | ||
{ | ||
Json::Value ports{Json::arrayValue}; | ||
for (auto const& port : app_.getServerHandler().setup().ports) | ||
{ | ||
// Don't publish admin ports for non-admin users | ||
if (!admin && | ||
!(port.admin_nets_v4.empty() && port.admin_nets_v6.empty() && | ||
port.admin_user.empty() && port.admin_password.empty())) | ||
continue; | ||
Comment on lines
+2675
to
+2678
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. I modified my unit tests to cover that case. |
||
std::vector<std::string> proto; | ||
std::set_intersection( | ||
std::begin(port.protocol), | ||
std::end(port.protocol), | ||
std::begin(protocols), | ||
std::end(protocols), | ||
std::back_inserter(proto)); | ||
if (!proto.empty()) | ||
{ | ||
auto& jv = ports.append(Json::Value(Json::objectValue)); | ||
jv[jss::port] = std::to_string(port.port); | ||
jv[jss::protocol] = Json::Value{Json::arrayValue}; | ||
for (auto const& p : proto) | ||
jv[jss::protocol].append(p); | ||
} | ||
} | ||
|
||
if (app_.config().exists("port_grpc")) | ||
{ | ||
auto const& grpcSection = app_.config().section("port_grpc"); | ||
auto const optPort = grpcSection.get("port"); | ||
if (optPort && grpcSection.get("ip")) | ||
{ | ||
auto& jv = ports.append(Json::Value(Json::objectValue)); | ||
jv[jss::port] = *optPort; | ||
jv[jss::protocol] = Json::Value{Json::arrayValue}; | ||
jv[jss::protocol].append("grpc"); | ||
} | ||
} | ||
info[jss::ports] = std::move(ports); | ||
} | ||
|
||
return info; | ||
} | ||
|
||
|
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.
Sneak in a minor improvement.
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.
The change you made here definitely is an improvement. You're now taking a reference instead of making a copy. And a
Section
is a heavy weight thing to copy. Good spotting.However, not everyone will agree that replacing an explicit type name with
auto
is an improvement. In my opinion it hides important information that could be visible explicitly in the source code. My personal opinion is that Herb Sutter was dead wrong when he said "almost alwaysauto
" years ago. So my preferred declaration here would look like...Folks who use an IDE with something like intellisense sometimes lose track of those of us who who develop code using just a text editor. Explicit type names (as opposed to
auto
) also are a big help when viewing code through browsers, like on Github or in code reviews.I'm not asking for a change here. Just providing a different perspective for you to think about when you make other changes in the future.