aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib
diff options
context:
space:
mode:
authorGravatar Yash Tibrewal <yashkt@google.com>2018-12-26 13:33:06 -0800
committerGravatar Yash Tibrewal <yashkt@google.com>2018-12-26 13:33:06 -0800
commit5a6183f1bdf3ff0c9e29fe454fde6e187e33fcc3 (patch)
tree3ccb35dfefa90df9f615ade0721a565ac579aed2 /src/core/lib
parent31a775b425eac37bb43c301cfb25e1f6a4bde106 (diff)
parentfc7d0911a3a44d7bc926d3db99b7300a0c0f33dc (diff)
Merge branch 'master' into failhijackedsend
Diffstat (limited to 'src/core/lib')
-rw-r--r--src/core/lib/iomgr/tcp_posix.cc29
-rw-r--r--src/core/lib/security/credentials/composite/composite_credentials.cc61
-rw-r--r--src/core/lib/security/credentials/composite/composite_credentials.h43
-rw-r--r--src/core/lib/security/credentials/jwt/jwt_verifier.cc2
4 files changed, 37 insertions, 98 deletions
diff --git a/src/core/lib/iomgr/tcp_posix.cc b/src/core/lib/iomgr/tcp_posix.cc
index cfcb190d60..c268c18664 100644
--- a/src/core/lib/iomgr/tcp_posix.cc
+++ b/src/core/lib/iomgr/tcp_posix.cc
@@ -126,6 +126,7 @@ struct grpc_tcp {
int bytes_counter;
bool socket_ts_enabled; /* True if timestamping options are set on the socket
*/
+ bool ts_capable; /* Cache whether we can set timestamping options */
gpr_atm
stop_error_notification; /* Set to 1 if we do not want to be notified on
errors anymore */
@@ -589,7 +590,7 @@ ssize_t tcp_send(int fd, const struct msghdr* msg) {
*/
static bool tcp_write_with_timestamps(grpc_tcp* tcp, struct msghdr* msg,
size_t sending_length,
- ssize_t* sent_length, grpc_error** error);
+ ssize_t* sent_length);
/** The callback function to be invoked when we get an error on the socket. */
static void tcp_handle_error(void* arg /* grpc_tcp */, grpc_error* error);
@@ -597,13 +598,11 @@ static void tcp_handle_error(void* arg /* grpc_tcp */, grpc_error* error);
#ifdef GRPC_LINUX_ERRQUEUE
static bool tcp_write_with_timestamps(grpc_tcp* tcp, struct msghdr* msg,
size_t sending_length,
- ssize_t* sent_length,
- grpc_error** error) {
+ ssize_t* sent_length) {
if (!tcp->socket_ts_enabled) {
uint32_t opt = grpc_core::kTimestampingSocketOptions;
if (setsockopt(tcp->fd, SOL_SOCKET, SO_TIMESTAMPING,
static_cast<void*>(&opt), sizeof(opt)) != 0) {
- *error = tcp_annotate_error(GRPC_OS_ERROR(errno, "setsockopt"), tcp);
grpc_slice_buffer_reset_and_unref_internal(tcp->outgoing_buffer);
if (grpc_tcp_trace.enabled()) {
gpr_log(GPR_ERROR, "Failed to set timestamping options on the socket.");
@@ -784,8 +783,7 @@ static void tcp_handle_error(void* arg /* grpc_tcp */, grpc_error* error) {
#else /* GRPC_LINUX_ERRQUEUE */
static bool tcp_write_with_timestamps(grpc_tcp* tcp, struct msghdr* msg,
size_t sending_length,
- ssize_t* sent_length,
- grpc_error** error) {
+ ssize_t* sent_length) {
gpr_log(GPR_ERROR, "Write with timestamps not supported for this platform");
GPR_ASSERT(0);
return false;
@@ -804,7 +802,7 @@ void tcp_shutdown_buffer_list(grpc_tcp* tcp) {
gpr_mu_lock(&tcp->tb_mu);
grpc_core::TracedBuffer::Shutdown(
&tcp->tb_head, tcp->outgoing_buffer_arg,
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("endpoint destroyed"));
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("TracedBuffer list shutdown"));
gpr_mu_unlock(&tcp->tb_mu);
tcp->outgoing_buffer_arg = nullptr;
}
@@ -820,7 +818,7 @@ static bool tcp_flush(grpc_tcp* tcp, grpc_error** error) {
struct msghdr msg;
struct iovec iov[MAX_WRITE_IOVEC];
msg_iovlen_type iov_size;
- ssize_t sent_length;
+ ssize_t sent_length = 0;
size_t sending_length;
size_t trailing;
size_t unwind_slice_idx;
@@ -855,13 +853,19 @@ static bool tcp_flush(grpc_tcp* tcp, grpc_error** error) {
msg.msg_iov = iov;
msg.msg_iovlen = iov_size;
msg.msg_flags = 0;
+ bool tried_sending_message = false;
if (tcp->outgoing_buffer_arg != nullptr) {
- if (!tcp_write_with_timestamps(tcp, &msg, sending_length, &sent_length,
- error)) {
+ if (!tcp->ts_capable ||
+ !tcp_write_with_timestamps(tcp, &msg, sending_length, &sent_length)) {
+ /* We could not set socket options to collect Fathom timestamps.
+ * Fallback on writing without timestamps. */
+ tcp->ts_capable = false;
tcp_shutdown_buffer_list(tcp);
- return true; /* something went wrong with timestamps */
+ } else {
+ tried_sending_message = true;
}
- } else {
+ }
+ if (!tried_sending_message) {
msg.msg_control = nullptr;
msg.msg_controllen = 0;
@@ -1117,6 +1121,7 @@ grpc_endpoint* grpc_tcp_create(grpc_fd* em_fd,
tcp->is_first_read = true;
tcp->bytes_counter = -1;
tcp->socket_ts_enabled = false;
+ tcp->ts_capable = true;
tcp->outgoing_buffer_arg = nullptr;
/* paired with unref in grpc_tcp_destroy */
gpr_ref_init(&tcp->refcount, 1);
diff --git a/src/core/lib/security/credentials/composite/composite_credentials.cc b/src/core/lib/security/credentials/composite/composite_credentials.cc
index 85dcd4693b..586bbed778 100644
--- a/src/core/lib/security/credentials/composite/composite_credentials.cc
+++ b/src/core/lib/security/credentials/composite/composite_credentials.cc
@@ -35,44 +35,6 @@
static void composite_call_metadata_cb(void* arg, grpc_error* error);
-grpc_call_credentials_array::~grpc_call_credentials_array() {
- for (size_t i = 0; i < num_creds_; ++i) {
- creds_array_[i].~RefCountedPtr<grpc_call_credentials>();
- }
- if (creds_array_ != nullptr) {
- gpr_free(creds_array_);
- }
-}
-
-grpc_call_credentials_array::grpc_call_credentials_array(
- const grpc_call_credentials_array& that)
- : num_creds_(that.num_creds_) {
- reserve(that.capacity_);
- for (size_t i = 0; i < num_creds_; ++i) {
- new (&creds_array_[i])
- grpc_core::RefCountedPtr<grpc_call_credentials>(that.creds_array_[i]);
- }
-}
-
-void grpc_call_credentials_array::reserve(size_t capacity) {
- if (capacity_ >= capacity) {
- return;
- }
- grpc_core::RefCountedPtr<grpc_call_credentials>* new_arr =
- static_cast<grpc_core::RefCountedPtr<grpc_call_credentials>*>(gpr_malloc(
- sizeof(grpc_core::RefCountedPtr<grpc_call_credentials>) * capacity));
- if (creds_array_ != nullptr) {
- for (size_t i = 0; i < num_creds_; ++i) {
- new (&new_arr[i]) grpc_core::RefCountedPtr<grpc_call_credentials>(
- std::move(creds_array_[i]));
- creds_array_[i].~RefCountedPtr<grpc_call_credentials>();
- }
- gpr_free(creds_array_);
- }
- creds_array_ = new_arr;
- capacity_ = capacity;
-}
-
namespace {
struct grpc_composite_call_credentials_metadata_context {
grpc_composite_call_credentials_metadata_context(
@@ -103,13 +65,13 @@ static void composite_call_metadata_cb(void* arg, grpc_error* error) {
grpc_composite_call_credentials_metadata_context* ctx =
static_cast<grpc_composite_call_credentials_metadata_context*>(arg);
if (error == GRPC_ERROR_NONE) {
- const grpc_call_credentials_array& inner = ctx->composite_creds->inner();
+ const grpc_composite_call_credentials::CallCredentialsList& inner =
+ ctx->composite_creds->inner();
/* See if we need to get some more metadata. */
if (ctx->creds_index < inner.size()) {
- if (inner.get(ctx->creds_index++)
- ->get_request_metadata(
- ctx->pollent, ctx->auth_md_context, ctx->md_array,
- &ctx->internal_on_request_metadata, &error)) {
+ if (inner[ctx->creds_index++]->get_request_metadata(
+ ctx->pollent, ctx->auth_md_context, ctx->md_array,
+ &ctx->internal_on_request_metadata, &error)) {
// Synchronous response, so call ourselves recursively.
composite_call_metadata_cb(arg, error);
GRPC_ERROR_UNREF(error);
@@ -130,12 +92,11 @@ bool grpc_composite_call_credentials::get_request_metadata(
ctx = grpc_core::New<grpc_composite_call_credentials_metadata_context>(
this, pollent, auth_md_context, md_array, on_request_metadata);
bool synchronous = true;
- const grpc_call_credentials_array& inner = ctx->composite_creds->inner();
+ const CallCredentialsList& inner = ctx->composite_creds->inner();
while (ctx->creds_index < inner.size()) {
- if (inner.get(ctx->creds_index++)
- ->get_request_metadata(ctx->pollent, ctx->auth_md_context,
- ctx->md_array,
- &ctx->internal_on_request_metadata, error)) {
+ if (inner[ctx->creds_index++]->get_request_metadata(
+ ctx->pollent, ctx->auth_md_context, ctx->md_array,
+ &ctx->internal_on_request_metadata, error)) {
if (*error != GRPC_ERROR_NONE) break;
} else {
synchronous = false; // Async return.
@@ -149,7 +110,7 @@ bool grpc_composite_call_credentials::get_request_metadata(
void grpc_composite_call_credentials::cancel_get_request_metadata(
grpc_credentials_mdelem_array* md_array, grpc_error* error) {
for (size_t i = 0; i < inner_.size(); ++i) {
- inner_.get(i)->cancel_get_request_metadata(md_array, GRPC_ERROR_REF(error));
+ inner_[i]->cancel_get_request_metadata(md_array, GRPC_ERROR_REF(error));
}
GRPC_ERROR_UNREF(error);
}
@@ -172,7 +133,7 @@ void grpc_composite_call_credentials::push_to_inner(
auto composite_creds =
static_cast<grpc_composite_call_credentials*>(creds.get());
for (size_t i = 0; i < composite_creds->inner().size(); ++i) {
- inner_.push_back(std::move(composite_creds->inner_.get_mutable(i)));
+ inner_.push_back(std::move(composite_creds->inner_[i]));
}
}
diff --git a/src/core/lib/security/credentials/composite/composite_credentials.h b/src/core/lib/security/credentials/composite/composite_credentials.h
index 6b7fca1370..7a1c7d5e42 100644
--- a/src/core/lib/security/credentials/composite/composite_credentials.h
+++ b/src/core/lib/security/credentials/composite/composite_credentials.h
@@ -21,43 +21,10 @@
#include <grpc/support/port_platform.h>
+#include "src/core/lib/gprpp/inlined_vector.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/security/credentials/credentials.h"
-// TODO(soheil): Replace this with InlinedVector once #16032 is resolved.
-class grpc_call_credentials_array {
- public:
- grpc_call_credentials_array() = default;
- grpc_call_credentials_array(const grpc_call_credentials_array& that);
-
- ~grpc_call_credentials_array();
-
- void reserve(size_t capacity);
-
- // Must reserve before pushing any data.
- void push_back(grpc_core::RefCountedPtr<grpc_call_credentials> cred) {
- GPR_DEBUG_ASSERT(capacity_ > num_creds_);
- new (&creds_array_[num_creds_++])
- grpc_core::RefCountedPtr<grpc_call_credentials>(std::move(cred));
- }
-
- const grpc_core::RefCountedPtr<grpc_call_credentials>& get(size_t i) const {
- GPR_DEBUG_ASSERT(i < num_creds_);
- return creds_array_[i];
- }
- grpc_core::RefCountedPtr<grpc_call_credentials>& get_mutable(size_t i) {
- GPR_DEBUG_ASSERT(i < num_creds_);
- return creds_array_[i];
- }
-
- size_t size() const { return num_creds_; }
-
- private:
- grpc_core::RefCountedPtr<grpc_call_credentials>* creds_array_ = nullptr;
- size_t num_creds_ = 0;
- size_t capacity_ = 0;
-};
-
/* -- Composite channel credentials. -- */
class grpc_composite_channel_credentials : public grpc_channel_credentials {
@@ -97,6 +64,10 @@ class grpc_composite_channel_credentials : public grpc_channel_credentials {
class grpc_composite_call_credentials : public grpc_call_credentials {
public:
+ using CallCredentialsList =
+ grpc_core::InlinedVector<grpc_core::RefCountedPtr<grpc_call_credentials>,
+ 2>;
+
grpc_composite_call_credentials(
grpc_core::RefCountedPtr<grpc_call_credentials> creds1,
grpc_core::RefCountedPtr<grpc_call_credentials> creds2);
@@ -111,13 +82,13 @@ class grpc_composite_call_credentials : public grpc_call_credentials {
void cancel_get_request_metadata(grpc_credentials_mdelem_array* md_array,
grpc_error* error) override;
- const grpc_call_credentials_array& inner() const { return inner_; }
+ const CallCredentialsList& inner() const { return inner_; }
private:
void push_to_inner(grpc_core::RefCountedPtr<grpc_call_credentials> creds,
bool is_composite);
- grpc_call_credentials_array inner_;
+ CallCredentialsList inner_;
};
#endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_COMPOSITE_COMPOSITE_CREDENTIALS_H \
diff --git a/src/core/lib/security/credentials/jwt/jwt_verifier.cc b/src/core/lib/security/credentials/jwt/jwt_verifier.cc
index c7d1b36ff0..cdef0f322a 100644
--- a/src/core/lib/security/credentials/jwt/jwt_verifier.cc
+++ b/src/core/lib/security/credentials/jwt/jwt_verifier.cc
@@ -31,7 +31,9 @@
#include <grpc/support/sync.h>
extern "C" {
+#include <openssl/bn.h>
#include <openssl/pem.h>
+#include <openssl/rsa.h>
}
#include "src/core/lib/gpr/string.h"