mirror of https://github.com/grpc/grpc.git
commit
c59ef5e451
150 changed files with 9991 additions and 3327 deletions
@ -1,36 +1,6 @@ |
||||
# Auto-generated by the tools/mkowners/mkowners.py tool |
||||
# Uses OWNERS files in different modules throughout the |
||||
# repository as the source of truth for module ownership. |
||||
/** @a11r @nicolasnoble @ctiller |
||||
/binding.gyp @murgatroid99 |
||||
/Gemfile @murgatroid99 |
||||
/grpc.gemspec @murgatroid99 |
||||
/package.json @murgatroid99 |
||||
/Rakefile @murgatroid99 |
||||
/**/OWNERS @markdroth @nicolasnoble @ctiller |
||||
/bazel/** @nicolasnoble @dgquintas @ctiller |
||||
/cmake/** @jtattermusch @a11r @nicolasnoble @ctiller |
||||
/doc/PROTOCOL-HTTP2.md @ejona86 @a11r @nicolasnoble @ctiller |
||||
/doc/interop-test-descriptions.md @ejona86 @a11r @nicolasnoble @ctiller |
||||
/etc/** @jboeuf @nicolasnoble @a11r @ctiller |
||||
/examples/node/** @murgatroid99 @a11r @nicolasnoble @ctiller |
||||
/include/** @ctiller @markdroth @dgquintas @a11r @nicolasnoble |
||||
/src/core/** @ctiller @markdroth @dgquintas @a11r @nicolasnoble |
||||
/src/core/lib/iomgr/*_uv.c @murgatroid99 @ctiller @markdroth @dgquintas @a11r @nicolasnoble |
||||
/src/core/lib/iomgr/*_uv.h @murgatroid99 @ctiller @markdroth @dgquintas @a11r @nicolasnoble |
||||
/src/cpp/** @ctiller @markdroth @dgquintas @a11r @nicolasnoble |
||||
/src/csharp/** @jtattermusch @apolcyn @a11r @nicolasnoble @ctiller |
||||
/src/node/** @murgatroid99 @a11r @nicolasnoble @ctiller |
||||
/src/objective-c/** @muxi @makdharma @a11r @nicolasnoble @ctiller |
||||
/src/php/** @stanley-cheung @murgatroid99 @a11r @nicolasnoble @ctiller |
||||
/src/python/** @nathanielmanistaatgoogle @kpayson64 @a11r @nicolasnoble @ctiller |
||||
/src/ruby/** @apolcyn @murgatroid99 @a11r @nicolasnoble @ctiller |
||||
/test/build/** @ctiller @markdroth @dgquintas @a11r @nicolasnoble |
||||
/test/core/** @ctiller @markdroth @dgquintas @a11r @nicolasnoble |
||||
/test/cpp/** @ctiller @markdroth @dgquintas @a11r @nicolasnoble |
||||
/test/distrib/node/** @murgatroid99 @a11r @nicolasnoble @ctiller |
||||
/tools/** @matt-kwong @jtattermusch @nicolasnoble @a11r @ctiller |
||||
/tools/codegen/core/** @ctiller @dgquintas @markdroth |
||||
/tools/dockerfile/** @matt-kwong @jtattermusch @nicolasnoble @a11r @ctiller |
||||
/tools/run_tests/** @matt-kwong @jtattermusch @nicolasnoble @a11r @ctiller |
||||
/tools/run_tests/artifacts/*_node* @murgatroid99 @matt-kwong @jtattermusch @nicolasnoble @a11r @ctiller |
||||
/tools/run_tests/helper_scripts/*_node* @murgatroid99 @matt-kwong @jtattermusch @nicolasnoble @a11r @ctiller |
||||
/src/core/ext/filters/client_channel/** @markdroth @dgquintas @ctiller |
||||
|
@ -1,2 +0,0 @@ |
||||
@jtattermusch |
||||
|
@ -1,2 +0,0 @@ |
||||
@ejona86 PROTOCOL-HTTP2.md interop-test-descriptions.md |
||||
|
@ -1,2 +0,0 @@ |
||||
@jboeuf |
||||
@nicolasnoble |
@ -1 +0,0 @@ |
||||
@murgatroid99 |
@ -1,4 +0,0 @@ |
||||
@ctiller |
||||
@markdroth |
||||
@dgquintas |
||||
|
@ -1,4 +0,0 @@ |
||||
@ctiller |
||||
@markdroth |
||||
@dgquintas |
||||
|
@ -1,5 +1,4 @@ |
||||
set noparent |
||||
@ctiller |
||||
@dgquintas |
||||
@markdroth |
||||
|
||||
@dgquintas |
||||
@ctiller |
@ -0,0 +1,29 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2017 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
#include "src/core/ext/transport/inproc/inproc_transport.h" |
||||
#include "src/core/lib/debug/trace.h" |
||||
|
||||
grpc_tracer_flag grpc_inproc_trace = GRPC_TRACER_INITIALIZER(false, "inproc"); |
||||
|
||||
void grpc_inproc_plugin_init(void) { |
||||
grpc_register_tracer(&grpc_inproc_trace); |
||||
grpc_inproc_transport_init(); |
||||
} |
||||
|
||||
void grpc_inproc_plugin_shutdown(void) { grpc_inproc_transport_shutdown(); } |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,41 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2017 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_CORE_EXT_TRANSPORT_INPROC_INPROC_TRANSPORT_H |
||||
#define GRPC_CORE_EXT_TRANSPORT_INPROC_INPROC_TRANSPORT_H |
||||
|
||||
#include "src/core/lib/transport/transport_impl.h" |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
grpc_channel *grpc_inproc_channel_create(grpc_server *server, |
||||
grpc_channel_args *args, |
||||
void *reserved); |
||||
|
||||
extern grpc_tracer_flag grpc_inproc_trace; |
||||
|
||||
void grpc_inproc_transport_init(void); |
||||
void grpc_inproc_transport_shutdown(void); |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* GRPC_CORE_EXT_TRANSPORT_INPROC_INPROC_TRANSPORT_H */ |
@ -0,0 +1,191 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2017 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
#include <grpc/support/alloc.h> |
||||
#include <grpc/support/log.h> |
||||
|
||||
#include "src/core/lib/compression/stream_compression.h" |
||||
#include "src/core/lib/iomgr/exec_ctx.h" |
||||
#include "src/core/lib/slice/slice_internal.h" |
||||
|
||||
#define OUTPUT_BLOCK_SIZE (1024) |
||||
|
||||
static bool gzip_flate(grpc_stream_compression_context *ctx, |
||||
grpc_slice_buffer *in, grpc_slice_buffer *out, |
||||
size_t *output_size, size_t max_output_size, int flush, |
||||
bool *end_of_context) { |
||||
GPR_ASSERT(flush == 0 || flush == Z_SYNC_FLUSH || flush == Z_FINISH); |
||||
/* Full flush is not allowed when inflating. */ |
||||
GPR_ASSERT(!(ctx->flate == inflate && (flush == Z_FINISH))); |
||||
|
||||
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
||||
int r; |
||||
bool eoc = false; |
||||
size_t original_max_output_size = max_output_size; |
||||
while (max_output_size > 0 && (in->length > 0 || flush) && !eoc) { |
||||
size_t slice_size = max_output_size < OUTPUT_BLOCK_SIZE ? max_output_size |
||||
: OUTPUT_BLOCK_SIZE; |
||||
grpc_slice slice_out = GRPC_SLICE_MALLOC(slice_size); |
||||
ctx->zs.avail_out = (uInt)slice_size; |
||||
ctx->zs.next_out = GRPC_SLICE_START_PTR(slice_out); |
||||
while (ctx->zs.avail_out > 0 && in->length > 0 && !eoc) { |
||||
grpc_slice slice = grpc_slice_buffer_take_first(in); |
||||
ctx->zs.avail_in = (uInt)GRPC_SLICE_LENGTH(slice); |
||||
ctx->zs.next_in = GRPC_SLICE_START_PTR(slice); |
||||
r = ctx->flate(&ctx->zs, Z_NO_FLUSH); |
||||
if (r < 0 && r != Z_BUF_ERROR) { |
||||
gpr_log(GPR_ERROR, "zlib error (%d)", r); |
||||
grpc_slice_unref_internal(&exec_ctx, slice_out); |
||||
grpc_exec_ctx_finish(&exec_ctx); |
||||
return false; |
||||
} else if (r == Z_STREAM_END && ctx->flate == inflate) { |
||||
eoc = true; |
||||
} |
||||
if (ctx->zs.avail_in > 0) { |
||||
grpc_slice_buffer_undo_take_first( |
||||
in, |
||||
grpc_slice_sub(slice, GRPC_SLICE_LENGTH(slice) - ctx->zs.avail_in, |
||||
GRPC_SLICE_LENGTH(slice))); |
||||
} |
||||
grpc_slice_unref_internal(&exec_ctx, slice); |
||||
} |
||||
if (flush != 0 && ctx->zs.avail_out > 0 && !eoc) { |
||||
GPR_ASSERT(in->length == 0); |
||||
r = ctx->flate(&ctx->zs, flush); |
||||
if (flush == Z_SYNC_FLUSH) { |
||||
switch (r) { |
||||
case Z_OK: |
||||
/* Maybe flush is not complete; just made some partial progress. */ |
||||
if (ctx->zs.avail_out > 0) { |
||||
flush = 0; |
||||
} |
||||
break; |
||||
case Z_BUF_ERROR: |
||||
case Z_STREAM_END: |
||||
flush = 0; |
||||
break; |
||||
default: |
||||
gpr_log(GPR_ERROR, "zlib error (%d)", r); |
||||
grpc_slice_unref_internal(&exec_ctx, slice_out); |
||||
grpc_exec_ctx_finish(&exec_ctx); |
||||
return false; |
||||
} |
||||
} else if (flush == Z_FINISH) { |
||||
switch (r) { |
||||
case Z_OK: |
||||
case Z_BUF_ERROR: |
||||
/* Wait for the next loop to assign additional output space. */ |
||||
GPR_ASSERT(ctx->zs.avail_out == 0); |
||||
break; |
||||
case Z_STREAM_END: |
||||
flush = 0; |
||||
break; |
||||
default: |
||||
gpr_log(GPR_ERROR, "zlib error (%d)", r); |
||||
grpc_slice_unref_internal(&exec_ctx, slice_out); |
||||
grpc_exec_ctx_finish(&exec_ctx); |
||||
return false; |
||||
} |
||||
} |
||||
} |
||||
|
||||
if (ctx->zs.avail_out == 0) { |
||||
grpc_slice_buffer_add(out, slice_out); |
||||
} else if (ctx->zs.avail_out < slice_size) { |
||||
slice_out.data.refcounted.length -= ctx->zs.avail_out; |
||||
grpc_slice_buffer_add(out, slice_out); |
||||
} else { |
||||
grpc_slice_unref_internal(&exec_ctx, slice_out); |
||||
} |
||||
max_output_size -= (slice_size - ctx->zs.avail_out); |
||||
} |
||||
grpc_exec_ctx_finish(&exec_ctx); |
||||
if (end_of_context) { |
||||
*end_of_context = eoc; |
||||
} |
||||
if (output_size) { |
||||
*output_size = original_max_output_size - max_output_size; |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
bool grpc_stream_compress(grpc_stream_compression_context *ctx, |
||||
grpc_slice_buffer *in, grpc_slice_buffer *out, |
||||
size_t *output_size, size_t max_output_size, |
||||
grpc_stream_compression_flush flush) { |
||||
GPR_ASSERT(ctx->flate == deflate); |
||||
int gzip_flush; |
||||
switch (flush) { |
||||
case GRPC_STREAM_COMPRESSION_FLUSH_NONE: |
||||
gzip_flush = 0; |
||||
break; |
||||
case GRPC_STREAM_COMPRESSION_FLUSH_SYNC: |
||||
gzip_flush = Z_SYNC_FLUSH; |
||||
break; |
||||
case GRPC_STREAM_COMPRESSION_FLUSH_FINISH: |
||||
gzip_flush = Z_FINISH; |
||||
break; |
||||
default: |
||||
gzip_flush = 0; |
||||
} |
||||
return gzip_flate(ctx, in, out, output_size, max_output_size, gzip_flush, |
||||
NULL); |
||||
} |
||||
|
||||
bool grpc_stream_decompress(grpc_stream_compression_context *ctx, |
||||
grpc_slice_buffer *in, grpc_slice_buffer *out, |
||||
size_t *output_size, size_t max_output_size, |
||||
bool *end_of_context) { |
||||
GPR_ASSERT(ctx->flate == inflate); |
||||
return gzip_flate(ctx, in, out, output_size, max_output_size, Z_SYNC_FLUSH, |
||||
end_of_context); |
||||
} |
||||
|
||||
grpc_stream_compression_context *grpc_stream_compression_context_create( |
||||
grpc_stream_compression_method method) { |
||||
grpc_stream_compression_context *ctx = |
||||
gpr_zalloc(sizeof(grpc_stream_compression_context)); |
||||
int r; |
||||
if (ctx == NULL) { |
||||
return NULL; |
||||
} |
||||
if (method == GRPC_STREAM_COMPRESSION_DECOMPRESS) { |
||||
r = inflateInit2(&ctx->zs, 0x1F); |
||||
ctx->flate = inflate; |
||||
} else { |
||||
r = deflateInit2(&ctx->zs, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 0x1F, 8, |
||||
Z_DEFAULT_STRATEGY); |
||||
ctx->flate = deflate; |
||||
} |
||||
if (r != Z_OK) { |
||||
gpr_free(ctx); |
||||
return NULL; |
||||
} |
||||
|
||||
return ctx; |
||||
} |
||||
|
||||
void grpc_stream_compression_context_destroy( |
||||
grpc_stream_compression_context *ctx) { |
||||
if (ctx->flate == inflate) { |
||||
inflateEnd(&ctx->zs); |
||||
} else { |
||||
deflateEnd(&ctx->zs); |
||||
} |
||||
gpr_free(ctx); |
||||
} |
@ -0,0 +1,90 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2017 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_CORE_LIB_COMPRESSION_STREAM_COMPRESSION_H |
||||
#define GRPC_CORE_LIB_COMPRESSION_STREAM_COMPRESSION_H |
||||
|
||||
#include <stdbool.h> |
||||
|
||||
#include <grpc/slice_buffer.h> |
||||
#include <zlib.h> |
||||
|
||||
/* Stream compression/decompression context */ |
||||
typedef struct grpc_stream_compression_context { |
||||
z_stream zs; |
||||
int (*flate)(z_stream *zs, int flush); |
||||
} grpc_stream_compression_context; |
||||
|
||||
typedef enum grpc_stream_compression_method { |
||||
GRPC_STREAM_COMPRESSION_COMPRESS = 0, |
||||
GRPC_STREAM_COMPRESSION_DECOMPRESS, |
||||
GRPC_STREAM_COMPRESSION_METHOD_COUNT |
||||
} grpc_stream_compression_method; |
||||
|
||||
typedef enum grpc_stream_compression_flush { |
||||
GRPC_STREAM_COMPRESSION_FLUSH_NONE = 0, |
||||
GRPC_STREAM_COMPRESSION_FLUSH_SYNC, |
||||
GRPC_STREAM_COMPRESSION_FLUSH_FINISH, |
||||
GRPC_STREAM_COMPRESSION_FLUSH_COUNT |
||||
} grpc_stream_compression_flush; |
||||
|
||||
/**
|
||||
* Compress bytes provided in \a in with a given context, with an optional flush |
||||
* at the end of compression. Emits at most \a max_output_size compressed bytes |
||||
* into \a out. If all the bytes in input buffer \a in are depleted and \a flush |
||||
* is not GRPC_STREAM_COMPRESSION_FLUSH_NONE, the corresponding flush method is |
||||
* executed. The total number of bytes emitted is outputed in \a output_size. |
||||
* |
||||
* A SYNC flush indicates that the entire messages in \a in can be decompressed |
||||
* from \a out. A FINISH flush implies a SYNC flush, and that any further |
||||
* compression will not be dependent on the state of the current context and any |
||||
* previous compressed bytes. It allows corresponding decompression context to |
||||
* be dropped when reaching this boundary. |
||||
*/ |
||||
bool grpc_stream_compress(grpc_stream_compression_context *ctx, |
||||
grpc_slice_buffer *in, grpc_slice_buffer *out, |
||||
size_t *output_size, size_t max_output_size, |
||||
grpc_stream_compression_flush flush); |
||||
|
||||
/**
|
||||
* Decompress bytes provided in \a in with a given context. Emits at most \a |
||||
* max_output_size decompressed bytes into \a out. If decompression process |
||||
* reached the end of a gzip stream, \a end_of_context is set to true; otherwise |
||||
* it is set to false. The total number of bytes emitted is outputed in \a |
||||
* output_size. |
||||
*/ |
||||
bool grpc_stream_decompress(grpc_stream_compression_context *ctx, |
||||
grpc_slice_buffer *in, grpc_slice_buffer *out, |
||||
size_t *output_size, size_t max_output_size, |
||||
bool *end_of_context); |
||||
|
||||
/**
|
||||
* Creates a stream compression context. \a pending_bytes_buffer is the input |
||||
* buffer for compression/decompression operations. \a method specifies whether |
||||
* the context is for compression or decompression. |
||||
*/ |
||||
grpc_stream_compression_context *grpc_stream_compression_context_create( |
||||
grpc_stream_compression_method method); |
||||
|
||||
/**
|
||||
* Destroys a stream compression context. |
||||
*/ |
||||
void grpc_stream_compression_context_destroy( |
||||
grpc_stream_compression_context *ctx); |
||||
|
||||
#endif |
@ -1 +0,0 @@ |
||||
@murgatroid99 *_uv.c *_uv.h |
@ -0,0 +1,40 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2017 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
#include "src/core/tsi/gts_transport_security.h" |
||||
|
||||
#include <string.h> |
||||
|
||||
static gts_shared_resource g_gts_resource; |
||||
|
||||
gts_shared_resource *gts_get_shared_resource(void) { return &g_gts_resource; } |
||||
|
||||
void grpc_tsi_gts_init() { |
||||
memset(&g_gts_resource, 0, sizeof(gts_shared_resource)); |
||||
gpr_mu_init(&g_gts_resource.mu); |
||||
} |
||||
|
||||
void grpc_tsi_gts_shutdown() { |
||||
gpr_mu_destroy(&g_gts_resource.mu); |
||||
if (g_gts_resource.cq == NULL) { |
||||
return; |
||||
} |
||||
grpc_completion_queue_destroy(g_gts_resource.cq); |
||||
grpc_channel_destroy(g_gts_resource.channel); |
||||
gpr_thd_join(g_gts_resource.thread_id); |
||||
} |
@ -0,0 +1,37 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2017 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_CORE_TSI_GTS_TRANSPORT_SECURITY_H |
||||
#define GRPC_CORE_TSI_GTS_TRANSPORT_SECURITY_H |
||||
|
||||
#include <grpc/grpc.h> |
||||
#include <grpc/support/sync.h> |
||||
#include <grpc/support/thd.h> |
||||
|
||||
typedef struct gts_shared_resource { |
||||
gpr_thd_id thread_id; |
||||
grpc_channel *channel; |
||||
grpc_completion_queue *cq; |
||||
gpr_mu mu; |
||||
} gts_shared_resource; |
||||
|
||||
/* This method returns the address of gts_shared_resource object shared by all
|
||||
* TSI handshakes. */ |
||||
gts_shared_resource *gts_get_shared_resource(void); |
||||
|
||||
#endif /* GRPC_CORE_TSI_GTS_TRANSPORT_SECURITY_H */ |
@ -1,4 +0,0 @@ |
||||
@ctiller |
||||
@markdroth |
||||
@dgquintas |
||||
|
@ -1,3 +0,0 @@ |
||||
@jtattermusch |
||||
@apolcyn |
||||
|
@ -1,2 +0,0 @@ |
||||
@murgatroid99 |
||||
|
@ -1,3 +0,0 @@ |
||||
@muxi |
||||
@makdharma |
||||
|
@ -1,3 +0,0 @@ |
||||
@stanley-cheung |
||||
@murgatroid99 |
||||
|
@ -1,3 +0,0 @@ |
||||
@nathanielmanistaatgoogle |
||||
@kpayson64 |
||||
|
@ -1,5 +1 @@ |
||||
proto/ |
||||
src/ |
||||
*_pb2.py |
||||
*_pb2_grpc.py |
||||
*.egg-info/ |
||||
/src/ |
||||
|
@ -1,3 +0,0 @@ |
||||
@apolcyn |
||||
@murgatroid99 |
||||
|
@ -1,4 +0,0 @@ |
||||
@ctiller |
||||
@markdroth |
||||
@dgquintas |
||||
|
@ -1,4 +0,0 @@ |
||||
@ctiller |
||||
@markdroth |
||||
@dgquintas |
||||
|
@ -0,0 +1,292 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2017 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
#include <string.h> |
||||
|
||||
#include <grpc/grpc.h> |
||||
#include <grpc/slice_buffer.h> |
||||
#include <grpc/support/alloc.h> |
||||
#include <grpc/support/log.h> |
||||
|
||||
#include "src/core/lib/compression/stream_compression.h" |
||||
|
||||
static void generate_random_payload(char *payload, size_t size) { |
||||
size_t i; |
||||
static const char chars[] = "abcdefghijklmnopqrstuvwxyz1234567890"; |
||||
for (i = 0; i < size - 1; ++i) { |
||||
payload[i] = chars[rand() % (int)(sizeof(chars) - 1)]; |
||||
} |
||||
payload[size - 1] = '\0'; |
||||
} |
||||
|
||||
static bool slice_buffer_equals_string(grpc_slice_buffer *buf, |
||||
const char *str) { |
||||
size_t i; |
||||
if (buf->length != strlen(str)) { |
||||
return false; |
||||
} |
||||
size_t pointer = 0; |
||||
for (i = 0; i < buf->count; i++) { |
||||
size_t slice_len = GRPC_SLICE_LENGTH(buf->slices[i]); |
||||
if (0 != strncmp(str + pointer, |
||||
(char *)GRPC_SLICE_START_PTR(buf->slices[i]), slice_len)) { |
||||
return false; |
||||
} |
||||
pointer += slice_len; |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
static void test_stream_compression_simple_compress_decompress() { |
||||
const char test_str[] = "aaaaaaabbbbbbbccccccctesttesttest"; |
||||
grpc_slice_buffer source, relay, sink; |
||||
grpc_slice_buffer_init(&source); |
||||
grpc_slice_buffer_init(&relay); |
||||
grpc_slice_buffer_init(&sink); |
||||
grpc_stream_compression_context *compress_ctx = |
||||
grpc_stream_compression_context_create(GRPC_STREAM_COMPRESSION_COMPRESS); |
||||
grpc_stream_compression_context *decompress_ctx = |
||||
grpc_stream_compression_context_create( |
||||
GRPC_STREAM_COMPRESSION_DECOMPRESS); |
||||
grpc_slice slice = grpc_slice_from_static_string(test_str); |
||||
grpc_slice_buffer_add(&source, slice); |
||||
GPR_ASSERT(grpc_stream_compress(compress_ctx, &source, &relay, NULL, |
||||
~(size_t)0, |
||||
GRPC_STREAM_COMPRESSION_FLUSH_FINISH)); |
||||
bool end_of_context; |
||||
size_t output_size; |
||||
GPR_ASSERT(grpc_stream_decompress(decompress_ctx, &relay, &sink, &output_size, |
||||
~(size_t)0, &end_of_context)); |
||||
GPR_ASSERT(output_size == sizeof(test_str) - 1); |
||||
grpc_stream_compression_context_destroy(compress_ctx); |
||||
grpc_stream_compression_context_destroy(decompress_ctx); |
||||
|
||||
GPR_ASSERT(slice_buffer_equals_string(&sink, test_str)); |
||||
|
||||
grpc_slice_buffer_destroy(&source); |
||||
grpc_slice_buffer_destroy(&relay); |
||||
grpc_slice_buffer_destroy(&sink); |
||||
} |
||||
|
||||
static void |
||||
test_stream_compression_simple_compress_decompress_with_output_size_constraint() { |
||||
const char test_str[] = "aaaaaaabbbbbbbccccccctesttesttest"; |
||||
grpc_slice_buffer source, relay, sink; |
||||
grpc_slice_buffer_init(&source); |
||||
grpc_slice_buffer_init(&relay); |
||||
grpc_slice_buffer_init(&sink); |
||||
grpc_stream_compression_context *compress_ctx = |
||||
grpc_stream_compression_context_create(GRPC_STREAM_COMPRESSION_COMPRESS); |
||||
grpc_stream_compression_context *decompress_ctx = |
||||
grpc_stream_compression_context_create( |
||||
GRPC_STREAM_COMPRESSION_DECOMPRESS); |
||||
grpc_slice slice = grpc_slice_from_static_string(test_str); |
||||
grpc_slice_buffer_add(&source, slice); |
||||
GPR_ASSERT(grpc_stream_compress(compress_ctx, &source, &relay, NULL, |
||||
~(size_t)0, |
||||
GRPC_STREAM_COMPRESSION_FLUSH_FINISH)); |
||||
grpc_stream_compression_context_destroy(compress_ctx); |
||||
|
||||
bool end_of_context; |
||||
size_t output_size; |
||||
size_t max_output_size = 2; |
||||
GPR_ASSERT(grpc_stream_decompress(decompress_ctx, &relay, &sink, &output_size, |
||||
max_output_size, &end_of_context)); |
||||
GPR_ASSERT(output_size == max_output_size); |
||||
GPR_ASSERT(end_of_context == false); |
||||
grpc_slice slice_recv = grpc_slice_buffer_take_first(&sink); |
||||
char *str_recv = (char *)GRPC_SLICE_START_PTR(slice_recv); |
||||
GPR_ASSERT(GRPC_SLICE_LENGTH(slice_recv) == max_output_size); |
||||
GPR_ASSERT(0 == strncmp(test_str, str_recv, max_output_size)); |
||||
grpc_slice_unref(slice_recv); |
||||
|
||||
size_t remaining_size = sizeof(test_str) - 1 - max_output_size; |
||||
GPR_ASSERT(grpc_stream_decompress(decompress_ctx, &relay, &sink, &output_size, |
||||
remaining_size, &end_of_context)); |
||||
GPR_ASSERT(output_size == remaining_size); |
||||
GPR_ASSERT(end_of_context == true); |
||||
|
||||
GPR_ASSERT(slice_buffer_equals_string(&sink, test_str + max_output_size)); |
||||
|
||||
grpc_stream_compression_context_destroy(decompress_ctx); |
||||
grpc_slice_buffer_destroy(&source); |
||||
grpc_slice_buffer_destroy(&relay); |
||||
grpc_slice_buffer_destroy(&sink); |
||||
} |
||||
|
||||
#define LARGE_DATA_SIZE (1024 * 1024) |
||||
static void |
||||
test_stream_compression_simple_compress_decompress_with_large_data() { |
||||
char *test_str = gpr_malloc(LARGE_DATA_SIZE * sizeof(char)); |
||||
generate_random_payload(test_str, LARGE_DATA_SIZE); |
||||
grpc_slice_buffer source, relay, sink; |
||||
grpc_slice_buffer_init(&source); |
||||
grpc_slice_buffer_init(&relay); |
||||
grpc_slice_buffer_init(&sink); |
||||
grpc_stream_compression_context *compress_ctx = |
||||
grpc_stream_compression_context_create(GRPC_STREAM_COMPRESSION_COMPRESS); |
||||
grpc_stream_compression_context *decompress_ctx = |
||||
grpc_stream_compression_context_create( |
||||
GRPC_STREAM_COMPRESSION_DECOMPRESS); |
||||
grpc_slice slice = grpc_slice_from_static_string(test_str); |
||||
grpc_slice_buffer_add(&source, slice); |
||||
GPR_ASSERT(grpc_stream_compress(compress_ctx, &source, &relay, NULL, |
||||
~(size_t)0, |
||||
GRPC_STREAM_COMPRESSION_FLUSH_FINISH)); |
||||
bool end_of_context; |
||||
size_t output_size; |
||||
GPR_ASSERT(grpc_stream_decompress(decompress_ctx, &relay, &sink, &output_size, |
||||
~(size_t)0, &end_of_context)); |
||||
GPR_ASSERT(output_size == LARGE_DATA_SIZE - 1); |
||||
grpc_stream_compression_context_destroy(compress_ctx); |
||||
grpc_stream_compression_context_destroy(decompress_ctx); |
||||
|
||||
GPR_ASSERT(slice_buffer_equals_string(&sink, test_str)); |
||||
|
||||
grpc_slice_buffer_destroy(&source); |
||||
grpc_slice_buffer_destroy(&relay); |
||||
grpc_slice_buffer_destroy(&sink); |
||||
gpr_free(test_str); |
||||
} |
||||
|
||||
static void test_stream_compression_drop_context() { |
||||
const char test_str[] = "aaaaaaabbbbbbbccccccc"; |
||||
const char test_str2[] = "dddddddeeeeeeefffffffggggg"; |
||||
grpc_slice_buffer source, relay, sink; |
||||
grpc_slice_buffer_init(&source); |
||||
grpc_slice_buffer_init(&relay); |
||||
grpc_slice_buffer_init(&sink); |
||||
grpc_stream_compression_context *compress_ctx = |
||||
grpc_stream_compression_context_create(GRPC_STREAM_COMPRESSION_COMPRESS); |
||||
grpc_slice slice = grpc_slice_from_static_string(test_str); |
||||
grpc_slice_buffer_add(&source, slice); |
||||
GPR_ASSERT(grpc_stream_compress(compress_ctx, &source, &relay, NULL, |
||||
~(size_t)0, |
||||
GRPC_STREAM_COMPRESSION_FLUSH_FINISH)); |
||||
grpc_stream_compression_context_destroy(compress_ctx); |
||||
|
||||
compress_ctx = |
||||
grpc_stream_compression_context_create(GRPC_STREAM_COMPRESSION_COMPRESS); |
||||
slice = grpc_slice_from_static_string(test_str2); |
||||
grpc_slice_buffer_add(&source, slice); |
||||
GPR_ASSERT(grpc_stream_compress(compress_ctx, &source, &relay, NULL, |
||||
~(size_t)0, |
||||
GRPC_STREAM_COMPRESSION_FLUSH_FINISH)); |
||||
grpc_stream_compression_context_destroy(compress_ctx); |
||||
|
||||
/* Concatenate the two compressed sliced into one to test decompressing two
|
||||
* contexts */ |
||||
grpc_slice slice1 = grpc_slice_buffer_take_first(&relay); |
||||
grpc_slice slice2 = grpc_slice_buffer_take_first(&relay); |
||||
grpc_slice slice3 = |
||||
grpc_slice_malloc(GRPC_SLICE_LENGTH(slice1) + GRPC_SLICE_LENGTH(slice2)); |
||||
memcpy(GRPC_SLICE_START_PTR(slice3), GRPC_SLICE_START_PTR(slice1), |
||||
GRPC_SLICE_LENGTH(slice1)); |
||||
memcpy(GRPC_SLICE_START_PTR(slice3) + GRPC_SLICE_LENGTH(slice1), |
||||
GRPC_SLICE_START_PTR(slice2), GRPC_SLICE_LENGTH(slice2)); |
||||
grpc_slice_unref(slice1); |
||||
grpc_slice_unref(slice2); |
||||
grpc_slice_buffer_add(&relay, slice3); |
||||
|
||||
grpc_stream_compression_context *decompress_ctx = |
||||
grpc_stream_compression_context_create( |
||||
GRPC_STREAM_COMPRESSION_DECOMPRESS); |
||||
bool end_of_context; |
||||
size_t output_size; |
||||
GPR_ASSERT(grpc_stream_decompress(decompress_ctx, &relay, &sink, &output_size, |
||||
~(size_t)0, &end_of_context)); |
||||
GPR_ASSERT(end_of_context == true); |
||||
GPR_ASSERT(output_size == sizeof(test_str) - 1); |
||||
|
||||
GPR_ASSERT(slice_buffer_equals_string(&sink, test_str)); |
||||
grpc_stream_compression_context_destroy(decompress_ctx); |
||||
grpc_slice_buffer_destroy(&sink); |
||||
|
||||
grpc_slice_buffer_init(&sink); |
||||
decompress_ctx = grpc_stream_compression_context_create( |
||||
GRPC_STREAM_COMPRESSION_DECOMPRESS); |
||||
GPR_ASSERT(grpc_stream_decompress(decompress_ctx, &relay, &sink, &output_size, |
||||
~(size_t)0, &end_of_context)); |
||||
GPR_ASSERT(end_of_context == true); |
||||
GPR_ASSERT(output_size == sizeof(test_str2) - 1); |
||||
GPR_ASSERT(slice_buffer_equals_string(&sink, test_str2)); |
||||
grpc_stream_compression_context_destroy(decompress_ctx); |
||||
|
||||
grpc_slice_buffer_destroy(&source); |
||||
grpc_slice_buffer_destroy(&relay); |
||||
grpc_slice_buffer_destroy(&sink); |
||||
} |
||||
|
||||
static void test_stream_compression_sync_flush() { |
||||
const char test_str[] = "aaaaaaabbbbbbbccccccc"; |
||||
const char test_str2[] = "dddddddeeeeeeefffffffggggg"; |
||||
grpc_slice_buffer source, relay, sink; |
||||
grpc_slice_buffer_init(&source); |
||||
grpc_slice_buffer_init(&relay); |
||||
grpc_slice_buffer_init(&sink); |
||||
grpc_stream_compression_context *compress_ctx = |
||||
grpc_stream_compression_context_create(GRPC_STREAM_COMPRESSION_COMPRESS); |
||||
grpc_slice slice = grpc_slice_from_static_string(test_str); |
||||
grpc_slice_buffer_add(&source, slice); |
||||
GPR_ASSERT(grpc_stream_compress(compress_ctx, &source, &relay, NULL, |
||||
~(size_t)0, |
||||
GRPC_STREAM_COMPRESSION_FLUSH_SYNC)); |
||||
|
||||
grpc_stream_compression_context *decompress_ctx = |
||||
grpc_stream_compression_context_create( |
||||
GRPC_STREAM_COMPRESSION_DECOMPRESS); |
||||
bool end_of_context; |
||||
size_t output_size; |
||||
GPR_ASSERT(grpc_stream_decompress(decompress_ctx, &relay, &sink, &output_size, |
||||
~(size_t)0, &end_of_context)); |
||||
GPR_ASSERT(end_of_context == false); |
||||
GPR_ASSERT(output_size == sizeof(test_str) - 1); |
||||
GPR_ASSERT(slice_buffer_equals_string(&sink, test_str)); |
||||
grpc_slice_buffer_destroy(&sink); |
||||
|
||||
grpc_slice_buffer_init(&sink); |
||||
slice = grpc_slice_from_static_string(test_str2); |
||||
grpc_slice_buffer_add(&source, slice); |
||||
GPR_ASSERT(grpc_stream_compress(compress_ctx, &source, &relay, NULL, |
||||
~(size_t)0, |
||||
GRPC_STREAM_COMPRESSION_FLUSH_FINISH)); |
||||
grpc_stream_compression_context_destroy(compress_ctx); |
||||
|
||||
GPR_ASSERT(grpc_stream_decompress(decompress_ctx, &relay, &sink, &output_size, |
||||
~(size_t)0, &end_of_context)); |
||||
GPR_ASSERT(end_of_context == true); |
||||
GPR_ASSERT(output_size == sizeof(test_str2) - 1); |
||||
GPR_ASSERT(slice_buffer_equals_string(&sink, test_str2)); |
||||
grpc_stream_compression_context_destroy(decompress_ctx); |
||||
|
||||
grpc_slice_buffer_destroy(&source); |
||||
grpc_slice_buffer_destroy(&relay); |
||||
grpc_slice_buffer_destroy(&sink); |
||||
} |
||||
|
||||
int main(int argc, char **argv) { |
||||
grpc_init(); |
||||
test_stream_compression_simple_compress_decompress(); |
||||
test_stream_compression_simple_compress_decompress_with_output_size_constraint(); |
||||
test_stream_compression_simple_compress_decompress_with_large_data(); |
||||
test_stream_compression_sync_flush(); |
||||
test_stream_compression_drop_context(); |
||||
grpc_shutdown(); |
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,96 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2017 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
#include "test/core/end2end/end2end_tests.h" |
||||
|
||||
#include <string.h> |
||||
|
||||
#include <grpc/support/alloc.h> |
||||
#include <grpc/support/host_port.h> |
||||
#include <grpc/support/log.h> |
||||
#include <grpc/support/sync.h> |
||||
#include <grpc/support/thd.h> |
||||
#include <grpc/support/useful.h> |
||||
#include "src/core/ext/filters/client_channel/client_channel.h" |
||||
#include "src/core/ext/filters/http/server/http_server_filter.h" |
||||
#include "src/core/ext/transport/inproc/inproc_transport.h" |
||||
#include "src/core/lib/channel/connected_channel.h" |
||||
#include "src/core/lib/surface/channel.h" |
||||
#include "src/core/lib/surface/server.h" |
||||
#include "test/core/util/port.h" |
||||
#include "test/core/util/test_config.h" |
||||
|
||||
typedef struct inproc_fixture_data { |
||||
bool dummy; // reserved for future expansion. Struct can't be empty
|
||||
} inproc_fixture_data; |
||||
|
||||
static grpc_end2end_test_fixture inproc_create_fixture( |
||||
grpc_channel_args *client_args, grpc_channel_args *server_args) { |
||||
grpc_end2end_test_fixture f; |
||||
inproc_fixture_data *ffd = gpr_malloc(sizeof(inproc_fixture_data)); |
||||
memset(&f, 0, sizeof(f)); |
||||
|
||||
f.fixture_data = ffd; |
||||
f.cq = grpc_completion_queue_create_for_next(NULL); |
||||
f.shutdown_cq = grpc_completion_queue_create_for_pluck(NULL); |
||||
|
||||
return f; |
||||
} |
||||
|
||||
void inproc_init_client(grpc_end2end_test_fixture *f, |
||||
grpc_channel_args *client_args) { |
||||
f->client = grpc_inproc_channel_create(f->server, client_args, NULL); |
||||
GPR_ASSERT(f->client); |
||||
} |
||||
|
||||
void inproc_init_server(grpc_end2end_test_fixture *f, |
||||
grpc_channel_args *server_args) { |
||||
if (f->server) { |
||||
grpc_server_destroy(f->server); |
||||
} |
||||
f->server = grpc_server_create(server_args, NULL); |
||||
grpc_server_register_completion_queue(f->server, f->cq, NULL); |
||||
grpc_server_start(f->server); |
||||
} |
||||
|
||||
void inproc_tear_down(grpc_end2end_test_fixture *f) { |
||||
inproc_fixture_data *ffd = f->fixture_data; |
||||
gpr_free(ffd); |
||||
} |
||||
|
||||
/* All test configurations */ |
||||
static grpc_end2end_test_config configs[] = { |
||||
{"inproc", FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER, inproc_create_fixture, |
||||
inproc_init_client, inproc_init_server, inproc_tear_down}, |
||||
}; |
||||
|
||||
int main(int argc, char **argv) { |
||||
size_t i; |
||||
|
||||
grpc_test_init(argc, argv); |
||||
grpc_end2end_tests_pre_init(); |
||||
grpc_init(); |
||||
|
||||
for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) { |
||||
grpc_end2end_tests(argc, argv, configs[i]); |
||||
} |
||||
|
||||
grpc_shutdown(); |
||||
|
||||
return 0; |
||||
} |
@ -1,4 +0,0 @@ |
||||
@ctiller |
||||
@markdroth |
||||
@dgquintas |
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue