Skip to content

Commit 8c33ecf

Browse files
committed
Fix linking issues.
Signed-off-by: John Plevyak <[email protected]>
1 parent 92992ce commit 8c33ecf

20 files changed

+338
-206
lines changed

BUILD

+6-5
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ cc_library(
99
"include/proxy-wasm/compat.h",
1010
"include/proxy-wasm/exports.h",
1111
"include/proxy-wasm/null.h",
12-
"include/proxy-wasm/word.h",
12+
"include/proxy-wasm/null_plugin.h",
13+
"include/proxy-wasm/null_vm.h",
14+
"include/proxy-wasm/null_vm_plugin.h",
1315
"include/proxy-wasm/v8.h",
1416
"include/proxy-wasm/wasm.h",
1517
"include/proxy-wasm/wasm_vm.h",
18+
"include/proxy-wasm/wasm_api_impl.h",
19+
"include/proxy-wasm/word.h",
1620
],
1721
copts = ["-std=c++14"],
1822
deps = [
@@ -32,17 +36,14 @@ cc_library(
3236
"src/v8/v8.cc",
3337
"src/null/null.cc",
3438
"src/null/null_plugin.cc",
35-
"src/null/null_plugin.h",
3639
"src/null/null_vm.cc",
37-
"src/null/null_vm.h",
38-
"src/null/null_vm_plugin.h",
39-
"src/null/wasm_api_impl.h",
4040
],
4141
copts = ["-std=c++14"],
4242
deps = [
4343
":include",
4444
"@proxy_wasm_cpp_sdk//:api_lib",
4545
"@proxy_wasm_cpp_sdk//:common_lib",
46+
"@envoy//external:abseil_flat_hash_map",
4647
"@envoy//external:abseil_strings",
4748
"@envoy//external:abseil_optional",
4849
"@envoy//external:zlib",

include/proxy-wasm/compat.h

+6
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,14 @@ namespace proxy_wasm {
2828
#ifndef __cpp_lib_optional
2929
using string_view = absl::string_view;
3030
template <typename T> using optional = absl::optional<T>;
31+
// Only available in C++17
32+
// inline constexpr absl::nullopt_t nullopt = absl::nullopt;
33+
#define PROXY_WASM_NULLOPT absl::nullopt
3134
#else
3235
using string_view = std::string_view;
3336
template <typename T> using optional = std::optional<T>;
37+
// Only available in C++17
38+
// inline constexpr std::nullopt_t nullopt = std::nullopt;
39+
#define PROXY_WASM_NULLOPT std::nullopt
3440
#endif
3541
} // namespace proxy_wasm

include/proxy-wasm/context.h

+93-28
Original file line numberDiff line numberDiff line change
@@ -103,31 +103,64 @@ class ContextBase {
103103
// General stream downcall on a new stream.
104104
virtual void onCreate(uint32_t root_context_id);
105105
// Network
106-
virtual FilterStatus onNetworkNewConnection();
107-
virtual FilterStatus onDownstreamData(int data_length, bool end_of_stream);
108-
virtual FilterStatus onUpstreamData(int data_length, bool end_of_stream);
106+
virtual FilterStatus onNetworkNewConnection() {
107+
unimplemented();
108+
return FilterStatus::Continue;
109+
}
110+
virtual FilterStatus onDownstreamData(int /* data_length */, bool /* end_of_stream */) {
111+
unimplemented();
112+
return FilterStatus::Continue;
113+
}
114+
virtual FilterStatus onUpstreamData(int /* data_length */, bool /* end_of_stream */) {
115+
unimplemented();
116+
return FilterStatus::Continue;
117+
}
109118
enum class PeerType : uint32_t {
110119
Unknown = 0,
111120
Local = 1,
112121
Remote = 2,
113122
};
114-
virtual void onDownstreamConnectionClose(PeerType);
115-
virtual void onUpstreamConnectionClose(PeerType);
123+
virtual void onDownstreamConnectionClose(PeerType) { unimplemented(); }
124+
virtual void onUpstreamConnectionClose(PeerType) { unimplemented(); }
116125
// HTTP Filter Stream Request Downcalls.
117-
virtual FilterHeadersStatus onRequestHeaders();
118-
virtual FilterDataStatus onRequestBody(int body_buffer_length, bool end_of_stream);
119-
virtual FilterTrailersStatus onRequestTrailers();
120-
virtual FilterMetadataStatus onRequestMetadata();
126+
virtual FilterHeadersStatus onRequestHeaders() {
127+
unimplemented();
128+
return FilterHeadersStatus::Continue;
129+
}
130+
virtual FilterDataStatus onRequestBody(int /* body_buffer_length */, bool /* end_of_stream */) {
131+
unimplemented();
132+
return FilterDataStatus::Continue;
133+
}
134+
virtual FilterTrailersStatus onRequestTrailers() {
135+
unimplemented();
136+
return FilterTrailersStatus::Continue;
137+
}
138+
virtual FilterMetadataStatus onRequestMetadata() {
139+
unimplemented();
140+
return FilterMetadataStatus::Continue;
141+
}
121142
// HTTP Filter Stream Response Downcalls.
122-
virtual FilterHeadersStatus onResponseHeaders();
123-
virtual FilterDataStatus onResponseBody(int body_buffer_length, bool end_of_stream);
124-
virtual FilterTrailersStatus onResponseTrailers();
125-
virtual FilterMetadataStatus onResponseMetadata();
143+
virtual FilterHeadersStatus onResponseHeaders() {
144+
unimplemented();
145+
return FilterHeadersStatus::Continue;
146+
}
147+
virtual FilterDataStatus onResponseBody(int /* body_buffer_length */, bool /* end_of_stream */) {
148+
unimplemented();
149+
return FilterDataStatus::Continue;
150+
}
151+
virtual FilterTrailersStatus onResponseTrailers() {
152+
unimplemented();
153+
return FilterTrailersStatus::Continue;
154+
}
155+
virtual FilterMetadataStatus onResponseMetadata() {
156+
unimplemented();
157+
return FilterMetadataStatus::Continue;
158+
}
126159
// Async call response.
127-
virtual void onHttpCallResponse(uint32_t token, uint32_t headers, uint32_t body_size,
128-
uint32_t trailers);
160+
virtual void onHttpCallResponse(uint32_t /* token */, uint32_t /* headers */,
161+
uint32_t /* body_size */, uint32_t /* trailers */) {}
129162
// Inter-VM shared queue message arrival.
130-
virtual void onQueueReady(uint32_t token);
163+
virtual void onQueueReady(uint32_t /* token */) { unimplemented(); }
131164
// General stream downcall when the stream/vm has ended.
132165
virtual bool onDone();
133166
// General stream downcall for logging. Occurs after onDone().
@@ -145,9 +178,13 @@ class ContextBase {
145178
// General Callbacks.
146179
//
147180
virtual WasmResult log(uint64_t /* level */, string_view /* message */) {
181+
unimplemented();
182+
return WasmResult::Unimplemented;
183+
}
184+
virtual WasmResult setTimerPeriod(std::chrono::milliseconds /* period */) {
185+
unimplemented();
148186
return WasmResult::Unimplemented;
149187
}
150-
virtual WasmResult setTimerPeriod(std::chrono::milliseconds period);
151188
virtual uint64_t getCurrentTimeNanoseconds() {
152189
struct timespec tpe;
153190
clock_gettime(CLOCK_REALTIME, &tpe);
@@ -156,11 +193,20 @@ class ContextBase {
156193
t += tpe.tv_nsec;
157194
return t;
158195
}
159-
virtual std::pair<uint32_t, string_view> getStatus();
196+
virtual std::pair<uint32_t, string_view> getStatus() {
197+
unimplemented();
198+
return std::make_pair(1, "unimplmemented");
199+
}
160200

161201
// Buffer
162-
virtual const BufferInterface *getBuffer(WasmBufferType type);
163-
virtual bool end_of_stream();
202+
virtual const BufferInterface *getBuffer(WasmBufferType /* type */) {
203+
unimplemented();
204+
return nullptr;
205+
}
206+
virtual bool end_of_stream() {
207+
unimplemented();
208+
return true;
209+
}
164210

165211
// HTTP
166212
// Returns a token which will be used with the corresponding onHttpCallResponse.
@@ -200,14 +246,33 @@ class ContextBase {
200246
}
201247

202248
// Metrics
203-
virtual WasmResult defineMetric(MetricType type, string_view name, uint32_t *metric_id_ptr);
204-
virtual WasmResult incrementMetric(uint32_t metric_id, int64_t offset);
205-
virtual WasmResult recordMetric(uint32_t metric_id, uint64_t value);
206-
virtual WasmResult getMetric(uint32_t metric_id, uint64_t *value_ptr);
207-
208-
// State accessors
209-
virtual WasmResult getProperty(string_view path, std::string *result);
210-
virtual WasmResult setProperty(string_view key, string_view serialized_value);
249+
virtual WasmResult defineMetric(MetricType /* type */, string_view /* name */,
250+
uint32_t * /* metric_id_ptr */) {
251+
unimplemented();
252+
return WasmResult::Unimplemented;
253+
}
254+
virtual WasmResult incrementMetric(uint32_t /* metric_id */, int64_t /* offset */) {
255+
unimplemented();
256+
return WasmResult::Unimplemented;
257+
}
258+
virtual WasmResult recordMetric(uint32_t /* metric_id */, uint64_t /* value */) {
259+
unimplemented();
260+
return WasmResult::Unimplemented;
261+
}
262+
virtual WasmResult getMetric(uint32_t /* metric_id */, uint64_t * /* value_ptr */) {
263+
unimplemented();
264+
return WasmResult::Unimplemented;
265+
}
266+
267+
// Properties
268+
virtual WasmResult getProperty(string_view /* path */, std::string * /* result */) {
269+
unimplemented();
270+
return WasmResult::Unimplemented;
271+
}
272+
virtual WasmResult setProperty(string_view /* key */, string_view /* serialized_value */) {
273+
unimplemented();
274+
return WasmResult::Unimplemented;
275+
}
211276

212277
// Continue
213278
virtual void continueRequest() { unimplemented(); }

include/proxy-wasm/exports.h

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ Word send_local_response(void *raw_context, Word response_code, Word response_co
3535
Word response_code_details_size, Word body_ptr, Word body_size,
3636
Word additional_response_header_pairs_ptr,
3737
Word additional_response_header_pairs_size, Word grpc_status);
38-
Word clear_route_cache(void *raw_context);
3938
Word get_shared_data(void *raw_context, Word key_ptr, Word key_size, Word value_ptr_ptr,
4039
Word value_size_ptr, Word cas_ptr);
4140
Word set_shared_data(void *raw_context, Word key_ptr, Word key_size, Word value_ptr,

src/null/null_plugin.h renamed to include/proxy-wasm/null_plugin.h

+7-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#include <memory>
1919

20-
#include "src/null/null_vm_plugin.h"
20+
#include "include/proxy-wasm/null_vm_plugin.h"
2121
#include "include/proxy-wasm/wasm.h"
2222

2323
#include <google/protobuf/message.h>
@@ -28,7 +28,7 @@ namespace null_plugin {
2828
} // namespace null_plugin
2929
} // namespace proxy_wasm
3030

31-
#include "src/null/wasm_api_impl.h"
31+
#include "include/proxy-wasm/wasm_api_impl.h"
3232

3333
namespace proxy_wasm {
3434
namespace null_plugin {
@@ -130,7 +130,7 @@ class NullPlugin : public NullVmPlugin {
130130
null_plugin::RootFactory root_factory = nullptr, \
131131
StringView root_id = "") { \
132132
if (!context_registry_) { \
133-
context_registry_ = new null_plugin::NullPluginRegistry; \
133+
context_registry_ = new NullPluginRegistry; \
134134
} \
135135
context_registry_->context_factories[std::string(root_id)] = context_factory; \
136136
context_registry_->root_factories[std::string(root_id)] = root_factory; \
@@ -148,7 +148,7 @@ class NullPlugin : public NullVmPlugin {
148148
namespace proxy_wasm { \
149149
namespace null_plugin { \
150150
namespace _name { \
151-
NULL_PLUGIN_REGISTRY
151+
PROXY_WASM_NULL_PLUGIN_REGISTRY
152152

153153
#define END_WASM_PLUGIN \
154154
} \
@@ -158,6 +158,9 @@ class NullPlugin : public NullVmPlugin {
158158
#define WASM_EXPORT(_t, _f, _a) \
159159
_t _f _a; \
160160
static int register_export_##_f() { \
161+
if (!context_registry_) { \
162+
context_registry_ = new NullPluginRegistry; \
163+
} \
161164
context_registry_->_f##_ = _f; \
162165
return 0; \
163166
}; \

src/null/null_vm.h renamed to include/proxy-wasm/null_vm.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include <utility>
2020
#include <vector>
2121

22-
#include "src/null/null_vm_plugin.h"
22+
#include "include/proxy-wasm/null_vm_plugin.h"
2323
#include "include/proxy-wasm/wasm_vm.h"
2424

2525
namespace proxy_wasm {
File renamed without changes.

include/proxy-wasm/wasm.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,9 @@ using WasmHandleCloneFactory =
261261

262262
// Returns nullptr on failure (i.e. initialization of the VM fails).
263263
std::shared_ptr<WasmHandle>
264-
createWasm(std::string code, std::shared_ptr<PluginBase> plugin, WasmHandleFactory factory,
265-
bool allow_precompiled, std::unique_ptr<ContextBase> root_context_for_testing = nullptr);
264+
createWasm(std::string vm_key, std::string code, std::shared_ptr<PluginBase> plugin,
265+
WasmHandleFactory factory, bool allow_precompiled,
266+
std::unique_ptr<ContextBase> root_context_for_testing = nullptr);
266267
// Get an existing ThreadLocal VM matching 'vm_id' or nullptr if there isn't one.
267268
std::shared_ptr<WasmHandle> getThreadLocalWasm(string_view vm_id);
268269
// Get an existing ThreadLocal VM matching 'vm_id' or create one using 'base_wavm' by cloning or by

src/null/wasm_api_impl.h renamed to include/proxy-wasm/wasm_api_impl.h

-3
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ proxy_send_local_response(uint32_t response_code, const char *response_code_deta
7878
WR(additional_response_header_pairs_ptr), WS(additional_response_header_pairs_size),
7979
WS(grpc_status)));
8080
}
81-
inline WasmResult proxy_clear_route_cache() {
82-
return wordToWasmResult(exports::clear_route_cache(current_context_));
83-
}
8481

8582
// SharedData
8683
inline WasmResult proxy_get_shared_data(const char *key_ptr, size_t key_size,

include/proxy-wasm/wasm_vm.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ enum class Cloneable {
9999

100100
// Integrator specific WasmVm operations.
101101
struct WasmVmIntegration {
102-
virtual ~WasmVmIntegration();
102+
virtual ~WasmVmIntegration() {}
103103
virtual WasmVmIntegration *clone() = 0;
104104
virtual void error(string_view message) = 0;
105105
};

src/base64.cc

+7-6
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ const static char encodeLookup[] =
55
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
66
const static char padCharacter = '=';
77

8-
std::basic_string<char> base64Encode(std::vector<uint8_t> inputBuffer) {
9-
std::basic_string<char> encodedString;
10-
encodedString.reserve(((inputBuffer.size() / 3) + (inputBuffer.size() % 3 > 0)) * 4);
8+
std::string base64Encode(const uint8_t *start, const uint8_t *end) {
9+
std::string encodedString;
10+
size_t size = end - start;
11+
encodedString.reserve(((size / 3) + (size % 3 > 0)) * 4);
1112
uint32_t temp;
12-
std::vector<unsigned char>::iterator cursor = inputBuffer.begin();
13-
for (size_t idx = 0; idx < inputBuffer.size() / 3; idx++) {
13+
auto cursor = start;
14+
for (size_t idx = 0; idx < size / 3; idx++) {
1415
temp = (*cursor++) << 16; // Convert to big endian
1516
temp += (*cursor++) << 8;
1617
temp += (*cursor++);
@@ -19,7 +20,7 @@ std::basic_string<char> base64Encode(std::vector<uint8_t> inputBuffer) {
1920
encodedString.append(1, encodeLookup[(temp & 0x00000FC0) >> 6]);
2021
encodedString.append(1, encodeLookup[(temp & 0x0000003F)]);
2122
}
22-
switch (inputBuffer.size() % 3) {
23+
switch (size % 3) {
2324
case 1:
2425
temp = (*cursor++) << 16; // Convert to big endian
2526
encodedString.append(1, encodeLookup[(temp & 0x00FC0000) >> 18]);

src/base64.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
#include <string>
66
#include <vector>
77

8-
std::basic_string<char> base64Encode(std::vector<uint8_t> input);
9-
bool base64Decode(const std::basic_string<char> &input, std::vector<uint8_t> *output);
8+
std::string base64Encode(const uint8_t *start, const uint8_t *end);
9+
bool base64Decode(const std::string &input, std::vector<uint8_t> *output);

src/context.cc

+27
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,25 @@ std::string PluginBase::makeLogPrefix() const {
197197
return prefix;
198198
}
199199

200+
ContextBase::ContextBase() : root_context_(this) {}
201+
202+
ContextBase::ContextBase(WasmBase *wasm) : wasm_(wasm), root_context_(this) {
203+
wasm_->contexts_[id_] = this;
204+
}
205+
206+
ContextBase::ContextBase(WasmBase *wasm, std::shared_ptr<PluginBase> plugin) {
207+
initializeRoot(wasm, plugin);
208+
}
209+
210+
ContextBase::ContextBase(WasmBase *wasm, uint32_t root_context_id,
211+
std::shared_ptr<PluginBase> plugin)
212+
: wasm_(wasm), id_(wasm->allocContextId()), root_context_id_(root_context_id), plugin_(plugin) {
213+
wasm_->contexts_[id_] = this;
214+
root_context_ = wasm_->contexts_[root_context_id_];
215+
}
216+
217+
WasmVm *ContextBase::wasmVm() const { return wasm_->wasm_vm(); }
218+
200219
void ContextBase::initializeRoot(WasmBase *wasm, std::shared_ptr<PluginBase> plugin) {
201220
wasm_ = wasm;
202221
id_ = wasm->allocContextId();
@@ -249,6 +268,14 @@ bool ContextBase::onConfigure(std::shared_ptr<PluginBase> plugin) {
249268
plugin_.reset();
250269
return result;
251270
}
271+
272+
void ContextBase::onCreate(uint32_t parent_context_id) {
273+
if (wasm_->on_context_create_) {
274+
DeferAfterCallActions actions(this);
275+
wasm_->on_context_create_(this, id_, parent_context_id);
276+
}
277+
}
278+
252279
// Shared Data
253280
WasmResult ContextBase::getSharedData(string_view key, std::pair<std::string, uint32_t> *data) {
254281
return global_shared_data.get(wasm_->vm_id(), key, data);

src/exports.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
#include "include/proxy-wasm/wasm.h"
1717

1818
namespace proxy_wasm {
19-
namespace exports {
2019

2120
extern thread_local uint32_t effective_context_id_;
2221

22+
namespace exports {
23+
2324
// Any currently executing Wasm call context.
2425
#define WASM_CONTEXT(_c) \
2526
(ContextOrEffectiveContext(static_cast<ContextBase *>((void)_c, current_context_)))

0 commit comments

Comments
 (0)