-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* new: watm-go desc and api Signed-off-by: Gaukas Wang <[email protected]> * update: more on go runtime Signed-off-by: Gaukas Wang <[email protected]> * new: watm v0 spec Signed-off-by: Gaukas Wang <[email protected]> --------- Signed-off-by: Gaukas Wang <[email protected]>
- Loading branch information
Showing
4 changed files
with
246 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
--- | ||
layout: default | ||
title: WATM Builder Helper in Go | ||
grand_parent: WebAssembly Transport Module | ||
parent: WATM in Go | ||
nav_order: 2 | ||
--- | ||
|
||
# `watm`: WATM Builder Helper | ||
|
||
[![Go Reference](https://pkg.go.dev/badge/github.com/refraction-networking/watm.svg)](https://pkg.go.dev/github.com/refraction-networking/watm) | ||
|
||
We provide `watm` ([GitHub Repository](https://github.com/refraction-networking/watm)) as a helper library one can use to build WATM from WebAssembly-agnostic Go code. It would reduce a lot of boilerplate code and make the integration process much easier when you have an existing transport written in Go and does not want to customize the WATM's behavior too much. | ||
|
||
Currently, `watm` is still under active development and supports only TinyGo as the compiler. | ||
|
||
## `tinygo/v0` package | ||
|
||
[![Go Reference](https://pkg.go.dev/badge/github.com/refraction-networking/watm.svg)](https://pkg.go.dev/github.com/refraction-networking/watm/tinygo/v0) | ||
|
||
The `tinygo/v0` package provides a set of helper functions to build WATM with spec version 0 from WebAssembly-agnostic Go code. It is designed to be used with TinyGo. | ||
|
||
<!-- TODO: Add documentations to API Reference? --> | ||
<details> | ||
<summary>API Reference</summary> | ||
|
||
```go | ||
type RelayWrapSelection bool | ||
|
||
const ( | ||
RelayWrapRemote RelayWrapSelection = false | ||
RelayWrapSource RelayWrapSelection = true | ||
) | ||
|
||
type ConfigurableTransport interface { | ||
Configure([]byte) error | ||
} | ||
|
||
type DialingTransport interface { | ||
SetDialer(dialer func(network, address string) (v0net.Conn, error)) | ||
Dial(network, address string) (v0net.Conn, error) | ||
} | ||
|
||
|
||
type ListeningTransport interface { | ||
SetListener(listener v0net.Listener) | ||
Accept() (v0net.Conn, error) | ||
} | ||
|
||
type WrappingTransport interface { | ||
Wrap(v0net.Conn) (v0net.Conn, error) | ||
} | ||
|
||
func BuildDialerWithDialingTransport(DialingTransport) | ||
func BuildDialerWithWrappingTransport(WrappingTransport) | ||
|
||
func BuildListenerWithListeningTransport(ListeningTransport) | ||
func BuildListenerWithWrappingTransport(WrappingTransport) | ||
|
||
func BuildRelayWithListeningDialingTransport(ListeningTransport, DialingTransport) | ||
func BuildRelayWithWrappingTransport(WrappingTransport, RelayWrapSelection) | ||
``` | ||
|
||
</details> | ||
|
||
### `tinygo/v0/net` package | ||
|
||
[![Go Reference](https://pkg.go.dev/badge/github.com/refraction-networking/watm.svg)](https://pkg.go.dev/github.com/refraction-networking/watm/tinygo/v0/net) | ||
|
||
The `tinygo/v0/net` package simulates the standard `net` package in Go, and provides a set of helper functions to build WATM with spec version 0 from WebAssembly-agnostic Go code. It is designed to be used with TinyGo. | ||
|
||
If you are using `tinygo/v0` properly, then most likely you don't have to interact with this package too much. However, more flexibility is provided here if you want to customize the behavior of the WATM. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
--- | ||
layout: default | ||
title: WATM Specification | ||
parent: WebAssembly Transport Module | ||
nav_order: 3 | ||
--- | ||
|
||
# Current WebAssembly Transport Module (WATM) Specification | ||
Currently we are in `v0` of the WebAssembly Transport Module (WATM) specification. This document describes the current version of the WATM specification. | ||
|
||
## API | ||
The current version of WATM utilizes the WebAssembly System Interface (WASI) Preview 1 to provide the basic functionalities to interact between the WebAssembly module and the host environment. In addition, we define the following API for the transport module. | ||
|
||
### Imports | ||
|
||
WATM imports the following functions from the host environment: | ||
|
||
| Function Signature | Parameters | Results | Description | | ||
| --- | --- | --- | --- | | ||
|`host_dial` | - | `net_fd: s32` | Ask the host to connect to a remote server. | | ||
| `host_accept` | - | `net_fd: s32` | Ask the host to accept an incoming connection. | | ||
| ~~`host_defer`~~ | - | - | ~~Ask the host to defer the execution of the current function.~~ Deprecated: this function is equal to `NOP`. | | ||
| `pull_config`* | - | `conf_fd: s32` | Ask the host to provide the configuration file. | | ||
|
||
### Exports | ||
|
||
WATM exports the following functions to the host environment: | ||
|
||
| Function Signature | Parameters | Results | Description | | ||
| --- | --- | --- | --- | | ||
| `_water_init` | - | `errno: s32` | Initialize the transport module. | | ||
| `_water_dial` | `internal_fd: s32` | `net_fd: s32` | Connect to a remote server. | | ||
| `_water_accept` | `internal_fd: s32` | `net_fd: s32` | Accept an incoming connection. | | ||
| `_water_associate` | - | `errno: s32` | Associate the transport module with the host environment. | | ||
| `_water_worker` | - | `errno: s32` | Start the worker thread. | | ||
|
||
## API Represented in Different Programming Languages | ||
To help developers understand the API, we provide the following representations of the API in different programming languages that could be more intuitive than the above table. | ||
|
||
### C representation | ||
(planned feature) | ||
|
||
### Go representation | ||
(to be added) | ||
|
||
### Rust representation | ||
(to be added) | ||
|
||
### WIT representation | ||
Similarly, such API can be represented in WIT. | ||
|
||
_Note that the following is a simplified example and may not strictly follow the WIT syntax. In other words, we do not guarantee the following code to be compilable._ | ||
|
||
#### Imported Functions | ||
```wit | ||
// imports.wit | ||
package env; | ||
interface host { | ||
host_dial: func() -> (net_fd: s32); | ||
host_accept: func() -> (net_fd: s32); | ||
host_defer: func(); // deprecated | ||
pull_config: func() -> (conf_fd: s32); | ||
} | ||
world host-world { | ||
import host; | ||
} | ||
``` | ||
|
||
#### Exported Functions | ||
```wit | ||
// exports.wit | ||
interface wasm { | ||
_water_init: func() -> (errno: s32) | ||
_water_dial: func(internal_fd: s32) -> (net_fd: s32); | ||
_water_accept: func(internal_fd: s32) -> (net_fd: s32); | ||
_water_associate: func() -> (errno: s32); | ||
_water_worker: func() -> (errno: s32); | ||
} | ||
world wasm-world { | ||
export wasm; | ||
} | ||
``` |