aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar ncteisen <ncteisen@gmail.com>2018-10-30 10:49:11 -0700
committerGravatar ncteisen <ncteisen@gmail.com>2018-10-30 10:49:11 -0700
commitc13de2eb1e12295cc576abb58d1f8060ff8035b4 (patch)
tree61b982eafb446aac0b6004344369814c695d76d0
parentd82dff4ea042752009f23aa2a87f56016050cc6c (diff)
Support direct channels peer_string
-rw-r--r--src/core/ext/transport/chttp2/transport/chttp2_transport.cc28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc
index d4665d5245..691331e177 100644
--- a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc
+++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc
@@ -397,23 +397,29 @@ static bool read_channel_args(grpc_chttp2_transport* t,
}
}
if (channelz_enabled) {
- // pick out just the host port (maybe trims off scheme prefix).
- grpc_uri* uri = grpc_uri_parse(t->peer_string, false);
- GPR_ASSERT(uri != nullptr);
- const char* host_port = uri->path;
- if (*host_port == '/') ++host_port;
- char* host;
- char* port;
- GPR_ASSERT(gpr_split_host_port(host_port, &host, &port));
+ char* host = nullptr;
int port_num = -1;
- if (port != nullptr) {
- port_num = atoi(port);
+ // try to pick out just the host port (maybe trims off scheme prefix).
+ grpc_uri* uri = grpc_uri_parse(t->peer_string, false);
+ // if peer string was a valid URI, we can use our lib to do the trimming.
+ if (uri != nullptr) {
+ const char* host_port = uri->path;
+ if (*host_port == '/') ++host_port;
+ char* port;
+ GPR_ASSERT(gpr_split_host_port(host_port, &host, &port));
+ if (port != nullptr) {
+ port_num = atoi(port);
+ }
+ gpr_free(port);
+ } else {
+ // if peer string is not a valid URI, just use the entire string to
+ // surface that info.
+ host = gpr_strdup(t->peer_string);
}
t->channelz_socket =
grpc_core::MakeRefCounted<grpc_core::channelz::SocketNode>(
grpc_core::UniquePtr<char>(host), port_num);
grpc_uri_destroy(uri);
- gpr_free(port);
}
return enable_bdp;
}