@@ -49,15 +49,19 @@ IpPreference ExtractIpPreference(std::string_view peer_address) {
4949 return IpPreference::kNone ;
5050}
5151
52+ bool IsAltsNegotiated (grpc::AuthContext const & auth_ctx) {
53+ if (!auth_ctx.IsPeerAuthenticated ()) return false ;
54+ std::vector<grpc::string_ref> const sec_types =
55+ auth_ctx.FindPropertyValues (" transport_security_type" );
56+ return std::any_of (sec_types.begin (), sec_types.end (),
57+ [](grpc::string_ref const & st) { return st == " alts" ; });
58+ }
59+
5260bool IsAltsNegotiated (grpc::ClientContext const & context) {
5361 std::shared_ptr<grpc::AuthContext const > const auth_ctx =
5462 context.auth_context ();
5563 if (auth_ctx == nullptr ) return false ;
56- if (!auth_ctx->IsPeerAuthenticated ()) return false ;
57- std::vector<grpc::string_ref> const sec_types =
58- auth_ctx->FindPropertyValues (" transport_security_type" );
59- return std::any_of (sec_types.begin (), sec_types.end (),
60- [](grpc::string_ref const & st) { return st == " alts" ; });
64+ return IsAltsNegotiated (*auth_ctx);
6165}
6266
6367bool IsPeerAuthenticated (grpc::ClientContext const & context) {
@@ -115,12 +119,6 @@ StatusOr<DirectPathProbeResult> DirectPathProber::Probe(
115119 GCP_ERROR_INFO ());
116120 }
117121
118- std::chrono::milliseconds timeout =
119- options.get <bigtable::experimental::DirectPathProbeTimeoutOption>();
120- if (timeout <= std::chrono::milliseconds::zero ()) {
121- timeout = std::chrono::milliseconds (2000 );
122- }
123-
124122 auto constexpr kDirectPathEndpoint = " google-c2p:///bigtable.googleapis.com" ;
125123 auto constexpr kAuthority = " bigtable.googleapis.com" ;
126124
@@ -144,6 +142,31 @@ StatusOr<DirectPathProbeResult> DirectPathProber::Probe(
144142 std::shared_ptr<BigtableStub> stub =
145143 CreateDecoratedStubs (auth, cq, probe_options, stub_factory);
146144
145+ return Probe (stub, instance_resource, probe_options);
146+ }
147+
148+ StatusOr<DirectPathProbeResult> DirectPathProber::Probe (
149+ std::shared_ptr<BigtableStub> stub,
150+ bigtable::InstanceResource const & instance_resource,
151+ Options const & options) {
152+ return Probe (std::move (stub), instance_resource, options, " " , nullptr );
153+ }
154+
155+ StatusOr<DirectPathProbeResult> DirectPathProber::Probe (
156+ std::shared_ptr<BigtableStub> stub,
157+ bigtable::InstanceResource const & instance_resource, Options const & options,
158+ std::string const & peer_address,
159+ std::shared_ptr<grpc::AuthContext const > auth_context) {
160+ if (!stub) {
161+ return internal::InternalError (" Stub cannot be null" , GCP_ERROR_INFO ());
162+ }
163+
164+ std::chrono::milliseconds timeout =
165+ options.get <bigtable::experimental::DirectPathProbeTimeoutOption>();
166+ if (timeout <= std::chrono::milliseconds::zero ()) {
167+ timeout = std::chrono::milliseconds (2000 );
168+ }
169+
147170 grpc::ClientContext client_context;
148171 client_context.set_deadline (std::chrono::system_clock::now () + timeout);
149172
@@ -154,13 +177,18 @@ StatusOr<DirectPathProbeResult> DirectPathProber::Probe(
154177 }
155178 OperationContext op_ctx;
156179 StatusOr<google::bigtable::v2::PingAndWarmResponse> response =
157- stub->PingAndWarm (client_context, probe_options , request, op_ctx);
180+ stub->PingAndWarm (client_context, options , request, op_ctx);
158181 if (!response.ok ()) return response.status ();
159182
160183 DirectPathProbeResult result;
161- result.peer_address = client_context.peer ();
162- bool const is_alts = IsAltsNegotiated (client_context);
163- bool const is_auth = IsPeerAuthenticated (client_context);
184+ result.peer_address =
185+ peer_address.empty () ? client_context.peer () : peer_address;
186+ bool const is_alts = auth_context != nullptr
187+ ? IsAltsNegotiated (*auth_context)
188+ : IsAltsNegotiated (client_context);
189+ bool const is_auth = auth_context != nullptr
190+ ? auth_context->IsPeerAuthenticated ()
191+ : IsPeerAuthenticated (client_context);
164192 bool const is_dp_ip = IsDirectPathIp (result.peer_address );
165193 result.success = is_alts || (is_auth && is_dp_ip);
166194 result.ip_preference = result.success
0 commit comments