diff options
author | ncteisen <ncteisen@gmail.com> | 2018-11-01 16:42:47 -0400 |
---|---|---|
committer | ncteisen <ncteisen@gmail.com> | 2018-11-01 16:42:47 -0400 |
commit | f776ee33c2212e3b84431b739fe855e99393a022 (patch) | |
tree | cd19209d260addadf3066ac3d45f5204ed0e293c | |
parent | 580216da82b9a5d78733219447997c9497749c2f (diff) |
clean up channelz URI parsing
-rw-r--r-- | src/core/lib/channel/channelz.cc | 62 | ||||
-rw-r--r-- | src/core/lib/channel/channelz.h | 2 |
2 files changed, 29 insertions, 35 deletions
diff --git a/src/core/lib/channel/channelz.cc b/src/core/lib/channel/channelz.cc index 376885cdd8..b31ab41f6a 100644 --- a/src/core/lib/channel/channelz.cc +++ b/src/core/lib/channel/channelz.cc @@ -288,44 +288,38 @@ static void PopulateSocketAddressJson(grpc_json* json, const char* name, GRPC_JSON_OBJECT, false); json = json_iterator; json_iterator = nullptr; - int port_num = -1; grpc_uri* uri = grpc_uri_parse(addr_str, true); - if (uri != nullptr && (strcmp(uri->scheme, "fd") != 0)) { + if ((uri != nullptr) && ((strcmp(uri->scheme, "ipv4") == 0) || + (strcmp(uri->scheme, "ipv6") == 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", - gpr_strdup(host_port), GRPC_JSON_STRING, true); - } else { - char* host = nullptr; - char* port = nullptr; - if (strcmp(uri->scheme, "localhost") == 0) { - host = gpr_strdup("::1"); - port_num = atoi(uri->path); - } else { - GPR_ASSERT(gpr_split_host_port(host_port, &host, &port)); - if (port != nullptr) { - port_num = atoi(port); - } - } - char* b64_host = grpc_base64_encode(host, strlen(host), false, false); - 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_num); - json_iterator = grpc_json_create_child(json_iterator, json, "ip_address", - b64_host, GRPC_JSON_STRING, true); - gpr_free(host); - gpr_free(port); + char* host = nullptr; + char* port = nullptr; + GPR_ASSERT(gpr_split_host_port(host_port, &host, &port)); + int port_num = -1; + if (port != nullptr) { + port_num = atoi(port); } + char* b64_host = grpc_base64_encode(host, strlen(host), false, false); + 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_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 if (uri != nullptr && 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", + gpr_strdup(uri->path), GRPC_JSON_STRING, true); } else { json_iterator = grpc_json_create_child(json_iterator, json, "other_address", nullptr, GRPC_JSON_OBJECT, false); diff --git a/src/core/lib/channel/channelz.h b/src/core/lib/channel/channelz.h index cdbae581fd..64ab5cb3a6 100644 --- a/src/core/lib/channel/channelz.h +++ b/src/core/lib/channel/channelz.h @@ -270,7 +270,7 @@ class SocketNode : public BaseNode { class ListenSocketNode : public BaseNode { public: // ListenSocketNode takes ownership of host. - ListenSocketNode(UniquePtr<char> local_addr); + explicit ListenSocketNode(UniquePtr<char> local_addr); ~ListenSocketNode() override {} grpc_json* RenderJson() override; |