diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS deleted file mode 100644 index 8f8246b7..00000000 --- a/.github/CODEOWNERS +++ /dev/null @@ -1 +0,0 @@ -* @mathetake diff --git a/.github/ISSUE_TEMPLATE/bug-error-report.md b/.github/ISSUE_TEMPLATE/bug-error-report.md deleted file mode 100644 index 27e7f252..00000000 --- a/.github/ISSUE_TEMPLATE/bug-error-report.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -name: Bug / Error report -about: Create a report to help us improve -title: '' -labels: '' -assignees: '' - ---- - - - -## Describe the bug / error - -## What is your Envoy/Istio version? - -## What is the SDK version? - -## What is your TinyGo version? - -## URL or snippet of your code including Envoy configuration - -## Additional context (Optional) diff --git a/.github/workflows/push-wasm-images.yaml b/.github/workflows/push-wasm-images.yaml deleted file mode 100644 index 3f592d4e..00000000 --- a/.github/workflows/push-wasm-images.yaml +++ /dev/null @@ -1,41 +0,0 @@ -name: push-wasm-images -on: - push: - branches: - - main -env: - TINYGO_VERSION: 0.30.0 - -jobs: - build-and-push-wasm-images: - name: Build and push Wasm images - runs-on: ubuntu-latest - steps: - - name: install Go - uses: actions/setup-go@v3 - with: - go-version: '1.21' - - - name: Install TinyGo - run: | - wget https://github.com/tinygo-org/tinygo/releases/download/v${TINYGO_VERSION}/tinygo_${TINYGO_VERSION}_amd64.deb - sudo dpkg -i tinygo_${TINYGO_VERSION}_amd64.deb - - - name: Checkout - uses: actions/checkout@v3 - - - name: Build examples - run: make build.examples - - - name: Login to GitHub Container Registry - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GHCR_TOKEN }} - - - name: Build/Push Docker images - run: make wasm_image.build_push - - - name: Build/Push OCI images - run: make wasm_image.build_push_oci diff --git a/.github/workflows/workflow.yaml b/.github/workflows/workflow.yaml deleted file mode 100644 index a17f00d1..00000000 --- a/.github/workflows/workflow.yaml +++ /dev/null @@ -1,111 +0,0 @@ -name: Test -on: - pull_request: - branches: - - main - push: - branches: - - main - -env: - TINYGO_VERSION: 0.30.0 - -jobs: - style: - name: Code style check - runs-on: ubuntu-latest - steps: - - name: install Go - uses: actions/setup-go@v3 - with: - go-version: '1.21' - - - name: checkout - uses: actions/checkout@v3 - - - name: run lint - run: make lint - - - name: run format check - run: make check - - sdk-tests: - name: SDK tests - runs-on: ubuntu-latest - steps: - - name: install Go - uses: actions/setup-go@v3 - with: - go-version: '1.21' - - - name: checkout - uses: actions/checkout@v3 - - - name: run tests - run: make test - - examples: - name: Examples (${{ matrix.envoy-image }}) - strategy: - fail-fast: false - matrix: - envoy-image: [ - "envoyproxy/envoy-dev:latest", - "envoyproxy/envoy:v1.21-latest", - "envoyproxy/envoy:v1.22-latest", - "envoyproxy/envoy:v1.23-latest", - "envoyproxy/envoy:v1.24-latest", - "envoyproxy/envoy:v1.25-latest", - "envoyproxy/envoy:v1.26-latest", - "envoyproxy/envoy:v1.27-latest", - "envoyproxy/envoy:v1.28-latest", - "istio/proxyv2:1.16.0", - "istio/proxyv2:1.17.0", - "istio/proxyv2:1.18.0", - "istio/proxyv2:1.19.0", - "istio/proxyv2:1.20.0", - ] - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Build cache - uses: actions/cache@v3 - with: - path: | - ~/.cache/go-build - ~/.cache/tinygo - ~/go/pkg/mod - ~/go/bin - key: examples-${{ hashFiles('**/go.mod', '**/go.sum') }}-v${{ env.TINYGO_VERSION }} - - - name: Install Go - uses: actions/setup-go@v3 - with: - go-version: '1.21' - - - name: Install TinyGo - run: | - gh release download v${TINYGO_VERSION} -p '*.linux-amd64.tar.gz' -D ~ -R github.com/tinygo-org/tinygo - tar -xf ~/tinygo${TINYGO_VERSION}.linux-amd64.tar.gz -C $HOME - echo "$HOME/tinygo/bin" >> $GITHUB_PATH - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Build examples - run: make build.examples - - - name: Test examples - run: make test.examples - - - name: Install Envoy - run: | - export ENVOY_BIN_DIR=$HOME/envoy/bin - mkdir -p $ENVOY_BIN_DIR - docker run -v $ENVOY_BIN_DIR:/tmp/proxy-wasm-go-sdk -w /tmp/proxy-wasm-go-sdk \ - --entrypoint /bin/cp ${{ matrix.envoy-image }} /usr/local/bin/envoy . - echo $ENVOY_BIN_DIR >> $GITHUB_PATH - - - name: Run e2e test - run: make test.e2e diff --git a/Makefile b/Makefile index c8319c07..615e9550 100755 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -goimports := golang.org/x/tools/cmd/goimports@v0.7.0 -golangci_lint := github.com/golangci/golangci-lint/cmd/golangci-lint@v1.52.2 +goimports := golang.org/x/tools/cmd/goimports@v0.21.0 +golangci_lint := github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.0 .PHONY: build.example @@ -26,21 +26,16 @@ test.examples: | xargs -I {} bash -c 'dirname {}' \ | xargs -I {} bash -c 'cd {} && go test ./...' -.PHONY: test.e2e -test.e2e: - @go test -v ./e2e -count=1 - -.PHONY: test.e2e.single -test.e2e.single: - @go test -v ./e2e -run '/${name}' -count=1 - .PHONY: run run: @envoy -c ./examples/${name}/envoy.yaml --concurrency 2 --log-format '%v' .PHONY: lint lint: - @go run $(golangci_lint) run + @find . -name "go.mod" \ + | grep go.mod \ + | xargs -I {} bash -c 'dirname {}' \ + | xargs -I {} bash -c 'echo "=> {}"; cd {}; go run $(golangci_lint) run; ' .PHONY: format format: @@ -60,33 +55,6 @@ check: git diff --exit-code; \ fi -# Build docker images of *compat* variant of Wasm Image Specification with built example binaries, -# and push to ghcr.io/tetratelabs/proxy-wasm-go-sdk-examples. -# See https://github.com/solo-io/wasm/blob/master/spec/spec-compat.md for details. -# Only-used in github workflow on the main branch, and not for developers. -.PHONY: wasm_image.build_push -wasm_image.build_push: - @for f in `find ./examples -type f -name "main.go"`; do \ - name=`echo $$f | sed -e 's/\\//-/g' | sed -e 's/\.-examples-//g' -e 's/\-main\.go//g'` ; \ - ref=ghcr.io/tetratelabs/proxy-wasm-go-sdk-examples:$$name; \ - docker build -t $$ref . -f examples/wasm-image.Dockerfile --build-arg WASM_BINARY_PATH=$$(dirname $$f)/main.wasm; \ - docker push $$ref; \ - done - -# Build OCI images of *compat* variant of Wasm Image Specification with built example binaries, -# and push to ghcr.io/tetratelabs/proxy-wasm-go-sdk-examples. -# See https://github.com/solo-io/wasm/blob/master/spec/spec-compat.md for details. -# Only-used in github workflow on the main branch, and not for developers. -# Requires "buildah" CLI. -.PHONY: wasm_image.build_push_oci -wasm_image.build_push_oci: - @for f in `find ./examples -type f -name "main.go"`; do \ - name=`echo $$f | sed -e 's/\\//-/g' | sed -e 's/\.-examples-//g' -e 's/\-main\.go//g'` ; \ - ref=ghcr.io/tetratelabs/proxy-wasm-go-sdk-examples:$$name-oci; \ - buildah bud -f examples/wasm-image.Dockerfile --build-arg WASM_BINARY_PATH=$$(dirname $$f)/main.wasm -t $$ref .; \ - buildah push $$ref; \ - done - .PHONY: tidy tidy: ## Runs go mod tidy on every module @find . -name "go.mod" \ diff --git a/NOTICE b/NOTICE index 871b9ceb..ad469643 100644 --- a/NOTICE +++ b/NOTICE @@ -1,2 +1,2 @@ proxy-wasm-go-sdk -Copyright 2020-2021 Tetrate +Copyright 2020-2024 Tetrate diff --git a/README.md b/README.md index 957ab88f..81cc8600 100644 --- a/README.md +++ b/README.md @@ -1,75 +1 @@ -# WebAssembly for Proxies (Go SDK) [![Build](https://github.com/tetratelabs/proxy-wasm-go-sdk/workflows/Test/badge.svg)](https://github.com/tetratelabs/proxy-wasm-go-sdk/actions) [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE) - -The Go SDK for - [Proxy-Wasm](https://github.com/proxy-wasm/spec), enabling developers to write Proxy-Wasm plugins in Go. -This SDK is powered by [TinyGo](https://tinygo.org/) and does not support the official Go compiler. - -## Getting Started - -- [examples](examples) directory contains the example codes on top of this SDK. -- [OVERVIEW.md](doc/OVERVIEW.md) the overview of Proxy-Wasm, the API of this SDK, and the things you should know when writing plugins. - -## Requirements - -- [TinyGo](https://tinygo.org/) - This SDK depends on TinyGo and leverages its [WASI](https://github.com/WebAssembly/WASI) (WebAssembly System Interface) target. Please follow the official instruction [here](https://tinygo.org/getting-started/) for installing TinyGo. -- [Envoy](https://www.envoyproxy.io) - To run compiled examples, you need to have Envoy binary. We recommend using [func-e](https://func-e.io) as the easiest way to get started with Envoy. Alternatively, you can follow [the official instruction](https://www.envoyproxy.io/docs/envoy/latest/start/install). - - -## Dealing with memory issues - -TinyGo's default memory allocator (Garbage Collector) is known to have some issues when it's used in the high workload environment (e.g. [1](https://github.com/tetratelabs/proxy-wasm-go-sdk/issues/349),[2](https://github.com/tetratelabs/proxy-wasm-go-sdk/issues/375)). -There's an alternative GC called [nottinygc](https://github.com/wasilibs/nottinygc) which not only resolves the memory related issues, but -also improves the performance on production usage. - -The following images are an end user's observation on the perf of their Go SDK-compiled plugin on a high-workload environment. -This clearly indicates that nottinygc performs pretty well compared to the default setting of TinyGo. - -![img](https://user-images.githubusercontent.com/13513977/235026482-ff8dcc3b-a7dc-444d-a1af-8137c64e1d53.png) -![img](https://user-images.githubusercontent.com/13513977/235026493-97122fe3-9de0-4417-93a0-dd3a32bebce7.png) - -It can be enabled by adding a single line in your source code. Please refer to https://github.com/wasilibs/nottinygc for detail. - -## Installation - -``` -go get github.com/tetratelabs/proxy-wasm-go-sdk -``` - -## Build and run Examples - -```bash -# Build all examples. -make build.examples - -# Build a specific example. -make build.example name=helloworld - -# Run a specific example. -make run name=helloworld -``` - -## Compatible Envoy builds - -Envoy is the first host side implementation of Proxy-Wasm ABI, -and we run end-to-end tests with multiple versions of Envoy and Envoy-based [istio/proxy](https://github.com/istio/proxy) in order to verify Proxy-Wasm Go SDK works as expected. - -Please refer to [workflow.yaml](.github/workflows/workflow.yaml) for which version is used for End-to-End tests. - -## Build tags - -The following build tags can be used to customize the behavior of the built plugin: - -- `proxywasm_timing`: Enables logging of time spent in invocation of the plugin's exported functions. This can be useful for debugging performance issues. - -## Contributing - -We welcome contributions from the community! See [CONTRIBUTING.md](doc/CONTRIBUTING.md) for how to contribute to this repository. - -## External links - -- [WebAssembly for Proxies (ABI specification)](https://github.com/proxy-wasm/spec) -- [WebAssembly for Proxies (AssemblyScript SDK)](https://github.com/solo-io/proxy-runtime) -- [WebAssembly for Proxies (C++ SDK)](https://github.com/proxy-wasm/proxy-wasm-cpp-sdk) -- [WebAssembly for Proxies (Rust SDK)](https://github.com/proxy-wasm/proxy-wasm-rust-sdk) -- [WebAssembly for Proxies (Zig SDK)](https://github.com/mathetake/proxy-wasm-zig-sdk) -- [TinyGo - Go compiler for small places](https://tinygo.org/) +The work here has been revived and continued at https://github.com/proxy-wasm/proxy-wasm-go-sdk for GOOS=wasip1 support. diff --git a/doc/CONTRIBUTING.md b/doc/CONTRIBUTING.md deleted file mode 100644 index f0312818..00000000 --- a/doc/CONTRIBUTING.md +++ /dev/null @@ -1,36 +0,0 @@ -# Contributing - -We welcome contributions from the community. Please read the following guidelines carefully to maximize the chances of your PR being merged. - -## Coding Style - -The code is linted using a stringent golang-ci. To run this linter (and a few others) use run `make check`. To format your files, you can run `make format`. - -## Running tests - -``` -# Run local tests without running envoy processes. -make test - -# Run all e2e tests. -# This requires you to have Envoy binary locally. -make test.e2e - -# Run e2e tests for a specific example. -# This requires you to have Envoy binary locally. -make test.e2e.single name=helloworld -``` - -## Code Reviews - -* Indicate the priority of each comment, following this -[feedback ladder](https://www.netlify.com/blog/2020/03/05/feedback-ladders-how-we-encode-code-reviews-at-netlify/). -If none was indicated it will be treated as `[dust]`. -* A single approval is sufficient to merge, except when the change cuts -across several components; then it should be approved by at least one owner -of each component. If a reviewer asks for changes in a PR they should be -addressed before the PR is merged, even if another reviewer has already -approved the PR. -* During the review, address the comments and commit the changes _without_ squashing the commits. -This facilitates incremental reviews since the reviewer does not go through all the code again to -find out what has changed since the last review. diff --git a/doc/OVERVIEW.md b/doc/OVERVIEW.md deleted file mode 100644 index a40ea57e..00000000 --- a/doc/OVERVIEW.md +++ /dev/null @@ -1,484 +0,0 @@ -# Introduction - -Proxy-Wasm project's key objective is to bring the extensibility to network proxies with any programming language in a flexible way. - -This Proxy-Wasm Go SDK is the SDK for extending network proxies (e.g. Envoyproxy) on top of the [Proxy-Wasm ABI specification](https://github.com/proxy-wasm/spec) with Go programming language, and the Proxy-Wasm ABI defines the interface between network proxies and Wasm virtual machines running inside network proxies. - -With this SDK, everyone can produce Proxy-Wasm spec compatible Wasm binaries easily *without knowing Proxy-Wasm ABI specification* which is low-level and overwhelming to anyone who doesn't have the expertise in this field. Instead, developers rely on the Go API of this SDK to perform what they want to do to extend network proxies. - -This document explains the things you should know when writing programs with this SDK for your custom plugins. - -**Note that this document assumes that you are using Envoyproxy, and relies on its implementation detail**. Therefore some statement may not apply to other network proxies such as [mosn](https://github.com/mosn). - -# TinyGo vs the official Go compiler - -This SDK relies on the TinyGo, a compiler implementation of Go programming language specification. So first of all, we answer the question "Why not the official Go?". - -There are several reasons why we cannot use the official Go compiler. Tl;dr is that as of this writing, the official compiler cannot produce Wasm binary which can run outside web browsers, and therefore cannot produce Proxy-Wasm compatible binaries. - -For those who are insterested in the detail, please refer to the related issues in the Go repository: -- https://github.com/golang/go/issues/25612 -- https://github.com/golang/go/issues/31105 -- https://github.com/golang/go/issues/38248 - -# Wasm VM, Plugin and Envoy configuration - -## Terminology - -*Wasm virtual machine (Wasm VM)* or simply *VM* means instances of loaded programs. In Envoy, VMs are usually created in *each thread* and isolated from each other. Therefore, your program will be copied up to the number of threads created by Envoy, and loaded on each of these virtual machines. - -*Plugin* means the basic unit of your configuration for extending your network proxies. Proxy-Wasm specification allows for having **multiple plugins in a single VM**. In other words, a VM may be used by multiple plugins of network proxies. With this SDK, there are three types of plugins that you can configure in Envoy; *Http Filter*, *Network(Tcp) Filter*, and *Wasm Service*. Given that, you can write programs which can be run as, for example, Network Filter and Http Filter at the same time. - -*Http Filter* is a type of plugins to handle Http protocol such as operating on Http request headers, body, trailers, etc. It uses a VM in worker threads which handle traffic. - -*Network Filter* is a type of plugins to handle Tcp protocol such as operating on Tcp data frame, connection establishment, etc. It uses a VM in worker threads which handle traffic. - -*Wasm Service* is a type of plugins running in a singleton VM (i.e. only one instance exists in the Envoy main thread). It is mainly used for doing some extra work in parallel to Network or Http Filters such as aggregating metrics, logs, etc. Sometimes, such a singleton VM itself is also called *Wasm Service*. - - - -## Envoy configuration - -Among all the types of plugins, we share the configuration for Envoy something like - -```yaml -vm_config: - vm_id: "foo" - runtime: "envoy.wasm.runtime.v8" - configuration: - "@type": type.googleapis.com/google.protobuf.StringValue - value: '{"my-vm-env": "dev"}' - code: - local: - filename: "example.wasm" -configuration: - "@type": type.googleapis.com/google.protobuf.StringValue - value: '{"my-plugin-config": "bar"}' -``` - -where - -| Field | Description | -| --- | --- | -| `vm_config` | configures specific Wasm VM on which this plugin runs | -| `vm_config.vm_id` | used for semantic isolation towards Cross-VM communications. Please refer to [Cross-VM communications](#cross-vm-communications) section for detail.| -| `vm_config.runtime` | specifies the Wasm runtime type. Usually set to `envoy.wasm.runtime.v8`. | -| `vm_config.configuration` | arbitray configuration data used for setting up the VM. | -| `vm_config.code` | location of a Wasm binary | -| `configuration` | corresponds to each *Plugin* instance (which we call `PluginContext` explained below) inside the Wasm VM. | - -The important thing is that **giving exactly the same `vm_config` field for multiple plugins ends up sharing one Wasm VM among them**. -That means you can use a single Wasm VM for multiple Http filters, or maybe Http and Tcp filters per thread (See [example config](#sharing-one-vm-among-multiple-plugins-per-thread) for detail). This is useful in terms of memory/cpu resource efficiency, startup latency, etc. - -The full API definition is [here](https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/wasm/v3/wasm.proto#envoy-v3-api-msg-extensions-wasm-v3-pluginconfig) and this is what we call *plugin config* here and elsewhere. - -Now here's some example configurations in Envoy for each plugin type. Note that how your Wasm VM is created by Envoy depends on these types. - -### Http Filter - -If a plugin config is given at `envoy.filter.http.wasm`, you can run your program as *Http Filter* plugin so that it can operate on Http events. - -```yaml -http_filters: -- name: envoy.filters.http.wasm - typed_config: - "@type": type.googleapis.com/envoy.extensions.filters.http.wasm.v3.Wasm - config: - vm_config: { ... } - # ... plugin config follows -- name: envoy.filters.http.router -``` - -In this case, Wasm VMs are created on *each worker thread* in Envoy, and each VM is responsible for operating on each Http streams on a listener handled by a corresponding worker thread. Note that the way VMs and Plugins get created is exactly the same as [*Network Filter*](#network-filter), and the only difference is that *Plugins* only operate on Http streams rather than Tcp streams. - -See [example.yaml](../examples/http_headers/envoy.yaml) for a full example. - -### Network Filter - -If a plugin config is given at `envoy.filter.network.wasm`, you can run your program as *Network Filter* plugin so that it can operate on Tcp events. - -```yaml -filter_chains: -- filters: - - name: envoy.filters.network.wasm - typed_config: - "@type": type.googleapis.com/envoy.extensions.filters.network.wasm.v3.Wasm - config: - vm_config: { ... } - # ... plugin config follows - - name: envoy.tcp_proxy -``` - -In this case, Wasm VMs are created on *each worker thread* in Envoy, and each VM is responsible for operating on each Tcp streams on a listener handled by a corresponding worker thread. Note that the way VMs and Plugins get created is exactly the same as [*Http Filter*](#http-filter), and the only difference is that *Plugins* only operate on Tcp streams rather than Http streams. - -See [example.yaml](../examples/network/envoy.yaml) for a full example. - -### Wasm Service - -If a plugin config is given at `envoy.bootstrap.wasm`, you can run your program as *Wasm Service* plugin. - -```yaml -bootstrap_extensions: -- name: envoy.bootstrap.wasm - typed_config: - "@type": type.googleapis.com/envoy.extensions.wasm.v3.WasmService - singleton: true - config: - vm_config: { ... } - # ... plugin config follows -``` - -The top `singleton` field is normally set `true`. In this way, only one VM for this configuration exists across all the threads of Envoy process, and runs on the Envoy's main thread so that it won't block any worker threads. - -See [example.yaml](../examples/shared_queue/envoy.yaml) for a full example. - -### Sharing one VM among multiple plugins per thread - -As we explained, we can share one VM across multiple plugins. Here's an example yaml for such configuration: - -```yaml -static_resources: - listeners: - - name: http-header-operation - address: - socket_address: - address: 0.0.0.0 - port_value: 18000 - filter_chains: - - filters: - - name: envoy.http_connection_manager - typed_config: - # .... - http_filters: - - name: envoy.filters.http.wasm - typed_config: - "@type": type.googleapis.com/envoy.extensions.filters.http.wasm.v3.Wasm - config: - configuration: - "@type": type.googleapis.com/google.protobuf.StringValue - value: "http-header-operation" - vm_config: - vm_id: "my-vm-id" - runtime: "envoy.wasm.runtime.v8" - configuration: - "@type": type.googleapis.com/google.protobuf.StringValue - value: "my-vm-configuration" - code: - local: - filename: "all-in-one.wasm" - - name: envoy.filters.http.router - - - name: http-body-operation - address: - socket_address: - address: 0.0.0.0 - port_value: 18001 - filter_chains: - - filters: - - name: envoy.http_connection_manager - typed_config: - # .... - http_filters: - - name: envoy.filters.http.wasm - typed_config: - "@type": type.googleapis.com/envoy.extensions.filters.http.wasm.v3.Wasm - config: - configuration: - "@type": type.googleapis.com/google.protobuf.StringValue - value: "http-body-operation" - vm_config: - vm_id: "my-vm-id" - runtime: "envoy.wasm.runtime.v8" - configuration: - "@type": type.googleapis.com/google.protobuf.StringValue - value: "my-vm-configuration" - code: - local: - filename: "all-in-one.wasm" - - name: envoy.filters.http.router - - - name: tcp-total-data-size-counter - address: - socket_address: - address: 0.0.0.0 - port_value: 18002 - filter_chains: - - filters: - - name: envoy.filters.network.wasm - typed_config: - "@type": type.googleapis.com/envoy.extensions.filters.network.wasm.v3.Wasm - config: - configuration: - "@type": type.googleapis.com/google.protobuf.StringValue - value: "tcp-total-data-size-counter" - vm_config: - vm_id: "my-vm-id" - runtime: "envoy.wasm.runtime.v8" - configuration: - "@type": type.googleapis.com/google.protobuf.StringValue - value: "my-vm-configuration" - code: - local: - filename: "all-in-one.wasm" - - name: envoy.tcp_proxy - typed_config: # ... -``` - -You see that `vm_config` fields are all the same on Http filter chains on 18000 and 18001 listeners plus a Network filter chain on 18002. That means one Wasm VM is used by multiple plugins in Envoy per worker thread in this case. In other words, all of `vm_config.vm_id`, `vm_config.runtime` `vm_config.configuration`, and `vm_config.code` must be same in order to reuse the same VMs. - -As a result, **Three** [`PluginContext`](#contexts) will be created per Wasm VM and each of them corresponds to each of the above filter configurations (the top `configuration` fields at 18000, 18001, and 18002 respectively). - -See [example.yaml](../examples/shared_queue/envoy.yaml) for a full example. - -# Proxy-Wasm Go SDK API - -So far we have explaind the concepts and *plugin configs*. Now we are ready to dive into the API of this SDK. - -## *Contexts* - -*Contexts* are collection of interfaces in Proxy-Wasm Go SDK, and all of them are mapped to the concepts explained above. They are defined in [types](../proxywasm/types) package, and developers are supposed to implement these interfaces in order to extend network proxies. - -There are four types of contexts: `VMContext`, `PluginContext`, `TcpContext` and `HttpContext`. Their relationship and how they are mapped to the concepts above can be described as the following diagram: - -``` - Wasm Virtual Machine - (.vm_config.code) -┌────────────────────────────────────────────────────────────────┐ -│ Your program (.vm_config.code) TcpContext │ -│ │ ╱ (Tcp stream) │ -│ │ 1: 1 ╱ │ -│ │ 1: N ╱ 1: N │ -│ VMContext ────────── PluginContext │ -│ (Plugin) ╲ 1: N │ -│ ╲ │ -│ ╲ HttpContext │ -│ (Http stream) │ -└────────────────────────────────────────────────────────────────┘ -``` - -To summarize, - -1) `VMContext` corresponds to each `.vm_config.code`, and only one `VMContext` exists in each VM. -2) `VMContext` is the parent of *PluginContexts*, and is responsible for creating arbitrary number of `PluginContext`s. -3) `PluginContext` corresponds to a *Plugin* instance. That means, a `PluginContext` corresponds to a *Http Filter* or *Network Filter* or maybe *Wasm Service*, configured via `.configuration` field in the *plugin config*. -4) `PluginContext` is the parent of `TcpContext` and `HttpContext`, and is responsible for creating arbitrary number of these contexts when it is configured at *Http Filter* or *Network Filter*. -5) `TcpContext` is responsible for handling each Tcp stream. -6) `HttpContext` is responsible for handling each Http stream. - -So all you have to do is implement `VMContext` and `PluginContext`. And if you want to plug in to *Http Filter* or *Network Filter*, then implement `HttpContext` or `TcpContext` respectively. - -Let's look at some of these interfaces. First we see `VMContext` is defined as follows: - -```go -type VMContext interface { - // OnVMStart is called after the VM is created and main function is called. - // During this call, GetVMConfiguration hostcall is available and can be used to - // retrieve the configuration set at vm_config.configuration. - // This is mainly used for doing Wasm VM-wise initialization. - OnVMStart(vmConfigurationSize int) OnVMStartStatus - - // NewPluginContext is used for creating PluginContext for each plugin configurations. - NewPluginContext(contextID uint32) PluginContext -} -``` - -As you expect, `VMContext` is responsible for creating `PluginContext` via `NewPluginContext` method. In addition, `OnVMStart` is called at the startup phase of the VM, and you can retrieve the value of `.vm_config.configuration` via `GetVMConfiguration` [hostcall API](#hostcall-api). This way you can do the VM-wise plugin-independent initialization and control the behavior of `VMContext`. - -Next is `PluginContext` and it it defined as (here we omit some of the methods for simplicity) - -```go -type PluginContext interface { - // OnPluginStart is called on all plugin contexts (after OnVmStart if this is the VM context). - // During this call, GetPluginConfiguration is available and can be used to - // retrieve the configuration set at config.configuration in envoy.yaml - OnPluginStart(pluginConfigurationSize int) OnPluginStartStatus - - // The following functions are used for creating contexts on streams, - // and developers *must* implement either of them corresponding to - // extension points. For example, if you configure this plugin context is running - // at Http filters, then NewHttpContext must be implemented. Same goes for - // Tcp filters. - // - // NewTcpContext is used for creating TcpContext for each Tcp streams. - NewTcpContext(contextID uint32) TcpContext - // NewHttpContext is used for creating HttpContext for each Http streams. - NewHttpContext(contextID uint32) HttpContext -} -``` - -Just like `VMContext`, `PluginContext` has `OnPluginStart` method which is called on the plugin creation in network proxies. During that call, the top level `.configuratin` field's value in the *plugin config* can be retrieved via `GetPluginConfiguration` [hostcall API](#hostcall-api). This way developers can inform a `PluginContext` how it should behave, for example, specifying a `PluginContext` should behave as a Http Filter and which custom headers it should insert as a request headers, etc. - -Also note that `PluginContext` has `NewTcpContext` and `NewHttpContext` methods which are called when creating these contexts in response to each Http or Tcp streams in network proxies. - -The definition of `HttpContext` and `TcpContext` is fairly straightforward so please refer to [context.go](../proxywasm/types/context.go) for detail. - -## Hostcall API - -Hostcall API provides a variety of ways to interact with network proxies from your program, and it is defined at [hostcall.go](../proxywasm/hostcall.go) in [proxywasm](../proxywasm) package. For example, `GetHttpRequestHeaders` API can be used for accessing Http request headers by `HttpContext`. The other example is that `LogInfo` API and it can be used for emitting strings as logs in Envoy. - -Please refer to [hostcall.go](../proxywasm/hostcall.go) for all the available hostcalls, and the documentation is given at the function definitions. - -## Entrypoint - -When Envoy creates VMs, it calls `main` function of your program at startup phase before it tries to create `VMContext` inside VMs. Therefore you must pass your own implementation of `VMContext` in `main` function. - -[proxywasm](../proxywasm) package's `SetVMContext` function is the entrypoint used for that purpose. That being said, your `main` function should look like the following: - -```go -func main() { - proxywasm.SetVMContext(&myVMContext{}) -} - -type myVMContext struct { .... } - -var _ types.VMContext = &myVMContext{} - -// Implementations follow... -``` - -# Cross-VM communications - -Given that VMs are created in the thread-local way, sometimes we may want to communicate with other VMs. For example, aggregating data or stats, caching data, etc. - -There are two concepts for Cross-VM communications called *Shared Data* and *Shared Queue*. - -We also recommend you watch [this talk](https://www.youtube.com/watch?v=XdWmm_mtVXI&t=1168s) for introduction. - -## *Shared Data (Shared KVS)* - -What if you want to have global request counters across all the Wasm VMs running in multiple worker threads? Or what if you want to cache some data that should be used by all of your Wasm VMs? Then *Shared Data* or equivalently *Shared KVS* will come into play. - -*Shared Data* is basically a key-value store that is shared across all the VMs (i.e. cross-VM or cross-threads). A shared-data KVS is created per [`vm_id`](#envoy-configuration) specified in the `vm_config`. That means you can share a key-value store across all Wasm VMs not necessarily with the same binary (`vm_config.code`). The only requirement is having the same `vm_id`. - - - -In the diagram above, you see that VMs with "vm_id=foo" share the same shared data storage even though they have different binary (hello.wasm and bye.wasm). - -Here's the shared data related API of this Go SDK in [hostcall.go](../proxywasm/hostcall.go): - -```go -// GetSharedData is used for retrieving the value for given "key". -// Returned "cas" is be used for SetSharedData on that key for -// thread-safe updates. -func GetSharedData(key string) (value []byte, cas uint32, err error) - -// SetSharedData is used for setting key-value pairs in the shared data storage -// which is defined per "vm_config.vm_id" in the hosts. -// -// ErrorStatusCasMismatch will be returned when a given CAS value is mismatched -// with the current value. That indicates that other Wasm VMs has already succeeded -// to set a value on the same key and the current CAS for the key is incremented. -// Having retry logic in the face of this error is recommended. -// -// Setting cas = 0 will never return ErrorStatusCasMismatch and always succeed, but -// it is not thread-safe, i.e. maybe another VM has already set the value -// and the value you see is already different from the one stored by the time -// when you call this function. -func SetSharedData(key string, value []byte, cas uint32) error -``` - - -The API is straightforward, but the important part is its thread-safety and cross-VM-safety with "cas" or [Compare-And-Swap](https://en.wikipedia.org/wiki/Compare-and-swap) value. - -Please refer to [an example](../examples/shared_data) for demonstration. - -## *Shared Queue* - -What if you want to aggregate metrics across all the Wasm VMs in parallel to request/response processing? Or what if you want to push some cross-VM aggregated information to a remote server? Now *Shared Queue* is here for you. - -*Shared Queue* is a FIFO(First-In-First-Out) queue created for a pair of `vm_id` and the name of the queue. And a *queue id* is assigned uniquely to the pair (vm_id, name) which is used for enqueue/dequeue operations. - -As you expect, the operations such as "enqueue" and "dequeue" have thread-safety and cross-VM-safety. Let's look at the *Shared Queue* related API in [hostcall.go](../proxywasm/hostcall.go): - -```golang -// DequeueSharedQueue dequeues an data from the shared queue of the given queueID. -// In order to get queue id for a target queue, use "ResolveSharedQueue" first. -func DequeueSharedQueue(queueID uint32) ([]byte, error) - -// RegisterSharedQueue registers the shared queue on this plugin context. -// "Register" means that OnQueueReady is called for this plugin context whenever a new item is enqueued on that queueID. -// Only available for types.PluginContext. The returned queueID can be used for Enqueue/DequeueSharedQueue. -// Note that "name" must be unique across all Wasm VMs which share a same "vm_id". -// That means you can use "vm_id" can be used for separating shared queue namespace. -// -// Only after RegisterSharedQueue is called, ResolveSharedQueue("this vm_id", "name") succeeds -// to retrive queueID by other VMs. -func RegisterSharedQueue(name string) (queueID uint32, err error) - -// EnqueueSharedQueue enqueues an data to the shared queue of the given queueID. -// In order to get queue id for a target queue, use "ResolveSharedQueue" first. -func EnqueueSharedQueue(queueID uint32, data []byte) error - -// ResolveSharedQueue acquires the queueID for the given vm_id and queue name. -// The returned queueID can be used for Enqueue/DequeueSharedQueue. -func ResolveSharedQueue(vmID, queueName string) (queueID uint32, err error) -``` - -Basically `RegisterSharedQueue` and `DequeueSharedQueue` are used by "consumer" of the queue -while `ResolveSharedQueue` and `EnqueueSharedQueue` are for "producer" of queue items. Note that - -- `RegisterSharedQueue` is used for creating a shared queue for `name` and `vm_id` of the caller. That means if you want to use a queue, then this must be called by a VM beforehand. This can be called by `PluginContext`, and therefore we can think of "comsumers" = `PluginContext`s. -- `ResolveSharedQueue` is used for getting the *queue id* for `name` and `vm_id`. Usually this is used by VMs that doesn't call `ResolveSharedQueue` but rather are supposed to enqueue items. This is for "producer". - -and both of these calls return a queue id, and it is used for `DequeueSharedQueue` and `EnqueueSharedQueue`. - -However, from the consumer's point of view, how can a consumer (= `PluginContext`) be notified when a queue is enqueued with an item? This is why we have the `OnQueueReady(queueID uint32)` interface in `PluginContext`. This method is called whenever an item is enqueued in a queue registered by that `PluginContext`. - -Also it is highly recommended that shared queues should be created by a singleton *Wasm Service*, i.e. on the Envoy's main thread. Otherwise `OnQueueReady` is called on worker threads which blocks their processing of Http or Tcp streams. - -The following diagram is an illustrative usage of shared queues: - - - -`my-singleton.wasm` is loaded as a singleton VM with `vm_id=foo` where two *Wasm Service* are created which correspond to `PluginContext 1` and `PluginContext 2` in the VM. Each of these plugin contexts calls `RegisterQueue` with "http" and "tcp" names, and that results in creating two corresponding queues. On the other hand, in the worker threads, two types of Wasm VMs are created per thread. They are processing Tcp streams and Http streams, and enqueue some data into the corresponding queues respectively. As we explained above, enqueueing data into a queue ends up calling the `OnQueueReady` method of a `PluginContext` which called `RegisterQueue` for that queue. In this example, enqueueing data into the queue with queue id=2 invokes `OnQueueReady(2)` of `PluginContext 2` in the singleton VM. - -Please refer to [an example](../examples/shared_queue) for demonstration. - -# Unit tests with testing framework - -This SDK contains the testing framework for unit testing Proxy-Wasm programs without actually running network proxies and with the official Go test toolchain. [proxytest](../proxywasm/proxytest) package implements the Envoy proxy emulator. That is, you can run tests just like you do when writing native programs: - -``` -go test ./... -``` - -Please refer to `main_test.go` files under [examples](../examples) directory for demonstrations. - -# Limitations and Considerations - -Here's what users should know when writing plugins with Proxy-Wasm Go SDK and Proxy-Wasm in general. - -## Some of existing libraries not available - -Some of existing libraries are not available (importable but runtime panic / non-importable). There are several reasons for this: -1. TinyGo's WASI target does not support some of syscall. -2. TinyGo does not implement all of reflect package. -3. [Proxy-Wasm C++ host](https://github.com/proxy-wasm/proxy-wasm-cpp-host) has not supported some of WASI APIs yet -4. Some language features are not available in TinyGo or Proxy-Wasm: examples include `recover` and `goroutine`. - -These issues will be mitigated as TinyGo and Proxy-Wasm evolve. - -## Performance overhead due to Garbage Collection - -There's performance overhead of using Go/TinyGo due to GC, although, optimistically speaking, we could say that the overhead of GC is small enough compared to the other operations in the proxy. - -Internally, `runtime.GC` is called whenever the heap runs out (see -[1](https://tinygo.org/lang-support/#garbage-collection), -[2](https://github.com/tinygo-org/tinygo/blob/v0.14.1/src/runtime/gc_conservative.go#L218-L239)) in TinyGo. - -TinyGo allows us to disable GC, but we cannot do that since internally we need to use maps (implicitly causes allocation) for saving the Virtual Machine's state. Theoretically, we can implement our own GC algorithms tailored for proxy-wasm through `alloc(uintptr)` [interface](https://github.com/tinygo-org/tinygo/blob/v0.14.1/src/runtime/gc_none.go#L13) with `-gc=none` option. This is a future TODO. - -## `recover` not implemented - -`recover` is not implemented (https://github.com/tinygo-org/tinygo/issues/891) in TinyGo, and there's no way to prevent the Wasm virtual machine from aborting. Also that means that codes rely on `recover` won't work as expected. - -## Goroutine support - -In TinyGo, Goroutine is implemented through LLVM's coroutine (see [this blog post](https://aykevl.nl/2019/02/tinygo-goroutines)). - -In Envoy, Wasm modules are run in the event driven manner, and therefore the "scheduler" is not executed once the main function exits. -That means you cannot have the expected behavior of Goroutine as in ordinary host environments. - -The question "How to deal with Goroutine in a thread local Wasm VM executed in the event drive manner" has yet to be answered. - -We strongly recommend that you implement the `OnTick` function for any asynchronous task instead of using Goroutine. diff --git a/doc/images/shared_data.png b/doc/images/shared_data.png deleted file mode 100644 index 8ee9b6b8..00000000 Binary files a/doc/images/shared_data.png and /dev/null differ diff --git a/doc/images/shared_queue.png b/doc/images/shared_queue.png deleted file mode 100644 index 48b6d8c6..00000000 Binary files a/doc/images/shared_queue.png and /dev/null differ diff --git a/doc/images/terminology.png b/doc/images/terminology.png deleted file mode 100644 index 592d8cc0..00000000 Binary files a/doc/images/terminology.png and /dev/null differ diff --git a/e2e/e2e_test.go b/e2e/e2e_test.go deleted file mode 100644 index 16904f78..00000000 --- a/e2e/e2e_test.go +++ /dev/null @@ -1,427 +0,0 @@ -// Copyright 2020-2021 Tetrate -// -// 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. - -package e2e - -import ( - "bytes" - "fmt" - "io" - "net/http" - "strings" - "testing" - "time" - - "github.com/stretchr/testify/require" -) - -func Test_dispatch_call_on_tick(t *testing.T) { - stdErr, kill := startEnvoy(t, 8001) - defer kill() - var count int = 1 - require.Eventually(t, func() bool { - if checkMessage(stdErr.String(), []string{ - fmt.Sprintf("called %d for contextID=1", count), - fmt.Sprintf("called %d for contextID=2", count), - ":status: 200", ":status: 503", - }) { - count++ - } - return count == 6 - }, 5*time.Second, 10*time.Millisecond, stdErr.String()) -} - -func Test_foreign_call_on_tick(t *testing.T) { - stdErr, kill := startEnvoy(t, 8001) - defer kill() - var count int = 1 - require.Eventually(t, func() bool { - if strings.Contains(stdErr.String(), fmt.Sprintf("foreign function (compress) called: %d", count)) { - count++ - } - return count == 6 - }, 5*time.Second, 10*time.Millisecond, stdErr.String()) -} - -func Test_helloworld(t *testing.T) { - stdErr, kill := startEnvoy(t, 8001) - defer kill() - require.Eventually(t, func() bool { - return checkMessage(stdErr.String(), []string{ - "OnPluginStart from Go!", - "It's", - }) - }, 10*time.Second, 100*time.Millisecond, stdErr.String()) -} - -func Test_http_auth_random(t *testing.T) { - stdErr, kill := startEnvoy(t, 8001) - defer kill() - key := "this-is-key" - value := "this-is-value" - req, err := http.NewRequest("GET", "http://localhost:18000/uuid", nil) - require.NoError(t, err) - req.Header.Add(key, value) - require.Eventually(t, func() bool { - res, err := http.DefaultClient.Do(req) - if err != nil { - return false - } - defer res.Body.Close() - return checkMessage(stdErr.String(), []string{ - "access forbidden", - "access granted", - "response header from httpbin: :status: 200", - }) - }, 10*time.Second, 100*time.Millisecond, stdErr.String()) -} - -func Test_http_body(t *testing.T) { - stdErr, kill := startEnvoy(t, 8001) - defer kill() - - for _, mode := range []string{ - "request", - "response", - } { - t.Run(mode, func(t *testing.T) { - for _, tc := range []struct { - op, expBody string - }{ - {op: "append", expBody: `[original body][this is appended body]`}, - {op: "prepend", expBody: `[this is prepended body][original body]`}, - {op: "replace", expBody: `[this is replaced body]`}, - // Should fall back to to the replace. - {op: "invalid", expBody: `[this is replaced body]`}, - } { - tc := tc - t.Run(tc.op, func(t *testing.T) { - require.Eventually(t, func() bool { - req, err := http.NewRequest("PUT", "http://localhost:18000/anything", - bytes.NewBuffer([]byte(`[original body]`))) - require.NoError(t, err) - req.Header.Add("buffer-replace-at", mode) - req.Header.Add("buffer-operation", tc.op) - res, err := http.DefaultClient.Do(req) - if err != nil { - return false - } - defer res.Body.Close() - body, err := io.ReadAll(res.Body) - require.NoError(t, err) - return tc.expBody == string(body) && checkMessage(stdErr.String(), []string{ - fmt.Sprintf(`original %s body: [original body]`, mode)}, - ) - }, 5*time.Second, 500*time.Millisecond) - }) - } - }) - } -} - -func Test_http_headers(t *testing.T) { - stdErr, kill := startEnvoy(t, 8001) - defer kill() - req, err := http.NewRequest("GET", "http://localhost:18000/uuid", nil) - require.NoError(t, err) - key := "this-is-key" - value := "this-is-value" - req.Header.Add(key, value) - require.Eventually(t, func() bool { - res, err := http.DefaultClient.Do(req) - if err != nil { - return false - } - defer res.Body.Close() - require.Equal(t, res.Header.Get("x-wasm-header"), "demo-wasm") - require.Equal(t, res.Header.Get("x-proxy-wasm-go-sdk-example"), "http_headers") - return checkMessage(stdErr.String(), []string{ - key, value, "server: envoy", "x-wasm-header", "x-proxy-wasm-go-sdk-example", - }) - }, 10*time.Second, 100*time.Millisecond, stdErr.String()) -} - -func Test_http_routing(t *testing.T) { - stdErr, kill := startEnvoy(t, 8001) - defer kill() - var primary, canary bool - require.Eventually(t, func() bool { - res, err := http.Get("http://localhost:18000") - if err != nil { - return false - } - raw, err := io.ReadAll(res.Body) - require.NoError(t, err) - defer res.Body.Close() - body := string(raw) - if strings.Contains(body, "canary") { - canary = true - } - if strings.Contains(body, "primary") { - primary = true - } - return primary && canary - }, 10*time.Second, 100*time.Millisecond, stdErr.String()) -} - -func Test_metrics(t *testing.T) { - _, kill := startEnvoy(t, 8001) - defer kill() - - const customHeaderKey = "my-custom-header" - customHeaderToExpectedCounts := map[string]int{ - "foo": 3, - "bar": 5, - } - for headerValue, expCount := range customHeaderToExpectedCounts { - var actualCount int - require.Eventually(t, func() bool { - req, err := http.NewRequest("GET", "http://localhost:18000", nil) - require.NoError(t, err) - req.Header.Add(customHeaderKey, headerValue) - res, err := http.DefaultClient.Do(req) - if err != nil { - return false - } - defer res.Body.Close() - if res.StatusCode != http.StatusOK { - return false - } - actualCount++ - return actualCount == expCount - }, 10*time.Second, 100*time.Millisecond, "Endpoint not healthy.") - } - - for headerValue, expCount := range customHeaderToExpectedCounts { - expectedMetric := fmt.Sprintf("custom_header_value_counts{value=\"%s\",reporter=\"wasmgosdk\"} %d", headerValue, expCount) - require.Eventually(t, func() bool { - res, err := http.Get("http://localhost:8001/stats/prometheus") - if err != nil { - return false - } - defer res.Body.Close() - raw, err := io.ReadAll(res.Body) - require.NoError(t, err) - return checkMessage(string(raw), []string{expectedMetric}) - }, 10*time.Second, 100*time.Millisecond, "Expected stats not found") - } -} - -func Test_network(t *testing.T) { - stdErr, kill := startEnvoy(t, 8001) - defer kill() - key := "This-Is-Key" - value := "this-is-value" - req, err := http.NewRequest("GET", "http://localhost:18000", nil) - require.NoError(t, err) - req.Header.Add(key, value) - req.Header.Add("Connection", "close") - require.Eventually(t, func() bool { - res, err := http.DefaultClient.Do(req) - if err != nil { - return false - } - defer res.Body.Close() - return checkMessage(stdErr.String(), []string{ - key, value, - "downstream data received", - "new connection!", - "downstream connection close!", - "upstream data received", - "connection complete!", - "remote address: 127.0.0.1:", - "upstream cluster metadata location[region]=ap-northeast-1", - "upstream cluster metadata location[cloud_provider]=aws", - "upstream cluster metadata location[az]=ap-northeast-1a", - }) - }, 10*time.Second, 100*time.Millisecond, stdErr.String()) -} - -func Test_postpone_requests(t *testing.T) { - stdErr, kill := startEnvoy(t, 8001) - defer kill() - require.Eventually(t, func() bool { - res, err := http.Get("http://localhost:18000") - if err != nil { - return false - } - defer res.Body.Close() - return checkMessage(stdErr.String(), []string{ - "postpone request with contextID=2", - "resume request with contextID=2", - }) - }, 6*time.Second, time.Millisecond, stdErr.String()) -} - -func Test_properties(t *testing.T) { - stdErr, kill := startEnvoy(t, 8001) - defer kill() - require.Eventually(t, func() bool { - baseUrl := "http://localhost:18000" - for _, tt := range []struct { - pathname string - authHeader [2]string - status int - }{ - {"/one", [2]string{}, http.StatusUnauthorized}, - {"/one", [2]string{"cookie", "value"}, http.StatusOK}, - {"/two", [2]string{}, http.StatusUnauthorized}, - {"/two", [2]string{"authorization", "token"}, http.StatusOK}, - {"/three", [2]string{}, http.StatusOK}, - } { - req, err := http.NewRequest("GET", baseUrl+tt.pathname, nil) - require.NoError(t, err) - if tt.authHeader[0] != "" && tt.authHeader[1] != "" { - req.Header.Add(tt.authHeader[0], tt.authHeader[1]) - } - res, err := http.DefaultClient.Do(req) - if err != nil { - return false - } - defer res.Body.Close() - - if res.StatusCode != tt.status { - return false - } - } - - return checkMessage(stdErr.String(), []string{ - "auth header is \"cookie\"", - "auth header is \"authorization\"", - "no auth header for route", - }) - }, 10*time.Second, 100*time.Millisecond, stdErr.String()) -} - -func Test_shared_data(t *testing.T) { - stdErr, kill := startEnvoy(t, 8001) - defer kill() - var count int - require.Eventually(t, func() bool { - res, err := http.Get("http://localhost:18000") - if err != nil { - return false - } - defer res.Body.Close() - if res.StatusCode != http.StatusOK { - return false - } - count++ - return count == 10 - }, 10*time.Second, 100*time.Millisecond, "Endpoint not healthy.") - require.Eventually(t, func() bool { - return checkMessage(stdErr.String(), []string{fmt.Sprintf("shared value: %d", count)}) - }, 10*time.Second, 100*time.Millisecond, stdErr.String()) - fmt.Println(stdErr.String()) -} - -func Test_shared_queue(t *testing.T) { - stdErr, kill := startEnvoy(t, 8001) - defer kill() - require.Eventually(t, func() bool { - res, err := http.Get("http://localhost:18000") - if err != nil || res.StatusCode != http.StatusOK { - return false - } - defer res.Body.Close() - - res, err = http.Get("http://localhost:18001") - if err != nil { - return false - } - defer res.Body.Close() - return res.StatusCode == http.StatusOK - }, 10*time.Second, 100*time.Millisecond, "Endpoint not healthy.") - require.Eventually(t, func() bool { - return checkMessage(stdErr.String(), []string{ - `enqueued data: {"key": ":method","value": "GET"}`, - `dequeued data from http_request_headers`, - `dequeued data from http_response_headers`, - `dequeued data from tcp_data_hashes`, - }) - }, 10*time.Second, 100*time.Millisecond, stdErr.String()) -} - -func Test_vm_plugin_configuration(t *testing.T) { - stdErr, kill := startEnvoy(t, 8001) - defer kill() - require.Eventually(t, func() bool { - return checkMessage(stdErr.String(), []string{ - "name\": \"vm configuration", "name\": \"plugin configuration", - }) - }, 10*time.Second, 100*time.Millisecond, stdErr.String()) -} - -func Test_json_validation(t *testing.T) { - stdErr, kill := startEnvoy(t, 8001) - defer kill() - - require.Eventually(t, func() bool { - req, _ := http.NewRequest("GET", "http://localhost:18000", nil) - res, err := http.DefaultClient.Do(req) - if err != nil { - return false - } - defer res.Body.Close() - - _, err = io.Copy(io.Discard, res.Body) - require.NoError(t, err) - require.Equal(t, http.StatusForbidden, res.StatusCode) - - jsonBody := `{"id": "abc123", "token": "xyz456"}` - - req, _ = http.NewRequest("POST", "http://localhost:18000", strings.NewReader(jsonBody)) - req.Header.Add("Content-Type", "application/json") - res, err = http.DefaultClient.Do(req) - if err != nil { - return false - } - defer res.Body.Close() - - _, err = io.Copy(io.Discard, res.Body) - require.NoError(t, err) - require.Equal(t, http.StatusOK, res.StatusCode) - - return true - }, 10*time.Second, 100*time.Millisecond, stdErr.String()) -} - -func Test_multiple_dispatches(t *testing.T) { - stdErr, kill := startEnvoy(t, 8001) - defer kill() - - require.Eventually(t, func() bool { - res, err := http.Get("http://localhost:18000") - if err != nil || res.StatusCode != http.StatusOK { - return false - } - defer res.Body.Close() - return res.StatusCode == http.StatusOK - }, 10*time.Second, 100*time.Millisecond, "Endpoint not healthy.") - - require.Eventually(t, func() bool { - return checkMessage(stdErr.String(), []string{ - "wasm log: pending dispatched requests: 9", - "wasm log: pending dispatched requests: 8", - "wasm log: pending dispatched requests: 7", - "wasm log: pending dispatched requests: 6", - "wasm log: pending dispatched requests: 5", - "wasm log: pending dispatched requests: 4", - "wasm log: pending dispatched requests: 3", - "wasm log: pending dispatched requests: 2", - "wasm log: pending dispatched requests: 1", - "wasm log: response resumed after processed 10 dispatched request", - }) - }, 10*time.Second, 100*time.Millisecond, stdErr.String()) -} diff --git a/e2e/main_test.go b/e2e/main_test.go deleted file mode 100644 index 7f4ac7a2..00000000 --- a/e2e/main_test.go +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2021 Tetrate -// -// 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. - -package e2e - -import ( - "bytes" - "fmt" - "log" - "net/http" - "os" - "os/exec" - "strconv" - "strings" - "testing" - "time" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -func TestMain(m *testing.M) { - if err := os.Chdir(".."); err != nil { - log.Fatal(err) - } - os.Exit(m.Run()) -} - -func checkMessage(str string, exps []string) bool { - for _, exp := range exps { - if !strings.Contains(str, exp) { - return false - } - } - return true -} - -func startEnvoy(t *testing.T, adminPort int) (stdErr *bytes.Buffer, kill func()) { - name := strings.TrimPrefix(t.Name(), "Test_") - cmd := exec.Command("envoy", - "--base-id", strconv.Itoa(adminPort), - "--concurrency", "1", "--component-log-level", "wasm:trace", - "-c", fmt.Sprintf("./examples/%s/envoy.yaml", name)) - - buf := new(bytes.Buffer) - cmd.Stderr = buf - require.NoError(t, cmd.Start()) - if !assert.Eventually(t, func() bool { - res, err := http.Get(fmt.Sprintf("http://localhost:%d/listeners", adminPort)) - if err != nil { - return false - } - defer res.Body.Close() - return res.StatusCode == http.StatusOK - }, 5*time.Second, 100*time.Millisecond, "Envoy has not started") { - t.Fatalf("Envoy stderr: %s", buf.String()) - } - return buf, func() { require.NoError(t, cmd.Process.Kill()) } -} diff --git a/examples/dispatch_call_on_tick/go.mod b/examples/dispatch_call_on_tick/go.mod index cbdf1145..5c834680 100644 --- a/examples/dispatch_call_on_tick/go.mod +++ b/examples/dispatch_call_on_tick/go.mod @@ -5,13 +5,13 @@ go 1.19 replace github.com/tetratelabs/proxy-wasm-go-sdk => ../.. require ( - github.com/stretchr/testify v1.8.4 + github.com/stretchr/testify v1.9.0 github.com/tetratelabs/proxy-wasm-go-sdk v0.0.0-00010101000000-000000000000 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/tetratelabs/wazero v1.6.0 // indirect + github.com/tetratelabs/wazero v1.7.2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/examples/dispatch_call_on_tick/go.sum b/examples/dispatch_call_on_tick/go.sum index 4d3e3fe2..f343b943 100644 --- a/examples/dispatch_call_on_tick/go.sum +++ b/examples/dispatch_call_on_tick/go.sum @@ -2,10 +2,10 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/tetratelabs/wazero v1.6.0 h1:z0H1iikCdP8t+q341xqepY4EWvHEw8Es7tlqiVzlP3g= -github.com/tetratelabs/wazero v1.6.0/go.mod h1:0U0G41+ochRKoPKCJlh0jMg1CHkyfK8kDqiirMmKY8A= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/tetratelabs/wazero v1.7.2 h1:1+z5nXJNwMLPAWaTePFi49SSTL0IMx/i3Fg8Yc25GDc= +github.com/tetratelabs/wazero v1.7.2/go.mod h1:ytl6Zuh20R/eROuyDaGPkp82O9C/DJfXAwJfQ3X6/7Y= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/examples/dispatch_call_on_tick/main.go b/examples/dispatch_call_on_tick/main.go index 685a2609..3bb03100 100644 --- a/examples/dispatch_call_on_tick/main.go +++ b/examples/dispatch_call_on_tick/main.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -27,17 +27,19 @@ func main() { proxywasm.SetVMContext(&vmContext{}) } +// vmContext implements types.VMContext. type vmContext struct { // Embed the default VM context here, // so that we don't need to reimplement all the methods. types.DefaultVMContext } -// Override types.DefaultVMContext. +// NewPluginContext implements types.VMContext. func (*vmContext) NewPluginContext(contextID uint32) types.PluginContext { return &pluginContext{contextID: contextID} } +// pluginContext implements types.PluginContext. type pluginContext struct { // Embed the default plugin context here, // so that we don't need to reimplement all the methods. @@ -47,7 +49,7 @@ type pluginContext struct { cnt int } -// Override types.DefaultPluginContext. +// OnPluginStart implements types.PluginContext. func (ctx *pluginContext) OnPluginStart(pluginConfigurationSize int) types.OnPluginStartStatus { if err := proxywasm.SetTickPeriodMilliSeconds(tickMilliseconds); err != nil { proxywasm.LogCriticalf("failed to set tick period: %v", err) @@ -75,7 +77,7 @@ func (ctx *pluginContext) OnPluginStart(pluginConfigurationSize int) types.OnPlu return types.OnPluginStartStatusOK } -// Override types.DefaultPluginContext. +// OnTick implements types.PluginContext. func (ctx *pluginContext) OnTick() { headers := [][2]string{ {":method", "GET"}, {":authority", "some_authority"}, {"accept", "*/*"}, diff --git a/examples/foreign_call_on_tick/go.mod b/examples/foreign_call_on_tick/go.mod index 11d8f3c3..f4daee71 100644 --- a/examples/foreign_call_on_tick/go.mod +++ b/examples/foreign_call_on_tick/go.mod @@ -5,13 +5,13 @@ go 1.19 replace github.com/tetratelabs/proxy-wasm-go-sdk => ../.. require ( - github.com/stretchr/testify v1.8.4 + github.com/stretchr/testify v1.9.0 github.com/tetratelabs/proxy-wasm-go-sdk v0.0.0-00010101000000-000000000000 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/tetratelabs/wazero v1.6.0 // indirect + github.com/tetratelabs/wazero v1.7.2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/examples/foreign_call_on_tick/go.sum b/examples/foreign_call_on_tick/go.sum index 4d3e3fe2..f343b943 100644 --- a/examples/foreign_call_on_tick/go.sum +++ b/examples/foreign_call_on_tick/go.sum @@ -2,10 +2,10 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/tetratelabs/wazero v1.6.0 h1:z0H1iikCdP8t+q341xqepY4EWvHEw8Es7tlqiVzlP3g= -github.com/tetratelabs/wazero v1.6.0/go.mod h1:0U0G41+ochRKoPKCJlh0jMg1CHkyfK8kDqiirMmKY8A= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/tetratelabs/wazero v1.7.2 h1:1+z5nXJNwMLPAWaTePFi49SSTL0IMx/i3Fg8Yc25GDc= +github.com/tetratelabs/wazero v1.7.2/go.mod h1:ytl6Zuh20R/eROuyDaGPkp82O9C/DJfXAwJfQ3X6/7Y= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/examples/foreign_call_on_tick/main.go b/examples/foreign_call_on_tick/main.go index 72f6702c..cc757f8f 100644 --- a/examples/foreign_call_on_tick/main.go +++ b/examples/foreign_call_on_tick/main.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -27,26 +27,27 @@ func main() { proxywasm.SetVMContext(&vmContext{}) } +// vmContext implements types.VMContext. type vmContext struct { // Embed the default VM context here, // so that we don't need to reimplement all the methods. types.DefaultVMContext } -// Override types.DefaultVMContext. +// NewPluginContext implements types.VMContext. func (*vmContext) NewPluginContext(contextID uint32) types.PluginContext { return &pluginContext{} } +// pluginContext implements types.PluginContext. type pluginContext struct { // Embed the default plugin context here, // so that we don't need to reimplement all the methods. types.DefaultPluginContext - contextID uint32 - callNum uint32 + callNum uint32 } -// Override types.DefaultPluginContext. +// OnPluginStart implements types.PluginContext. func (ctx *pluginContext) OnPluginStart(pluginConfigurationSize int) types.OnPluginStartStatus { if err := proxywasm.SetTickPeriodMilliSeconds(tickMilliseconds); err != nil { proxywasm.LogCriticalf("failed to set tick period: %v", err) @@ -56,7 +57,7 @@ func (ctx *pluginContext) OnPluginStart(pluginConfigurationSize int) types.OnPlu return types.OnPluginStartStatusOK } -// Override types.DefaultPluginContext. +// OnTick implements types.PluginContext. func (ctx *pluginContext) OnTick() { ctx.callNum++ ret, err := proxywasm.CallForeignFunction("compress", []byte("hello world!")) diff --git a/examples/helloworld/go.mod b/examples/helloworld/go.mod index 07648604..34fa1311 100644 --- a/examples/helloworld/go.mod +++ b/examples/helloworld/go.mod @@ -5,13 +5,13 @@ go 1.19 replace github.com/tetratelabs/proxy-wasm-go-sdk => ../.. require ( - github.com/stretchr/testify v1.8.4 + github.com/stretchr/testify v1.9.0 github.com/tetratelabs/proxy-wasm-go-sdk v0.0.0-00010101000000-000000000000 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/tetratelabs/wazero v1.6.0 // indirect + github.com/tetratelabs/wazero v1.7.2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/examples/helloworld/go.sum b/examples/helloworld/go.sum index 4d3e3fe2..f343b943 100644 --- a/examples/helloworld/go.sum +++ b/examples/helloworld/go.sum @@ -2,10 +2,10 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/tetratelabs/wazero v1.6.0 h1:z0H1iikCdP8t+q341xqepY4EWvHEw8Es7tlqiVzlP3g= -github.com/tetratelabs/wazero v1.6.0/go.mod h1:0U0G41+ochRKoPKCJlh0jMg1CHkyfK8kDqiirMmKY8A= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/tetratelabs/wazero v1.7.2 h1:1+z5nXJNwMLPAWaTePFi49SSTL0IMx/i3Fg8Yc25GDc= +github.com/tetratelabs/wazero v1.7.2/go.mod h1:ytl6Zuh20R/eROuyDaGPkp82O9C/DJfXAwJfQ3X6/7Y= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/examples/helloworld/main.go b/examples/helloworld/main.go index 722c303c..e9801ce3 100644 --- a/examples/helloworld/main.go +++ b/examples/helloworld/main.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -28,25 +28,26 @@ func main() { proxywasm.SetVMContext(&vmContext{}) } +// vmContext implements types.VMContext. type vmContext struct { // Embed the default VM context here, // so that we don't need to reimplement all the methods. types.DefaultVMContext } -// Override types.DefaultVMContext. +// NewPluginContext implements types.VMContext. func (*vmContext) NewPluginContext(contextID uint32) types.PluginContext { return &helloWorld{} } +// helloWorld implements types.PluginContext. type helloWorld struct { // Embed the default plugin context here, // so that we don't need to reimplement all the methods. types.DefaultPluginContext - contextID uint32 } -// Override types.DefaultPluginContext. +// OnPluginStart implements types.PluginContext. func (ctx *helloWorld) OnPluginStart(pluginConfigurationSize int) types.OnPluginStartStatus { rand.Seed(time.Now().UnixNano()) @@ -58,12 +59,12 @@ func (ctx *helloWorld) OnPluginStart(pluginConfigurationSize int) types.OnPlugin return types.OnPluginStartStatusOK } -// Override types.DefaultPluginContext. +// OnTick implements types.PluginContext. func (ctx *helloWorld) OnTick() { t := time.Now().UnixNano() proxywasm.LogInfof("It's %d: random value: %d", t, rand.Uint64()) proxywasm.LogInfof("OnTick called") } -// Override types.DefaultPluginContext. +// NewHttpContext implements types.PluginContext. func (*helloWorld) NewHttpContext(uint32) types.HttpContext { return &types.DefaultHttpContext{} } diff --git a/examples/http_auth_random/go.mod b/examples/http_auth_random/go.mod index 1e3aa4c6..5869e0a6 100644 --- a/examples/http_auth_random/go.mod +++ b/examples/http_auth_random/go.mod @@ -5,13 +5,13 @@ go 1.19 replace github.com/tetratelabs/proxy-wasm-go-sdk => ../.. require ( - github.com/stretchr/testify v1.8.4 + github.com/stretchr/testify v1.9.0 github.com/tetratelabs/proxy-wasm-go-sdk v0.0.0-00010101000000-000000000000 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/tetratelabs/wazero v1.6.0 // indirect + github.com/tetratelabs/wazero v1.7.2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/examples/http_auth_random/go.sum b/examples/http_auth_random/go.sum index 4d3e3fe2..f343b943 100644 --- a/examples/http_auth_random/go.sum +++ b/examples/http_auth_random/go.sum @@ -2,10 +2,10 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/tetratelabs/wazero v1.6.0 h1:z0H1iikCdP8t+q341xqepY4EWvHEw8Es7tlqiVzlP3g= -github.com/tetratelabs/wazero v1.6.0/go.mod h1:0U0G41+ochRKoPKCJlh0jMg1CHkyfK8kDqiirMmKY8A= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/tetratelabs/wazero v1.7.2 h1:1+z5nXJNwMLPAWaTePFi49SSTL0IMx/i3Fg8Yc25GDc= +github.com/tetratelabs/wazero v1.7.2/go.mod h1:ytl6Zuh20R/eROuyDaGPkp82O9C/DJfXAwJfQ3X6/7Y= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/examples/http_auth_random/main.go b/examples/http_auth_random/main.go index 2e5e3a98..443160ac 100644 --- a/examples/http_auth_random/main.go +++ b/examples/http_auth_random/main.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -27,28 +27,31 @@ func main() { proxywasm.SetVMContext(&vmContext{}) } +// vmContext implements types.VMContext. type vmContext struct { // Embed the default VM context here, // so that we don't need to reimplement all the methods. types.DefaultVMContext } -// Override types.DefaultVMContext. +// NewPluginContext implements types.VMContext. func (*vmContext) NewPluginContext(contextID uint32) types.PluginContext { return &pluginContext{} } +// pluginContext implements types.PluginContext. type pluginContext struct { // Embed the default plugin context here, // so that we don't need to reimplement all the methods. types.DefaultPluginContext } -// Override types.DefaultPluginContext. +// NewHttpContext implements types.PluginContext. func (*pluginContext) NewHttpContext(contextID uint32) types.HttpContext { return &httpAuthRandom{contextID: contextID} } +// httpAuthRandom implements types.HttpContext. type httpAuthRandom struct { // Embed the default http context here, // so that we don't need to reimplement all the methods. @@ -56,7 +59,7 @@ type httpAuthRandom struct { contextID uint32 } -// Override types.DefaultHttpContext. +// OnHttpRequestHeaders implements types.HttpContext. func (ctx *httpAuthRandom) OnHttpRequestHeaders(numHeaders int, endOfStream bool) types.Action { hs, err := proxywasm.GetHttpRequestHeaders() if err != nil { @@ -77,6 +80,7 @@ func (ctx *httpAuthRandom) OnHttpRequestHeaders(numHeaders int, endOfStream bool return types.ActionPause } +// httpCallResponseCallback is a callback function when the http call response is received after dispatching. func httpCallResponseCallback(numHeaders, bodySize, numTrailers int) { hs, err := proxywasm.GetHttpCallResponseHeaders() if err != nil { @@ -91,20 +95,20 @@ func httpCallResponseCallback(numHeaders, bodySize, numTrailers int) { b, err := proxywasm.GetHttpCallResponseBody(0, bodySize) if err != nil { proxywasm.LogCriticalf("failed to get response body: %v", err) - proxywasm.ResumeHttpRequest() + _ = proxywasm.ResumeHttpRequest() return } s := fnv.New32a() if _, err := s.Write(b); err != nil { proxywasm.LogCriticalf("failed to calculate hash: %v", err) - proxywasm.ResumeHttpRequest() + _ = proxywasm.ResumeHttpRequest() return } if s.Sum32()%2 == 0 { proxywasm.LogInfo("access granted") - proxywasm.ResumeHttpRequest() + _ = proxywasm.ResumeHttpRequest() return } @@ -114,6 +118,6 @@ func httpCallResponseCallback(numHeaders, bodySize, numTrailers int) { {"powered-by", "proxy-wasm-go-sdk!!"}, }, []byte(body), -1); err != nil { proxywasm.LogErrorf("failed to send local response: %v", err) - proxywasm.ResumeHttpRequest() + _ = proxywasm.ResumeHttpRequest() } } diff --git a/examples/http_body/go.mod b/examples/http_body/go.mod index 9c776a5e..c9f091fa 100644 --- a/examples/http_body/go.mod +++ b/examples/http_body/go.mod @@ -5,13 +5,13 @@ go 1.19 replace github.com/tetratelabs/proxy-wasm-go-sdk => ../.. require ( - github.com/stretchr/testify v1.8.4 + github.com/stretchr/testify v1.9.0 github.com/tetratelabs/proxy-wasm-go-sdk v0.0.0-00010101000000-000000000000 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/tetratelabs/wazero v1.6.0 // indirect + github.com/tetratelabs/wazero v1.7.2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/examples/http_body/go.sum b/examples/http_body/go.sum index 4d3e3fe2..f343b943 100644 --- a/examples/http_body/go.sum +++ b/examples/http_body/go.sum @@ -2,10 +2,10 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/tetratelabs/wazero v1.6.0 h1:z0H1iikCdP8t+q341xqepY4EWvHEw8Es7tlqiVzlP3g= -github.com/tetratelabs/wazero v1.6.0/go.mod h1:0U0G41+ochRKoPKCJlh0jMg1CHkyfK8kDqiirMmKY8A= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/tetratelabs/wazero v1.7.2 h1:1+z5nXJNwMLPAWaTePFi49SSTL0IMx/i3Fg8Yc25GDc= +github.com/tetratelabs/wazero v1.7.2/go.mod h1:ytl6Zuh20R/eROuyDaGPkp82O9C/DJfXAwJfQ3X6/7Y= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/examples/http_body/main.go b/examples/http_body/main.go index c8a07a81..3c9d39e4 100644 --- a/examples/http_body/main.go +++ b/examples/http_body/main.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -29,17 +29,19 @@ func main() { proxywasm.SetVMContext(&vmContext{}) } +// vmContext implements types.VMContext. type vmContext struct { // Embed the default VM context here, // so that we don't need to reimplement all the methods. types.DefaultVMContext } -// Override types.DefaultVMContext. +// NewPluginContext implements types.VMContext. func (*vmContext) NewPluginContext(contextID uint32) types.PluginContext { return &pluginContext{} } +// pluginContext implements types.PluginContext. type pluginContext struct { // Embed the default plugin context here, // so that we don't need to reimplement all the methods. @@ -47,7 +49,7 @@ type pluginContext struct { shouldEchoBody bool } -// Override types.DefaultPluginContext. +// NewHttpContext implements types.PluginContext. func (ctx *pluginContext) NewHttpContext(contextID uint32) types.HttpContext { if ctx.shouldEchoBody { return &echoBodyContext{} @@ -55,7 +57,7 @@ func (ctx *pluginContext) NewHttpContext(contextID uint32) types.HttpContext { return &setBodyContext{} } -// Override types.DefaultPluginContext. +// OnPluginStart implements types.PluginContext. func (ctx *pluginContext) OnPluginStart(pluginConfigurationSize int) types.OnPluginStartStatus { data, err := proxywasm.GetPluginConfiguration() if err != nil { @@ -65,6 +67,7 @@ func (ctx *pluginContext) OnPluginStart(pluginConfigurationSize int) types.OnPlu return types.OnPluginStartStatusOK } +// setBodyContext implements types.HttpContext. type setBodyContext struct { // Embed the default root http context here, // so that we don't need to reimplement all the methods. @@ -73,7 +76,7 @@ type setBodyContext struct { bufferOperation string } -// Override types.DefaultHttpContext. +// OnHttpRequestHeaders implements types.HttpContext. func (ctx *setBodyContext) OnHttpRequestHeaders(numHeaders int, endOfStream bool) types.Action { mode, err := proxywasm.GetHttpRequestHeader("buffer-replace-at") if err == nil && mode == "response" { @@ -104,7 +107,7 @@ func (ctx *setBodyContext) OnHttpRequestHeaders(numHeaders int, endOfStream bool return types.ActionContinue } -// Override types.DefaultHttpContext. +// OnHttpRequestBody implements types.HttpContext. func (ctx *setBodyContext) OnHttpRequestBody(bodySize int, endOfStream bool) types.Action { if ctx.modifyResponse { return types.ActionContinue @@ -137,7 +140,7 @@ func (ctx *setBodyContext) OnHttpRequestBody(bodySize int, endOfStream bool) typ return types.ActionContinue } -// Override types.DefaultHttpContext. +// OnHttpResponseHeaders implements types.HttpContext. func (ctx *setBodyContext) OnHttpResponseHeaders(numHeaders int, endOfStream bool) types.Action { if !ctx.modifyResponse { return types.ActionContinue @@ -151,7 +154,7 @@ func (ctx *setBodyContext) OnHttpResponseHeaders(numHeaders int, endOfStream boo return types.ActionContinue } -// Override types.DefaultHttpContext. +// OnHttpResponseBody implements types.HttpContext. func (ctx *setBodyContext) OnHttpResponseBody(bodySize int, endOfStream bool) types.Action { if !ctx.modifyResponse { return types.ActionContinue @@ -184,6 +187,7 @@ func (ctx *setBodyContext) OnHttpResponseBody(bodySize int, endOfStream bool) ty return types.ActionContinue } +// echoBodyContext implements types.HttpContext. type echoBodyContext struct { // Embed the default plugin context // so that you don't need to reimplement all the methods by yourself. @@ -191,7 +195,7 @@ type echoBodyContext struct { totalRequestBodySize int } -// Override types.DefaultHttpContext. +// OnHttpRequestBody implements types.HttpContext. func (ctx *echoBodyContext) OnHttpRequestBody(bodySize int, endOfStream bool) types.Action { ctx.totalRequestBodySize = bodySize if !endOfStream { diff --git a/examples/http_body_chunk/go.mod b/examples/http_body_chunk/go.mod index 60a5f635..606534ec 100644 --- a/examples/http_body_chunk/go.mod +++ b/examples/http_body_chunk/go.mod @@ -5,13 +5,13 @@ go 1.19 replace github.com/tetratelabs/proxy-wasm-go-sdk => ../.. require ( - github.com/stretchr/testify v1.8.4 + github.com/stretchr/testify v1.9.0 github.com/tetratelabs/proxy-wasm-go-sdk v0.0.0-00010101000000-000000000000 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/tetratelabs/wazero v1.6.0 // indirect + github.com/tetratelabs/wazero v1.7.2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/examples/http_body_chunk/go.sum b/examples/http_body_chunk/go.sum index 4d3e3fe2..f343b943 100644 --- a/examples/http_body_chunk/go.sum +++ b/examples/http_body_chunk/go.sum @@ -2,10 +2,10 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/tetratelabs/wazero v1.6.0 h1:z0H1iikCdP8t+q341xqepY4EWvHEw8Es7tlqiVzlP3g= -github.com/tetratelabs/wazero v1.6.0/go.mod h1:0U0G41+ochRKoPKCJlh0jMg1CHkyfK8kDqiirMmKY8A= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/tetratelabs/wazero v1.7.2 h1:1+z5nXJNwMLPAWaTePFi49SSTL0IMx/i3Fg8Yc25GDc= +github.com/tetratelabs/wazero v1.7.2/go.mod h1:ytl6Zuh20R/eROuyDaGPkp82O9C/DJfXAwJfQ3X6/7Y= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/examples/http_body_chunk/main.go b/examples/http_body_chunk/main.go index 84b15d42..62e53eee 100644 --- a/examples/http_body_chunk/main.go +++ b/examples/http_body_chunk/main.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -26,33 +26,36 @@ func main() { proxywasm.SetVMContext(&vmContext{}) } +// vmContext implements types.VMContext. type vmContext struct { // Embed the default VM context here, // so that we don't need to reimplement all the methods. types.DefaultVMContext } -// Override types.DefaultVMContext. +// NewPluginContext implements types.VMContext. func (*vmContext) NewPluginContext(contextID uint32) types.PluginContext { return &pluginContext{} } +// pluginContext implements types.PluginContext. type pluginContext struct { // Embed the default plugin context here, // so that we don't need to reimplement all the methods. types.DefaultPluginContext } -// Override types.DefaultPluginContext. +// NewHttpContext implements types.PluginContext. func (ctx *pluginContext) NewHttpContext(contextID uint32) types.HttpContext { return &setBodyContext{} } -// Override types.DefaultPluginContext. +// OnPluginStart implements types.PluginContext. func (ctx *pluginContext) OnPluginStart(pluginConfigurationSize int) types.OnPluginStartStatus { return types.OnPluginStartStatusOK } +// setBodyContext implements types.HttpContext. type setBodyContext struct { // Embed the default root http context here, // so that we don't need to reimplement all the methods. @@ -61,7 +64,7 @@ type setBodyContext struct { receivedChunks int } -// Override types.DefaultHttpContext. +// OnHttpRequestBody implements types.HttpContext. func (ctx *setBodyContext) OnHttpRequestBody(bodySize int, endOfStream bool) types.Action { proxywasm.LogInfof("OnHttpRequestBody called. BodySize: %d, totalRequestBodyReadSize: %d, endOfStream: %v", bodySize, ctx.totalRequestBodyReadSize, endOfStream) @@ -87,7 +90,7 @@ func (ctx *setBodyContext) OnHttpRequestBody(bodySize int, endOfStream bool) typ {"powered-by", "proxy-wasm-go-sdk"}, }, []byte(patternFound), -1); err != nil { proxywasm.LogCriticalf("failed to send local response: %v", err) - proxywasm.ResumeHttpRequest() + _ = proxywasm.ResumeHttpRequest() } else { proxywasm.LogInfo("local 403 response sent") } diff --git a/examples/http_headers/go.mod b/examples/http_headers/go.mod index 85648c54..55e981bc 100644 --- a/examples/http_headers/go.mod +++ b/examples/http_headers/go.mod @@ -5,7 +5,7 @@ go 1.19 replace github.com/tetratelabs/proxy-wasm-go-sdk => ../.. require ( - github.com/stretchr/testify v1.8.4 + github.com/stretchr/testify v1.9.0 github.com/tetratelabs/proxy-wasm-go-sdk v0.0.0-00010101000000-000000000000 github.com/tidwall/gjson v1.14.3 ) @@ -13,7 +13,7 @@ require ( require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/tetratelabs/wazero v1.6.0 // indirect + github.com/tetratelabs/wazero v1.7.2 // indirect github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/examples/http_headers/go.sum b/examples/http_headers/go.sum index 371698c4..bc578497 100644 --- a/examples/http_headers/go.sum +++ b/examples/http_headers/go.sum @@ -2,10 +2,10 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/tetratelabs/wazero v1.6.0 h1:z0H1iikCdP8t+q341xqepY4EWvHEw8Es7tlqiVzlP3g= -github.com/tetratelabs/wazero v1.6.0/go.mod h1:0U0G41+ochRKoPKCJlh0jMg1CHkyfK8kDqiirMmKY8A= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/tetratelabs/wazero v1.7.2 h1:1+z5nXJNwMLPAWaTePFi49SSTL0IMx/i3Fg8Yc25GDc= +github.com/tetratelabs/wazero v1.7.2/go.mod h1:ytl6Zuh20R/eROuyDaGPkp82O9C/DJfXAwJfQ3X6/7Y= github.com/tidwall/gjson v1.14.3 h1:9jvXn7olKEHU1S9vwoMGliaT8jq1vJ7IH/n9zD9Dnlw= github.com/tidwall/gjson v1.14.3/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= diff --git a/examples/http_headers/main.go b/examples/http_headers/main.go index ca3d5301..fc6a2ed4 100644 --- a/examples/http_headers/main.go +++ b/examples/http_headers/main.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -27,17 +27,19 @@ func main() { proxywasm.SetVMContext(&vmContext{}) } +// vmContext implements types.VMContext. type vmContext struct { // Embed the default VM context here, // so that we don't need to reimplement all the methods. types.DefaultVMContext } -// Override types.DefaultVMContext. +// NewPluginContext implements types.VMContext. func (*vmContext) NewPluginContext(contextID uint32) types.PluginContext { return &pluginContext{} } +// pluginContext implements types.PluginContext. type pluginContext struct { // Embed the default plugin context here, // so that we don't need to reimplement all the methods. @@ -49,7 +51,7 @@ type pluginContext struct { headerValue string } -// Override types.DefaultPluginContext. +// NewHttpContext implements types.PluginContext. func (p *pluginContext) NewHttpContext(contextID uint32) types.HttpContext { return &httpHeaders{ contextID: contextID, @@ -58,6 +60,7 @@ func (p *pluginContext) NewHttpContext(contextID uint32) types.HttpContext { } } +// OnPluginStart implements types.PluginContext. func (p *pluginContext) OnPluginStart(pluginConfigurationSize int) types.OnPluginStartStatus { proxywasm.LogDebug("loading plugin config") data, err := proxywasm.GetPluginConfiguration() @@ -88,6 +91,7 @@ func (p *pluginContext) OnPluginStart(pluginConfigurationSize int) types.OnPlugi return types.OnPluginStartStatusOK } +// httpHeaders implements types.HttpContext. type httpHeaders struct { // Embed the default http context here, // so that we don't need to reimplement all the methods. @@ -97,7 +101,7 @@ type httpHeaders struct { headerValue string } -// Override types.DefaultHttpContext. +// OnHttpRequestHeaders implements types.HttpContext. func (ctx *httpHeaders) OnHttpRequestHeaders(numHeaders int, endOfStream bool) types.Action { err := proxywasm.ReplaceHttpRequestHeader("test", "best") if err != nil { @@ -115,7 +119,7 @@ func (ctx *httpHeaders) OnHttpRequestHeaders(numHeaders int, endOfStream bool) t return types.ActionContinue } -// Override types.DefaultHttpContext. +// OnHttpResponseHeaders implements types.HttpContext. func (ctx *httpHeaders) OnHttpResponseHeaders(_ int, _ bool) types.Action { proxywasm.LogInfof("adding header: %s=%s", ctx.headerName, ctx.headerValue) @@ -143,7 +147,7 @@ func (ctx *httpHeaders) OnHttpResponseHeaders(_ int, _ bool) types.Action { return types.ActionContinue } -// Override types.DefaultHttpContext. +// OnHttpStreamDone implements types.HttpContext. func (ctx *httpHeaders) OnHttpStreamDone() { proxywasm.LogInfof("%d finished", ctx.contextID) } diff --git a/examples/http_routing/go.mod b/examples/http_routing/go.mod index c97f3c65..91fbb23c 100644 --- a/examples/http_routing/go.mod +++ b/examples/http_routing/go.mod @@ -5,13 +5,13 @@ go 1.19 replace github.com/tetratelabs/proxy-wasm-go-sdk => ../.. require ( - github.com/stretchr/testify v1.8.4 + github.com/stretchr/testify v1.9.0 github.com/tetratelabs/proxy-wasm-go-sdk v0.0.0-00010101000000-000000000000 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/tetratelabs/wazero v1.6.0 // indirect + github.com/tetratelabs/wazero v1.7.2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/examples/http_routing/go.sum b/examples/http_routing/go.sum index 4d3e3fe2..f343b943 100644 --- a/examples/http_routing/go.sum +++ b/examples/http_routing/go.sum @@ -2,10 +2,10 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/tetratelabs/wazero v1.6.0 h1:z0H1iikCdP8t+q341xqepY4EWvHEw8Es7tlqiVzlP3g= -github.com/tetratelabs/wazero v1.6.0/go.mod h1:0U0G41+ochRKoPKCJlh0jMg1CHkyfK8kDqiirMmKY8A= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/tetratelabs/wazero v1.7.2 h1:1+z5nXJNwMLPAWaTePFi49SSTL0IMx/i3Fg8Yc25GDc= +github.com/tetratelabs/wazero v1.7.2/go.mod h1:ytl6Zuh20R/eROuyDaGPkp82O9C/DJfXAwJfQ3X6/7Y= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/examples/http_routing/main.go b/examples/http_routing/main.go index 371aa101..89ab9b9e 100644 --- a/examples/http_routing/main.go +++ b/examples/http_routing/main.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -26,17 +26,19 @@ func main() { proxywasm.SetVMContext(&vmContext{}) } +// vmContext implements types.VMContext. type vmContext struct { // Embed the default VM context here, // so that we don't need to reimplement all the methods. types.DefaultVMContext } -// Override types.DefaultVMContext. +// NewPluginContext implements types.VMContext. func (*vmContext) NewPluginContext(contextID uint32) types.PluginContext { return &pluginContext{} } +// pluginContext implements types.PluginContext. type pluginContext struct { // Embed the default plugin context here, // so that we don't need to reimplement all the methods. @@ -45,7 +47,7 @@ type pluginContext struct { diceOverride uint32 // For unit test } -// Override types.DefaultPluginContext. +// OnPluginStart implements types.PluginContext. func (ctx *pluginContext) OnPluginStart(pluginConfigurationSize int) types.OnPluginStartStatus { data, err := proxywasm.GetPluginConfiguration() if err != nil && err != types.ErrorStatusNotFound { @@ -62,11 +64,12 @@ func (ctx *pluginContext) OnPluginStart(pluginConfigurationSize int) types.OnPlu return types.OnPluginStartStatusOK } -// Override types.DefaultPluginContext. +// NewHttpContext implements types.PluginContext. func (ctx *pluginContext) NewHttpContext(contextID uint32) types.HttpContext { return &httpRouting{diceOverride: ctx.diceOverride} } +// httpRouting implements types.HttpContext. type httpRouting struct { // Embed the default http context here, // so that we don't need to reimplement all the methods. @@ -82,7 +85,7 @@ func dice() uint32 { return binary.LittleEndian.Uint32(buf) } -// Override types.DefaultHttpContext. +// OnHttpRequestHeaders implements types.HttpContext. func (ctx *httpRouting) OnHttpRequestHeaders(numHeaders int, endOfStream bool) types.Action { // Randomly routing to the canary cluster. var value uint32 diff --git a/examples/json_validation/go.mod b/examples/json_validation/go.mod index 09b6c721..51a7aac6 100644 --- a/examples/json_validation/go.mod +++ b/examples/json_validation/go.mod @@ -5,7 +5,7 @@ go 1.19 replace github.com/tetratelabs/proxy-wasm-go-sdk => ../.. require ( - github.com/stretchr/testify v1.8.4 + github.com/stretchr/testify v1.9.0 github.com/tetratelabs/proxy-wasm-go-sdk v0.16.0 github.com/tidwall/gjson v1.14.1 ) @@ -13,7 +13,7 @@ require ( require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/tetratelabs/wazero v1.6.0 // indirect + github.com/tetratelabs/wazero v1.7.2 // indirect github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/examples/json_validation/go.sum b/examples/json_validation/go.sum index e9c069f1..928d098b 100644 --- a/examples/json_validation/go.sum +++ b/examples/json_validation/go.sum @@ -2,10 +2,10 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/tetratelabs/wazero v1.6.0 h1:z0H1iikCdP8t+q341xqepY4EWvHEw8Es7tlqiVzlP3g= -github.com/tetratelabs/wazero v1.6.0/go.mod h1:0U0G41+ochRKoPKCJlh0jMg1CHkyfK8kDqiirMmKY8A= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/tetratelabs/wazero v1.7.2 h1:1+z5nXJNwMLPAWaTePFi49SSTL0IMx/i3Fg8Yc25GDc= +github.com/tetratelabs/wazero v1.7.2/go.mod h1:ytl6Zuh20R/eROuyDaGPkp82O9C/DJfXAwJfQ3X6/7Y= github.com/tidwall/gjson v1.14.1 h1:iymTbGkQBhveq21bEvAQ81I0LEBork8BFe1CUZXdyuo= github.com/tidwall/gjson v1.14.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= diff --git a/examples/json_validation/main.go b/examples/json_validation/main.go index d8a3402e..1d688e90 100644 --- a/examples/json_validation/main.go +++ b/examples/json_validation/main.go @@ -16,19 +16,19 @@ func main() { proxywasm.SetVMContext(&vmContext{}) } -// vmContext implements types.VMContext interface of proxy-wasm-go SDK. +// vmContext implements types.VMContext. type vmContext struct { // Embed the default VM context here, // so that we don't need to reimplement all the methods. types.DefaultVMContext } -// Override types.DefaultVMContext. +// NewPluginContext implements types.VMContext. func (*vmContext) NewPluginContext(contextID uint32) types.PluginContext { return &pluginContext{} } -// pluginContext implements types.PluginContext interface of proxy-wasm-go SDK. +// pluginContext implements types.PluginContext. type pluginContext struct { // Embed the default plugin context here, // so that we don't need to reimplement all the methods. @@ -43,7 +43,7 @@ type pluginConfiguration struct { requiredKeys []string } -// Override types.DefaultPluginContext. +// OnPluginStart implements types.PluginContext. func (ctx *pluginContext) OnPluginStart(pluginConfigurationSize int) types.OnPluginStartStatus { data, err := proxywasm.GetPluginConfiguration() if err != nil && err != types.ErrorStatusNotFound { @@ -59,7 +59,7 @@ func (ctx *pluginContext) OnPluginStart(pluginConfigurationSize int) types.OnPlu return types.OnPluginStartStatusOK } -// parsePluginConfiguration parses the json plugin confiuration data and returns pluginConfiguration. +// parsePluginConfiguration parses the json plugin configuration data and returns pluginConfiguration. // Note that this parses the json data by gjson, since TinyGo doesn't support encoding/json. // You can also try https://github.com/mailru/easyjson, which supports decoding to a struct. func parsePluginConfiguration(data []byte) (pluginConfiguration, error) { @@ -81,12 +81,12 @@ func parsePluginConfiguration(data []byte) (pluginConfiguration, error) { return *config, nil } -// Override types.DefaultPluginContext. +// NewHttpContext implements types.PluginContext. func (ctx *pluginContext) NewHttpContext(contextID uint32) types.HttpContext { return &payloadValidationContext{requiredKeys: ctx.configuration.requiredKeys} } -// payloadValidationContext implements types.HttpContext interface of proxy-wasm-go SDK. +// payloadValidationContext implements types.HttpContext. type payloadValidationContext struct { // Embed the default root http context here, // so that we don't need to reimplement all the methods. @@ -95,9 +95,7 @@ type payloadValidationContext struct { requiredKeys []string } -var _ types.HttpContext = (*payloadValidationContext)(nil) - -// Override types.DefaultHttpContext. +// OnHttpRequestHeaders implements types.HttpContext. func (*payloadValidationContext) OnHttpRequestHeaders(numHeaders int, _ bool) types.Action { contentType, err := proxywasm.GetHttpRequestHeader("content-type") if err != nil || contentType != "application/json" { @@ -113,7 +111,7 @@ func (*payloadValidationContext) OnHttpRequestHeaders(numHeaders int, _ bool) ty return types.ActionContinue } -// Override types.DefaultHttpContext. +// OnHttpRequestBody implements types.HttpContext. func (ctx *payloadValidationContext) OnHttpRequestBody(bodySize int, endOfStream bool) types.Action { ctx.totalRequestBodySize += bodySize if !endOfStream { diff --git a/examples/metrics/go.mod b/examples/metrics/go.mod index 397ca2e4..c1dd325f 100644 --- a/examples/metrics/go.mod +++ b/examples/metrics/go.mod @@ -5,13 +5,13 @@ go 1.19 replace github.com/tetratelabs/proxy-wasm-go-sdk => ../.. require ( - github.com/stretchr/testify v1.8.4 + github.com/stretchr/testify v1.9.0 github.com/tetratelabs/proxy-wasm-go-sdk v0.0.0-00010101000000-000000000000 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/tetratelabs/wazero v1.6.0 // indirect + github.com/tetratelabs/wazero v1.7.2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/examples/metrics/go.sum b/examples/metrics/go.sum index 4d3e3fe2..f343b943 100644 --- a/examples/metrics/go.sum +++ b/examples/metrics/go.sum @@ -2,10 +2,10 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/tetratelabs/wazero v1.6.0 h1:z0H1iikCdP8t+q341xqepY4EWvHEw8Es7tlqiVzlP3g= -github.com/tetratelabs/wazero v1.6.0/go.mod h1:0U0G41+ochRKoPKCJlh0jMg1CHkyfK8kDqiirMmKY8A= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/tetratelabs/wazero v1.7.2 h1:1+z5nXJNwMLPAWaTePFi49SSTL0IMx/i3Fg8Yc25GDc= +github.com/tetratelabs/wazero v1.7.2/go.mod h1:ytl6Zuh20R/eROuyDaGPkp82O9C/DJfXAwJfQ3X6/7Y= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/examples/metrics/main.go b/examples/metrics/main.go index f502f07e..c7695df1 100644 --- a/examples/metrics/main.go +++ b/examples/metrics/main.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -25,28 +25,31 @@ func main() { proxywasm.SetVMContext(&vmContext{}) } +// vmContext implements types.VMContext. type vmContext struct { // Embed the default VM context here, // so that we don't need to reimplement all the methods. types.DefaultVMContext } -// Override types.DefaultVMContext. +// NewPluginContext implements types.VMContext. func (*vmContext) NewPluginContext(contextID uint32) types.PluginContext { return &metricPluginContext{} } +// metricPluginContext implements types.PluginContext. type metricPluginContext struct { // Embed the default plugin context here, // so that we don't need to reimplement all the methods. types.DefaultPluginContext } -// Override types.DefaultPluginContext. +// NewHttpContext implements types.PluginContext. func (ctx *metricPluginContext) NewHttpContext(contextID uint32) types.HttpContext { return &metricHttpContext{} } +// metricHttpContext implements types.HttpContext. type metricHttpContext struct { // Embed the default http context here, // so that we don't need to reimplement all the methods. @@ -58,9 +61,11 @@ const ( customHeaderValueTagKey = "value" ) +// counters is a map from custom header value to a counter metric. +// Note that Proxy-Wasm plugins are single threaded, so no need to use a lock. var counters = map[string]proxywasm.MetricCounter{} -// Override types.DefaultHttpContext. +// OnHttpRequestHeaders implements types.HttpContext. func (ctx *metricHttpContext) OnHttpRequestHeaders(numHeaders int, endOfStream bool) types.Action { customHeaderValue, err := proxywasm.GetHttpRequestHeader(customHeaderKey) if err == nil { diff --git a/examples/multiple_dispatches/go.mod b/examples/multiple_dispatches/go.mod index 4e6b8462..61502ed5 100644 --- a/examples/multiple_dispatches/go.mod +++ b/examples/multiple_dispatches/go.mod @@ -5,13 +5,13 @@ go 1.19 replace github.com/tetratelabs/proxy-wasm-go-sdk => ../.. require ( - github.com/stretchr/testify v1.8.4 + github.com/stretchr/testify v1.9.0 github.com/tetratelabs/proxy-wasm-go-sdk v0.0.0-00010101000000-000000000000 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/tetratelabs/wazero v1.6.0 // indirect + github.com/tetratelabs/wazero v1.7.2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/examples/multiple_dispatches/go.sum b/examples/multiple_dispatches/go.sum index 4d3e3fe2..f343b943 100644 --- a/examples/multiple_dispatches/go.sum +++ b/examples/multiple_dispatches/go.sum @@ -2,10 +2,10 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/tetratelabs/wazero v1.6.0 h1:z0H1iikCdP8t+q341xqepY4EWvHEw8Es7tlqiVzlP3g= -github.com/tetratelabs/wazero v1.6.0/go.mod h1:0U0G41+ochRKoPKCJlh0jMg1CHkyfK8kDqiirMmKY8A= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/tetratelabs/wazero v1.7.2 h1:1+z5nXJNwMLPAWaTePFi49SSTL0IMx/i3Fg8Yc25GDc= +github.com/tetratelabs/wazero v1.7.2/go.mod h1:ytl6Zuh20R/eROuyDaGPkp82O9C/DJfXAwJfQ3X6/7Y= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/examples/multiple_dispatches/main.go b/examples/multiple_dispatches/main.go index 79ba30b3..87e2ac30 100644 --- a/examples/multiple_dispatches/main.go +++ b/examples/multiple_dispatches/main.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -27,28 +27,31 @@ func main() { proxywasm.SetVMContext(&vmContext{}) } +// vmContext implements types.VMContext. type vmContext struct { // Embed the default VM context here, // so that we don't need to reimplement all the methods. types.DefaultVMContext } -// Override types.DefaultVMContext. +// NewPluginContext implements types.VMContext. func (*vmContext) NewPluginContext(contextID uint32) types.PluginContext { return &pluginContext{} } +// pluginContext implements types.PluginContext. type pluginContext struct { // Embed the default plugin context here, // so that we don't need to reimplement all the methods. types.DefaultPluginContext } -// Override types.DefaultPluginContext. +// NewHttpContext implements types.PluginContext. func (*pluginContext) NewHttpContext(contextID uint32) types.HttpContext { return &httpContext{contextID: contextID} } +// httpContext implements types.HttpContext. type httpContext struct { // Embed the default http context here, // so that we don't need to reimplement all the methods. @@ -61,7 +64,7 @@ type httpContext struct { const totalDispatchNum = 10 -// Override types.DefaultHttpContext. +// OnHttpResponseHeaders implements types.HttpContext. func (ctx *httpContext) OnHttpResponseHeaders(numHeaders int, endOfStream bool) types.Action { // On each request response, we dispatch the http calls `totalDispatchNum` times. // Note: DispatchHttpCall is asynchronously processed, so each loop is non-blocking. @@ -86,9 +89,9 @@ func (ctx *httpContext) dispatchCallback(numHeaders, bodySize, numTrailers int) if ctx.pendingDispatchedRequest == 0 { // This case, all the dispatched request was processed. // Adds a response header to the original response. - proxywasm.AddHttpResponseHeader("total-dispatched", strconv.Itoa(totalDispatchNum)) + _ = proxywasm.AddHttpResponseHeader("total-dispatched", strconv.Itoa(totalDispatchNum)) // And then contniue the original reponse. - proxywasm.ResumeHttpResponse() + _ = proxywasm.ResumeHttpResponse() proxywasm.LogInfof("response resumed after processed %d dispatched request", totalDispatchNum) } else { proxywasm.LogInfof("pending dispatched requests: %d", ctx.pendingDispatchedRequest) diff --git a/examples/network/go.mod b/examples/network/go.mod index 5d009e30..a94c306a 100644 --- a/examples/network/go.mod +++ b/examples/network/go.mod @@ -5,13 +5,13 @@ go 1.19 replace github.com/tetratelabs/proxy-wasm-go-sdk => ../.. require ( - github.com/stretchr/testify v1.8.4 + github.com/stretchr/testify v1.9.0 github.com/tetratelabs/proxy-wasm-go-sdk v0.0.0-00010101000000-000000000000 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/tetratelabs/wazero v1.6.0 // indirect + github.com/tetratelabs/wazero v1.7.2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/examples/network/go.sum b/examples/network/go.sum index 4d3e3fe2..f343b943 100644 --- a/examples/network/go.sum +++ b/examples/network/go.sum @@ -2,10 +2,10 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/tetratelabs/wazero v1.6.0 h1:z0H1iikCdP8t+q341xqepY4EWvHEw8Es7tlqiVzlP3g= -github.com/tetratelabs/wazero v1.6.0/go.mod h1:0U0G41+ochRKoPKCJlh0jMg1CHkyfK8kDqiirMmKY8A= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/tetratelabs/wazero v1.7.2 h1:1+z5nXJNwMLPAWaTePFi49SSTL0IMx/i3Fg8Yc25GDc= +github.com/tetratelabs/wazero v1.7.2/go.mod h1:ytl6Zuh20R/eROuyDaGPkp82O9C/DJfXAwJfQ3X6/7Y= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/examples/network/main.go b/examples/network/main.go index bcaef31b..12416f76 100644 --- a/examples/network/main.go +++ b/examples/network/main.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -23,17 +23,19 @@ func main() { proxywasm.SetVMContext(&vmContext{}) } +// vmContext implements types.VMContext. type vmContext struct { // Embed the default VM context here, // so that we don't need to reimplement all the methods. types.DefaultVMContext } -// Override types.DefaultVMContext. +// NewPluginContext implements types.VMContext. func (*vmContext) NewPluginContext(contextID uint32) types.PluginContext { return &pluginContext{counter: proxywasm.DefineCounterMetric("proxy_wasm_go.connection_counter")} } +// pluginContext implements types.PluginContext. type pluginContext struct { // Embed the default plugin context here, // so that we don't need to reimplement all the methods. @@ -41,11 +43,12 @@ type pluginContext struct { counter proxywasm.MetricCounter } -// Override types.DefaultPluginContext. +// NewTcpContext implements types.PluginContext. func (ctx *pluginContext) NewTcpContext(contextID uint32) types.TcpContext { return &networkContext{counter: ctx.counter} } +// networkContext implements types.TcpContext. type networkContext struct { // Embed the default tcp context here, // so that we don't need to reimplement all the methods. @@ -53,13 +56,13 @@ type networkContext struct { counter proxywasm.MetricCounter } -// Override types.DefaultTcpContext. +// OnNewConnection implements types.TcpContext. func (ctx *networkContext) OnNewConnection() types.Action { proxywasm.LogInfo("new connection!") return types.ActionContinue } -// Override types.DefaultTcpContext. +// OnDownstreamData implements types.TcpContext. func (ctx *networkContext) OnDownstreamData(dataSize int, endOfStream bool) types.Action { if dataSize == 0 { return types.ActionContinue @@ -75,13 +78,12 @@ func (ctx *networkContext) OnDownstreamData(dataSize int, endOfStream bool) type return types.ActionContinue } -// Override types.DefaultTcpContext. +// OnDownstreamClose implements types.TcpContext. func (ctx *networkContext) OnDownstreamClose(types.PeerType) { proxywasm.LogInfo("downstream connection close!") - return } -// Override types.DefaultTcpContext. +// OnUpstreamData implements types.TcpContext. func (ctx *networkContext) OnUpstreamData(dataSize int, endOfStream bool) types.Action { if dataSize == 0 { return types.ActionContinue @@ -115,7 +117,7 @@ func (ctx *networkContext) OnUpstreamData(dataSize int, endOfStream bool) types. return types.ActionContinue } -// Override types.DefaultTcpContext. +// OnStreamDone implements types.TcpContext. func (ctx *networkContext) OnStreamDone() { ctx.counter.Increment(1) proxywasm.LogInfo("connection complete!") diff --git a/examples/postpone_requests/go.mod b/examples/postpone_requests/go.mod index 539cfd5a..67ca9b72 100644 --- a/examples/postpone_requests/go.mod +++ b/examples/postpone_requests/go.mod @@ -5,13 +5,13 @@ go 1.19 replace github.com/tetratelabs/proxy-wasm-go-sdk => ../.. require ( - github.com/stretchr/testify v1.8.4 + github.com/stretchr/testify v1.9.0 github.com/tetratelabs/proxy-wasm-go-sdk v0.0.0-00010101000000-000000000000 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/tetratelabs/wazero v1.6.0 // indirect + github.com/tetratelabs/wazero v1.7.2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/examples/postpone_requests/go.sum b/examples/postpone_requests/go.sum index 4d3e3fe2..f343b943 100644 --- a/examples/postpone_requests/go.sum +++ b/examples/postpone_requests/go.sum @@ -2,10 +2,10 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/tetratelabs/wazero v1.6.0 h1:z0H1iikCdP8t+q341xqepY4EWvHEw8Es7tlqiVzlP3g= -github.com/tetratelabs/wazero v1.6.0/go.mod h1:0U0G41+ochRKoPKCJlh0jMg1CHkyfK8kDqiirMmKY8A= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/tetratelabs/wazero v1.7.2 h1:1+z5nXJNwMLPAWaTePFi49SSTL0IMx/i3Fg8Yc25GDc= +github.com/tetratelabs/wazero v1.7.2/go.mod h1:ytl6Zuh20R/eROuyDaGPkp82O9C/DJfXAwJfQ3X6/7Y= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/examples/postpone_requests/main.go b/examples/postpone_requests/main.go index 6ba7e5bb..974e73a8 100644 --- a/examples/postpone_requests/main.go +++ b/examples/postpone_requests/main.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -25,13 +25,14 @@ func main() { proxywasm.SetVMContext(&vmContext{}) } +// vmContext implements types.VMContext. type vmContext struct { // Embed the default VM context here, // so that we don't need to reimplement all the methods. types.DefaultVMContext } -// Override types.DefaultVMContext. +// NewPluginContext implements types.VMContext. func (*vmContext) NewPluginContext(contextID uint32) types.PluginContext { return &pluginContext{ contextID: contextID, @@ -39,6 +40,7 @@ func (*vmContext) NewPluginContext(contextID uint32) types.PluginContext { } } +// pluginContext implements types.PluginContext. type pluginContext struct { // Embed the default plugin context here, // so that we don't need to reimplement all the methods. @@ -47,7 +49,7 @@ type pluginContext struct { postponed []uint32 } -// Override types.DefaultPluginContext. +// OnPluginStart implements types.PluginContext. func (ctx *pluginContext) OnPluginStart(pluginConfigurationSize int) types.OnPluginStartStatus { if err := proxywasm.SetTickPeriodMilliSeconds(tickMilliseconds); err != nil { proxywasm.LogCriticalf("failed to set tick period: %v", err) @@ -56,18 +58,18 @@ func (ctx *pluginContext) OnPluginStart(pluginConfigurationSize int) types.OnPlu return types.OnPluginStartStatusOK } -// Override types.DefaultPluginContext. +// OnTick implements types.PluginContext. func (ctx *pluginContext) OnTick() { for len(ctx.postponed) > 0 { httpCtxId, tail := ctx.postponed[0], ctx.postponed[1:] proxywasm.LogInfof("resume request with contextID=%v", httpCtxId) - proxywasm.SetEffectiveContext(httpCtxId) - proxywasm.ResumeHttpRequest() + _ = proxywasm.SetEffectiveContext(httpCtxId) + _ = proxywasm.ResumeHttpRequest() ctx.postponed = tail } } -// Override types.DefaultPluginContext. +// NewHttpContext implements types.PluginContext. func (ctx *pluginContext) NewHttpContext(contextID uint32) types.HttpContext { return &httpContext{ contextID: contextID, @@ -75,6 +77,7 @@ func (ctx *pluginContext) NewHttpContext(contextID uint32) types.HttpContext { } } +// httpContext implements types.HttpContext. type httpContext struct { // Embed the default http context here, // so that we don't need to reimplement all the methods. @@ -83,7 +86,7 @@ type httpContext struct { pluginCtx *pluginContext } -// Override types.DefaultHttpContext. +// OnHttpRequestHeaders implements types.HttpContext. func (ctx *httpContext) OnHttpRequestHeaders(numHeaders int, endOfStream bool) types.Action { proxywasm.LogInfof("postpone request with contextID=%d", ctx.contextID) ctx.pluginCtx.postponed = append(ctx.pluginCtx.postponed, ctx.contextID) diff --git a/examples/properties/go.mod b/examples/properties/go.mod index 04c8d69f..47a98e18 100644 --- a/examples/properties/go.mod +++ b/examples/properties/go.mod @@ -5,13 +5,13 @@ go 1.19 replace github.com/tetratelabs/proxy-wasm-go-sdk => ../.. require ( - github.com/stretchr/testify v1.8.4 + github.com/stretchr/testify v1.9.0 github.com/tetratelabs/proxy-wasm-go-sdk v0.0.0-00010101000000-000000000000 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/tetratelabs/wazero v1.6.0 // indirect + github.com/tetratelabs/wazero v1.7.2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/examples/properties/go.sum b/examples/properties/go.sum index 4d3e3fe2..f343b943 100644 --- a/examples/properties/go.sum +++ b/examples/properties/go.sum @@ -2,10 +2,10 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/tetratelabs/wazero v1.6.0 h1:z0H1iikCdP8t+q341xqepY4EWvHEw8Es7tlqiVzlP3g= -github.com/tetratelabs/wazero v1.6.0/go.mod h1:0U0G41+ochRKoPKCJlh0jMg1CHkyfK8kDqiirMmKY8A= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/tetratelabs/wazero v1.7.2 h1:1+z5nXJNwMLPAWaTePFi49SSTL0IMx/i3Fg8Yc25GDc= +github.com/tetratelabs/wazero v1.7.2/go.mod h1:ytl6Zuh20R/eROuyDaGPkp82O9C/DJfXAwJfQ3X6/7Y= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/examples/properties/main.go b/examples/properties/main.go index 4f110e4d..fbc1d5f3 100644 --- a/examples/properties/main.go +++ b/examples/properties/main.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -23,13 +23,14 @@ func main() { proxywasm.SetVMContext(&vmContext{}) } +// vmContext implements types.VMContext. type vmContext struct { // Embed the default VM context here, // so that we don't need to reimplement all the methods. types.DefaultVMContext } -// Override types.DefaultVMContext. +// NewPluginContext implements types.VMContext. func (*vmContext) NewPluginContext(contextID uint32) types.PluginContext { return &pluginContext{} } @@ -40,11 +41,12 @@ type pluginContext struct { types.DefaultPluginContext } -// Override types.DefaultPluginContext. +// NewHttpContext implements types.PluginContext. func (*pluginContext) NewHttpContext(contextID uint32) types.HttpContext { return &properties{contextID: contextID} } +// properties implements types.HttpContext. type properties struct { // Embed the default http context here, // so that we don't need to reimplement all the methods. @@ -58,7 +60,7 @@ var propertyPrefix = []string{ "envoy.filters.http.wasm", } -// Override types.DefaultHttpContext. +// OnHttpRequestHeaders implements types.HttpContext. func (ctx *properties) OnHttpRequestHeaders(numHeaders int, endOfStream bool) types.Action { auth, err := proxywasm.GetProperty(append(propertyPrefix, "auth")) if err != nil { @@ -86,14 +88,14 @@ func (ctx *properties) OnHttpRequestHeaders(numHeaders int, endOfStream bool) ty // Reject requests without authentication header if !authHeader { - proxywasm.SendHttpResponse(401, nil, nil, 16) + _ = proxywasm.SendHttpResponse(401, nil, nil, 16) return types.ActionPause } return types.ActionContinue } -// Override types.DefaultHttpContext. +// OnHttpStreamDone implements types.HttpContext. func (ctx *properties) OnHttpStreamDone() { proxywasm.LogInfof("%d finished", ctx.contextID) } diff --git a/examples/properties/main_test.go b/examples/properties/main_test.go index 49446eac..80ac20f2 100644 --- a/examples/properties/main_test.go +++ b/examples/properties/main_test.go @@ -34,14 +34,15 @@ func TestProperties_OnHttpRequestHeaders(t *testing.T) { // Check Envoy logs. logs := host.GetInfoLogs() - require.Contains(t, logs, fmt.Sprintf("no auth header for route")) + require.Contains(t, logs, "no auth header for route") require.Contains(t, logs, fmt.Sprintf("%d finished", id)) }) // Set property path := "auth" data := "cookie" - host.SetProperty(append(propertyPrefix, path), []byte(data)) + err := host.SetProperty(append(propertyPrefix, path), []byte(data)) + require.NoError(t, err) // Get property actualData, _ := host.GetProperty(append(propertyPrefix, path)) diff --git a/examples/shared_data/go.mod b/examples/shared_data/go.mod index 67795712..8914f46a 100644 --- a/examples/shared_data/go.mod +++ b/examples/shared_data/go.mod @@ -5,13 +5,13 @@ go 1.19 replace github.com/tetratelabs/proxy-wasm-go-sdk => ../.. require ( - github.com/stretchr/testify v1.8.4 + github.com/stretchr/testify v1.9.0 github.com/tetratelabs/proxy-wasm-go-sdk v0.0.0-00010101000000-000000000000 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/tetratelabs/wazero v1.6.0 // indirect + github.com/tetratelabs/wazero v1.7.2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/examples/shared_data/go.sum b/examples/shared_data/go.sum index 4d3e3fe2..f343b943 100644 --- a/examples/shared_data/go.sum +++ b/examples/shared_data/go.sum @@ -2,10 +2,10 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/tetratelabs/wazero v1.6.0 h1:z0H1iikCdP8t+q341xqepY4EWvHEw8Es7tlqiVzlP3g= -github.com/tetratelabs/wazero v1.6.0/go.mod h1:0U0G41+ochRKoPKCJlh0jMg1CHkyfK8kDqiirMmKY8A= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/tetratelabs/wazero v1.7.2 h1:1+z5nXJNwMLPAWaTePFi49SSTL0IMx/i3Fg8Yc25GDc= +github.com/tetratelabs/wazero v1.7.2/go.mod h1:ytl6Zuh20R/eROuyDaGPkp82O9C/DJfXAwJfQ3X6/7Y= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/examples/shared_data/main.go b/examples/shared_data/main.go index a09ed64e..e1168a9a 100644 --- a/examples/shared_data/main.go +++ b/examples/shared_data/main.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -31,13 +31,15 @@ func main() { } type ( - vmContext struct{} + // vmContext implements types.VMContext. + vmContext struct{} + // pluginContext implements types.PluginContext. pluginContext struct { // Embed the default plugin context here, // so that we don't need to reimplement all the methods. types.DefaultPluginContext } - + // httpContext implements types.HttpContext. httpContext struct { // Embed the default http context here, // so that we don't need to reimplement all the methods. @@ -45,7 +47,7 @@ type ( } ) -// Override types.VMContext. +// OnVMStart implements types.VMContext. func (*vmContext) OnVMStart(vmConfigurationSize int) types.OnVMStartStatus { initialValueBuf := make([]byte, 0) // Empty data to indicate that the data is not initialized. if err := proxywasm.SetSharedData(sharedDataKey, initialValueBuf, 0); err != nil { @@ -54,17 +56,17 @@ func (*vmContext) OnVMStart(vmConfigurationSize int) types.OnVMStartStatus { return types.OnVMStartStatusOK } -// Override types.DefaultVMContext. +// NewPluginContext implements types.VMContext. func (*vmContext) NewPluginContext(contextID uint32) types.PluginContext { return &pluginContext{} } -// Override types.DefaultPluginContext. +// NewHttpContext implements types.PluginContext. func (*pluginContext) NewHttpContext(contextID uint32) types.HttpContext { return &httpContext{} } -// Override types.DefaultHttpContext. +// OnHttpRequestHeaders implements types.HttpContext. func (ctx *httpContext) OnHttpRequestHeaders(numHeaders int, endOfStream bool) types.Action { for { value, err := ctx.incrementData() @@ -78,6 +80,7 @@ func (ctx *httpContext) OnHttpRequestHeaders(numHeaders int, endOfStream bool) t return types.ActionContinue } +// incrementData increments the shared data value by 1. func (ctx *httpContext) incrementData() (uint64, error) { data, cas, err := proxywasm.GetSharedData(sharedDataKey) if err != nil { diff --git a/examples/shared_queue/receiver/main.go b/examples/shared_queue/receiver/main.go index a01b9ec4..41528947 100644 --- a/examples/shared_queue/receiver/main.go +++ b/examples/shared_queue/receiver/main.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -25,17 +25,19 @@ func main() { proxywasm.SetVMContext(&vmContext{}) } +// vmContext implements types.VMContext. type vmContext struct { // Embed the default VM context here, // so that we don't need to reimplement all the methods. types.DefaultVMContext } -// Override types.DefaultVMContext. +// NewPluginContext implements types.VMContext. func (*vmContext) NewPluginContext(contextID uint32) types.PluginContext { return &receiverPluginContext{contextID: contextID} } +// receiverPluginContext implements types.PluginContext. type receiverPluginContext struct { // Embed the default plugin context here, // so that we don't need to reimplement all the methods. @@ -44,7 +46,7 @@ type receiverPluginContext struct { queueName string } -// Override types.DefaultPluginContext. +// OnPluginStart implements types.PluginContext. func (ctx *receiverPluginContext) OnPluginStart(pluginConfigurationSize int) types.OnPluginStartStatus { // Get Plugin configuration. config, err := proxywasm.GetPluginConfiguration() @@ -63,7 +65,7 @@ func (ctx *receiverPluginContext) OnPluginStart(pluginConfigurationSize int) typ return types.OnPluginStartStatusOK } -// Override types.DefaultPluginContext. +// OnQueueReady implements types.PluginContext. func (ctx *receiverPluginContext) OnQueueReady(queueID uint32) { data, err := proxywasm.DequeueSharedQueue(queueID) switch err { diff --git a/examples/shared_queue/sender/main.go b/examples/shared_queue/sender/main.go index 78424866..8499b6bd 100644 --- a/examples/shared_queue/sender/main.go +++ b/examples/shared_queue/sender/main.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -23,26 +23,25 @@ import ( "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types" ) -const ( - receiverVMID = "receiver" - queueName = "http_headers" -) +const receiverVMID = "receiver" func main() { proxywasm.SetVMContext(&vmContext{}) } +// vmContext implements types.VMContext. type vmContext struct { // Embed the default VM context here, // so that we don't need to reimplement all the methods. types.DefaultVMContext } -// Override types.DefaultVMContext. +// NewPluginContext implements types.VMContext. func (*vmContext) NewPluginContext(contextID uint32) types.PluginContext { return &senderPluginContext{contextID: contextID} } +// senderPluginContext implements types.PluginContext. type senderPluginContext struct { // Embed the default plugin context here, // so that we don't need to reimplement all the methods. @@ -51,11 +50,7 @@ type senderPluginContext struct { contextID uint32 } -func newPluginContext(uint32) types.PluginContext { - return &senderPluginContext{} -} - -// Override types.DefaultPluginContext. +// OnPluginStart implements types.PluginContext. func (ctx *senderPluginContext) OnPluginStart(pluginConfigurationSize int) types.OnPluginStartStatus { // Get Plugin configuration. config, err := proxywasm.GetPluginConfiguration() @@ -67,7 +62,7 @@ func (ctx *senderPluginContext) OnPluginStart(pluginConfigurationSize int) types return types.OnPluginStartStatusOK } -// Override types.DefaultPluginContext. +// NewHttpContext implements types.PluginContext. func (ctx *senderPluginContext) NewHttpContext(contextID uint32) types.HttpContext { // If this PluginContext is not configured for Http, then return nil. if ctx.config != "http" { @@ -93,6 +88,7 @@ func (ctx *senderPluginContext) NewHttpContext(contextID uint32) types.HttpConte } } +// senderHttpContext implements types.HttpContext. type senderHttpContext struct { // Embed the default http context here, // so that we don't need to reimplement all the methods. @@ -100,7 +96,7 @@ type senderHttpContext struct { contextID, requestHeadersQueueID, responseHeadersQueueID uint32 } -// Override types.DefaultHttpContext. +// OnHttpRequestHeaders implements types.HttpContext. func (ctx *senderHttpContext) OnHttpRequestHeaders(int, bool) types.Action { headers, err := proxywasm.GetHttpRequestHeaders() if err != nil { @@ -117,7 +113,7 @@ func (ctx *senderHttpContext) OnHttpRequestHeaders(int, bool) types.Action { return types.ActionContinue } -// Override types.DefaultHttpContext. +// OnHttpResponseHeaders implements types.HttpContext. func (ctx *senderHttpContext) OnHttpResponseHeaders(int, bool) types.Action { headers, err := proxywasm.GetHttpResponseHeaders() if err != nil { @@ -134,6 +130,7 @@ func (ctx *senderHttpContext) OnHttpResponseHeaders(int, bool) types.Action { return types.ActionContinue } +// NewTcpContext implements types.PluginContext. func (ctx *senderPluginContext) NewTcpContext(contextID uint32) types.TcpContext { // If this PluginContext is not configured for Tcp, then return nil. if ctx.config != "tcp" { @@ -153,6 +150,7 @@ func (ctx *senderPluginContext) NewTcpContext(contextID uint32) types.TcpContext } } +// senderTcpContext implements types.TcpContext. type senderTcpContext struct { types.DefaultTcpContext // Embed the default http context here, @@ -161,6 +159,7 @@ type senderTcpContext struct { contextID uint32 } +// OnUpstreamData implements types.TcpContext. func (ctx *senderTcpContext) OnUpstreamData(dataSize int, endOfStream bool) types.Action { if dataSize == 0 { return types.ActionContinue diff --git a/examples/vm_plugin_configuration/go.mod b/examples/vm_plugin_configuration/go.mod index cbc68197..7c1334be 100644 --- a/examples/vm_plugin_configuration/go.mod +++ b/examples/vm_plugin_configuration/go.mod @@ -5,13 +5,13 @@ go 1.19 replace github.com/tetratelabs/proxy-wasm-go-sdk => ../.. require ( - github.com/stretchr/testify v1.8.4 + github.com/stretchr/testify v1.9.0 github.com/tetratelabs/proxy-wasm-go-sdk v0.0.0-00010101000000-000000000000 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/tetratelabs/wazero v1.6.0 // indirect + github.com/tetratelabs/wazero v1.7.2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/examples/vm_plugin_configuration/go.sum b/examples/vm_plugin_configuration/go.sum index 4d3e3fe2..f343b943 100644 --- a/examples/vm_plugin_configuration/go.sum +++ b/examples/vm_plugin_configuration/go.sum @@ -2,10 +2,10 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/tetratelabs/wazero v1.6.0 h1:z0H1iikCdP8t+q341xqepY4EWvHEw8Es7tlqiVzlP3g= -github.com/tetratelabs/wazero v1.6.0/go.mod h1:0U0G41+ochRKoPKCJlh0jMg1CHkyfK8kDqiirMmKY8A= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/tetratelabs/wazero v1.7.2 h1:1+z5nXJNwMLPAWaTePFi49SSTL0IMx/i3Fg8Yc25GDc= +github.com/tetratelabs/wazero v1.7.2/go.mod h1:ytl6Zuh20R/eROuyDaGPkp82O9C/DJfXAwJfQ3X6/7Y= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/examples/vm_plugin_configuration/main.go b/examples/vm_plugin_configuration/main.go index 4a31c11e..3ce2adb4 100644 --- a/examples/vm_plugin_configuration/main.go +++ b/examples/vm_plugin_configuration/main.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -23,8 +23,10 @@ func main() { proxywasm.SetVMContext(&vmContext{}) } +// vmContext implements types.VMContext. type vmContext struct{} +// OnVMStart implements types.VMContext. func (*vmContext) OnVMStart(vmConfigurationSize int) types.OnVMStartStatus { data, err := proxywasm.GetVMConfiguration() if err != nil { @@ -35,18 +37,19 @@ func (*vmContext) OnVMStart(vmConfigurationSize int) types.OnVMStartStatus { return types.OnVMStartStatusOK } -// Implement types.VMContext. +// NewPluginContext implements types.VMContext. func (*vmContext) NewPluginContext(uint32) types.PluginContext { return &pluginContext{} } +// pluginContext implements types.PluginContext. type pluginContext struct { // Embed the default plugin context here, // so that we don't need to reimplement all the methods. types.DefaultPluginContext } -// Override types.DefaultPluginContext. +// OnPluginStart implements types.PluginContext. func (ctx pluginContext) OnPluginStart(pluginConfigurationSize int) types.OnPluginStartStatus { data, err := proxywasm.GetPluginConfiguration() if err != nil { diff --git a/go.mod b/go.mod index 79b29849..c69ef244 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,8 @@ module github.com/tetratelabs/proxy-wasm-go-sdk go 1.19 require ( - github.com/stretchr/testify v1.8.4 - github.com/tetratelabs/wazero v1.6.0 + github.com/stretchr/testify v1.9.0 + github.com/tetratelabs/wazero v1.7.2 ) require ( diff --git a/go.sum b/go.sum index 4d3e3fe2..f343b943 100644 --- a/go.sum +++ b/go.sum @@ -2,10 +2,10 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/tetratelabs/wazero v1.6.0 h1:z0H1iikCdP8t+q341xqepY4EWvHEw8Es7tlqiVzlP3g= -github.com/tetratelabs/wazero v1.6.0/go.mod h1:0U0G41+ochRKoPKCJlh0jMg1CHkyfK8kDqiirMmKY8A= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/tetratelabs/wazero v1.7.2 h1:1+z5nXJNwMLPAWaTePFi49SSTL0IMx/i3Fg8Yc25GDc= +github.com/tetratelabs/wazero v1.7.2/go.mod h1:ytl6Zuh20R/eROuyDaGPkp82O9C/DJfXAwJfQ3X6/7Y= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/proxywasm/entrypoint.go b/proxywasm/entrypoint.go index 8f8cf2ca..758d47e5 100644 --- a/proxywasm/entrypoint.go +++ b/proxywasm/entrypoint.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/proxywasm/hostcall.go b/proxywasm/hostcall.go index 5dc14ad9..04013a86 100644 --- a/proxywasm/hostcall.go +++ b/proxywasm/hostcall.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/proxywasm/hostcall_test.go b/proxywasm/hostcall_test.go index 5dddce5a..ebc9de4b 100644 --- a/proxywasm/hostcall_test.go +++ b/proxywasm/hostcall_test.go @@ -1,4 +1,4 @@ -// Copyright 2021 Tetrate +// Copyright 2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/proxywasm/internal/abi_callback_alloc.go b/proxywasm/internal/abi_callback_alloc.go index c9566cb0..1c5ec830 100644 --- a/proxywasm/internal/abi_callback_alloc.go +++ b/proxywasm/internal/abi_callback_alloc.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/proxywasm/internal/abi_callback_configuration.go b/proxywasm/internal/abi_callback_configuration.go index 60da346f..16071c91 100644 --- a/proxywasm/internal/abi_callback_configuration.go +++ b/proxywasm/internal/abi_callback_configuration.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/proxywasm/internal/abi_callback_configuration_test.go b/proxywasm/internal/abi_callback_configuration_test.go index 903bac43..f56547e4 100644 --- a/proxywasm/internal/abi_callback_configuration_test.go +++ b/proxywasm/internal/abi_callback_configuration_test.go @@ -1,4 +1,4 @@ -// Copyright 2021 Tetrate +// Copyright 2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/proxywasm/internal/abi_callback_l4.go b/proxywasm/internal/abi_callback_l4.go index ea3c526a..f9cc9d57 100644 --- a/proxywasm/internal/abi_callback_l4.go +++ b/proxywasm/internal/abi_callback_l4.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/proxywasm/internal/abi_callback_l4_test.go b/proxywasm/internal/abi_callback_l4_test.go index c6eff1b9..af57666c 100644 --- a/proxywasm/internal/abi_callback_l4_test.go +++ b/proxywasm/internal/abi_callback_l4_test.go @@ -1,4 +1,4 @@ -// Copyright 2021 Tetrate +// Copyright 2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/proxywasm/internal/abi_callback_l7.go b/proxywasm/internal/abi_callback_l7.go index 43d000d3..83960d68 100644 --- a/proxywasm/internal/abi_callback_l7.go +++ b/proxywasm/internal/abi_callback_l7.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/proxywasm/internal/abi_callback_l7_test.go b/proxywasm/internal/abi_callback_l7_test.go index 02a0969c..241c7cca 100644 --- a/proxywasm/internal/abi_callback_l7_test.go +++ b/proxywasm/internal/abi_callback_l7_test.go @@ -1,4 +1,4 @@ -// Copyright 2021 Tetrate +// Copyright 2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/proxywasm/internal/abi_callback_lifecycle.go b/proxywasm/internal/abi_callback_lifecycle.go index 3f2ebac8..c28fee5a 100644 --- a/proxywasm/internal/abi_callback_lifecycle.go +++ b/proxywasm/internal/abi_callback_lifecycle.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/proxywasm/internal/abi_callback_lifecycle_test.go b/proxywasm/internal/abi_callback_lifecycle_test.go index 2c2d652c..18688a7c 100644 --- a/proxywasm/internal/abi_callback_lifecycle_test.go +++ b/proxywasm/internal/abi_callback_lifecycle_test.go @@ -1,4 +1,4 @@ -// Copyright 2021 Tetrate +// Copyright 2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/proxywasm/internal/abi_callback_queue.go b/proxywasm/internal/abi_callback_queue.go index a5b82313..6b8021ab 100644 --- a/proxywasm/internal/abi_callback_queue.go +++ b/proxywasm/internal/abi_callback_queue.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/proxywasm/internal/abi_callback_queue_test.go b/proxywasm/internal/abi_callback_queue_test.go index 9135f212..50520277 100644 --- a/proxywasm/internal/abi_callback_queue_test.go +++ b/proxywasm/internal/abi_callback_queue_test.go @@ -1,4 +1,4 @@ -// Copyright 2021 Tetrate +// Copyright 2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/proxywasm/internal/abi_callback_test_export.go b/proxywasm/internal/abi_callback_test_export.go index 51983d16..1c18d4ee 100644 --- a/proxywasm/internal/abi_callback_test_export.go +++ b/proxywasm/internal/abi_callback_test_export.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/proxywasm/internal/abi_callback_timers.go b/proxywasm/internal/abi_callback_timers.go index 6c00ac46..2f4061e2 100644 --- a/proxywasm/internal/abi_callback_timers.go +++ b/proxywasm/internal/abi_callback_timers.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/proxywasm/internal/abi_callback_timers_test.go b/proxywasm/internal/abi_callback_timers_test.go index b6fe6644..80f37aac 100644 --- a/proxywasm/internal/abi_callback_timers_test.go +++ b/proxywasm/internal/abi_callback_timers_test.go @@ -1,4 +1,4 @@ -// Copyright 2021 Tetrate +// Copyright 2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/proxywasm/internal/abi_callback_version.go b/proxywasm/internal/abi_callback_version.go index 82461dc3..ade6b8fe 100644 --- a/proxywasm/internal/abi_callback_version.go +++ b/proxywasm/internal/abi_callback_version.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/proxywasm/internal/abi_hostcalls.go b/proxywasm/internal/abi_hostcalls.go index 152c401a..eb5d4ea4 100644 --- a/proxywasm/internal/abi_hostcalls.go +++ b/proxywasm/internal/abi_hostcalls.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/proxywasm/internal/abi_hostcalls_mock.go b/proxywasm/internal/abi_hostcalls_mock.go index 68c151de..edc9a54a 100644 --- a/proxywasm/internal/abi_hostcalls_mock.go +++ b/proxywasm/internal/abi_hostcalls_mock.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/proxywasm/internal/hostcall_utils_go.go b/proxywasm/internal/hostcall_utils.go similarity index 95% rename from proxywasm/internal/hostcall_utils_go.go rename to proxywasm/internal/hostcall_utils.go index 3e8f611f..f9cd4d29 100644 --- a/proxywasm/internal/hostcall_utils_go.go +++ b/proxywasm/internal/hostcall_utils.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build !tinygo - // Since the difference of the types in SliceHeader.{Len, Cap} between tinygo and go, // we have to have separated functions for converting bytes // https://github.com/tinygo-org/tinygo/issues/1284 diff --git a/proxywasm/internal/hostcall_utils_test.go b/proxywasm/internal/hostcall_utils_test.go index 7a08eb06..6d1de3a4 100644 --- a/proxywasm/internal/hostcall_utils_test.go +++ b/proxywasm/internal/hostcall_utils_test.go @@ -1,4 +1,4 @@ -// Copyright 2021 Tetrate +// Copyright 2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/proxywasm/internal/hostcall_utils_tinygo.go b/proxywasm/internal/hostcall_utils_tinygo.go deleted file mode 100644 index 229e658d..00000000 --- a/proxywasm/internal/hostcall_utils_tinygo.go +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2020-2021 Tetrate -// -// 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. - -//go:build tinygo - -// Since the difference of the types in SliceHeader.{Len, Cap} between tinygo and go, -// we have to have separated functions for converting bytes -// https://github.com/tinygo-org/tinygo/issues/1284 - -package internal - -import ( - "reflect" - "unsafe" -) - -func RawBytePtrToString(raw *byte, size int) string { - return *(*string)(unsafe.Pointer(&reflect.SliceHeader{ - Data: uintptr(unsafe.Pointer(raw)), - Len: uintptr(size), - Cap: uintptr(size), - })) -} - -func RawBytePtrToByteSlice(raw *byte, size int) []byte { - return *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{ - Data: uintptr(unsafe.Pointer(raw)), - Len: uintptr(size), - Cap: uintptr(size), - })) -} diff --git a/proxywasm/internal/hostcall_utls.go b/proxywasm/internal/hostcall_utls.go index b853fd39..b960ca02 100644 --- a/proxywasm/internal/hostcall_utls.go +++ b/proxywasm/internal/hostcall_utls.go @@ -1,4 +1,4 @@ -// Copyright 2021 Tetrate +// Copyright 2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/proxywasm/internal/serde.go b/proxywasm/internal/serde.go index 8355ce44..cb0cd023 100644 --- a/proxywasm/internal/serde.go +++ b/proxywasm/internal/serde.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/proxywasm/internal/serde_test.go b/proxywasm/internal/serde_test.go index f60ba6fd..0339b173 100644 --- a/proxywasm/internal/serde_test.go +++ b/proxywasm/internal/serde_test.go @@ -1,4 +1,4 @@ -// Copyright 2021 Tetrate +// Copyright 2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/proxywasm/internal/vmstate.go b/proxywasm/internal/vmstate.go index d9a062ac..b7680ebe 100644 --- a/proxywasm/internal/vmstate.go +++ b/proxywasm/internal/vmstate.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/proxywasm/internal/vmstate_test.go b/proxywasm/internal/vmstate_test.go index 0bec0d65..034183bc 100644 --- a/proxywasm/internal/vmstate_test.go +++ b/proxywasm/internal/vmstate_test.go @@ -1,4 +1,4 @@ -// Copyright 2021 Tetrate +// Copyright 2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/proxywasm/internal/vmstate_test_export.go b/proxywasm/internal/vmstate_test_export.go index 7ca78be8..3ef1e933 100644 --- a/proxywasm/internal/vmstate_test_export.go +++ b/proxywasm/internal/vmstate_test_export.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/proxywasm/proxytest/http.go b/proxywasm/proxytest/http.go index 49c66391..ed4eee3d 100644 --- a/proxywasm/proxytest/http.go +++ b/proxywasm/proxytest/http.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/proxywasm/proxytest/network.go b/proxywasm/proxytest/network.go index 6254cee6..f9884ac4 100644 --- a/proxywasm/proxytest/network.go +++ b/proxywasm/proxytest/network.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/proxywasm/proxytest/option.go b/proxywasm/proxytest/option.go index 7aaaf724..1ab53962 100644 --- a/proxywasm/proxytest/option.go +++ b/proxywasm/proxytest/option.go @@ -1,4 +1,4 @@ -// Copyright 2021 Tetrate +// Copyright 2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/proxywasm/proxytest/proxytest.go b/proxywasm/proxytest/proxytest.go index 93a7afdf..bb397db7 100644 --- a/proxywasm/proxytest/proxytest.go +++ b/proxywasm/proxytest/proxytest.go @@ -1,4 +1,4 @@ -// Copyright 2021 Tetrate +// Copyright 2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/proxywasm/proxytest/root.go b/proxywasm/proxytest/root.go index f4797ada..c07d8288 100644 --- a/proxywasm/proxytest/root.go +++ b/proxywasm/proxytest/root.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/proxywasm/types/context.go b/proxywasm/types/context.go index a70b234d..577749ff 100644 --- a/proxywasm/types/context.go +++ b/proxywasm/types/context.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/proxywasm/types/types.go b/proxywasm/types/types.go index d4e86e4b..c94095a8 100644 --- a/proxywasm/types/types.go +++ b/proxywasm/types/types.go @@ -1,4 +1,4 @@ -// Copyright 2020-2021 Tetrate +// Copyright 2020-2024 Tetrate // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License.