Skip to content

Commit 2682cf1

Browse files
committed
Address review comments.
Signed-off-by: Michael Warres <[email protected]>
1 parent cda54bd commit 2682cf1

File tree

3 files changed

+25
-32
lines changed

3 files changed

+25
-32
lines changed

docs/api_overview.md

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ these to create and return instances of its own subclasses of `RootContext` and
5959

6060
```c++
6161
static RegisterContextFactory register_ExampleContext(
62-
CONTEXT_FACTORY(ExampleContext), ROOT_FACTORY(ExampleRootContext),
63-
"my_root_id");
62+
CONTEXT_FACTORY(ExampleContext), ROOT_FACTORY(ExampleRootContext));
6463
```
6564
6665
`ROOT_FACTORY` and `CONTEXT_FACTORY` are convenience macros for lambdas that
@@ -113,24 +112,36 @@ in the lifecycle of a stream:
113112
* `onCreate`: called when handling of a new stream starts.
114113
* `onDone`: called when the host is done processing the stream.
115114
* `onLog`: called after the host is done processing the stream, if the plugin is
116-
being used for access logging.
115+
being used for access logging (for example, in Envoy, as a
116+
[WasmAccessLog](https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/access_loggers/wasm/v3/wasm.proto#extensions-access-loggers-wasm-v3-wasmaccesslog)
117+
extension).
117118
* `onDelete`: called after the plugin has completed all processing related to
118119
the stream, as indication to release resources.
119120
120-
`Context` instances also receive callbacks corresponding to stream events:
121+
`Context` instances also receive callbacks corresponding to stream events. For
122+
HTTP or gRPC streams, these are:
121123
122124
* `onRequestHeaders`: called when HTTP or gRPC request headers are received.
123125
* `onRequestBody`: called when HTTP or gRPC request body data is received.
124126
* `onRequestTrailers`: called when HTTP or gRPC request trailers are received.
125127
* `onResponseHeaders`: called when HTTP or gRPC response headers are received.
126128
* `onResponseBody`: called when HTTP or gRPC response body data is received.
127129
* `onResponseTrailers`: called when HTTP or gRPC response trailers are received.
130+
131+
For TCP streams, `Context` instances may receive the following callbacks:
132+
128133
* `onNewConnection`: called when a new connection is established.
129134
* `onDownstreamData`: called when a new chunk of data is received from
130135
downstream over a connection.
131136
* `onUpstreamData`: called when a new chunk of data is received from upstream
132137
over a connection.
133138
139+
Callback methods return status enums that indicate whether and how the host
140+
should continue to process the stream. Status enum meanings are specified in the
141+
doc comments in [proxy_wasm_enums.h]. Callbacks can also generate an immediate
142+
local response to an HTTP or gRPC request using the `sendLocalResponse`
143+
hostcall.
144+
134145
For API details, see doc comments for the `Context` class in [proxy_wasm_api.h].
135146
136147
## Buffers
@@ -217,7 +228,7 @@ inspect data sent by the upstream client could override the
217228
`Context::onUpstreamData` method.
218229
219230
To access the actual data being proxied, plugin code would use the
220-
buffer-related hostcalls described in [Buffers], specifying
231+
buffer-related hostcalls described in [Buffers](#Buffers), specifying
221232
`NetworkUpstreamData` as the `WasmBufferType`.
222233
223234
## Timers
@@ -326,18 +337,8 @@ prepended to the log message:
326337
* `LOG_ERROR`
327338
* `LOG_CRITICAL`
328339
329-
Additionally, there is a LOG macro that accepts log level as a
330-
parameter. These macros layer on top of hostcall functions:
331-
332-
* `logTrace`
333-
* `logDebug`
334-
* `logInfo`
335-
* `logWarn`
336-
* `logError`
337-
* `logCritical`
338-
339-
All macros and hostcalls above allow plugin execution to continue. There
340-
is one further logging hostcall that terminates plugin execution:
340+
The macros above allow plugin execution to continue. There is also a logging
341+
hostcall that terminates plugin execution:
341342
342343
* `logAbort`: logs at Critical level, then aborts the plugin
343344

docs/building.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,4 @@ cp protobuf-wasm/src/.libs/libprotobuf-lite.a ${CPP_API}/libprotobuf-lite.a
225225
cp protobuf-wasm/src/.libs/libprotobuf.a ${CPP_API}/libprotobuf.a
226226
```
227227

228-
### WAVM binaries
229-
230-
```bash
231-
git clone [email protected]:WAVM/WAVM.git
232-
cd WAVM
233-
cmake "."
234-
make
235-
sudo make install
236-
```
237-
238228
Note: ensure /usr/local/bin is in your path.

proxy_wasm_api.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,18 +168,20 @@ template <typename Pairs> size_t pairsSize(const Pairs &result) {
168168
return size;
169169
}
170170

171-
// Marshals `result` to the memory buffer `buffer`.
172-
template <typename Pairs> void marshalPairs(const Pairs &result, char *buffer) {
171+
// Marshals `pairs` to the memory buffer `buffer`. `Pairs` is a map-like type
172+
// that provides a `size` method and iteration over elements that are
173+
// `std::pair`s of `std::string` or `std::string_view`s.
174+
template <typename Pairs> void marshalPairs(const Pairs &pairs, char *buffer) {
173175
char *b = buffer;
174-
*reinterpret_cast<uint32_t *>(b) = result.size();
176+
*reinterpret_cast<uint32_t *>(b) = pairs.size();
175177
b += sizeof(uint32_t);
176-
for (auto &p : result) {
178+
for (auto &p : pairs) {
177179
*reinterpret_cast<uint32_t *>(b) = p.first.size();
178180
b += sizeof(uint32_t);
179181
*reinterpret_cast<uint32_t *>(b) = p.second.size();
180182
b += sizeof(uint32_t);
181183
}
182-
for (auto &p : result) {
184+
for (auto &p : pairs) {
183185
memcpy(b, p.first.data(), p.first.size());
184186
b += p.first.size();
185187
*b++ = 0;

0 commit comments

Comments
 (0)