mirror of https://github.com/grpc/grpc.git
commit
0cedc27cb6
26 changed files with 399 additions and 175 deletions
@ -0,0 +1,79 @@ |
|||||||
|
/*
|
||||||
|
* |
||||||
|
* Copyright 2015 gRPC authors. |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
* |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef GRPCPP_CREATE_CHANNEL_IMPL_H |
||||||
|
#define GRPCPP_CREATE_CHANNEL_IMPL_H |
||||||
|
|
||||||
|
#include <memory> |
||||||
|
|
||||||
|
#include <grpcpp/channel.h> |
||||||
|
#include <grpcpp/impl/codegen/client_interceptor.h> |
||||||
|
#include <grpcpp/security/credentials.h> |
||||||
|
#include <grpcpp/support/channel_arguments.h> |
||||||
|
#include <grpcpp/support/config.h> |
||||||
|
|
||||||
|
namespace grpc_impl { |
||||||
|
|
||||||
|
/// Create a new \a Channel pointing to \a target.
|
||||||
|
///
|
||||||
|
/// \param target The URI of the endpoint to connect to.
|
||||||
|
/// \param creds Credentials to use for the created channel. If it does not
|
||||||
|
/// hold an object or is invalid, a lame channel (one on which all operations
|
||||||
|
/// fail) is returned.
|
||||||
|
std::shared_ptr<grpc::Channel> CreateChannel( |
||||||
|
const grpc::string& target, |
||||||
|
const std::shared_ptr<grpc::ChannelCredentials>& creds); |
||||||
|
|
||||||
|
/// Create a new \em custom \a Channel pointing to \a target.
|
||||||
|
///
|
||||||
|
/// \warning For advanced use and testing ONLY. Override default channel
|
||||||
|
/// arguments only if necessary.
|
||||||
|
///
|
||||||
|
/// \param target The URI of the endpoint to connect to.
|
||||||
|
/// \param creds Credentials to use for the created channel. If it does not
|
||||||
|
/// hold an object or is invalid, a lame channel (one on which all operations
|
||||||
|
/// fail) is returned.
|
||||||
|
/// \param args Options for channel creation.
|
||||||
|
std::shared_ptr<grpc::Channel> CreateCustomChannel( |
||||||
|
const grpc::string& target, |
||||||
|
const std::shared_ptr<grpc::ChannelCredentials>& creds, |
||||||
|
const grpc::ChannelArguments& args); |
||||||
|
|
||||||
|
namespace experimental { |
||||||
|
/// Create a new \em custom \a Channel pointing to \a target with \a
|
||||||
|
/// interceptors being invoked per call.
|
||||||
|
///
|
||||||
|
/// \warning For advanced use and testing ONLY. Override default channel
|
||||||
|
/// arguments only if necessary.
|
||||||
|
///
|
||||||
|
/// \param target The URI of the endpoint to connect to.
|
||||||
|
/// \param creds Credentials to use for the created channel. If it does not
|
||||||
|
/// hold an object or is invalid, a lame channel (one on which all operations
|
||||||
|
/// fail) is returned.
|
||||||
|
/// \param args Options for channel creation.
|
||||||
|
std::shared_ptr<grpc::Channel> CreateCustomChannelWithInterceptors( |
||||||
|
const grpc::string& target, |
||||||
|
const std::shared_ptr<grpc::ChannelCredentials>& creds, |
||||||
|
const grpc::ChannelArguments& args, |
||||||
|
std::vector< |
||||||
|
std::unique_ptr<grpc::experimental::ClientInterceptorFactoryInterface>> |
||||||
|
interceptor_creators); |
||||||
|
} // namespace experimental
|
||||||
|
} // namespace grpc_impl
|
||||||
|
|
||||||
|
#endif // GRPCPP_CREATE_CHANNEL_IMPL_H
|
@ -0,0 +1,54 @@ |
|||||||
|
/*
|
||||||
|
* |
||||||
|
* Copyright 2018 gRPC authors. |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
* |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef GRPCPP_EXT_SERVER_LOAD_REPORTING_IMPL_H |
||||||
|
#define GRPCPP_EXT_SERVER_LOAD_REPORTING_IMPL_H |
||||||
|
|
||||||
|
#include <grpc/support/port_platform.h> |
||||||
|
|
||||||
|
#include <grpc/load_reporting.h> |
||||||
|
#include <grpcpp/impl/codegen/config.h> |
||||||
|
#include <grpcpp/impl/codegen/server_context.h> |
||||||
|
#include <grpcpp/impl/server_builder_option.h> |
||||||
|
|
||||||
|
namespace grpc_impl { |
||||||
|
namespace load_reporter { |
||||||
|
namespace experimental { |
||||||
|
|
||||||
|
// The ServerBuilderOption to enable server-side load reporting feature. To
|
||||||
|
// enable the feature, please make sure the binary builds with the
|
||||||
|
// grpcpp_server_load_reporting library and set this option in the
|
||||||
|
// ServerBuilder.
|
||||||
|
class LoadReportingServiceServerBuilderOption |
||||||
|
: public grpc::ServerBuilderOption { |
||||||
|
public: |
||||||
|
void UpdateArguments(::grpc::ChannelArguments* args) override; |
||||||
|
void UpdatePlugins(std::vector<std::unique_ptr<::grpc::ServerBuilderPlugin>>* |
||||||
|
plugins) override; |
||||||
|
}; |
||||||
|
|
||||||
|
// Adds the load reporting cost with \a cost_name and \a cost_value in the
|
||||||
|
// trailing metadata of the server context.
|
||||||
|
void AddLoadReportingCost(grpc::ServerContext* ctx, |
||||||
|
const grpc::string& cost_name, double cost_value); |
||||||
|
|
||||||
|
} // namespace experimental
|
||||||
|
} // namespace load_reporter
|
||||||
|
} // namespace grpc_impl
|
||||||
|
|
||||||
|
#endif // GRPCPP_EXT_SERVER_LOAD_REPORTING_IMPL_H
|
@ -0,0 +1,61 @@ |
|||||||
|
/*
|
||||||
|
* |
||||||
|
* Copyright 2015 gRPC authors. |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
* |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef GRPCPP_SECURITY_AUTH_METADATA_PROCESSOR_IMPL_H |
||||||
|
#define GRPCPP_SECURITY_AUTH_METADATA_PROCESSOR_IMPL_H |
||||||
|
|
||||||
|
#include <map> |
||||||
|
|
||||||
|
#include <grpcpp/security/auth_context.h> |
||||||
|
#include <grpcpp/support/status.h> |
||||||
|
#include <grpcpp/support/string_ref.h> |
||||||
|
|
||||||
|
namespace grpc_impl { |
||||||
|
|
||||||
|
/// Interface allowing custom server-side authorization based on credentials
|
||||||
|
/// encoded in metadata. Objects of this type can be passed to
|
||||||
|
/// \a ServerCredentials::SetAuthMetadataProcessor().
|
||||||
|
class AuthMetadataProcessor { |
||||||
|
public: |
||||||
|
typedef std::multimap<grpc::string_ref, grpc::string_ref> InputMetadata; |
||||||
|
typedef std::multimap<grpc::string, grpc::string> OutputMetadata; |
||||||
|
|
||||||
|
virtual ~AuthMetadataProcessor() {} |
||||||
|
|
||||||
|
/// If this method returns true, the \a Process function will be scheduled in
|
||||||
|
/// a different thread from the one processing the call.
|
||||||
|
virtual bool IsBlocking() const { return true; } |
||||||
|
|
||||||
|
/// context is read/write: it contains the properties of the channel peer and
|
||||||
|
/// it is the job of the Process method to augment it with properties derived
|
||||||
|
/// from the passed-in auth_metadata.
|
||||||
|
/// consumed_auth_metadata needs to be filled with metadata that has been
|
||||||
|
/// consumed by the processor and will be removed from the call.
|
||||||
|
/// response_metadata is the metadata that will be sent as part of the
|
||||||
|
/// response.
|
||||||
|
/// If the return value is not Status::OK, the rpc call will be aborted with
|
||||||
|
/// the error code and error message sent back to the client.
|
||||||
|
virtual grpc::Status Process(const InputMetadata& auth_metadata, |
||||||
|
grpc::AuthContext* context, |
||||||
|
OutputMetadata* consumed_auth_metadata, |
||||||
|
OutputMetadata* response_metadata) = 0; |
||||||
|
}; |
||||||
|
|
||||||
|
} // namespace grpc_impl
|
||||||
|
|
||||||
|
#endif // GRPCPP_SECURITY_AUTH_METADATA_PROCESSOR_IMPL_H
|
@ -0,0 +1,48 @@ |
|||||||
|
/*
|
||||||
|
* |
||||||
|
* Copyright 2017 gRPC authors. |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
* |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef GRPCPP_SUPPORT_ERROR_DETAILS_IMPL_H |
||||||
|
#define GRPCPP_SUPPORT_ERROR_DETAILS_IMPL_H |
||||||
|
|
||||||
|
#include <grpcpp/support/status.h> |
||||||
|
|
||||||
|
namespace google { |
||||||
|
namespace rpc { |
||||||
|
class Status; |
||||||
|
} // namespace rpc
|
||||||
|
} // namespace google
|
||||||
|
|
||||||
|
namespace grpc_impl { |
||||||
|
|
||||||
|
/// Map a \a grpc::Status to a \a google::rpc::Status.
|
||||||
|
/// The given \a to object will be cleared.
|
||||||
|
/// On success, returns status with OK.
|
||||||
|
/// Returns status with \a INVALID_ARGUMENT, if failed to deserialize.
|
||||||
|
/// Returns status with \a FAILED_PRECONDITION, if \a to is nullptr.
|
||||||
|
grpc::Status ExtractErrorDetails(const grpc::Status& from, |
||||||
|
::google::rpc::Status* to); |
||||||
|
|
||||||
|
/// Map \a google::rpc::Status to a \a grpc::Status.
|
||||||
|
/// Returns OK on success.
|
||||||
|
/// Returns status with \a FAILED_PRECONDITION if \a to is nullptr.
|
||||||
|
grpc::Status SetErrorDetails(const ::google::rpc::Status& from, |
||||||
|
grpc::Status* to); |
||||||
|
|
||||||
|
} // namespace grpc_impl
|
||||||
|
|
||||||
|
#endif // GRPCPP_SUPPORT_ERROR_DETAILS_IMPL_H
|
Loading…
Reference in new issue