aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar Nicolas "Pixel" Noble <pixel@nobis-crew.org>2015-08-08 01:45:38 +0200
committerGravatar Nicolas "Pixel" Noble <pixel@nobis-crew.org>2015-08-08 01:45:38 +0200
commit9d72b149a9e3462c2fa13afa27a1e52bfe7bf186 (patch)
treeeedff1af6f56fc97e61c3bee236b109b6d007d69 /include
parentf75df57a8ffaddb11f064dfa5e54ec8404a81e08 (diff)
parent95a98ca768683f3864b1aefc9d6f266b22705b2a (diff)
Merge branch 'master' of github.com:grpc/grpc into the-ultimate-showdown
Conflicts: include/grpc/grpc.h src/core/surface/channel.c src/core/surface/channel_create.c src/core/surface/completion_queue.c src/cpp/client/channel.cc src/cpp/client/insecure_credentials.cc src/csharp/ext/grpc_csharp_ext.c src/node/ext/call.cc src/node/ext/channel.cc src/php/ext/grpc/call.c src/php/ext/grpc/channel.c src/python/grpcio/grpc/_adapter/_c/types/channel.c src/ruby/ext/grpc/rb_channel.c test/core/end2end/dualstack_socket_test.c test/core/end2end/fixtures/chttp2_fullstack.c test/core/end2end/fixtures/chttp2_fullstack_compression.c test/core/end2end/fixtures/chttp2_fullstack_uds_posix.c test/core/end2end/fixtures/chttp2_fullstack_with_poll.c test/core/end2end/multiple_server_queues_test.c test/core/end2end/no_server_test.c test/core/end2end/tests/bad_hostname.c test/core/end2end/tests/cancel_after_accept.c test/core/end2end/tests/cancel_after_accept_and_writes_closed.c test/core/end2end/tests/cancel_after_invoke.c test/core/end2end/tests/cancel_before_invoke.c test/core/end2end/tests/cancel_in_a_vacuum.c test/core/end2end/tests/census_simple_request.c test/core/end2end/tests/disappearing_server.c test/core/end2end/tests/early_server_shutdown_finishes_inflight_calls.c test/core/end2end/tests/empty_batch.c test/core/end2end/tests/graceful_server_shutdown.c test/core/end2end/tests/invoke_large_request.c test/core/end2end/tests/max_concurrent_streams.c test/core/end2end/tests/max_message_length.c test/core/end2end/tests/ping_pong_streaming.c test/core/end2end/tests/registered_call.c test/core/end2end/tests/request_response_with_binary_metadata_and_payload.c test/core/end2end/tests/request_response_with_metadata_and_payload.c test/core/end2end/tests/request_response_with_payload.c test/core/end2end/tests/request_response_with_payload_and_call_creds.c test/core/end2end/tests/request_response_with_trailing_metadata_and_payload.c test/core/end2end/tests/request_with_compressed_payload.c test/core/end2end/tests/request_with_flags.c test/core/end2end/tests/request_with_large_metadata.c test/core/end2end/tests/request_with_payload.c test/core/end2end/tests/server_finishes_request.c test/core/end2end/tests/simple_delayed_request.c test/core/end2end/tests/simple_request.c test/core/end2end/tests/simple_request_with_high_initial_sequence_number.c test/core/fling/client.c test/core/fling/server.c test/core/surface/lame_client_test.c
Diffstat (limited to 'include')
-rw-r--r--include/grpc++/channel_interface.h30
-rw-r--r--include/grpc++/client_context.h76
-rw-r--r--include/grpc++/config.h2
-rw-r--r--include/grpc++/credentials.h6
-rw-r--r--include/grpc++/dynamic_thread_pool.h82
-rw-r--r--include/grpc++/impl/sync_no_cxx11.h2
-rw-r--r--include/grpc++/server_context.h25
-rw-r--r--include/grpc++/server_credentials.h3
-rw-r--r--include/grpc++/stream.h6
-rw-r--r--include/grpc++/stub_options.h43
-rw-r--r--include/grpc/census.h43
-rw-r--r--include/grpc/grpc.h132
-rw-r--r--include/grpc/grpc_security.h66
-rw-r--r--include/grpc/support/atm_gcc_atomic.h2
-rw-r--r--include/grpc/support/atm_gcc_sync.h5
-rw-r--r--include/grpc/support/atm_win32.h5
-rw-r--r--include/grpc/support/host_port.h6
17 files changed, 462 insertions, 72 deletions
diff --git a/include/grpc++/channel_interface.h b/include/grpc++/channel_interface.h
index 10fb9538bc..4176cded7b 100644
--- a/include/grpc++/channel_interface.h
+++ b/include/grpc++/channel_interface.h
@@ -36,6 +36,7 @@
#include <memory>
+#include <grpc/grpc.h>
#include <grpc++/status.h>
#include <grpc++/impl/call.h>
@@ -47,7 +48,6 @@ class CallOpBuffer;
class ClientContext;
class CompletionQueue;
class RpcMethod;
-class CallInterface;
class ChannelInterface : public CallHook,
public std::enable_shared_from_this<ChannelInterface> {
@@ -57,6 +57,34 @@ class ChannelInterface : public CallHook,
virtual void* RegisterMethod(const char* method_name) = 0;
virtual Call CreateCall(const RpcMethod& method, ClientContext* context,
CompletionQueue* cq) = 0;
+
+ // Get the current channel state. If the channel is in IDLE and try_to_connect
+ // is set to true, try to connect.
+ virtual grpc_connectivity_state GetState(bool try_to_connect) = 0;
+
+ // Return the tag on cq when the channel state is changed or deadline expires.
+ // GetState needs to called to get the current state.
+ template <typename T>
+ void NotifyOnStateChange(grpc_connectivity_state last_observed, T deadline,
+ CompletionQueue* cq, void* tag) {
+ TimePoint<T> deadline_tp(deadline);
+ NotifyOnStateChangeImpl(last_observed, deadline_tp.raw_time(), cq, tag);
+ }
+
+ // Blocking wait for channel state change or deadline expiration.
+ // GetState needs to called to get the current state.
+ template <typename T>
+ bool WaitForStateChange(grpc_connectivity_state last_observed, T deadline) {
+ TimePoint<T> deadline_tp(deadline);
+ return WaitForStateChangeImpl(last_observed, deadline_tp.raw_time());
+ }
+
+ private:
+ virtual void NotifyOnStateChangeImpl(grpc_connectivity_state last_observed,
+ gpr_timespec deadline,
+ CompletionQueue* cq, void* tag) = 0;
+ virtual bool WaitForStateChangeImpl(grpc_connectivity_state last_observed,
+ gpr_timespec deadline) = 0;
};
} // namespace grpc
diff --git a/include/grpc++/client_context.h b/include/grpc++/client_context.h
index 9df76699d2..34945f3282 100644
--- a/include/grpc++/client_context.h
+++ b/include/grpc++/client_context.h
@@ -39,6 +39,7 @@
#include <string>
#include <grpc/compression.h>
+#include <grpc/grpc.h>
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include <grpc++/auth_context.h>
@@ -46,8 +47,6 @@
#include <grpc++/status.h>
#include <grpc++/time.h>
-struct grpc_call;
-struct grpc_completion_queue;
struct census_context;
namespace grpc {
@@ -70,12 +69,68 @@ template <class R, class W>
class ClientAsyncReaderWriter;
template <class R>
class ClientAsyncResponseReader;
+class ServerContext;
+
+class PropagationOptions {
+ public:
+ PropagationOptions() : propagate_(GRPC_PROPAGATE_DEFAULTS) {}
+
+ PropagationOptions& enable_deadline_propagation() {
+ propagate_ |= GRPC_PROPAGATE_DEADLINE;
+ return *this;
+ }
+
+ PropagationOptions& disable_deadline_propagation() {
+ propagate_ &= ~GRPC_PROPAGATE_DEADLINE;
+ return *this;
+ }
+
+ PropagationOptions& enable_census_stats_propagation() {
+ propagate_ |= GRPC_PROPAGATE_CENSUS_STATS_CONTEXT;
+ return *this;
+ }
+
+ PropagationOptions& disable_census_stats_propagation() {
+ propagate_ &= ~GRPC_PROPAGATE_CENSUS_STATS_CONTEXT;
+ return *this;
+ }
+
+ PropagationOptions& enable_census_tracing_propagation() {
+ propagate_ |= GRPC_PROPAGATE_CENSUS_TRACING_CONTEXT;
+ return *this;
+ }
+
+ PropagationOptions& disable_census_tracing_propagation() {
+ propagate_ &= ~GRPC_PROPAGATE_CENSUS_TRACING_CONTEXT;
+ return *this;
+ }
+
+ PropagationOptions& enable_cancellation_propagation() {
+ propagate_ |= GRPC_PROPAGATE_CANCELLATION;
+ return *this;
+ }
+
+ PropagationOptions& disable_cancellation_propagation() {
+ propagate_ &= ~GRPC_PROPAGATE_CANCELLATION;
+ return *this;
+ }
+
+ gpr_uint32 c_bitmask() const { return propagate_; }
+
+ private:
+ gpr_uint32 propagate_;
+};
class ClientContext {
public:
ClientContext();
~ClientContext();
+ /// Create a new ClientContext that propagates some or all of its attributes
+ static std::unique_ptr<ClientContext> FromServerContext(
+ const ServerContext& server_context,
+ PropagationOptions options = PropagationOptions());
+
void AddMetadata(const grpc::string& meta_key,
const grpc::string& meta_value);
@@ -110,7 +165,7 @@ class ClientContext {
creds_ = creds;
}
- grpc_compression_algorithm get_compression_algorithm() const {
+ grpc_compression_algorithm compression_algorithm() const {
return compression_algorithm_;
}
@@ -118,9 +173,15 @@ class ClientContext {
std::shared_ptr<const AuthContext> auth_context() const;
+ // Return the peer uri in a string.
+ // WARNING: this value is never authenticated or subject to any security
+ // related code. It must not be used for any authentication related
+ // functionality. Instead, use auth_context.
+ grpc::string peer() const;
+
// Get and set census context
- void set_census_context(census_context* ccp) { census_context_ = ccp; }
- census_context* get_census_context() const { return census_context_; }
+ void set_census_context(struct census_context* ccp) { census_context_ = ccp; }
+ struct census_context* census_context() const { return census_context_; }
void TryCancel();
@@ -170,11 +231,14 @@ class ClientContext {
grpc::string authority_;
std::shared_ptr<Credentials> creds_;
mutable std::shared_ptr<const AuthContext> auth_context_;
- census_context* census_context_;
+ struct census_context* census_context_;
std::multimap<grpc::string, grpc::string> send_initial_metadata_;
std::multimap<grpc::string, grpc::string> recv_initial_metadata_;
std::multimap<grpc::string, grpc::string> trailing_metadata_;
+ grpc_call* propagate_from_call_;
+ PropagationOptions propagation_options_;
+
grpc_compression_algorithm compression_algorithm_;
};
diff --git a/include/grpc++/config.h b/include/grpc++/config.h
index 1362c0a1fa..889dc39eb7 100644
--- a/include/grpc++/config.h
+++ b/include/grpc++/config.h
@@ -79,6 +79,7 @@
#ifdef GRPC_CXX0X_NO_NULLPTR
#include <memory>
+namespace grpc {
const class {
public:
template <class T>
@@ -98,6 +99,7 @@ const class {
private:
void operator&() const = delete;
} nullptr = {};
+}
#endif
#ifndef GRPC_CUSTOM_STRING
diff --git a/include/grpc++/credentials.h b/include/grpc++/credentials.h
index 0eaaefcbca..a4f1e73118 100644
--- a/include/grpc++/credentials.h
+++ b/include/grpc++/credentials.h
@@ -106,13 +106,13 @@ std::shared_ptr<Credentials> ServiceAccountCredentials(
const grpc::string& json_key, const grpc::string& scope,
long token_lifetime_seconds);
-// Builds JWT credentials.
+// Builds Service Account JWT Access credentials.
// json_key is the JSON key string containing the client's private key.
// token_lifetime_seconds is the lifetime in seconds of each Json Web Token
// (JWT) created with this credentials. It should not exceed
// grpc_max_auth_token_lifetime or will be cropped to this value.
-std::shared_ptr<Credentials> JWTCredentials(const grpc::string& json_key,
- long token_lifetime_seconds);
+std::shared_ptr<Credentials> ServiceAccountJWTAccessCredentials(
+ const grpc::string& json_key, long token_lifetime_seconds);
// Builds refresh token credentials.
// json_refresh_token is the JSON string containing the refresh token along
diff --git a/include/grpc++/dynamic_thread_pool.h b/include/grpc++/dynamic_thread_pool.h
new file mode 100644
index 0000000000..f0cd35940f
--- /dev/null
+++ b/include/grpc++/dynamic_thread_pool.h
@@ -0,0 +1,82 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef GRPCXX_DYNAMIC_THREAD_POOL_H
+#define GRPCXX_DYNAMIC_THREAD_POOL_H
+
+#include <grpc++/config.h>
+
+#include <grpc++/impl/sync.h>
+#include <grpc++/impl/thd.h>
+#include <grpc++/thread_pool_interface.h>
+
+#include <list>
+#include <memory>
+#include <queue>
+
+namespace grpc {
+
+class DynamicThreadPool GRPC_FINAL : public ThreadPoolInterface {
+ public:
+ explicit DynamicThreadPool(int reserve_threads);
+ ~DynamicThreadPool();
+
+ void Add(const std::function<void()>& callback) GRPC_OVERRIDE;
+
+ private:
+ class DynamicThread {
+ public:
+ DynamicThread(DynamicThreadPool *pool);
+ ~DynamicThread();
+ private:
+ DynamicThreadPool *pool_;
+ std::unique_ptr<grpc::thread> thd_;
+ void ThreadFunc();
+ };
+ grpc::mutex mu_;
+ grpc::condition_variable cv_;
+ grpc::condition_variable shutdown_cv_;
+ bool shutdown_;
+ std::queue<std::function<void()>> callbacks_;
+ int reserve_threads_;
+ int nthreads_;
+ int threads_waiting_;
+ std::list<DynamicThread*> dead_threads_;
+
+ void ThreadFunc();
+ static void ReapThreads(std::list<DynamicThread*>* tlist);
+};
+
+} // namespace grpc
+
+#endif // GRPCXX_DYNAMIC_THREAD_POOL_H
diff --git a/include/grpc++/impl/sync_no_cxx11.h b/include/grpc++/impl/sync_no_cxx11.h
index dda939bf71..5869b04c76 100644
--- a/include/grpc++/impl/sync_no_cxx11.h
+++ b/include/grpc++/impl/sync_no_cxx11.h
@@ -87,7 +87,7 @@ class condition_variable {
~condition_variable() { gpr_cv_destroy(&cv_); }
void wait(lock_guard<mutex> &mu) {
mu.locked = false;
- gpr_cv_wait(&cv_, &mu.mu_.mu_, gpr_inf_future);
+ gpr_cv_wait(&cv_, &mu.mu_.mu_, gpr_inf_future(GPR_CLOCK_REALTIME));
mu.locked = true;
}
void notify_one() { gpr_cv_signal(&cv_); }
diff --git a/include/grpc++/server_context.h b/include/grpc++/server_context.h
index 3bfa48fbb6..4f7fc54ef1 100644
--- a/include/grpc++/server_context.h
+++ b/include/grpc++/server_context.h
@@ -46,9 +46,11 @@
struct gpr_timespec;
struct grpc_metadata;
struct grpc_call;
+struct census_context;
namespace grpc {
+class ClientContext;
template <class W, class R>
class ServerAsyncReader;
template <class W>
@@ -104,18 +106,34 @@ class ServerContext {
return client_metadata_;
}
- grpc_compression_level get_compression_level() const {
+ grpc_compression_level compression_level() const {
return compression_level_;
}
void set_compression_level(grpc_compression_level level);
- grpc_compression_algorithm get_compression_algorithm() const {
+ grpc_compression_algorithm compression_algorithm() const {
return compression_algorithm_;
}
void set_compression_algorithm(grpc_compression_algorithm algorithm);
std::shared_ptr<const AuthContext> auth_context() const;
+ // Return the peer uri in a string.
+ // WARNING: this value is never authenticated or subject to any security
+ // related code. It must not be used for any authentication related
+ // functionality. Instead, use auth_context.
+ grpc::string peer() const;
+
+ const struct census_context* census_context() const;
+
+ // Async only. Has to be called before the rpc starts.
+ // Returns the tag in completion queue when the rpc finishes.
+ // IsCancelled() can then be called to check whether the rpc was cancelled.
+ void AsyncNotifyWhenDone(void* tag) {
+ has_notify_when_done_tag_ = true;
+ async_notify_when_done_tag_ = tag;
+ }
+
private:
friend class ::grpc::testing::InteropContextInspector;
friend class ::grpc::Server;
@@ -141,6 +159,7 @@ class ServerContext {
friend class ServerStreamingHandler;
template <class ServiceType, class RequestType, class ResponseType>
friend class BidiStreamingHandler;
+ friend class ::grpc::ClientContext;
// Prevent copying.
ServerContext(const ServerContext&);
@@ -156,6 +175,8 @@ class ServerContext {
void set_call(grpc_call* call);
CompletionOp* completion_op_;
+ bool has_notify_when_done_tag_;
+ void* async_notify_when_done_tag_;
gpr_timespec deadline_;
grpc_call* call_;
diff --git a/include/grpc++/server_credentials.h b/include/grpc++/server_credentials.h
index 83ae9fd1eb..11acd67e8a 100644
--- a/include/grpc++/server_credentials.h
+++ b/include/grpc++/server_credentials.h
@@ -58,12 +58,15 @@ class ServerCredentials {
// Options to create ServerCredentials with SSL
struct SslServerCredentialsOptions {
+ SslServerCredentialsOptions() : force_client_auth(false) {}
+
struct PemKeyCertPair {
grpc::string private_key;
grpc::string cert_chain;
};
grpc::string pem_root_certs;
std::vector<PemKeyCertPair> pem_key_cert_pairs;
+ bool force_client_auth;
};
// Builds SSL ServerCredentials given SSL specific options
diff --git a/include/grpc++/stream.h b/include/grpc++/stream.h
index 3903f2ec06..bc0c3c0f3b 100644
--- a/include/grpc++/stream.h
+++ b/include/grpc++/stream.h
@@ -54,7 +54,11 @@ class ClientStreamingInterface {
// client side declares it has no more message to send, either implicitly or
// by calling WritesDone, it needs to make sure there is no more message to
// be received from the server, either implicitly or by getting a false from
- // a Read(). Otherwise, this implicitly cancels the stream.
+ // a Read().
+ // This function will return either:
+ // - when all incoming messages have been read and the server has returned
+ // status
+ // - OR when the server has returned a non-OK status
virtual Status Finish() = 0;
};
diff --git a/include/grpc++/stub_options.h b/include/grpc++/stub_options.h
new file mode 100644
index 0000000000..c7c16dcd55
--- /dev/null
+++ b/include/grpc++/stub_options.h
@@ -0,0 +1,43 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef GRPCXX_STUB_OPTIONS_H
+#define GRPCXX_STUB_OPTIONS_H
+
+namespace grpc {
+
+class StubOptions {};
+
+} // namespace grpc
+
+#endif // GRPCXX_STUB_OPTIONS_H
diff --git a/include/grpc/census.h b/include/grpc/census.h
index 3fc07affc8..7603dfdce1 100644
--- a/include/grpc/census.h
+++ b/include/grpc/census.h
@@ -44,26 +44,30 @@
extern "C" {
#endif
-/* Identify census functionality that can be enabled via census_initialize(). */
-enum census_functions {
- CENSUS_NONE = 0, /* Do not enable census. */
- CENSUS_TRACING = 1, /* Enable census tracing. */
- CENSUS_STATS = 2, /* Enable Census stats collection. */
- CENSUS_CPU = 4, /* Enable Census CPU usage collection. */
- CENSUS_ALL = CENSUS_TRACING | CENSUS_STATS | CENSUS_CPU
+/* Identify census features that can be enabled via census_initialize(). */
+enum census_features {
+ CENSUS_FEATURE_NONE = 0, /* Do not enable census. */
+ CENSUS_FEATURE_TRACING = 1, /* Enable census tracing. */
+ CENSUS_FEATURE_STATS = 2, /* Enable Census stats collection. */
+ CENSUS_FEATURE_CPU = 4, /* Enable Census CPU usage collection. */
+ CENSUS_FEATURE_ALL =
+ CENSUS_FEATURE_TRACING | CENSUS_FEATURE_STATS | CENSUS_FEATURE_CPU
};
-/* Shutdown and startup census subsystem. The 'functions' argument should be
- * the OR (|) of census_functions values. If census fails to initialize, then
+/** Shutdown and startup census subsystem. The 'features' argument should be
+ * the OR (|) of census_features values. If census fails to initialize, then
* census_initialize() will return a non-zero value. It is an error to call
* census_initialize() more than once (without an intervening
* census_shutdown()). */
-int census_initialize(int functions);
-void census_shutdown();
+int census_initialize(int features);
+void census_shutdown(void);
-/* If any census feature has been initialized, this funtion will return a
- * non-zero value. */
-int census_available();
+/** Return the features supported by the current census implementation (not all
+ * features will be available on all platforms). */
+int census_supported(void);
+
+/** Return the census features currently enabled. */
+int census_enabled(void);
/* Internally, Census relies on a context, which should be propagated across
* RPC's. From the RPC subsystems viewpoint, this is an opaque data structure.
@@ -100,6 +104,17 @@ int census_context_deserialize(const char *buffer, census_context **context);
* future census calls will result in undefined behavior. */
void census_context_destroy(census_context *context);
+/* A census statistic to be recorded comprises two parts: an ID for the
+ * particular statistic and the value to be recorded against it. */
+typedef struct {
+ int id;
+ double value;
+} census_stat;
+
+/* Record new stats against the given context. */
+void census_record_stat(census_context *context, census_stat *stats,
+ size_t nstats);
+
#ifdef __cplusplus
}
#endif
diff --git a/include/grpc/grpc.h b/include/grpc/grpc.h
index 736aff79b1..2471a0937e 100644
--- a/include/grpc/grpc.h
+++ b/include/grpc/grpc.h
@@ -50,7 +50,7 @@ extern "C" {
* \section intro_sec The GRPC Core library is a low-level library designed
* to be wrapped by higher level libraries.
*
- * The top-level API is provided in grpc.h.
+ * The top-level API is provided in grpc.h.
* Security related functionality lives in grpc_security.h.
*/
@@ -126,6 +126,8 @@ typedef struct {
/** Initial sequence number for http2 transports */
#define GRPC_ARG_HTTP2_INITIAL_SEQUENCE_NUMBER \
"grpc.http2.initial_sequence_number"
+/** Default authority to pass if none specified on call construction */
+#define GRPC_ARG_DEFAULT_AUTHORITY "grpc.default_authority"
/** Primary user agent: goes at the start of the user-agent metadata
sent on each request */
#define GRPC_ARG_PRIMARY_USER_AGENT_STRING "grpc.primary_user_agent"
@@ -175,7 +177,9 @@ typedef enum grpc_call_error {
GRPC_CALL_ERROR_INVALID_FLAGS,
/** invalid metadata was passed to this call */
GRPC_CALL_ERROR_INVALID_METADATA,
- /** completion queue for notification has not been registered with the
+ /** invalid message was passed to this call */
+ GRPC_CALL_ERROR_INVALID_MESSAGE,
+ /** completion queue for notification has not been registered with the
server */
GRPC_CALL_ERROR_NOT_SERVER_COMPLETION_QUEUE
} grpc_call_error;
@@ -199,7 +203,8 @@ typedef struct grpc_metadata {
gpr_uint32 flags;
/** The following fields are reserved for grpc internal use.
- There is no need to initialize them, and they will be set to garbage during
+ There is no need to initialize them, and they will be set to garbage
+ during
calls to grpc. */
struct {
void *obfuscated[4];
@@ -258,24 +263,25 @@ typedef enum {
/** Send a message: 0 or more of these operations can occur for each call */
GRPC_OP_SEND_MESSAGE,
/** Send a close from the client: one and only one instance MUST be sent from
- the client, unless the call was cancelled - in which case this can be
+ the client, unless the call was cancelled - in which case this can be
skipped */
GRPC_OP_SEND_CLOSE_FROM_CLIENT,
/** Send status from the server: one and only one instance MUST be sent from
- the server unless the call was cancelled - in which case this can be
+ the server unless the call was cancelled - in which case this can be
skipped */
GRPC_OP_SEND_STATUS_FROM_SERVER,
- /** Receive initial metadata: one and only one MUST be made on the client,
+ /** Receive initial metadata: one and only one MUST be made on the client,
must not be made on the server */
GRPC_OP_RECV_INITIAL_METADATA,
- /** Receive a message: 0 or more of these operations can occur for each call */
+ /** Receive a message: 0 or more of these operations can occur for each call
+ */
GRPC_OP_RECV_MESSAGE,
/** Receive status on the client: one and only one must be made on the client.
This operation always succeeds, meaning ops paired with this operation
will also appear to succeed, even though they may not have. In that case
the status will indicate some failure. */
GRPC_OP_RECV_STATUS_ON_CLIENT,
- /** Receive close on the server: one and only one must be made on the
+ /** Receive close on the server: one and only one must be made on the
server */
GRPC_OP_RECV_CLOSE_ON_SERVER
} grpc_op_type;
@@ -286,7 +292,7 @@ typedef struct grpc_op {
/** Operation type, as defined by grpc_op_type */
grpc_op_type op;
/** Write flags bitset for grpc_begin_messages */
- gpr_uint32 flags;
+ gpr_uint32 flags;
/** Reserved for future usage */
void *reserved;
union {
@@ -311,21 +317,23 @@ typedef struct grpc_op {
After the operation completes, call grpc_metadata_array_destroy on this
value, or reuse it in a future op. */
grpc_metadata_array *recv_initial_metadata;
- /** ownership of the byte buffer is moved to the caller; the caller must call
- grpc_byte_buffer_destroy on this value, or reuse it in a future op. */
+ /** ownership of the byte buffer is moved to the caller; the caller must
+ call grpc_byte_buffer_destroy on this value, or reuse it in a future op.
+ */
grpc_byte_buffer **recv_message;
struct {
/** ownership of the array is with the caller, but ownership of the
- elements stays with the call object (ie key, value members are owned
+ elements stays with the call object (ie key, value members are owned
by the call object, trailing_metadata->array is owned by the caller).
- After the operation completes, call grpc_metadata_array_destroy on this
+ After the operation completes, call grpc_metadata_array_destroy on
+ this
value, or reuse it in a future op. */
grpc_metadata_array *trailing_metadata;
grpc_status_code *status;
/** status_details is a buffer owned by the application before the op
completes and after the op has completed. During the operation
- status_details may be reallocated to a size larger than
- *status_details_capacity, in which case *status_details_capacity will
+ status_details may be reallocated to a size larger than
+ *status_details_capacity, in which case *status_details_capacity will
be updated with the new array capacity.
Pre-allocating space:
@@ -353,6 +361,26 @@ typedef struct grpc_op {
} data;
} grpc_op;
+/* Propagation bits: this can be bitwise or-ed to form propagation_mask for
+ * grpc_call */
+/** Propagate deadline */
+#define GRPC_PROPAGATE_DEADLINE ((gpr_uint32)1)
+/** Propagate census context */
+#define GRPC_PROPAGATE_CENSUS_STATS_CONTEXT ((gpr_uint32)2)
+#define GRPC_PROPAGATE_CENSUS_TRACING_CONTEXT ((gpr_uint32)4)
+/** Propagate cancellation */
+#define GRPC_PROPAGATE_CANCELLATION ((gpr_uint32)8)
+
+/* Default propagation mask: clients of the core API are encouraged to encode
+ deltas from this in their implementations... ie write:
+ GRPC_PROPAGATE_DEFAULTS & ~GRPC_PROPAGATE_DEADLINE to disable deadline
+ propagation. Doing so gives flexibility in the future to define new
+ propagation types that are default inherited or not. */
+#define GRPC_PROPAGATE_DEFAULTS \
+ ((gpr_uint32)(( \
+ 0xffff | GRPC_PROPAGATE_DEADLINE | GRPC_PROPAGATE_CENSUS_STATS_CONTEXT | \
+ GRPC_PROPAGATE_CENSUS_TRACING_CONTEXT | GRPC_PROPAGATE_CANCELLATION)))
+
/** Initialize the grpc library.
It is not safe to call any other grpc functions before calling this.
@@ -393,10 +421,17 @@ grpc_event grpc_completion_queue_next(grpc_completion_queue *cq,
otherwise a grpc_event describing the event that occurred.
Callers must not call grpc_completion_queue_next and
- grpc_completion_queue_pluck simultaneously on the same completion queue. */
+ grpc_completion_queue_pluck simultaneously on the same completion queue.
+
+ Completion queues support a maximum of GRPC_MAX_COMPLETION_QUEUE_PLUCKERS
+ concurrently executing plucks at any time. */
grpc_event grpc_completion_queue_pluck(grpc_completion_queue *cq, void *tag,
gpr_timespec deadline, void *reserved);
+/** Maximum number of outstanding grpc_completion_queue_pluck executions per
+ completion queue */
+#define GRPC_MAX_COMPLETION_QUEUE_PLUCKERS 6
+
/** Begin destruction of a completion queue. Once all possible events are
drained then grpc_completion_queue_next will start to produce
GRPC_QUEUE_SHUTDOWN events only. At that point it's safe to call
@@ -410,10 +445,28 @@ void grpc_completion_queue_shutdown(grpc_completion_queue *cq);
drained and no threads are executing grpc_completion_queue_next */
void grpc_completion_queue_destroy(grpc_completion_queue *cq);
+/** Check the connectivity state of a channel. */
+grpc_connectivity_state grpc_channel_check_connectivity_state(
+ grpc_channel *channel, int try_to_connect);
+
+/** Watch for a change in connectivity state.
+ Once the channel connectivity state is different from last_observed_state,
+ tag will be enqueued on cq with success=1.
+ If deadline expires BEFORE the state is changed, tag will be enqueued on cq
+ with success=0. */
+void grpc_channel_watch_connectivity_state(
+ grpc_channel *channel, grpc_connectivity_state last_observed_state,
+ gpr_timespec deadline, grpc_completion_queue *cq, void *tag);
+
/** Create a call given a grpc_channel, in order to call 'method'. All
completions are sent to 'completion_queue'. 'method' and 'host' need only
- live through the invocation of this function. */
+ live through the invocation of this function.
+ If parent_call is non-NULL, it must be a server-side call. It will be used
+ to propagate properties from the server call to this new client call.
+ */
grpc_call *grpc_channel_create_call(grpc_channel *channel,
+ grpc_call *parent_call,
+ gpr_uint32 propagation_mask,
grpc_completion_queue *completion_queue,
const char *method, const char *host,
gpr_timespec deadline, void *reserved);
@@ -424,8 +477,9 @@ void *grpc_channel_register_call(grpc_channel *channel, const char *method,
/** Create a call given a handle returned from grpc_channel_register_call */
grpc_call *grpc_channel_create_registered_call(
- grpc_channel *channel, grpc_completion_queue *completion_queue,
- void *registered_call_handle, gpr_timespec deadline, void *reserved);
+ grpc_channel *channel, grpc_call *parent_call, gpr_uint32 propagation_mask,
+ grpc_completion_queue *completion_queue, void *registered_call_handle,
+ gpr_timespec deadline, void *reserved);
/** Start a batch of operations defined in the array ops; when complete, post a
completion of type 'tag' to the completion queue bound to the call.
@@ -441,17 +495,41 @@ grpc_call *grpc_channel_create_registered_call(
grpc_call_error grpc_call_start_batch(grpc_call *call, const grpc_op *ops,
size_t nops, void *tag, void *reserved);
+/** Returns a newly allocated string representing the endpoint to which this
+ call is communicating with. The string is in the uri format accepted by
+ grpc_channel_create.
+ The returned string should be disposed of with gpr_free().
+
+ WARNING: this value is never authenticated or subject to any security
+ related code. It must not be used for any authentication related
+ functionality. Instead, use grpc_auth_context. */
+char *grpc_call_get_peer(grpc_call *call);
+
+struct census_context;
+
+/* Set census context for a call; Must be called before first call to
+ grpc_call_start_batch(). */
+void grpc_census_call_set_context(grpc_call *call,
+ struct census_context *context);
+
+/* Retrieve the calls current census context. */
+struct census_context *grpc_census_call_get_context(grpc_call *call);
+
+/** Return a newly allocated string representing the target a channel was
+ created for. */
+char *grpc_channel_get_target(grpc_channel *channel);
+
/** Create a client channel to 'target'. Additional channel level configuration
MAY be provided by grpc_channel_args, though the expectation is that most
clients will want to simply pass NULL. See grpc_channel_args definition for
more on this. The data in 'args' need only live through the invocation of
this function. */
-grpc_channel *grpc_channel_create(const char *target,
- const grpc_channel_args *args,
- void *reserved);
+grpc_channel *grpc_insecure_channel_create(const char *target,
+ const grpc_channel_args *args,
+ void *reserved);
/** Create a lame client: this client fails every operation attempted on it. */
-grpc_channel *grpc_lame_client_channel_create(void);
+grpc_channel *grpc_lame_client_channel_create(const char *target);
/** Close and destroy a grpc channel */
void grpc_channel_destroy(grpc_channel *channel);
@@ -485,7 +563,7 @@ grpc_call_error grpc_call_cancel_with_status(grpc_call *call,
void grpc_call_destroy(grpc_call *call);
/** Request notification of a new call. 'cq_for_notification' must
- have been registered to the server via
+ have been registered to the server via
grpc_server_register_completion_queue. */
grpc_call_error grpc_server_request_call(
grpc_server *server, grpc_call **call, grpc_call_details *details,
@@ -503,8 +581,8 @@ grpc_call_error grpc_server_request_call(
void *grpc_server_register_method(grpc_server *server, const char *method,
const char *host);
-/** Request notification of a new pre-registered call. 'cq_for_notification'
- must have been registered to the server via
+/** Request notification of a new pre-registered call. 'cq_for_notification'
+ must have been registered to the server via
grpc_server_register_completion_queue. */
grpc_call_error grpc_server_request_registered_call(
grpc_server *server, void *registered_method, grpc_call **call,
@@ -531,7 +609,7 @@ void grpc_server_register_completion_queue(grpc_server *server,
/** Add a HTTP2 over plaintext over tcp listener.
Returns bound port number on success, 0 on failure.
REQUIRES: server not started */
-int grpc_server_add_http2_port(grpc_server *server, const char *addr);
+int grpc_server_add_insecure_http2_port(grpc_server *server, const char *addr);
/** Start a server - tells all listeners to start listening */
void grpc_server_start(grpc_server *server);
diff --git a/include/grpc/grpc_security.h b/include/grpc/grpc_security.h
index 37d66c04ae..640c1fda98 100644
--- a/include/grpc/grpc_security.h
+++ b/include/grpc/grpc_security.h
@@ -87,7 +87,7 @@ typedef struct {
directory).
- pem_key_cert_pair is a pointer on the object containing client's private
key and certificate chain. This parameter can be NULL if the client does
- not have such a key/cert pair. */
+ not have such a key/cert pair. */
grpc_credentials *grpc_ssl_credentials_create(
const char *pem_root_certs, grpc_ssl_pem_key_cert_pair *pem_key_cert_pair);
@@ -119,8 +119,8 @@ grpc_credentials *grpc_service_account_credentials_create(
- token_lifetime is the lifetime of each Json Web Token (JWT) created with
this credentials. It should not exceed grpc_max_auth_token_lifetime or
will be cropped to this value. */
-grpc_credentials *grpc_jwt_credentials_create(const char *json_key,
- gpr_timespec token_lifetime);
+grpc_credentials *grpc_service_account_jwt_access_credentials_create(
+ const char *json_key, gpr_timespec token_lifetime);
/* Creates an Oauth2 Refresh Token credentials object. May return NULL if the
input is invalid.
@@ -140,9 +140,6 @@ grpc_credentials *grpc_access_token_credentials_create(
grpc_credentials *grpc_iam_credentials_create(const char *authorization_token,
const char *authority_selector);
-/* Creates a fake transport security credentials object for testing. */
-grpc_credentials *grpc_fake_transport_security_credentials_create(void);
-
/* --- Secure channel creation. --- */
/* The caller of the secure_channel_create functions may override the target
@@ -177,14 +174,13 @@ void grpc_server_credentials_release(grpc_server_credentials *creds);
- pem_key_cert_pairs is an array private key / certificate chains of the
server. This parameter cannot be NULL.
- num_key_cert_pairs indicates the number of items in the private_key_files
- and cert_chain_files parameters. It should be at least 1. */
+ and cert_chain_files parameters. It should be at least 1.
+ - force_client_auth, if set to non-zero will force the client to authenticate
+ with an SSL cert. Note that this option is ignored if pem_root_certs is
+ NULL. */
grpc_server_credentials *grpc_ssl_server_credentials_create(
const char *pem_root_certs, grpc_ssl_pem_key_cert_pair *pem_key_cert_pairs,
- size_t num_key_cert_pairs);
-
-/* Creates a fake server transport security credentials object for testing. */
-grpc_server_credentials *grpc_fake_transport_security_server_credentials_create(
- void);
+ size_t num_key_cert_pairs, int force_client_auth);
/* --- Server-side secure ports. --- */
@@ -203,10 +199,7 @@ grpc_call_error grpc_call_set_credentials(grpc_call *call,
/* --- Authentication Context. --- */
-/* TODO(jboeuf): Define some well-known property names. */
-
#define GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME "transport_security_type"
-#define GRPC_FAKE_TRANSPORT_SECURITY_TYPE "fake"
#define GRPC_SSL_TRANSPORT_SECURITY_TYPE "ssl"
#define GRPC_X509_CN_PROPERTY_NAME "x509_common_name"
@@ -260,6 +253,49 @@ grpc_auth_context *grpc_call_auth_context(grpc_call *call);
/* Releases the auth context returned from grpc_call_auth_context. */
void grpc_auth_context_release(grpc_auth_context *context);
+/* --
+ The following auth context methods should only be called by a server metadata
+ processor to set properties extracted from auth metadata.
+ -- */
+
+/* Add a property. */
+void grpc_auth_context_add_property(grpc_auth_context *ctx, const char *name,
+ const char *value, size_t value_length);
+
+/* Add a C string property. */
+void grpc_auth_context_add_cstring_property(grpc_auth_context *ctx,
+ const char *name,
+ const char *value);
+
+/* Sets the property name. Returns 1 if successful or 0 in case of failure
+ (which means that no property with this name exists). */
+int grpc_auth_context_set_peer_identity_property_name(grpc_auth_context *ctx,
+ const char *name);
+
+/* --- Auth Metadata Processing --- */
+
+/* Callback function that is called when the metadata processing is done.
+ success is 1 if processing succeeded, 0 otherwise.
+ Consumed metadata will be removed from the set of metadata available on the
+ call. */
+typedef void (*grpc_process_auth_metadata_done_cb)(
+ void *user_data, const grpc_metadata *consumed_md, size_t num_consumed_md,
+ int success);
+
+/* Pluggable server-side metadata processor object. */
+typedef struct {
+ /* The context object is read/write: it contains the properties of the
+ channel peer and it is the job of the process function to augment it with
+ properties derived from the passed-in metadata. */
+ void (*process)(void *state, grpc_auth_context *context,
+ const grpc_metadata *md, size_t md_count,
+ grpc_process_auth_metadata_done_cb cb, void *user_data);
+ void *state;
+} grpc_auth_metadata_processor;
+
+void grpc_server_credentials_set_auth_metadata_processor(
+ grpc_server_credentials *creds, grpc_auth_metadata_processor processor);
+
#ifdef __cplusplus
}
#endif
diff --git a/include/grpc/support/atm_gcc_atomic.h b/include/grpc/support/atm_gcc_atomic.h
index 65d3d0c60f..a2c8386028 100644
--- a/include/grpc/support/atm_gcc_atomic.h
+++ b/include/grpc/support/atm_gcc_atomic.h
@@ -46,6 +46,8 @@ typedef gpr_intptr gpr_atm;
#define gpr_atm_no_barrier_load(p) (__atomic_load_n((p), __ATOMIC_RELAXED))
#define gpr_atm_rel_store(p, value) \
(__atomic_store_n((p), (gpr_intptr)(value), __ATOMIC_RELEASE))
+#define gpr_atm_no_barrier_store(p, value) \
+ (__atomic_store_n((p), (gpr_intptr)(value), __ATOMIC_RELAXED))
#define gpr_atm_no_barrier_fetch_add(p, delta) \
(__atomic_fetch_add((p), (gpr_intptr)(delta), __ATOMIC_RELAXED))
diff --git a/include/grpc/support/atm_gcc_sync.h b/include/grpc/support/atm_gcc_sync.h
index 4955e4436f..38b5a9eec2 100644
--- a/include/grpc/support/atm_gcc_sync.h
+++ b/include/grpc/support/atm_gcc_sync.h
@@ -68,6 +68,11 @@ static __inline void gpr_atm_rel_store(gpr_atm *p, gpr_atm value) {
*p = value;
}
+static __inline void gpr_atm_no_barrier_store(gpr_atm *p, gpr_atm value) {
+ GPR_ATM_COMPILE_BARRIER_();
+ *p = value;
+}
+
#undef GPR_ATM_LS_BARRIER_
#undef GPR_ATM_COMPILE_BARRIER_
diff --git a/include/grpc/support/atm_win32.h b/include/grpc/support/atm_win32.h
index da99021c24..694528a9ba 100644
--- a/include/grpc/support/atm_win32.h
+++ b/include/grpc/support/atm_win32.h
@@ -57,6 +57,11 @@ static __inline void gpr_atm_rel_store(gpr_atm *p, gpr_atm value) {
*p = value;
}
+static __inline void gpr_atm_no_barrier_store(gpr_atm *p, gpr_atm value) {
+ /* TODO(ctiller): Can we implement something better here? */
+ gpr_atm_rel_store(p, value);
+}
+
static __inline int gpr_atm_no_barrier_cas(gpr_atm *p, gpr_atm o, gpr_atm n) {
/* InterlockedCompareExchangePointerNoFence() not available on vista or
windows7 */
diff --git a/include/grpc/support/host_port.h b/include/grpc/support/host_port.h
index 3cc2f498e8..30267ab1df 100644
--- a/include/grpc/support/host_port.h
+++ b/include/grpc/support/host_port.h
@@ -52,8 +52,10 @@ int gpr_join_host_port(char **out, const char *host, int port);
/* Given a name in the form "host:port" or "[ho:st]:port", split into hostname
and port number, into newly allocated strings, which must later be
- destroyed using gpr_free(). */
-void gpr_split_host_port(const char *name, char **host, char **port);
+ destroyed using gpr_free().
+ Return 1 on success, 0 on failure. Guarantees *host and *port == NULL on
+ failure. */
+int gpr_split_host_port(const char *name, char **host, char **port);
#ifdef __cplusplus
}