aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/grpc/support/time.h4
-rw-r--r--src/core/iomgr/timer.c4
-rw-r--r--src/core/profiling/basic_timers.c7
-rw-r--r--src/core/security/credentials.c4
-rw-r--r--src/core/statistics/window_stats.c2
-rw-r--r--src/core/support/log_linux.c4
-rw-r--r--src/core/support/log_posix.c4
-rw-r--r--src/core/support/log_win32.c4
-rw-r--r--src/core/support/time.c64
-rw-r--r--src/core/support/time_posix.c17
-rw-r--r--src/core/support/time_precise.c4
-rw-r--r--src/core/support/time_win32.c6
-rw-r--r--src/core/surface/channel.c8
-rw-r--r--src/core/surface/channel_connectivity.c6
-rw-r--r--src/core/surface/completion_queue.c8
-rw-r--r--src/core/transport/chttp2/timeout_encoding.c10
-rw-r--r--src/core/transport/transport_op_string.c4
-rw-r--r--src/cpp/util/time.cc8
-rw-r--r--src/csharp/Grpc.Core.Tests/Internal/TimespecTest.cs91
-rw-r--r--src/csharp/Grpc.Core/Internal/Timespec.cs23
-rw-r--r--src/php/ext/grpc/call.c32
-rw-r--r--src/php/ext/grpc/call.h4
-rw-r--r--src/php/ext/grpc/call_credentials.c101
-rwxr-xr-xsrc/php/ext/grpc/call_credentials.h14
-rw-r--r--src/php/lib/Grpc/AbstractCall.php24
-rwxr-xr-xsrc/php/lib/Grpc/BaseStub.php81
-rw-r--r--src/php/tests/generated_code/AbstractGeneratedCodeTest.php3
-rwxr-xr-xsrc/php/tests/interop/interop_client.php30
-rw-r--r--src/php/tests/unit_tests/CallCredentialsTest.php137
-rw-r--r--src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxd6
-rw-r--r--src/python/grpcio/tests/interop/client.py2
-rw-r--r--src/python/grpcio/tests/interop/resources.py4
-rw-r--r--src/python/grpcio/tests/unit/resources.py4
-rwxr-xr-xsrc/ruby/bin/apis/pubsub_demo.rb12
-rw-r--r--src/ruby/ext/grpc/rb_channel_credentials.c25
-rw-r--r--src/ruby/ext/grpc/rb_grpc.c4
-rwxr-xr-xsrc/ruby/pb/test/client.rb10
-rw-r--r--src/ruby/spec/channel_credentials_spec.rb9
-rw-r--r--test/core/bad_client/tests/simple_request.c30
-rw-r--r--test/core/iomgr/tcp_client_posix_test.c5
-rw-r--r--test/core/support/sync_test.c2
-rw-r--r--test/core/support/time_test.c4
-rw-r--r--test/core/surface/lame_client_test.c38
-rw-r--r--tools/jenkins/grpc_interop_php/Dockerfile4
-rwxr-xr-xtools/run_tests/run_interop_tests.py15
45 files changed, 582 insertions, 300 deletions
diff --git a/include/grpc/support/time.h b/include/grpc/support/time.h
index f8ed893bc0..722866aa46 100644
--- a/include/grpc/support/time.h
+++ b/include/grpc/support/time.h
@@ -61,8 +61,8 @@ typedef enum {
} gpr_clock_type;
typedef struct gpr_timespec {
- time_t tv_sec;
- int tv_nsec;
+ gpr_int64 tv_sec;
+ gpr_int32 tv_nsec;
/** Against which clock was this time measured? (or GPR_TIMESPAN if
this is a relative time meaure) */
gpr_clock_type clock_type;
diff --git a/src/core/iomgr/timer.c b/src/core/iomgr/timer.c
index 66fafe75ad..c0e3175c4c 100644
--- a/src/core/iomgr/timer.c
+++ b/src/core/iomgr/timer.c
@@ -126,8 +126,8 @@ static double ts_to_dbl(gpr_timespec ts) {
static gpr_timespec dbl_to_ts(double d) {
gpr_timespec ts;
- ts.tv_sec = (time_t)d;
- ts.tv_nsec = (int)(1e9 * (d - (double)ts.tv_sec));
+ ts.tv_sec = (gpr_int64)d;
+ ts.tv_nsec = (gpr_int32)(1e9 * (d - (double)ts.tv_sec));
ts.clock_type = GPR_TIMESPAN;
return ts;
}
diff --git a/src/core/profiling/basic_timers.c b/src/core/profiling/basic_timers.c
index f0fce7858d..eedd387ebc 100644
--- a/src/core/profiling/basic_timers.c
+++ b/src/core/profiling/basic_timers.c
@@ -141,10 +141,11 @@ static void write_log(gpr_timer_log *log) {
entry->tm = gpr_time_0(entry->tm.clock_type);
}
fprintf(output_file,
- "{\"t\": %ld.%09d, \"thd\": \"%d\", \"type\": \"%c\", \"tag\": "
+ "{\"t\": %lld.%09d, \"thd\": \"%d\", \"type\": \"%c\", \"tag\": "
"\"%s\", \"file\": \"%s\", \"line\": %d, \"imp\": %d}\n",
- entry->tm.tv_sec, entry->tm.tv_nsec, entry->thd, entry->type,
- entry->tagstr, entry->file, entry->line, entry->important);
+ (long long)entry->tm.tv_sec, (int)entry->tm.tv_nsec, entry->thd,
+ entry->type, entry->tagstr, entry->file, entry->line,
+ entry->important);
}
}
diff --git a/src/core/security/credentials.c b/src/core/security/credentials.c
index 38a6710cd4..15cc8e6c0e 100644
--- a/src/core/security/credentials.c
+++ b/src/core/security/credentials.c
@@ -510,9 +510,9 @@ grpc_call_credentials *grpc_service_account_jwt_access_credentials_create(
"grpc_service_account_jwt_access_credentials_create("
"json_key=%s, "
"token_lifetime="
- "gpr_timespec { tv_sec: %ld, tv_nsec: %d, clock_type: %d }, "
+ "gpr_timespec { tv_sec: %lld, tv_nsec: %d, clock_type: %d }, "
"reserved=%p)",
- 5, (json_key, (long)token_lifetime.tv_sec, token_lifetime.tv_nsec,
+ 5, (json_key, (long long)token_lifetime.tv_sec, (int)token_lifetime.tv_nsec,
(int)token_lifetime.clock_type, reserved));
GPR_ASSERT(reserved == NULL);
return grpc_service_account_jwt_access_credentials_create_from_auth_json_key(
diff --git a/src/core/statistics/window_stats.c b/src/core/statistics/window_stats.c
index 4d0d3cca4a..e744006bb5 100644
--- a/src/core/statistics/window_stats.c
+++ b/src/core/statistics/window_stats.c
@@ -94,7 +94,7 @@ static gpr_int64 timespec_to_ns(const gpr_timespec ts) {
if (ts.tv_sec > max_seconds) {
return GPR_INT64_MAX - 1;
}
- return (gpr_int64)ts.tv_sec * GPR_NS_PER_SEC + ts.tv_nsec;
+ return ts.tv_sec * GPR_NS_PER_SEC + ts.tv_nsec;
}
static void cws_initialize_statistic(void *statistic,
diff --git a/src/core/support/log_linux.c b/src/core/support/log_linux.c
index 02f64d8b7e..d66b7a3cc0 100644
--- a/src/core/support/log_linux.c
+++ b/src/core/support/log_linux.c
@@ -76,16 +76,18 @@ void gpr_default_log(gpr_log_func_args *args) {
char *prefix;
const char *display_file;
char time_buffer[64];
+ time_t timer;
gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME);
struct tm tm;
+ timer = (time_t)now.tv_sec;
final_slash = strrchr(args->file, '/');
if (final_slash == NULL)
display_file = args->file;
else
display_file = final_slash + 1;
- if (!localtime_r(&now.tv_sec, &tm)) {
+ if (!localtime_r(&timer, &tm)) {
strcpy(time_buffer, "error:localtime");
} else if (0 ==
strftime(time_buffer, sizeof(time_buffer), "%m%d %H:%M:%S", &tm)) {
diff --git a/src/core/support/log_posix.c b/src/core/support/log_posix.c
index 8b050dbee7..8986254e4e 100644
--- a/src/core/support/log_posix.c
+++ b/src/core/support/log_posix.c
@@ -75,16 +75,18 @@ void gpr_default_log(gpr_log_func_args *args) {
char *final_slash;
const char *display_file;
char time_buffer[64];
+ time_t timer;
gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME);
struct tm tm;
+ timer = (time_t)now.tv_sec;
final_slash = strrchr(args->file, '/');
if (final_slash == NULL)
display_file = args->file;
else
display_file = final_slash + 1;
- if (!localtime_r(&now.tv_sec, &tm)) {
+ if (!localtime_r(&timer, &tm)) {
strcpy(time_buffer, "error:localtime");
} else if (0 ==
strftime(time_buffer, sizeof(time_buffer), "%m%d %H:%M:%S", &tm)) {
diff --git a/src/core/support/log_win32.c b/src/core/support/log_win32.c
index b68239f8f5..28e7768f80 100644
--- a/src/core/support/log_win32.c
+++ b/src/core/support/log_win32.c
@@ -84,16 +84,18 @@ void gpr_default_log(gpr_log_func_args *args) {
char *final_slash;
const char *display_file;
char time_buffer[64];
+ time_t timer;
gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME);
struct tm tm;
+ timer = (time_t)now.tv_sec;
final_slash = strrchr(args->file, '\\');
if (final_slash == NULL)
display_file = args->file;
else
display_file = final_slash + 1;
- if (localtime_s(&tm, &now.tv_sec)) {
+ if (localtime_s(&tm, &timer)) {
strcpy(time_buffer, "error:localtime");
} else if (0 ==
strftime(time_buffer, sizeof(time_buffer), "%m%d %H:%M:%S", &tm)) {
diff --git a/src/core/support/time.c b/src/core/support/time.c
index 929adac918..197fa9ad44 100644
--- a/src/core/support/time.c
+++ b/src/core/support/time.c
@@ -56,22 +56,6 @@ gpr_timespec gpr_time_max(gpr_timespec a, gpr_timespec b) {
return gpr_time_cmp(a, b) > 0 ? a : b;
}
-/* There's no standard TIME_T_MIN and TIME_T_MAX, so we construct them. The
- following assumes that signed types are two's-complement and that bytes are
- 8 bits. */
-
-/* The top bit of integral type t. */
-#define TOP_BIT_OF_TYPE(t) (((gpr_uintmax)1) << ((8 * sizeof(t)) - 1))
-
-/* Return whether integral type t is signed. */
-#define TYPE_IS_SIGNED(t) (((t)1) > (t) ~(t)0)
-
-/* The minimum and maximum value of integral type t. */
-#define TYPE_MIN(t) ((t)(TYPE_IS_SIGNED(t) ? TOP_BIT_OF_TYPE(t) : 0))
-#define TYPE_MAX(t) \
- ((t)(TYPE_IS_SIGNED(t) ? (TOP_BIT_OF_TYPE(t) - 1) \
- : ((TOP_BIT_OF_TYPE(t) - 1) << 1) + 1))
-
gpr_timespec gpr_time_0(gpr_clock_type type) {
gpr_timespec out;
out.tv_sec = 0;
@@ -82,7 +66,7 @@ gpr_timespec gpr_time_0(gpr_clock_type type) {
gpr_timespec gpr_inf_future(gpr_clock_type type) {
gpr_timespec out;
- out.tv_sec = TYPE_MAX(time_t);
+ out.tv_sec = INT64_MAX;
out.tv_nsec = 0;
out.clock_type = type;
return out;
@@ -90,7 +74,7 @@ gpr_timespec gpr_inf_future(gpr_clock_type type) {
gpr_timespec gpr_inf_past(gpr_clock_type type) {
gpr_timespec out;
- out.tv_sec = TYPE_MIN(time_t);
+ out.tv_sec = INT64_MIN;
out.tv_nsec = 0;
out.clock_type = type;
return out;
@@ -108,11 +92,11 @@ gpr_timespec gpr_time_from_nanos(long ns, gpr_clock_type type) {
result = gpr_inf_past(type);
} else if (ns >= 0) {
result.tv_sec = ns / GPR_NS_PER_SEC;
- result.tv_nsec = (int)(ns - result.tv_sec * GPR_NS_PER_SEC);
+ result.tv_nsec = (gpr_int32)(ns - result.tv_sec * GPR_NS_PER_SEC);
} else {
/* Calculation carefully formulated to avoid any possible under/overflow. */
result.tv_sec = (-(999999999 - (ns + GPR_NS_PER_SEC)) / GPR_NS_PER_SEC) - 1;
- result.tv_nsec = (int)(ns - result.tv_sec * GPR_NS_PER_SEC);
+ result.tv_nsec = (gpr_int32)(ns - result.tv_sec * GPR_NS_PER_SEC);
}
return result;
}
@@ -126,11 +110,11 @@ gpr_timespec gpr_time_from_micros(long us, gpr_clock_type type) {
result = gpr_inf_past(type);
} else if (us >= 0) {
result.tv_sec = us / 1000000;
- result.tv_nsec = (int)((us - result.tv_sec * 1000000) * 1000);
+ result.tv_nsec = (gpr_int32)((us - result.tv_sec * 1000000) * 1000);
} else {
/* Calculation carefully formulated to avoid any possible under/overflow. */
result.tv_sec = (-(999999 - (us + 1000000)) / 1000000) - 1;
- result.tv_nsec = (int)((us - result.tv_sec * 1000000) * 1000);
+ result.tv_nsec = (gpr_int32)((us - result.tv_sec * 1000000) * 1000);
}
return result;
}
@@ -144,11 +128,11 @@ gpr_timespec gpr_time_from_millis(long ms, gpr_clock_type type) {
result = gpr_inf_past(type);
} else if (ms >= 0) {
result.tv_sec = ms / 1000;
- result.tv_nsec = (int)((ms - result.tv_sec * 1000) * 1000000);
+ result.tv_nsec = (gpr_int32)((ms - result.tv_sec * 1000) * 1000000);
} else {
/* Calculation carefully formulated to avoid any possible under/overflow. */
result.tv_sec = (-(999 - (ms + 1000)) / 1000) - 1;
- result.tv_nsec = (int)((ms - result.tv_sec * 1000) * 1000000);
+ result.tv_nsec = (gpr_int32)((ms - result.tv_sec * 1000) * 1000000);
}
return result;
}
@@ -197,7 +181,7 @@ gpr_timespec gpr_time_from_hours(long h, gpr_clock_type type) {
gpr_timespec gpr_time_add(gpr_timespec a, gpr_timespec b) {
gpr_timespec sum;
- int inc = 0;
+ gpr_int64 inc = 0;
GPR_ASSERT(b.clock_type == GPR_TIMESPAN);
sum.clock_type = a.clock_type;
sum.tv_nsec = a.tv_nsec + b.tv_nsec;
@@ -205,17 +189,17 @@ gpr_timespec gpr_time_add(gpr_timespec a, gpr_timespec b) {
sum.tv_nsec -= GPR_NS_PER_SEC;
inc++;
}
- if (a.tv_sec == TYPE_MAX(time_t) || a.tv_sec == TYPE_MIN(time_t)) {
+ if (a.tv_sec == INT64_MAX || a.tv_sec == INT64_MIN) {
sum = a;
- } else if (b.tv_sec == TYPE_MAX(time_t) ||
- (b.tv_sec >= 0 && a.tv_sec >= TYPE_MAX(time_t) - b.tv_sec)) {
+ } else if (b.tv_sec == INT64_MAX ||
+ (b.tv_sec >= 0 && a.tv_sec >= INT64_MAX - b.tv_sec)) {
sum = gpr_inf_future(sum.clock_type);
- } else if (b.tv_sec == TYPE_MIN(time_t) ||
- (b.tv_sec <= 0 && a.tv_sec <= TYPE_MIN(time_t) - b.tv_sec)) {
+ } else if (b.tv_sec == INT64_MIN ||
+ (b.tv_sec <= 0 && a.tv_sec <= INT64_MIN - b.tv_sec)) {
sum = gpr_inf_past(sum.clock_type);
} else {
sum.tv_sec = a.tv_sec + b.tv_sec;
- if (inc != 0 && sum.tv_sec == TYPE_MAX(time_t) - 1) {
+ if (inc != 0 && sum.tv_sec == INT64_MAX - 1) {
sum = gpr_inf_future(sum.clock_type);
} else {
sum.tv_sec += inc;
@@ -226,7 +210,7 @@ gpr_timespec gpr_time_add(gpr_timespec a, gpr_timespec b) {
gpr_timespec gpr_time_sub(gpr_timespec a, gpr_timespec b) {
gpr_timespec diff;
- int dec = 0;
+ gpr_int64 dec = 0;
if (b.clock_type == GPR_TIMESPAN) {
diff.clock_type = a.clock_type;
} else {
@@ -238,17 +222,17 @@ gpr_timespec gpr_time_sub(gpr_timespec a, gpr_timespec b) {
diff.tv_nsec += GPR_NS_PER_SEC;
dec++;
}
- if (a.tv_sec == TYPE_MAX(time_t) || a.tv_sec == TYPE_MIN(time_t)) {
+ if (a.tv_sec == INT64_MAX || a.tv_sec == INT64_MIN) {
diff = a;
- } else if (b.tv_sec == TYPE_MIN(time_t) ||
- (b.tv_sec <= 0 && a.tv_sec >= TYPE_MAX(time_t) + b.tv_sec)) {
+ } else if (b.tv_sec == INT64_MIN ||
+ (b.tv_sec <= 0 && a.tv_sec >= INT64_MAX + b.tv_sec)) {
diff = gpr_inf_future(GPR_CLOCK_REALTIME);
- } else if (b.tv_sec == TYPE_MAX(time_t) ||
- (b.tv_sec >= 0 && a.tv_sec <= TYPE_MIN(time_t) + b.tv_sec)) {
+ } else if (b.tv_sec == INT64_MAX ||
+ (b.tv_sec >= 0 && a.tv_sec <= INT64_MIN + b.tv_sec)) {
diff = gpr_inf_past(GPR_CLOCK_REALTIME);
} else {
diff.tv_sec = a.tv_sec - b.tv_sec;
- if (dec != 0 && diff.tv_sec == TYPE_MIN(time_t) + 1) {
+ if (dec != 0 && diff.tv_sec == INT64_MIN + 1) {
diff = gpr_inf_past(GPR_CLOCK_REALTIME);
} else {
diff.tv_sec -= dec;
@@ -297,11 +281,11 @@ gpr_timespec gpr_convert_clock_type(gpr_timespec t, gpr_clock_type clock_type) {
}
if (t.tv_nsec == 0) {
- if (t.tv_sec == TYPE_MAX(time_t)) {
+ if (t.tv_sec == INT64_MAX) {
t.clock_type = clock_type;
return t;
}
- if (t.tv_sec == TYPE_MIN(time_t)) {
+ if (t.tv_sec == INT64_MIN) {
t.clock_type = clock_type;
return t;
}
diff --git a/src/core/support/time_posix.c b/src/core/support/time_posix.c
index 02cfca8555..05d6cc0ca8 100644
--- a/src/core/support/time_posix.c
+++ b/src/core/support/time_posix.c
@@ -45,7 +45,11 @@
static struct timespec timespec_from_gpr(gpr_timespec gts) {
struct timespec rv;
- rv.tv_sec = gts.tv_sec;
+ if (sizeof(time_t) < sizeof(gpr_int64)) {
+ /* fine to assert, as this is only used in gpr_sleep_until */
+ GPR_ASSERT(gts.tv_sec <= INT32_MAX && gts.tv_sec >= INT32_MIN);
+ }
+ rv.tv_sec = (time_t)gts.tv_sec;
rv.tv_nsec = gts.tv_nsec;
return rv;
}
@@ -53,9 +57,14 @@ static struct timespec timespec_from_gpr(gpr_timespec gts) {
#if _POSIX_TIMERS > 0
static gpr_timespec gpr_from_timespec(struct timespec ts,
gpr_clock_type clock_type) {
+ /*
+ * timespec.tv_sec can have smaller size than gpr_timespec.tv_sec,
+ * but we are only using this function to implement gpr_now
+ * so there's no need to handle "infinity" values.
+ */
gpr_timespec rv;
rv.tv_sec = ts.tv_sec;
- rv.tv_nsec = (int)ts.tv_nsec;
+ rv.tv_nsec = (gpr_int32)ts.tv_nsec;
rv.clock_type = clock_type;
return rv;
}
@@ -110,8 +119,8 @@ gpr_timespec gpr_now(gpr_clock_type clock) {
break;
case GPR_CLOCK_MONOTONIC:
now_dbl = (mach_absolute_time() - g_time_start) * g_time_scale;
- now.tv_sec = (time_t)(now_dbl * 1e-9);
- now.tv_nsec = (int)(now_dbl - ((double)now.tv_sec) * 1e9);
+ now.tv_sec = (gpr_int64)(now_dbl * 1e-9);
+ now.tv_nsec = (gpr_int32)(now_dbl - ((double)now.tv_sec) * 1e9);
break;
case GPR_CLOCK_PRECISE:
gpr_precise_clock_now(&now);
diff --git a/src/core/support/time_precise.c b/src/core/support/time_precise.c
index b37517e639..4de1d9b071 100644
--- a/src/core/support/time_precise.c
+++ b/src/core/support/time_precise.c
@@ -75,8 +75,8 @@ void gpr_precise_clock_now(gpr_timespec *clk) {
gpr_get_cycle_counter(&counter);
secs = (double)(counter - start_cycle) / cycles_per_second;
clk->clock_type = GPR_CLOCK_PRECISE;
- clk->tv_sec = (time_t)secs;
- clk->tv_nsec = (int)(1e9 * (secs - (double)clk->tv_sec));
+ clk->tv_sec = (gpr_int64)secs;
+ clk->tv_nsec = (gpr_int32)(1e9 * (secs - (double)clk->tv_sec));
}
#else /* GRPC_TIMERS_RDTSC */
diff --git a/src/core/support/time_win32.c b/src/core/support/time_win32.c
index 623a8d9233..7ccaaa248d 100644
--- a/src/core/support/time_win32.c
+++ b/src/core/support/time_win32.c
@@ -62,15 +62,15 @@ gpr_timespec gpr_now(gpr_clock_type clock) {
switch (clock) {
case GPR_CLOCK_REALTIME:
_ftime_s(&now_tb);
- now_tv.tv_sec = now_tb.time;
+ now_tv.tv_sec = (gpr_int64)now_tb.time;
now_tv.tv_nsec = now_tb.millitm * 1000000;
break;
case GPR_CLOCK_MONOTONIC:
case GPR_CLOCK_PRECISE:
QueryPerformanceCounter(&timestamp);
now_dbl = (timestamp.QuadPart - g_start_time.QuadPart) * g_time_scale;
- now_tv.tv_sec = (time_t)now_dbl;
- now_tv.tv_nsec = (int)((now_dbl - (double)now_tv.tv_sec) * 1e9);
+ now_tv.tv_sec = (gpr_int64)now_dbl;
+ now_tv.tv_nsec = (gpr_int32)((now_dbl - (double)now_tv.tv_sec) * 1e9);
break;
}
return now_tv;
diff --git a/src/core/surface/channel.c b/src/core/surface/channel.c
index 573a0e742f..a873c39441 100644
--- a/src/core/surface/channel.c
+++ b/src/core/surface/channel.c
@@ -195,10 +195,10 @@ grpc_call *grpc_channel_create_call(grpc_channel *channel,
"grpc_channel_create_call("
"channel=%p, parent_call=%p, propagation_mask=%x, cq=%p, method=%s, "
"host=%s, "
- "deadline=gpr_timespec { tv_sec: %ld, tv_nsec: %d, clock_type: %d }, "
+ "deadline=gpr_timespec { tv_sec: %lld, tv_nsec: %d, clock_type: %d }, "
"reserved=%p)",
10, (channel, parent_call, (unsigned)propagation_mask, cq, method, host,
- (long)deadline.tv_sec, deadline.tv_nsec, (int)deadline.clock_type,
+ (long long)deadline.tv_sec, (int)deadline.tv_nsec, (int)deadline.clock_type,
reserved));
GPR_ASSERT(!reserved);
return grpc_channel_create_call_internal(
@@ -239,10 +239,10 @@ grpc_call *grpc_channel_create_registered_call(
"grpc_channel_create_registered_call("
"channel=%p, parent_call=%p, propagation_mask=%x, completion_queue=%p, "
"registered_call_handle=%p, "
- "deadline=gpr_timespec { tv_sec: %ld, tv_nsec: %d, clock_type: %d }, "
+ "deadline=gpr_timespec { tv_sec: %lld, tv_nsec: %d, clock_type: %d }, "
"reserved=%p)",
9, (channel, parent_call, (unsigned)propagation_mask, completion_queue,
- registered_call_handle, (long)deadline.tv_sec, deadline.tv_nsec,
+ registered_call_handle, (long long)deadline.tv_sec, (int)deadline.tv_nsec,
(int)deadline.clock_type, reserved));
GPR_ASSERT(!reserved);
return grpc_channel_create_call_internal(
diff --git a/src/core/surface/channel_connectivity.c b/src/core/surface/channel_connectivity.c
index ad1c9b334e..57529ff903 100644
--- a/src/core/surface/channel_connectivity.c
+++ b/src/core/surface/channel_connectivity.c
@@ -184,10 +184,10 @@ void grpc_channel_watch_connectivity_state(
GRPC_API_TRACE(
"grpc_channel_watch_connectivity_state("
"channel=%p, last_observed_state=%d, "
- "deadline=gpr_timespec { tv_sec: %ld, tv_nsec: %d, clock_type: %d }, "
+ "deadline=gpr_timespec { tv_sec: %lld, tv_nsec: %d, clock_type: %d }, "
"cq=%p, tag=%p)",
- 7, (channel, (int)last_observed_state, (long)deadline.tv_sec,
- deadline.tv_nsec, (int)deadline.clock_type, cq, tag));
+ 7, (channel, (int)last_observed_state, (long long)deadline.tv_sec,
+ (int)deadline.tv_nsec, (int)deadline.clock_type, cq, tag));
grpc_cq_begin_op(cq);
diff --git a/src/core/surface/completion_queue.c b/src/core/surface/completion_queue.c
index d56e5cbe84..c71b9b02b0 100644
--- a/src/core/surface/completion_queue.c
+++ b/src/core/surface/completion_queue.c
@@ -247,9 +247,9 @@ grpc_event grpc_completion_queue_next(grpc_completion_queue *cc,
GRPC_API_TRACE(
"grpc_completion_queue_next("
"cc=%p, "
- "deadline=gpr_timespec { tv_sec: %ld, tv_nsec: %d, clock_type: %d }, "
+ "deadline=gpr_timespec { tv_sec: %lld, tv_nsec: %d, clock_type: %d }, "
"reserved=%p)",
- 5, (cc, (long)deadline.tv_sec, deadline.tv_nsec, (int)deadline.clock_type,
+ 5, (cc, (long long)deadline.tv_sec, (int)deadline.tv_nsec, (int)deadline.clock_type,
reserved));
GPR_ASSERT(!reserved);
@@ -335,9 +335,9 @@ grpc_event grpc_completion_queue_pluck(grpc_completion_queue *cc, void *tag,
GRPC_API_TRACE(
"grpc_completion_queue_pluck("
"cc=%p, tag=%p, "
- "deadline=gpr_timespec { tv_sec: %ld, tv_nsec: %d, clock_type: %d }, "
+ "deadline=gpr_timespec { tv_sec: %lld, tv_nsec: %d, clock_type: %d }, "
"reserved=%p)",
- 6, (cc, tag, (long)deadline.tv_sec, deadline.tv_nsec,
+ 6, (cc, tag, (long long)deadline.tv_sec, (int)deadline.tv_nsec,
(int)deadline.clock_type, reserved));
GPR_ASSERT(!reserved);
diff --git a/src/core/transport/chttp2/timeout_encoding.c b/src/core/transport/chttp2/timeout_encoding.c
index cf81c18a20..7ec8b4e8bf 100644
--- a/src/core/transport/chttp2/timeout_encoding.c
+++ b/src/core/transport/chttp2/timeout_encoding.c
@@ -39,12 +39,12 @@
#include <grpc/support/port_platform.h>
#include "src/core/support/string.h"
-static int round_up(int x, int divisor) {
+static gpr_int64 round_up(gpr_int64 x, gpr_int64 divisor) {
return (x / divisor + (x % divisor != 0)) * divisor;
}
/* round an integer up to the next value with three significant figures */
-static int round_up_to_three_sig_figs(int x) {
+static gpr_int64 round_up_to_three_sig_figs(gpr_int64 x) {
if (x < 1000) return x;
if (x < 10000) return round_up(x, 10);
if (x < 100000) return round_up(x, 100);
@@ -74,7 +74,7 @@ static void enc_seconds(char *buffer, gpr_int64 sec) {
}
}
-static void enc_nanos(char *buffer, int x) {
+static void enc_nanos(char *buffer, gpr_int64 x) {
x = round_up_to_three_sig_figs(x);
if (x < 100000) {
if (x % 1000 == 0) {
@@ -98,7 +98,7 @@ static void enc_nanos(char *buffer, int x) {
}
}
-static void enc_micros(char *buffer, int x) {
+static void enc_micros(char *buffer, gpr_int64 x) {
x = round_up_to_three_sig_figs(x);
if (x < 100000) {
if (x % 1000 == 0) {
@@ -124,7 +124,7 @@ void grpc_chttp2_encode_timeout(gpr_timespec timeout, char *buffer) {
enc_nanos(buffer, timeout.tv_nsec);
} else if (timeout.tv_sec < 1000 && timeout.tv_nsec != 0) {
enc_micros(buffer,
- (int)(timeout.tv_sec * 1000000) +
+ (gpr_int64)(timeout.tv_sec * 1000000) +
(timeout.tv_nsec / 1000 + (timeout.tv_nsec % 1000 != 0)));
} else {
enc_seconds(buffer, timeout.tv_sec + (timeout.tv_nsec != 0));
diff --git a/src/core/transport/transport_op_string.c b/src/core/transport/transport_op_string.c
index f3b6db29d6..98b51afc88 100644
--- a/src/core/transport/transport_op_string.c
+++ b/src/core/transport/transport_op_string.c
@@ -63,8 +63,8 @@ static void put_metadata_list(gpr_strvec *b, grpc_metadata_batch md) {
}
if (gpr_time_cmp(md.deadline, gpr_inf_future(md.deadline.clock_type)) != 0) {
char *tmp;
- gpr_asprintf(&tmp, " deadline=%d.%09d", md.deadline.tv_sec,
- md.deadline.tv_nsec);
+ gpr_asprintf(&tmp, " deadline=%lld.%09d", (long long)md.deadline.tv_sec,
+ (int)md.deadline.tv_nsec);
gpr_strvec_add(b, tmp);
}
}
diff --git a/src/cpp/util/time.cc b/src/cpp/util/time.cc
index 6157a37745..9c38b34879 100644
--- a/src/cpp/util/time.cc
+++ b/src/cpp/util/time.cc
@@ -57,8 +57,8 @@ void Timepoint2Timespec(const system_clock::time_point& from,
return;
}
nanoseconds nsecs = duration_cast<nanoseconds>(deadline - secs);
- to->tv_sec = (time_t)secs.count();
- to->tv_nsec = (int)nsecs.count();
+ to->tv_sec = (gpr_int64)secs.count();
+ to->tv_nsec = (gpr_int32)nsecs.count();
to->clock_type = GPR_CLOCK_REALTIME;
}
@@ -73,8 +73,8 @@ void TimepointHR2Timespec(const high_resolution_clock::time_point& from,
return;
}
nanoseconds nsecs = duration_cast<nanoseconds>(deadline - secs);
- to->tv_sec = (time_t)secs.count();
- to->tv_nsec = (int)nsecs.count();
+ to->tv_sec = (gpr_int64)secs.count();
+ to->tv_nsec = (gpr_int32)nsecs.count();
to->clock_type = GPR_CLOCK_REALTIME;
}
diff --git a/src/csharp/Grpc.Core.Tests/Internal/TimespecTest.cs b/src/csharp/Grpc.Core.Tests/Internal/TimespecTest.cs
index 9be5450d81..48b5d78ca9 100644
--- a/src/csharp/Grpc.Core.Tests/Internal/TimespecTest.cs
+++ b/src/csharp/Grpc.Core.Tests/Internal/TimespecTest.cs
@@ -82,17 +82,17 @@ namespace Grpc.Core.Internal.Tests
public void ToDateTime()
{
Assert.AreEqual(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc),
- new Timespec(IntPtr.Zero, 0).ToDateTime());
+ new Timespec(0, 0).ToDateTime());
Assert.AreEqual(new DateTime(1970, 1, 1, 0, 0, 10, DateTimeKind.Utc).AddTicks(50),
- new Timespec(new IntPtr(10), 5000).ToDateTime());
+ new Timespec(10, 5000).ToDateTime());
Assert.AreEqual(new DateTime(2015, 7, 21, 4, 21, 48, DateTimeKind.Utc),
- new Timespec(new IntPtr(1437452508), 0).ToDateTime());
+ new Timespec(1437452508, 0).ToDateTime());
// before epoch
Assert.AreEqual(new DateTime(1969, 12, 31, 23, 59, 55, DateTimeKind.Utc).AddTicks(10),
- new Timespec(new IntPtr(-5), 1000).ToDateTime());
+ new Timespec(-5, 1000).ToDateTime());
// infinity
Assert.AreEqual(DateTime.MaxValue, Timespec.InfFuture.ToDateTime());
@@ -100,80 +100,62 @@ namespace Grpc.Core.Internal.Tests
// nanos are rounded to ticks are rounded up
Assert.AreEqual(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddTicks(1),
- new Timespec(IntPtr.Zero, 99).ToDateTime());
+ new Timespec(0, 99).ToDateTime());
// Illegal inputs
Assert.Throws(typeof(InvalidOperationException),
- () => new Timespec(new IntPtr(0), -2).ToDateTime());
+ () => new Timespec(0, -2).ToDateTime());
Assert.Throws(typeof(InvalidOperationException),
- () => new Timespec(new IntPtr(0), 1000 * 1000 * 1000).ToDateTime());
+ () => new Timespec(0, 1000 * 1000 * 1000).ToDateTime());
Assert.Throws(typeof(InvalidOperationException),
- () => new Timespec(new IntPtr(0), 0, GPRClockType.Monotonic).ToDateTime());
+ () => new Timespec(0, 0, GPRClockType.Monotonic).ToDateTime());
}
[Test]
public void ToDateTime_ReturnsUtc()
{
- Assert.AreEqual(DateTimeKind.Utc, new Timespec(new IntPtr(1437452508), 0).ToDateTime().Kind);
- Assert.AreNotEqual(DateTimeKind.Unspecified, new Timespec(new IntPtr(1437452508), 0).ToDateTime().Kind);
+ Assert.AreEqual(DateTimeKind.Utc, new Timespec(1437452508, 0).ToDateTime().Kind);
+ Assert.AreNotEqual(DateTimeKind.Unspecified, new Timespec(1437452508, 0).ToDateTime().Kind);
}
[Test]
public void ToDateTime_Overflow()
- {
- // we can only get overflow in ticks arithmetic on 64-bit
- if (IntPtr.Size == 8)
- {
- var timespec = new Timespec(new IntPtr(long.MaxValue - 100), 0);
- Assert.AreNotEqual(Timespec.InfFuture, timespec);
- Assert.AreEqual(DateTime.MaxValue, timespec.ToDateTime());
-
- Assert.AreEqual(DateTime.MinValue, new Timespec(new IntPtr(long.MinValue + 100), 0).ToDateTime());
- }
- else
- {
- Console.WriteLine("Test cannot be run on this platform, skipping the test.");
- }
+ {
+ var timespec = new Timespec(long.MaxValue - 100, 0);
+ Assert.AreNotEqual(Timespec.InfFuture, timespec);
+ Assert.AreEqual(DateTime.MaxValue, timespec.ToDateTime());
+
+ Assert.AreEqual(DateTime.MinValue, new Timespec(long.MinValue + 100, 0).ToDateTime());
}
[Test]
public void ToDateTime_OutOfDateTimeRange()
{
- // we can only get out of range on 64-bit, on 32 bit the max
- // timestamp is ~ Jan 19 2038, which is far within range of DateTime
- // same case for min value.
- if (IntPtr.Size == 8)
- {
- // DateTime range goes up to year 9999, 20000 years from now should
- // be out of range.
- long seconds = 20000L * 365L * 24L * 3600L;
-
- var timespec = new Timespec(new IntPtr(seconds), 0);
- Assert.AreNotEqual(Timespec.InfFuture, timespec);
- Assert.AreEqual(DateTime.MaxValue, timespec.ToDateTime());
-
- Assert.AreEqual(DateTime.MinValue, new Timespec(new IntPtr(-seconds), 0).ToDateTime());
- }
- else
- {
- Console.WriteLine("Test cannot be run on this platform, skipping the test");
- }
+ // DateTime range goes up to year 9999, 20000 years from now should
+ // be out of range.
+ long seconds = 20000L * 365L * 24L * 3600L;
+
+ var timespec = new Timespec(seconds, 0);
+ Assert.AreNotEqual(Timespec.InfFuture, timespec);
+ Assert.AreEqual(DateTime.MaxValue, timespec.ToDateTime());
+
+ Assert.AreEqual(DateTime.MinValue, new Timespec(-seconds, 0).ToDateTime());
}
[Test]
public void FromDateTime()
{
- Assert.AreEqual(new Timespec(IntPtr.Zero, 0),
+ Assert.AreEqual(new Timespec(0, 0),
Timespec.FromDateTime(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)));
- Assert.AreEqual(new Timespec(new IntPtr(10), 5000),
+ Assert.AreEqual(new Timespec(10, 5000),
Timespec.FromDateTime(new DateTime(1970, 1, 1, 0, 0, 10, DateTimeKind.Utc).AddTicks(50)));
- Assert.AreEqual(new Timespec(new IntPtr(1437452508), 0),
+ Assert.AreEqual(new Timespec(1437452508, 0),
Timespec.FromDateTime(new DateTime(2015, 7, 21, 4, 21, 48, DateTimeKind.Utc)));
// before epoch
- Assert.AreEqual(new Timespec(new IntPtr(-5), 1000),
+ Assert.AreEqual(new Timespec(-5, 1000),
Timespec.FromDateTime(new DateTime(1969, 12, 31, 23, 59, 55, DateTimeKind.Utc).AddTicks(10)));
// infinity
@@ -184,21 +166,6 @@ namespace Grpc.Core.Internal.Tests
Assert.Throws(typeof(ArgumentException),
() => Timespec.FromDateTime(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Unspecified)));
}
-
- [Test]
- public void FromDateTime_OutOfTimespecRange()
- {
- // we can only get overflow in Timespec on 32-bit
- if (IntPtr.Size == 4)
- {
- Assert.AreEqual(Timespec.InfFuture, Timespec.FromDateTime(new DateTime(2040, 1, 1, 0, 0, 0, DateTimeKind.Utc)));
- Assert.AreEqual(Timespec.InfPast, Timespec.FromDateTime(new DateTime(1800, 1, 1, 0, 0, 0, DateTimeKind.Utc)));
- }
- else
- {
- Console.WriteLine("Test cannot be run on this platform, skipping the test.");
- }
- }
// Test attribute commented out to prevent running as part of the default test suite.
// [Test]
diff --git a/src/csharp/Grpc.Core/Internal/Timespec.cs b/src/csharp/Grpc.Core/Internal/Timespec.cs
index 38fc067d9f..3031175c8a 100644
--- a/src/csharp/Grpc.Core/Internal/Timespec.cs
+++ b/src/csharp/Grpc.Core/Internal/Timespec.cs
@@ -63,20 +63,18 @@ namespace Grpc.Core.Internal
[DllImport("grpc_csharp_ext.dll")]
static extern int gprsharp_sizeof_timespec();
- public Timespec(IntPtr tv_sec, int tv_nsec) : this(tv_sec, tv_nsec, GPRClockType.Realtime)
+ public Timespec(long tv_sec, int tv_nsec) : this(tv_sec, tv_nsec, GPRClockType.Realtime)
{
}
- public Timespec(IntPtr tv_sec, int tv_nsec, GPRClockType clock_type)
+ public Timespec(long tv_sec, int tv_nsec, GPRClockType clock_type)
{
this.tv_sec = tv_sec;
this.tv_nsec = tv_nsec;
this.clock_type = clock_type;
}
- // NOTE: on linux 64bit sizeof(gpr_timespec) = 16, on windows 32bit sizeof(gpr_timespec) = 8
- // so IntPtr seems to have the right size to work on both.
- private System.IntPtr tv_sec;
+ private long tv_sec;
private int tv_nsec;
private GPRClockType clock_type;
@@ -116,7 +114,7 @@ namespace Grpc.Core.Internal
/// <summary>
/// Seconds since unix epoch.
/// </summary>
- public IntPtr TimevalSeconds
+ public long TimevalSeconds
{
get
{
@@ -176,18 +174,18 @@ namespace Grpc.Core.Internal
{
// convert nanos to ticks, round up to the nearest tick
long ticksFromNanos = tv_nsec / NanosPerTick + ((tv_nsec % NanosPerTick != 0) ? 1 : 0);
- long ticksTotal = checked(tv_sec.ToInt64() * TicksPerSecond + ticksFromNanos);
+ long ticksTotal = checked(tv_sec * TicksPerSecond + ticksFromNanos);
return UnixEpoch.AddTicks(ticksTotal);
}
catch (OverflowException)
{
// ticks out of long range
- return tv_sec.ToInt64() > 0 ? DateTime.MaxValue : DateTime.MinValue;
+ return tv_sec > 0 ? DateTime.MaxValue : DateTime.MinValue;
}
catch (ArgumentOutOfRangeException)
{
// resulting date time would be larger than MaxValue
- return tv_sec.ToInt64() > 0 ? DateTime.MaxValue : DateTime.MinValue;
+ return tv_sec > 0 ? DateTime.MaxValue : DateTime.MinValue;
}
}
@@ -226,12 +224,7 @@ namespace Grpc.Core.Internal
seconds--;
nanos += (int)NanosPerSecond;
}
- // new IntPtr possibly throws OverflowException
- return new Timespec(new IntPtr(seconds), nanos);
- }
- catch (OverflowException)
- {
- return dateTime > UnixEpoch ? Timespec.InfFuture : Timespec.InfPast;
+ return new Timespec(seconds, nanos);
}
catch (ArgumentOutOfRangeException)
{
diff --git a/src/php/ext/grpc/call.c b/src/php/ext/grpc/call.c
index 3b99de7538..7ba14a38d8 100644
--- a/src/php/ext/grpc/call.c
+++ b/src/php/ext/grpc/call.c
@@ -42,13 +42,13 @@
#include <ext/standard/info.h>
#include <ext/spl/spl_exceptions.h>
#include "php_grpc.h"
+#include "call_credentials.h"
#include <zend_exceptions.h>
#include <zend_hash.h>
#include <stdbool.h>
-#include <grpc/support/log.h>
#include <grpc/support/alloc.h>
#include <grpc/grpc.h>
@@ -515,11 +515,41 @@ PHP_METHOD(Call, cancel) {
grpc_call_cancel(call->wrapped, NULL);
}
+/**
+ * Set the CallCredentials for this call.
+ * @param CallCredentials creds_obj The CallCredentials object
+ * @param int The error code
+ */
+PHP_METHOD(Call, setCredentials) {
+ zval *creds_obj;
+
+ /* "O" == 1 Object */
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &creds_obj,
+ grpc_ce_call_credentials) == FAILURE) {
+ zend_throw_exception(spl_ce_InvalidArgumentException,
+ "setCredentials expects 1 CallCredentials",
+ 1 TSRMLS_CC);
+ return;
+ }
+
+ wrapped_grpc_call_credentials *creds =
+ (wrapped_grpc_call_credentials *)zend_object_store_get_object(
+ creds_obj TSRMLS_CC);
+
+ wrapped_grpc_call *call =
+ (wrapped_grpc_call *)zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ grpc_call_error error = GRPC_CALL_ERROR;
+ error = grpc_call_set_credentials(call->wrapped, creds->wrapped);
+ RETURN_LONG(error);
+}
+
static zend_function_entry call_methods[] = {
PHP_ME(Call, __construct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
PHP_ME(Call, startBatch, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Call, getPeer, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Call, cancel, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Call, setCredentials, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END};
void grpc_init_call(TSRMLS_D) {
diff --git a/src/php/ext/grpc/call.h b/src/php/ext/grpc/call.h
index f3ef89dc97..73efadae35 100644
--- a/src/php/ext/grpc/call.h
+++ b/src/php/ext/grpc/call.h
@@ -66,4 +66,8 @@ zval *grpc_php_wrap_call(grpc_call *wrapped, bool owned);
* call metadata */
zval *grpc_parse_metadata_array(grpc_metadata_array *metadata_array);
+/* Populates a grpc_metadata_array with the data in a PHP array object.
+ Returns true on success and false on failure */
+bool create_metadata_array(zval *array, grpc_metadata_array *metadata);
+
#endif /* NET_GRPC_PHP_GRPC_CHANNEL_H_ */
diff --git a/src/php/ext/grpc/call_credentials.c b/src/php/ext/grpc/call_credentials.c
index 17f167befb..285c4e7c85 100644
--- a/src/php/ext/grpc/call_credentials.c
+++ b/src/php/ext/grpc/call_credentials.c
@@ -43,6 +43,7 @@
#include <ext/standard/info.h>
#include <ext/spl/spl_exceptions.h>
#include "php_grpc.h"
+#include "call.h"
#include <zend_exceptions.h>
#include <zend_hash.h>
@@ -103,7 +104,7 @@ PHP_METHOD(CallCredentials, createComposite) {
zval *cred1_obj;
zval *cred2_obj;
- /* "OO" == 3 Objects */
+ /* "OO" == 2 Objects */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "OO", &cred1_obj,
grpc_ce_call_credentials, &cred2_obj,
grpc_ce_call_credentials) == FAILURE) {
@@ -125,9 +126,107 @@ PHP_METHOD(CallCredentials, createComposite) {
RETURN_DESTROY_ZVAL(creds_object);
}
+/**
+ * Create a call credentials object from the plugin API
+ * @param function callback The callback function
+ * @return CallCredentials The new call credentials object
+ */
+PHP_METHOD(CallCredentials, createFromPlugin) {
+ zend_fcall_info *fci;
+ zend_fcall_info_cache *fci_cache;
+
+ fci = (zend_fcall_info *)emalloc(sizeof(zend_fcall_info));
+ fci_cache = (zend_fcall_info_cache *)emalloc(sizeof(zend_fcall_info_cache));
+ memset(fci, 0, sizeof(zend_fcall_info));
+ memset(fci_cache, 0, sizeof(zend_fcall_info_cache));
+
+ /* "f" == 1 function */
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "f", fci,
+ fci_cache,
+ fci->params,
+ fci->param_count) == FAILURE) {
+ zend_throw_exception(spl_ce_InvalidArgumentException,
+ "createFromPlugin expects 1 callback",
+ 1 TSRMLS_CC);
+ return;
+ }
+
+ plugin_state *state;
+ state = (plugin_state *)emalloc(sizeof(plugin_state));
+ memset(state, 0, sizeof(plugin_state));
+
+ /* save the user provided PHP callback function */
+ state->fci = fci;
+ state->fci_cache = fci_cache;
+
+ grpc_metadata_credentials_plugin plugin;
+ plugin.get_metadata = plugin_get_metadata;
+ plugin.destroy = plugin_destroy_state;
+ plugin.state = (void *)state;
+ plugin.type = "";
+
+ grpc_call_credentials *creds = grpc_metadata_credentials_create_from_plugin(
+ plugin, NULL);
+ zval *creds_object = grpc_php_wrap_call_credentials(creds);
+ RETURN_DESTROY_ZVAL(creds_object);
+}
+
+/* Callback function for plugin creds API */
+void plugin_get_metadata(void *ptr, grpc_auth_metadata_context context,
+ grpc_credentials_plugin_metadata_cb cb,
+ void *user_data) {
+ plugin_state *state = (plugin_state *)ptr;
+
+ /* prepare to call the user callback function with info from the
+ * grpc_auth_metadata_context */
+ zval **params[1];
+ zval *arg;
+ zval *retval;
+ MAKE_STD_ZVAL(arg);
+ object_init(arg);
+ add_property_string(arg, "service_url", context.service_url, true);
+ add_property_string(arg, "method_name", context.method_name, true);
+ params[0] = &arg;
+ state->fci->param_count = 1;
+ state->fci->params = params;
+ state->fci->retval_ptr_ptr = &retval;
+
+ /* call the user callback function */
+ zend_call_function(state->fci, state->fci_cache);
+
+ if (Z_TYPE_P(retval) != IS_ARRAY) {
+ zend_throw_exception(spl_ce_InvalidArgumentException,
+ "plugin callback must return metadata array",
+ 1 TSRMLS_CC);
+ }
+
+ grpc_metadata_array metadata;
+ if (!create_metadata_array(retval, &metadata)) {
+ zend_throw_exception(spl_ce_InvalidArgumentException,
+ "invalid metadata", 1 TSRMLS_CC);
+ grpc_metadata_array_destroy(&metadata);
+ }
+
+ /* TODO: handle error */
+ grpc_status_code code = GRPC_STATUS_OK;
+
+ /* Pass control back to core */
+ cb(user_data, metadata.metadata, metadata.count, code, NULL);
+}
+
+/* Cleanup function for plugin creds API */
+void plugin_destroy_state(void *ptr) {
+ plugin_state *state = (plugin_state *)ptr;
+ efree(state->fci);
+ efree(state->fci_cache);
+ efree(state);
+}
+
static zend_function_entry call_credentials_methods[] = {
PHP_ME(CallCredentials, createComposite, NULL,
ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
+ PHP_ME(CallCredentials, createFromPlugin, NULL,
+ ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_FE_END};
void grpc_init_call_credentials(TSRMLS_D) {
diff --git a/src/php/ext/grpc/call_credentials.h b/src/php/ext/grpc/call_credentials.h
index 8f35ac68bc..d2f6a92449 100755
--- a/src/php/ext/grpc/call_credentials.h
+++ b/src/php/ext/grpc/call_credentials.h
@@ -57,6 +57,20 @@ typedef struct wrapped_grpc_call_credentials {
grpc_call_credentials *wrapped;
} wrapped_grpc_call_credentials;
+/* Struct to hold callback function for plugin creds API */
+typedef struct plugin_state {
+ zend_fcall_info *fci;
+ zend_fcall_info_cache *fci_cache;
+} plugin_state;
+
+/* Callback function for plugin creds API */
+void plugin_get_metadata(void *state, grpc_auth_metadata_context context,
+ grpc_credentials_plugin_metadata_cb cb,
+ void *user_data);
+
+/* Cleanup function for plugin creds API */
+void plugin_destroy_state(void *ptr);
+
/* Initializes the CallCredentials PHP class */
void grpc_init_call_credentials(TSRMLS_D);
diff --git a/src/php/lib/Grpc/AbstractCall.php b/src/php/lib/Grpc/AbstractCall.php
index 53849d51fc..c80cf4464e 100644
--- a/src/php/lib/Grpc/AbstractCall.php
+++ b/src/php/lib/Grpc/AbstractCall.php
@@ -43,19 +43,20 @@ abstract class AbstractCall
/**
* Create a new Call wrapper object.
*
- * @param Channel $channel The channel to communicate on
- * @param string $method The method to call on the
- * remote server
- * @param callback $deserialize A callback function to deserialize
- * the response
- * @param (optional) long $timeout Timeout in microseconds
+ * @param Channel $channel The channel to communicate on
+ * @param string $method The method to call on the
+ * remote server
+ * @param callback $deserialize A callback function to deserialize
+ * the response
+ * @param array $options Call options (optional)
*/
public function __construct(Channel $channel,
$method,
$deserialize,
- $timeout = false)
+ $options = [])
{
- if ($timeout) {
+ if (isset($options['timeout']) &&
+ is_numeric($timeout = $options['timeout'])) {
$now = Timeval::now();
$delta = new Timeval($timeout);
$deadline = $now->add($delta);
@@ -65,6 +66,13 @@ abstract class AbstractCall
$this->call = new Call($channel, $method, $deadline);
$this->deserialize = $deserialize;
$this->metadata = null;
+ if (isset($options['call_credentials_callback']) &&
+ is_callable($call_credentials_callback =
+ $options['call_credentials_callback'])) {
+ $call_credentials = CallCredentials::createFromPlugin(
+ $call_credentials_callback);
+ $this->call->setCredentials($call_credentials);
+ }
}
/**
diff --git a/src/php/lib/Grpc/BaseStub.php b/src/php/lib/Grpc/BaseStub.php
index 7b2627f516..8e9dedf73b 100755
--- a/src/php/lib/Grpc/BaseStub.php
+++ b/src/php/lib/Grpc/BaseStub.php
@@ -159,25 +159,6 @@ class BaseStub
}
/**
- * extract $timeout from $metadata.
- *
- * @param $metadata The metadata map
- *
- * @return list($metadata_copy, $timeout)
- */
- private function _extract_timeout_from_metadata($metadata)
- {
- $timeout = false;
- $metadata_copy = $metadata;
- if (isset($metadata['timeout'])) {
- $timeout = $metadata['timeout'];
- unset($metadata_copy['timeout']);
- }
-
- return [$metadata_copy, $timeout];
- }
-
- /**
* validate and normalize the metadata array.
*
* @param $metadata The metadata map
@@ -220,21 +201,19 @@ class BaseStub
$metadata = [],
$options = [])
{
- list($actual_metadata, $timeout) =
- $this->_extract_timeout_from_metadata($metadata);
$call = new UnaryCall($this->channel,
$method,
$deserialize,
- $timeout);
+ $options);
$jwt_aud_uri = $this->_get_jwt_aud_uri($method);
if (is_callable($this->update_metadata)) {
- $actual_metadata = call_user_func($this->update_metadata,
- $actual_metadata,
+ $metadata = call_user_func($this->update_metadata,
+ $metadata,
$jwt_aud_uri);
}
- $actual_metadata = $this->_validate_and_normalize_metadata(
- $actual_metadata);
- $call->start($argument, $actual_metadata, $options);
+ $metadata = $this->_validate_and_normalize_metadata(
+ $metadata);
+ $call->start($argument, $metadata, $options);
return $call;
}
@@ -253,23 +232,22 @@ class BaseStub
*/
public function _clientStreamRequest($method,
callable $deserialize,
- $metadata = [])
+ $metadata = [],
+ $options = [])
{
- list($actual_metadata, $timeout) =
- $this->_extract_timeout_from_metadata($metadata);
$call = new ClientStreamingCall($this->channel,
$method,
$deserialize,
- $timeout);
+ $options);
$jwt_aud_uri = $this->_get_jwt_aud_uri($method);
if (is_callable($this->update_metadata)) {
- $actual_metadata = call_user_func($this->update_metadata,
- $actual_metadata,
+ $metadata = call_user_func($this->update_metadata,
+ $metadata,
$jwt_aud_uri);
}
- $actual_metadata = $this->_validate_and_normalize_metadata(
- $actual_metadata);
- $call->start($actual_metadata);
+ $metadata = $this->_validate_and_normalize_metadata(
+ $metadata);
+ $call->start($metadata);
return $call;
}
@@ -291,21 +269,19 @@ class BaseStub
$metadata = [],
$options = [])
{
- list($actual_metadata, $timeout) =
- $this->_extract_timeout_from_metadata($metadata);
$call = new ServerStreamingCall($this->channel,
$method,
$deserialize,
- $timeout);
+ $options);
$jwt_aud_uri = $this->_get_jwt_aud_uri($method);
if (is_callable($this->update_metadata)) {
- $actual_metadata = call_user_func($this->update_metadata,
- $actual_metadata,
+ $metadata = call_user_func($this->update_metadata,
+ $metadata,
$jwt_aud_uri);
}
- $actual_metadata = $this->_validate_and_normalize_metadata(
- $actual_metadata);
- $call->start($argument, $actual_metadata, $options);
+ $metadata = $this->_validate_and_normalize_metadata(
+ $metadata);
+ $call->start($argument, $metadata, $options);
return $call;
}
@@ -321,23 +297,22 @@ class BaseStub
*/
public function _bidiRequest($method,
callable $deserialize,
- $metadata = [])
+ $metadata = [],
+ $options = [])
{
- list($actual_metadata, $timeout) =
- $this->_extract_timeout_from_metadata($metadata);
$call = new BidiStreamingCall($this->channel,
$method,
$deserialize,
- $timeout);
+ $options);
$jwt_aud_uri = $this->_get_jwt_aud_uri($method);
if (is_callable($this->update_metadata)) {
- $actual_metadata = call_user_func($this->update_metadata,
- $actual_metadata,
+ $metadata = call_user_func($this->update_metadata,
+ $metadata,
$jwt_aud_uri);
}
- $actual_metadata = $this->_validate_and_normalize_metadata(
- $actual_metadata);
- $call->start($actual_metadata);
+ $metadata = $this->_validate_and_normalize_metadata(
+ $metadata);
+ $call->start($metadata);
return $call;
}
diff --git a/src/php/tests/generated_code/AbstractGeneratedCodeTest.php b/src/php/tests/generated_code/AbstractGeneratedCodeTest.php
index 4a0bd6a1f1..aa6906192f 100644
--- a/src/php/tests/generated_code/AbstractGeneratedCodeTest.php
+++ b/src/php/tests/generated_code/AbstractGeneratedCodeTest.php
@@ -41,7 +41,6 @@ abstract class AbstractGeneratedCodeTest extends PHPUnit_Framework_TestCase
* running on $GRPC_TEST_HOST.
*/
protected static $client;
- protected static $timeout;
public function testWaitForNotReady()
{
@@ -93,7 +92,7 @@ abstract class AbstractGeneratedCodeTest extends PHPUnit_Framework_TestCase
public function testTimeout()
{
$div_arg = new math\DivArgs();
- $call = self::$client->Div($div_arg, ['timeout' => 100]);
+ $call = self::$client->Div($div_arg, [], ['timeout' => 100]);
list($response, $status) = $call->wait();
$this->assertSame(\Grpc\STATUS_DEADLINE_EXCEEDED, $status->code);
}
diff --git a/src/php/tests/interop/interop_client.php b/src/php/tests/interop/interop_client.php
index 9aab5c966c..ee604a387c 100755
--- a/src/php/tests/interop/interop_client.php
+++ b/src/php/tests/interop/interop_client.php
@@ -84,7 +84,7 @@ function largeUnary($stub)
* @param $fillOauthScope boolean whether to fill result with oauth scope
*/
function performLargeUnary($stub, $fillUsername = false, $fillOauthScope = false,
- $metadata = [])
+ $callback = false)
{
$request_len = 271828;
$response_len = 314159;
@@ -99,7 +99,12 @@ function performLargeUnary($stub, $fillUsername = false, $fillOauthScope = false
$request->setFillUsername($fillUsername);
$request->setFillOauthScope($fillOauthScope);
- list($result, $status) = $stub->UnaryCall($request, $metadata)->wait();
+ $options = false;
+ if ($callback) {
+ $options['call_credentials_callback'] = $callback;
+ }
+
+ list($result, $status) = $stub->UnaryCall($request, [], $options)->wait();
hardAssert($status->code === Grpc\STATUS_OK, 'Call did not complete successfully');
hardAssert($result !== null, 'Call returned a null response');
$payload = $result->getPayload();
@@ -186,6 +191,15 @@ function oauth2AuthToken($stub, $args)
'invalid email returned');
}
+function updateAuthMetadataCallback($context)
+{
+ $authUri = $context->service_url;
+ $methodName = $context->method_name;
+ $auth_credentials = ApplicationDefaultCredentials::getCredentials();
+
+ return $auth_credentials->updateMetadata($metadata = [], $authUri);
+}
+
/**
* Run the per_rpc_creds auth test.
*
@@ -197,15 +211,9 @@ function perRpcCreds($stub, $args)
$jsonKey = json_decode(
file_get_contents(getenv(CredentialsLoader::ENV_VAR)),
true);
- $auth_credentials = ApplicationDefaultCredentials::getCredentials(
- $args['oauth_scope']
- );
- $token = $auth_credentials->fetchAuthToken();
- $metadata = [CredentialsLoader::AUTH_METADATA_KEY => [sprintf('%s %s',
- $token['token_type'],
- $token['access_token'])]];
+
$result = performLargeUnary($stub, $fillUsername = true, $fillOauthScope = true,
- $metadata);
+ 'updateAuthMetadataCallback');
hardAssert($result->getUsername() == $jsonKey['client_email'],
'invalid email returned');
}
@@ -363,7 +371,7 @@ function cancelAfterFirstResponse($stub)
function timeoutOnSleepingServer($stub)
{
- $call = $stub->FullDuplexCall(['timeout' => 1000]);
+ $call = $stub->FullDuplexCall([], ['timeout' => 1000]);
$request = new grpc\testing\StreamingOutputCallRequest();
$request->setResponseType(grpc\testing\PayloadType::COMPRESSABLE);
$response_parameters = new grpc\testing\ResponseParameters();
diff --git a/src/php/tests/unit_tests/CallCredentialsTest.php b/src/php/tests/unit_tests/CallCredentialsTest.php
new file mode 100644
index 0000000000..0918412781
--- /dev/null
+++ b/src/php/tests/unit_tests/CallCredentialsTest.php
@@ -0,0 +1,137 @@
+<?php
+/*
+ *
+ * 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.
+ *
+ */
+
+class CallCredentialsTest extends PHPUnit_Framework_TestCase
+{
+ public function setUp()
+ {
+ $credentials = Grpc\ChannelCredentials::createSsl(
+ file_get_contents(dirname(__FILE__).'/../data/ca.pem'));
+ $call_credentials = Grpc\CallCredentials::createFromPlugin(
+ array($this, 'callbackFunc'));
+ $credentials = Grpc\ChannelCredentials::createComposite(
+ $credentials,
+ $call_credentials
+ );
+ $server_credentials = Grpc\ServerCredentials::createSsl(
+ null,
+ file_get_contents(dirname(__FILE__).'/../data/server1.key'),
+ file_get_contents(dirname(__FILE__).'/../data/server1.pem'));
+ $this->server = new Grpc\Server();
+ $this->port = $this->server->addSecureHttp2Port('0.0.0.0:0',
+ $server_credentials);
+ $this->server->start();
+ $this->host_override = 'foo.test.google.fr';
+ $this->channel = new Grpc\Channel(
+ 'localhost:'.$this->port,
+ [
+ 'grpc.ssl_target_name_override' => $this->host_override,
+ 'grpc.default_authority' => $this->host_override,
+ 'credentials' => $credentials,
+ ]
+ );
+ }
+
+ public function tearDown()
+ {
+ unset($this->channel);
+ unset($this->server);
+ }
+
+ public function callbackFunc($context)
+ {
+ $this->assertTrue(is_string($context->service_url));
+ $this->assertTrue(is_string($context->method_name));
+
+ return ['k1' => ['v1'], 'k2' => ['v2']];
+ }
+
+ public function testCreateFromPlugin()
+ {
+ $deadline = Grpc\Timeval::infFuture();
+ $status_text = 'xyz';
+ $call = new Grpc\Call($this->channel,
+ '/abc/dummy_method',
+ $deadline,
+ $this->host_override);
+
+ $event = $call->startBatch([
+ Grpc\OP_SEND_INITIAL_METADATA => [],
+ Grpc\OP_SEND_CLOSE_FROM_CLIENT => true,
+ ]);
+
+ $this->assertTrue($event->send_metadata);
+ $this->assertTrue($event->send_close);
+
+ $event = $this->server->requestCall();
+
+ $this->assertTrue(is_array($event->metadata));
+ $metadata = $event->metadata;
+ $this->assertTrue(array_key_exists('k1', $metadata));
+ $this->assertTrue(array_key_exists('k2', $metadata));
+ $this->assertSame($metadata['k1'], ['v1']);
+ $this->assertSame($metadata['k2'], ['v2']);
+
+ $this->assertSame('/abc/dummy_method', $event->method);
+ $server_call = $event->call;
+
+ $event = $server_call->startBatch([
+ Grpc\OP_SEND_INITIAL_METADATA => [],
+ Grpc\OP_SEND_STATUS_FROM_SERVER => [
+ 'metadata' => [],
+ 'code' => Grpc\STATUS_OK,
+ 'details' => $status_text,
+ ],
+ Grpc\OP_RECV_CLOSE_ON_SERVER => true,
+ ]);
+
+ $this->assertTrue($event->send_metadata);
+ $this->assertTrue($event->send_status);
+ $this->assertFalse($event->cancelled);
+
+ $event = $call->startBatch([
+ Grpc\OP_RECV_INITIAL_METADATA => true,
+ Grpc\OP_RECV_STATUS_ON_CLIENT => true,
+ ]);
+
+ $this->assertSame([], $event->metadata);
+ $status = $event->status;
+ $this->assertSame([], $status->metadata);
+ $this->assertSame(Grpc\STATUS_OK, $status->code);
+ $this->assertSame($status_text, $status->details);
+
+ unset($call);
+ unset($server_call);
+ }
+}
diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxd b/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxd
index 10c948cd0a..643cdc9e3d 100644
--- a/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxd
+++ b/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxd
@@ -60,6 +60,8 @@ cdef extern from "grpc/support/port_platform.h":
# type exactly; just close enough that the operations will be supported in the
# underlying C layers.
ctypedef unsigned int gpr_uint32
+ ctypedef int gpr_int32
+ ctypedef long int gpr_int64
cdef extern from "grpc/support/time.h":
@@ -71,8 +73,8 @@ cdef extern from "grpc/support/time.h":
GPR_TIMESPAN
ctypedef struct gpr_timespec:
- libc.time.time_t seconds "tv_sec"
- int nanoseconds "tv_nsec"
+ gpr_int64 seconds "tv_sec"
+ gpr_int32 nanoseconds "tv_nsec"
gpr_clock_type clock_type
gpr_timespec gpr_time_0(gpr_clock_type type)
diff --git a/src/python/grpcio/tests/interop/client.py b/src/python/grpcio/tests/interop/client.py
index 5c00bce014..573ec2bd71 100644
--- a/src/python/grpcio/tests/interop/client.py
+++ b/src/python/grpcio/tests/interop/client.py
@@ -90,7 +90,7 @@ def _stub(args):
if args.use_test_ca:
root_certificates = resources.test_root_certificates()
else:
- root_certificates = resources.prod_root_certificates()
+ root_certificates = None # will load default roots.
channel = test_utilities.not_really_secure_channel(
args.server_host, args.server_port,
diff --git a/src/python/grpcio/tests/interop/resources.py b/src/python/grpcio/tests/interop/resources.py
index 1122499418..c424385cf6 100644
--- a/src/python/grpcio/tests/interop/resources.py
+++ b/src/python/grpcio/tests/interop/resources.py
@@ -44,10 +44,6 @@ def test_root_certificates():
__name__, _ROOT_CERTIFICATES_RESOURCE_PATH)
-def prod_root_certificates():
- return open(os.environ['SSL_CERT_FILE'], mode='rb').read()
-
-
def private_key():
return pkg_resources.resource_string(__name__, _PRIVATE_KEY_RESOURCE_PATH)
diff --git a/src/python/grpcio/tests/unit/resources.py b/src/python/grpcio/tests/unit/resources.py
index 2c3045313d..023cdb155f 100644
--- a/src/python/grpcio/tests/unit/resources.py
+++ b/src/python/grpcio/tests/unit/resources.py
@@ -43,10 +43,6 @@ def test_root_certificates():
__name__, _ROOT_CERTIFICATES_RESOURCE_PATH)
-def prod_root_certificates():
- return open(os.environ['SSL_CERT_FILE'], mode='rb').read()
-
-
def private_key():
return pkg_resources.resource_string(__name__, _PRIVATE_KEY_RESOURCE_PATH)
diff --git a/src/ruby/bin/apis/pubsub_demo.rb b/src/ruby/bin/apis/pubsub_demo.rb
index 003e91a6b3..983be6e823 100755
--- a/src/ruby/bin/apis/pubsub_demo.rb
+++ b/src/ruby/bin/apis/pubsub_demo.rb
@@ -32,7 +32,6 @@
# pubsub_demo demos accesses the Google PubSub API via its gRPC interface
#
# $ GOOGLE_APPLICATION_CREDENTIALS=<path_to_service_account_key_file> \
-# SSL_CERT_FILE=<path/to/ssl/certs> \
# path/to/pubsub_demo.rb \
# [--action=<chosen_demo_action> ]
#
@@ -55,18 +54,9 @@ require 'google/protobuf/empty'
require 'tech/pubsub/proto/pubsub'
require 'tech/pubsub/proto/pubsub_services'
-# loads the certificates used to access the test server securely.
-def load_prod_cert
- fail 'could not find a production cert' if ENV['SSL_CERT_FILE'].nil?
- p "loading prod certs from #{ENV['SSL_CERT_FILE']}"
- File.open(ENV['SSL_CERT_FILE']) do |f|
- return f.read
- end
-end
-
# creates a SSL Credentials from the production certificates.
def ssl_creds
- GRPC::Core::ChannelCredentials.new(load_prod_cert)
+ GRPC::Core::ChannelCredentials.new()
end
# Builds the metadata authentication update proc.
diff --git a/src/ruby/ext/grpc/rb_channel_credentials.c b/src/ruby/ext/grpc/rb_channel_credentials.c
index 072a6f54ab..5badd4bd7d 100644
--- a/src/ruby/ext/grpc/rb_channel_credentials.c
+++ b/src/ruby/ext/grpc/rb_channel_credentials.c
@@ -148,11 +148,13 @@ static ID id_pem_cert_chain;
/*
call-seq:
- creds1 = Credentials.new(pem_root_certs)
+ creds1 = Credentials.new()
...
- creds2 = Credentials.new(pem_root_certs, pem_private_key,
+ creds2 = Credentials.new(pem_root_certs)
+ ...
+ creds3 = Credentials.new(pem_root_certs, pem_private_key,
pem_cert_chain)
- pem_root_certs: (required) PEM encoding of the server root certificate
+ pem_root_certs: (optional) PEM encoding of the server root certificate
pem_private_key: (optional) PEM encoding of the client's private key
pem_cert_chain: (optional) PEM encoding of the client's cert chain
Initializes Credential instances. */
@@ -163,26 +165,23 @@ static VALUE grpc_rb_channel_credentials_init(int argc, VALUE *argv, VALUE self)
grpc_rb_channel_credentials *wrapper = NULL;
grpc_channel_credentials *creds = NULL;
grpc_ssl_pem_key_cert_pair key_cert_pair;
+ const char *pem_root_certs_cstr = NULL;
MEMZERO(&key_cert_pair, grpc_ssl_pem_key_cert_pair, 1);
- /* TODO: Remove mandatory arg when we support default roots. */
- /* "12" == 1 mandatory arg, 2 (credentials) is optional */
- rb_scan_args(argc, argv, "12", &pem_root_certs, &pem_private_key,
+ /* "03" == no mandatory arg, 3 optional */
+ rb_scan_args(argc, argv, "03", &pem_root_certs, &pem_private_key,
&pem_cert_chain);
TypedData_Get_Struct(self, grpc_rb_channel_credentials,
&grpc_rb_channel_credentials_data_type, wrapper);
- if (pem_root_certs == Qnil) {
- rb_raise(rb_eRuntimeError,
- "could not create a credential: nil pem_root_certs");
- return Qnil;
+ if (pem_root_certs != Qnil) {
+ pem_root_certs_cstr = RSTRING_PTR(pem_root_certs);
}
if (pem_private_key == Qnil && pem_cert_chain == Qnil) {
- creds =
- grpc_ssl_credentials_create(RSTRING_PTR(pem_root_certs), NULL, NULL);
+ creds = grpc_ssl_credentials_create(pem_root_certs_cstr, NULL, NULL);
} else {
key_cert_pair.private_key = RSTRING_PTR(pem_private_key);
key_cert_pair.cert_chain = RSTRING_PTR(pem_cert_chain);
- creds = grpc_ssl_credentials_create(RSTRING_PTR(pem_root_certs),
+ creds = grpc_ssl_credentials_create(pem_root_certs_cstr,
&key_cert_pair, NULL);
}
if (creds == NULL) {
diff --git a/src/ruby/ext/grpc/rb_grpc.c b/src/ruby/ext/grpc/rb_grpc.c
index 7c7c2d3440..8318e12795 100644
--- a/src/ruby/ext/grpc/rb_grpc.c
+++ b/src/ruby/ext/grpc/rb_grpc.c
@@ -91,7 +91,7 @@ static ID id_tv_sec;
static ID id_tv_nsec;
/**
- * grpc_rb_time_timeval creates a time_eval from a ruby time object.
+ * grpc_rb_time_timeval creates a timeval from a ruby time object.
*
* This func is copied from ruby source, MRI/source/time.c, which is published
* under the same license as the ruby.h, on which the entire extensions is
@@ -137,7 +137,7 @@ gpr_timespec grpc_rb_time_timeval(VALUE time, int interval) {
d += 1;
f -= 1;
}
- t.tv_sec = (time_t)f;
+ t.tv_sec = (gpr_int64)f;
if (f != t.tv_sec) {
rb_raise(rb_eRangeError, "%f out of Time range",
RFLOAT_VALUE(time));
diff --git a/src/ruby/pb/test/client.rb b/src/ruby/pb/test/client.rb
index 329e2dc98b..6eb727ccbe 100755
--- a/src/ruby/pb/test/client.rb
+++ b/src/ruby/pb/test/client.rb
@@ -93,13 +93,6 @@ def load_test_certs
files.map { |f| File.open(File.join(data_dir, f)).read }
end
-# loads the certificates used to access the test server securely.
-def load_prod_cert
- fail 'could not find a production cert' if ENV['SSL_CERT_FILE'].nil?
- GRPC.logger.info("loading prod certs from #{ENV['SSL_CERT_FILE']}")
- File.open(ENV['SSL_CERT_FILE']).read
-end
-
# creates SSL Credentials from the test certificates.
def test_creds
certs = load_test_certs
@@ -108,8 +101,7 @@ end
# creates SSL Credentials from the production certificates.
def prod_creds
- cert_text = load_prod_cert
- GRPC::Core::ChannelCredentials.new(cert_text)
+ GRPC::Core::ChannelCredentials.new()
end
# creates the SSL Credentials.
diff --git a/src/ruby/spec/channel_credentials_spec.rb b/src/ruby/spec/channel_credentials_spec.rb
index b2bdf7032e..f25cd78c91 100644
--- a/src/ruby/spec/channel_credentials_spec.rb
+++ b/src/ruby/spec/channel_credentials_spec.rb
@@ -54,10 +54,15 @@ describe GRPC::Core::ChannelCredentials do
expect { ChannelCredentials.new(root_cert) }.not_to raise_error
end
- it 'cannot be constructed with a nil server roots' do
+ it 'can be constructed with a nil server roots' do
_, client_key, client_chain = load_test_certs
blk = proc { ChannelCredentials.new(nil, client_key, client_chain) }
- expect(&blk).to raise_error
+ expect(&blk).not_to raise_error
+ end
+
+ it 'can be constructed with no params' do
+ blk = proc { ChannelCredentials.new(nil) }
+ expect(&blk).not_to raise_error
end
end
end
diff --git a/test/core/bad_client/tests/simple_request.c b/test/core/bad_client/tests/simple_request.c
index 5cddafc0b5..b3cd556421 100644
--- a/test/core/bad_client/tests/simple_request.c
+++ b/test/core/bad_client/tests/simple_request.c
@@ -99,6 +99,14 @@ static void verifier(grpc_server *server, grpc_completion_queue *cq) {
cq_verifier_destroy(cqv);
}
+static void failure_verifier(grpc_server *server, grpc_completion_queue *cq) {
+ while (grpc_server_has_open_connections(server)) {
+ GPR_ASSERT(grpc_completion_queue_next(cq,
+ GRPC_TIMEOUT_MILLIS_TO_DEADLINE(20),
+ NULL).type == GRPC_QUEUE_TIMEOUT);
+ }
+}
+
int main(int argc, char **argv) {
grpc_test_init(argc, argv);
@@ -115,6 +123,28 @@ int main(int argc, char **argv) {
/* push a data frame with bad flags */
GRPC_RUN_BAD_CLIENT_TEST(verifier,
PFX_STR "\x00\x00\x00\x00\x02\x00\x00\x00\x01", 0);
+ /* push a window update with a bad length */
+ GRPC_RUN_BAD_CLIENT_TEST(failure_verifier,
+ PFX_STR "\x00\x00\x01\x08\x00\x00\x00\x00\x01", 0);
+ /* push a window update with bad flags */
+ GRPC_RUN_BAD_CLIENT_TEST(failure_verifier,
+ PFX_STR "\x00\x00\x00\x08\x10\x00\x00\x00\x01", 0);
+ /* push a window update with bad data */
+ GRPC_RUN_BAD_CLIENT_TEST(failure_verifier,
+ PFX_STR "\x00\x00\x04\x08\x00\x00\x00\x00\x01" "\xff\xff\xff\xff", 0);
+ /* push a short goaway */
+ GRPC_RUN_BAD_CLIENT_TEST(failure_verifier,
+ PFX_STR "\x00\x00\x04\x07\x00\x00\x00\x00\x00", 0);
+ /* disconnect before sending goaway */
+ GRPC_RUN_BAD_CLIENT_TEST(failure_verifier,
+ PFX_STR "\x00\x01\x12\x07\x00\x00\x00\x00\x00",
+ GRPC_BAD_CLIENT_DISCONNECT);
+ /* push a rst_stream with a bad length */
+ GRPC_RUN_BAD_CLIENT_TEST(failure_verifier,
+ PFX_STR "\x00\x00\x01\x03\x00\x00\x00\x00\x01", 0);
+ /* push a rst_stream with bad flags */
+ GRPC_RUN_BAD_CLIENT_TEST(failure_verifier,
+ PFX_STR "\x00\x00\x00\x03\x10\x00\x00\x00\x01", 0);
return 0;
}
diff --git a/test/core/iomgr/tcp_client_posix_test.c b/test/core/iomgr/tcp_client_posix_test.c
index a61cccdb02..833ceace54 100644
--- a/test/core/iomgr/tcp_client_posix_test.c
+++ b/test/core/iomgr/tcp_client_posix_test.c
@@ -234,8 +234,9 @@ void test_times_out(void) {
if (gpr_time_cmp(now, finish_time) > 0) {
break;
}
- gpr_log(GPR_DEBUG, "now=%d.%09d connect_deadline=%d.%09d", now.tv_sec,
- now.tv_nsec, connect_deadline.tv_sec, connect_deadline.tv_nsec);
+ gpr_log(GPR_DEBUG, "now=%lld.%09d connect_deadline=%lld.%09d",
+ (long long)now.tv_sec, (int)now.tv_nsec,
+ (long long)connect_deadline.tv_sec, (int)connect_deadline.tv_nsec);
if (is_after_deadline && gpr_time_cmp(now, restart_verifying_time) <= 0) {
/* allow some slack before insisting that things be done */
} else {
diff --git a/test/core/support/sync_test.c b/test/core/support/sync_test.c
index 6bc5f792e5..e538af93f2 100644
--- a/test/core/support/sync_test.c
+++ b/test/core/support/sync_test.c
@@ -272,7 +272,7 @@ static void test(const char *name, void (*body)(void *m),
test_destroy(m);
}
time_taken = gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), start);
- fprintf(stderr, " done %ld.%09d s\n", (long)time_taken.tv_sec,
+ fprintf(stderr, " done %lld.%09d s\n", (long long)time_taken.tv_sec,
(int)time_taken.tv_nsec);
}
diff --git a/test/core/support/time_test.c b/test/core/support/time_test.c
index ce35edd83c..b921052e7b 100644
--- a/test/core/support/time_test.c
+++ b/test/core/support/time_test.c
@@ -98,7 +98,7 @@ static void test_values(void) {
fprintf(stderr, "far future ");
i_to_s(x.tv_sec, 16, 16, &to_fp, stderr);
fprintf(stderr, "\n");
- GPR_ASSERT(x.tv_sec >= INT_MAX);
+ GPR_ASSERT(x.tv_sec == INT64_MAX);
fprintf(stderr, "far future ");
ts_to_s(x, &to_fp, stderr);
fprintf(stderr, "\n");
@@ -107,7 +107,7 @@ static void test_values(void) {
fprintf(stderr, "far past ");
i_to_s(x.tv_sec, 16, 16, &to_fp, stderr);
fprintf(stderr, "\n");
- GPR_ASSERT(x.tv_sec <= INT_MIN);
+ GPR_ASSERT(x.tv_sec == INT64_MIN);
fprintf(stderr, "far past ");
ts_to_s(x, &to_fp, stderr);
fprintf(stderr, "\n");
diff --git a/test/core/surface/lame_client_test.c b/test/core/surface/lame_client_test.c
index 971055e6fd..1b1955fa0e 100644
--- a/test/core/surface/lame_client_test.c
+++ b/test/core/surface/lame_client_test.c
@@ -36,11 +36,47 @@
#include <grpc/grpc.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
+#include "src/core/channel/channel_stack.h"
+#include "src/core/iomgr/closure.h"
+#include "src/core/surface/channel.h"
+#include "src/core/transport/transport.h"
#include "test/core/end2end/cq_verifier.h"
#include "test/core/util/test_config.h"
+grpc_closure transport_op_cb;
+
static void *tag(gpr_intptr x) { return (void *)x; }
+void verify_connectivity(grpc_exec_ctx *exec_ctx, void *arg, int success) {
+ grpc_transport_op* op = arg;
+ GPR_ASSERT(GRPC_CHANNEL_FATAL_FAILURE == *op->connectivity_state);
+ GPR_ASSERT(success);
+}
+
+void do_nothing(grpc_exec_ctx *exec_ctx, void *arg, int success) { }
+
+void test_transport_op(grpc_channel *channel) {
+ grpc_transport_op op;
+ grpc_channel_element *elem;
+ grpc_connectivity_state state = GRPC_CHANNEL_IDLE;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+
+ memset(&op, 0, sizeof(op));
+ grpc_closure_init(&transport_op_cb, verify_connectivity, &op);
+
+ op.on_connectivity_state_change = &transport_op_cb;
+ op.connectivity_state = &state;
+ elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(channel), 0);
+ elem->filter->start_transport_op(&exec_ctx, elem, &op);
+ grpc_exec_ctx_finish(&exec_ctx);
+
+ memset(&op, 0, sizeof(op));
+ grpc_closure_init(&transport_op_cb, do_nothing, NULL);
+ op.on_consumed = &transport_op_cb;
+ elem->filter->start_transport_op(&exec_ctx, elem, &op);
+ grpc_exec_ctx_finish(&exec_ctx);
+}
+
int main(int argc, char **argv) {
grpc_channel *chan;
grpc_call *call;
@@ -66,6 +102,8 @@ int main(int argc, char **argv) {
"lampoon:national", GRPC_STATUS_UNKNOWN, "Rpc sent on a lame channel.");
GPR_ASSERT(chan);
+ test_transport_op(chan);
+
GPR_ASSERT(GRPC_CHANNEL_FATAL_FAILURE ==
grpc_channel_check_connectivity_state(chan, 0));
diff --git a/tools/jenkins/grpc_interop_php/Dockerfile b/tools/jenkins/grpc_interop_php/Dockerfile
index 492d20cdb5..078089424b 100644
--- a/tools/jenkins/grpc_interop_php/Dockerfile
+++ b/tools/jenkins/grpc_interop_php/Dockerfile
@@ -100,6 +100,10 @@ RUN /bin/bash -l -c "rvm all do gem install ronn rake"
RUN curl -sS https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer
+# attempt to force a rebuild of the docker image after this point because
+# Protobuf-PHP codegen has been updated
+RUN echo 1
+
# Download the patched PHP protobuf so that PHP gRPC clients can be generated
# from proto3 schemas.
RUN git clone https://github.com/stanley-cheung/Protobuf-PHP.git /var/local/git/protobuf-php
diff --git a/tools/run_tests/run_interop_tests.py b/tools/run_tests/run_interop_tests.py
index 7a09feb70d..e69e9877c5 100755
--- a/tools/run_tests/run_interop_tests.py
+++ b/tools/run_tests/run_interop_tests.py
@@ -54,11 +54,6 @@ os.chdir(ROOT)
_DEFAULT_SERVER_PORT=8080
-# TOOD(jtattermusch) wrapped languages use this variable for location
-# of roots.pem. We might want to use GRPC_DEFAULT_SSL_ROOTS_FILE_PATH
-# supported by C core SslCredentials instead.
-_SSL_CERT_ENV = { 'SSL_CERT_FILE':'/usr/local/share/grpc/roots.pem' }
-
_SKIP_COMPRESSION = ['large_compressed_unary',
'server_compressed_streaming']
@@ -105,7 +100,7 @@ class CSharpLanguage:
return ['mono', 'Grpc.IntegrationTesting.Client.exe'] + args
def cloud_to_prod_env(self):
- return _SSL_CERT_ENV
+ return {}
def server_cmd(self, args):
return ['mono', 'Grpc.IntegrationTesting.Server.exe', '--use_tls=true'] + args
@@ -222,7 +217,7 @@ class NodeLanguage:
return ['node', 'src/node/interop/interop_client.js'] + args
def cloud_to_prod_env(self):
- return _SSL_CERT_ENV
+ return {}
def server_cmd(self, args):
return ['node', 'src/node/interop/interop_server.js', '--use_tls=true'] + args
@@ -250,7 +245,7 @@ class PHPLanguage:
return ['src/php/bin/interop_client.sh'] + args
def cloud_to_prod_env(self):
- return _SSL_CERT_ENV
+ return {}
def global_env(self):
return {}
@@ -276,7 +271,7 @@ class RubyLanguage:
return ['ruby', 'src/ruby/bin/interop/interop_client.rb'] + args
def cloud_to_prod_env(self):
- return _SSL_CERT_ENV
+ return {}
def server_cmd(self, args):
return ['ruby', 'src/ruby/bin/interop/interop_server.rb', '--use_tls=true'] + args
@@ -311,7 +306,7 @@ class PythonLanguage:
]
def cloud_to_prod_env(self):
- return _SSL_CERT_ENV
+ return {}
def server_cmd(self, args):
return [