Skip to content

Commit

Permalink
Add gRPC support for WASM (envoyproxy#55)
Browse files Browse the repository at this point in the history
* Add gRPC support for WASM.
  • Loading branch information
John Plevyak authored May 8, 2019
1 parent 1c02570 commit 34b0348
Show file tree
Hide file tree
Showing 51 changed files with 175,061 additions and 349,661 deletions.
3 changes: 1 addition & 2 deletions api/wasm/cpp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ proxy_wasm_intrinsics.pb.h: proxy_wasm_intrinsics.proto
protoc --cpp_out=. proxy_wasm_intrinsics.proto

proxy_wasm_intrinsics_lite.pb.h struct_lite.pb.h: proxy_wasm_intrinsics_lite.proto
protoc --cpp_out=. proxy_wasm_intrinsics_lite.proto
protoc --cpp_out=. -I. proxy_wasm_intrinsics_lite.proto
protoc --cpp_out=. struct_lite.proto

37 changes: 37 additions & 0 deletions api/wasm/cpp/proxy_wasm_intrinsics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,40 @@ extern "C" EMSCRIPTEN_KEEPALIVE void proxy_onDelete(uint32_t context_id) {
c->onDelete();
context_map.erase(context_id);
}

extern "C" EMSCRIPTEN_KEEPALIVE void proxy_onGrpcCreateInitialMetadata(uint32_t context_id, uint32_t token) {
auto c = getContext(context_id);
if (!c)
return;
c->onGrpcCreateInitialMetadata(token);
}

extern "C" EMSCRIPTEN_KEEPALIVE void proxy_onGrpcReceiveInitialMetadata(uint32_t context_id, uint32_t token) {
auto c = getContext(context_id);
if (!c)
return;
c->onGrpcReceiveInitialMetadata(token);
}

extern "C" EMSCRIPTEN_KEEPALIVE void proxy_onGrpcReceiveTrailingMetadata(uint32_t context_id, uint32_t token) {
auto c = getContext(context_id);
if (!c)
return;
c->onGrpcReceiveTrailingMetadata(token);
}

extern "C" EMSCRIPTEN_KEEPALIVE void proxy_onGrpcReceive(uint32_t context_id, uint32_t token,
uint32_t response_ptr, uint32_t response_size) {
auto c = getContext(context_id);
if (!c)
return;
c->onGrpcReceive(token, std::make_unique<WasmData>(reinterpret_cast<char*>(response_ptr), response_size));
}

extern "C" EMSCRIPTEN_KEEPALIVE void proxy_onGrpcClose(uint32_t context_id, uint32_t token,
uint32_t status_code, uint32_t status_message_ptr, uint32_t status_message_size) {
auto c = getContext(context_id);
if (!c)
return;
c->onGrpcClose(token, static_cast<GrpcStatus>(status_code), std::make_unique<WasmData>(reinterpret_cast<char*>(status_message_ptr), status_message_size));
}
616 changes: 511 additions & 105 deletions api/wasm/cpp/proxy_wasm_intrinsics.h

Large diffs are not rendered by default.

30 changes: 10 additions & 20 deletions api/wasm/cpp/proxy_wasm_intrinsics.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,21 @@ mergeInto(LibraryManager.library, {
proxy_setMetadataStruct: function () {},
proxy_continueRequest: function () {},
proxy_continueResponse: function () {},
proxy_addRequestHeader: function () {},
proxy_getRequestHeader: function () {},
proxy_getRequestHeaderPairs: function () {},
proxy_replaceRequestHeader: function () {},
proxy_removeRequestHeader: function () {},
proxy_addRequestTrailer: function () {},
proxy_getRequestTrailer: function () {},
proxy_getRequestTrailerPairs: function () {},
proxy_replaceRequestTrailer: function () {},
proxy_removeRequestTrailer: function () {},
proxy_addHeaderMapValue: function () {},
proxy_getHeaderMapValue: function () {},
proxy_getHeaderMapPairs: function () {},
proxy_replaceHeaderMapValue: function () {},
proxy_removeHeaderMapValue: function () {},
proxy_getRequestBodyBufferBytes: function () {},
proxy_addResponseHeader: function () {},
proxy_getResponseHeader: function () {},
proxy_getResponseHeaderPairs: function () {},
proxy_replaceResponseHeader: function () {},
proxy_removeResponseHeader: function () {},
proxy_addResponseTrailer: function () {},
proxy_getResponseTrailer: function () {},
proxy_getResponseTrailerPairs: function () {},
proxy_replaceResponseTrailer: function () {},
proxy_removeResponseTrailer: function () {},
proxy_getResponseBodyBufferBytes: function () {},
proxy_httpCall: function () {},
proxy_defineMetric: function () {},
proxy_incrementMetric: function () {},
proxy_recordMetric: function () {},
proxy_getMetric: function () {},
proxy_grpcCall : function () {},
proxy_grpcStream : function () {},
proxy_grpcSend : function () {},
proxy_grpcClose : function () {},
proxy_grpcCancel : function () {},
});
Loading

0 comments on commit 34b0348

Please sign in to comment.