|
|
|
@ -30,6 +30,7 @@ |
|
|
|
|
|
|
|
|
|
#include "src/core/lib/channel/channelz_registry.h" |
|
|
|
|
#include "src/core/lib/channel/status_util.h" |
|
|
|
|
#include "src/core/lib/gpr/host_port.h" |
|
|
|
|
#include "src/core/lib/gpr/string.h" |
|
|
|
|
#include "src/core/lib/gpr/useful.h" |
|
|
|
|
#include "src/core/lib/gprpp/memory.h" |
|
|
|
@ -39,6 +40,7 @@ |
|
|
|
|
#include "src/core/lib/surface/channel.h" |
|
|
|
|
#include "src/core/lib/surface/server.h" |
|
|
|
|
#include "src/core/lib/transport/error_utils.h" |
|
|
|
|
#include "src/core/lib/uri/uri_parser.h" |
|
|
|
|
|
|
|
|
|
namespace grpc_core { |
|
|
|
|
namespace channelz { |
|
|
|
@ -277,62 +279,59 @@ grpc_json* ServerNode::RenderJson() { |
|
|
|
|
return top_level_json; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
SocketAddress::SocketAddress() : type_(AddressType::kUnset), port_(-1) {} |
|
|
|
|
|
|
|
|
|
SocketAddress::SocketAddress(SocketAddress&& other) { |
|
|
|
|
type_ = other.type_; |
|
|
|
|
port_ = other.port_; |
|
|
|
|
blob_.reset((other.blob_.release())); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void SocketAddress::PopulateJson(const char* name, grpc_json* json) { |
|
|
|
|
if (type_ == AddressType::kUnset) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
static void PopulateSocketAddressJson(grpc_json* json, const char* name, |
|
|
|
|
const char* addr_str) { |
|
|
|
|
if (addr_str == nullptr) return; |
|
|
|
|
grpc_json* json_iterator = nullptr; |
|
|
|
|
json_iterator = grpc_json_create_child(json_iterator, json, name, nullptr, |
|
|
|
|
GRPC_JSON_OBJECT, false); |
|
|
|
|
json = json_iterator; |
|
|
|
|
json_iterator = nullptr; |
|
|
|
|
switch (type_) { |
|
|
|
|
case AddressType::kTcpAddress: |
|
|
|
|
json_iterator = |
|
|
|
|
grpc_json_create_child(json_iterator, json, "tcpip_address", nullptr, |
|
|
|
|
GRPC_JSON_OBJECT, false); |
|
|
|
|
json = json_iterator; |
|
|
|
|
json_iterator = nullptr; |
|
|
|
|
json_iterator = |
|
|
|
|
grpc_json_add_number_string_child(json, json_iterator, "port", port_); |
|
|
|
|
json_iterator = |
|
|
|
|
grpc_json_create_child(json_iterator, json, "ip_address", blob_.get(), |
|
|
|
|
GRPC_JSON_STRING, false); |
|
|
|
|
break; |
|
|
|
|
case AddressType::kUdsAddress: |
|
|
|
|
int port_num = -1; |
|
|
|
|
grpc_uri* uri = grpc_uri_parse(addr_str, true); |
|
|
|
|
if (uri != nullptr && (strcmp(uri->scheme, "fd") != 0)) { |
|
|
|
|
const char* host_port = uri->path; |
|
|
|
|
if (*host_port == '/') ++host_port; |
|
|
|
|
if (strcmp(uri->scheme, "unix") == 0) { |
|
|
|
|
json_iterator = grpc_json_create_child(json_iterator, json, "uds_address", |
|
|
|
|
nullptr, GRPC_JSON_OBJECT, false); |
|
|
|
|
json = json_iterator; |
|
|
|
|
json_iterator = nullptr; |
|
|
|
|
json_iterator = |
|
|
|
|
grpc_json_create_child(json_iterator, json, "filename", blob_.get(), |
|
|
|
|
GRPC_JSON_STRING, false); |
|
|
|
|
break; |
|
|
|
|
case AddressType::kDirectChannelAddress: |
|
|
|
|
grpc_json_create_child(json_iterator, json, "filename", |
|
|
|
|
gpr_strdup(host_port), GRPC_JSON_STRING, true); |
|
|
|
|
} else { |
|
|
|
|
char* host = nullptr; |
|
|
|
|
char* port = nullptr; |
|
|
|
|
GPR_ASSERT(gpr_split_host_port(host_port, &host, &port)); |
|
|
|
|
if (port != nullptr) { |
|
|
|
|
port_num = atoi(port); |
|
|
|
|
} |
|
|
|
|
char* b64_host = gpr_string_base64_encode(host); |
|
|
|
|
json_iterator = |
|
|
|
|
grpc_json_create_child(json_iterator, json, "other_address", nullptr, |
|
|
|
|
grpc_json_create_child(json_iterator, json, "tcpip_address", nullptr, |
|
|
|
|
GRPC_JSON_OBJECT, false); |
|
|
|
|
json = json_iterator; |
|
|
|
|
json_iterator = nullptr; |
|
|
|
|
json_iterator = grpc_json_create_child( |
|
|
|
|
json_iterator, json, "name", blob_.get(), GRPC_JSON_STRING, false); |
|
|
|
|
break; |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
GPR_UNREACHABLE_CODE(GPR_ASSERT(0)); |
|
|
|
|
break; |
|
|
|
|
json_iterator = grpc_json_add_number_string_child(json, json_iterator, |
|
|
|
|
"port", port_num); |
|
|
|
|
json_iterator = grpc_json_create_child(json_iterator, json, "ip_address", |
|
|
|
|
b64_host, GRPC_JSON_STRING, true); |
|
|
|
|
gpr_free(host); |
|
|
|
|
gpr_free(port); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
json_iterator = grpc_json_create_child(json_iterator, json, "other_address", |
|
|
|
|
nullptr, GRPC_JSON_OBJECT, false); |
|
|
|
|
json = json_iterator; |
|
|
|
|
json_iterator = nullptr; |
|
|
|
|
json_iterator = grpc_json_create_child(json_iterator, json, "name", |
|
|
|
|
addr_str, GRPC_JSON_STRING, false); |
|
|
|
|
} |
|
|
|
|
grpc_uri_destroy(uri); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
SocketNode::SocketNode(SocketAddress local, SocketAddress remote) |
|
|
|
|
SocketNode::SocketNode(UniquePtr<char> local, UniquePtr<char> remote) |
|
|
|
|
: BaseNode(EntityType::kSocket), |
|
|
|
|
local_(std::move(local)), |
|
|
|
|
remote_(std::move(remote)) {} |
|
|
|
@ -374,8 +373,8 @@ grpc_json* SocketNode::RenderJson() { |
|
|
|
|
json_iterator = grpc_json_add_number_string_child(json, json_iterator, |
|
|
|
|
"socketId", uuid()); |
|
|
|
|
json = top_level_json; |
|
|
|
|
remote_.PopulateJson("remote", json); |
|
|
|
|
local_.PopulateJson("local", json); |
|
|
|
|
PopulateSocketAddressJson(json, "remote", remote_.get()); |
|
|
|
|
PopulateSocketAddressJson(json, "local", local_.get()); |
|
|
|
|
// reset json iterators to top level object
|
|
|
|
|
json = top_level_json; |
|
|
|
|
json_iterator = nullptr; |
|
|
|
@ -435,8 +434,8 @@ grpc_json* SocketNode::RenderJson() { |
|
|
|
|
return top_level_json; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ListenSocketNode::ListenSocketNode(UniquePtr<char> host, int port) |
|
|
|
|
: BaseNode(EntityType::kSocket), host_(std::move(host)), port_(port) {} |
|
|
|
|
ListenSocketNode::ListenSocketNode(UniquePtr<char> local_addr) |
|
|
|
|
: BaseNode(EntityType::kSocket), local_addr_(std::move(local_addr)) {} |
|
|
|
|
|
|
|
|
|
grpc_json* ListenSocketNode::RenderJson() { |
|
|
|
|
// We need to track these three json objects to build our object
|
|
|
|
@ -450,20 +449,7 @@ grpc_json* ListenSocketNode::RenderJson() { |
|
|
|
|
json_iterator = nullptr; |
|
|
|
|
json_iterator = grpc_json_add_number_string_child(json, json_iterator, |
|
|
|
|
"socketId", uuid()); |
|
|
|
|
json = top_level_json; |
|
|
|
|
json_iterator = nullptr; |
|
|
|
|
json_iterator = grpc_json_create_child(json_iterator, json, "local", nullptr, |
|
|
|
|
GRPC_JSON_OBJECT, false); |
|
|
|
|
json = json_iterator; |
|
|
|
|
json_iterator = nullptr; |
|
|
|
|
json_iterator = grpc_json_create_child(json_iterator, json, "tcpip_address", |
|
|
|
|
nullptr, GRPC_JSON_OBJECT, false); |
|
|
|
|
json = json_iterator; |
|
|
|
|
json_iterator = nullptr; |
|
|
|
|
json_iterator = |
|
|
|
|
grpc_json_add_number_string_child(json, json_iterator, "port", port_); |
|
|
|
|
json_iterator = grpc_json_create_child(json_iterator, json, "ip_address", |
|
|
|
|
host_.get(), GRPC_JSON_STRING, false); |
|
|
|
|
PopulateSocketAddressJson(json, "local", local_addr_.get()); |
|
|
|
|
|
|
|
|
|
return top_level_json; |
|
|
|
|
} |
|
|
|
|