Skip to content

Commit

Permalink
new: WATM v1 Spec documentation (#13)
Browse files Browse the repository at this point in the history
* update: make spec a directory and move v0 spec

Signed-off-by: Gaukas Wang <[email protected]>

* new: v1 spec

Signed-off-by: Gaukas Wang <[email protected]>

---------

Signed-off-by: Gaukas Wang <[email protected]>
  • Loading branch information
gaukas authored May 6, 2024
1 parent 6f5e69d commit 475ed7a
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 16 deletions.
18 changes: 18 additions & 0 deletions transport-module/spec/spec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
layout: default
title: WATM Specification
parent: WebAssembly Transport Module
nav_order: 3
has_children: true
permalink: /transport-module/spec.html
---

# WebAssembly Transport Module (WATM) Specification
By design, WATER supports multiple different implementations of the standard WebAssembly Transport Module (WATM) specification, for versioning and customization purposes. This page lists the available official versions of the WATM specification.

## Current Version
We are rolling out [v1](spec/v1.html) as the most current WebAssembly Transport Module (WATM) specification.

## Deprecated Versions

- [v0](spec/v0.html)
31 changes: 15 additions & 16 deletions transport-module/spec.md → transport-module/spec/v0.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
---
layout: default
title: WATM Specification
parent: WebAssembly Transport Module
nav_order: 3
title: v0
grand_parent: WebAssembly Transport Module
parent: WATM Specification
nav_order: 99
---

# 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.
# v0 (Deprecated)
`v0` defines the original proof-of-concept version of the WebAssembly Transport Module (WATM) specification. This version is now deprecated and should not be used for production purposes. We encourage all developers to use the latest version of the specification as specified in [spec](../spec.html).

## 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. |
| `pull_config`* | - | `conf_fd: s32` | Ask the host to provide the configuration file. |
| ~~`host_defer`~~ | - | - | ~~Ask the host to defer the execution of the current function.~~ Deprecated: this function is equal to `NOP`. |
|`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 |
| `pull_config`* | - | `conf_fd: s32` | Ask the host to provide the configuration file |
| ~~`host_defer`~~ | - | - | ~~Ask the host to defer the execution of the current function~~ Deprecated: this function is equal to `NOP` |

### Exports

WATM exports the following functions to the host environment:

| Function Signature | Parameters | Results | Description |
| --- | --- | --- | --- |
| `_water_v0` | - | - | Version 0 identifier. |
| `_water_init` | - | `errno: s32` | Initialize the transport module. |
| `_water_init` | - | `errno: s32` | Initialize the transport module |
| `_water_cancel_with` | `cancel_fd: s32` | `errno: s32` | Cancel the operation with the given file descriptor. |
| `_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. |
| `_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 next incoming connection with an outgoing connection (relay) |
| `_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.
Expand Down
156 changes: 156 additions & 0 deletions transport-module/spec/v1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
---
layout: default
title: v1
grand_parent: WebAssembly Transport Module
parent: WATM Specification
nav_order: 1
---

# v1
`v1` defines the first production-ready version of the WebAssembly Transport Module (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 |
| --- | --- | --- | --- |
| `water_dial` | `network_iovs: ciovec_array, address_iovs: ciovec_array` | `fd: s32` | Dial a remote address specified by `network` and `address` |
| `water_dial_fixed` | - | `fd: s32` | Dial a remote address controlled by WATER Runtime |
| `water_accept` | - | `net_fd: s32` | Accept an incoming connection from the listener managed by WATER Runtime |

### Exports
WATM exports the following functions to the host environment:

| Function Signature | Parameters | Results | Description |
| --- | --- | --- | --- |
| `watm_init_v1` | - | `errno: s32` | Initialize the transport module |
| `watm_ctrlpipe_v1` | `ctrl_fd: s32` | `errno: s32` | Set the control pipe to the given file descriptor. Called before `watm_start_v1` |
| `watm_dial_v1` | `internal_fd: s32` | `net_fd: s32` | Connect to a remote server specified by WATER Runtime |
| `watm_dial_fixed_v1` | `internal_fd: s32` | `net_fd: s32` | Connect to a remote server specified by WATM |
| `watm_accept_v1` | `internal_fd: s32` | `net_fd: s32` | Accept an incoming connection |
| `watm_associate_v1` | - | `errno: s32` | Associate the next incoming connection with an outgoing connection (relay) |
| `watm_start_v1` | - | `errno: s32` | Start the (blocking) 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

<details>
<summary>Imports</summary>

<div class="highlighter-rouge">
<div class="highlight">
<pre class="highlight">
<code>//go:wasmimport env water_dial
//go:noescape
func water_dial(
networkIovs unsafe.Pointer, networkIovsLen size,
addressIovs unsafe.Pointer, addressIovsLen size,
) (fd int32)

//go:wasmimport env water_dial_fixed
//go:noescape
func water_dial_fixed() (fd int32)

//go:wasmimport env water_accept
//go:noescape
func water_accept() (fd int32)</code>
</pre>
</div>
</div>
</details>

<details>
<summary>Exports</summary>

<div class="highlighter-rouge">
<div class="highlight">
<pre class="highlight">
<code>//export watm_init_v1
func _init() int32

//export watm_ctrlpipe_v1
func _ctrlpipe(ctrlFd int32) int32

//export watm_dial_v1
func _dial(internalFd int32) (networkFd int32)

//export watm_dial_fixed_v1
func _dial_fixed(internalFd int32) (networkFd int32)

//export watm_accept_v1
func _accept(internalFd int32) (networkFd int32)

//export watm_associate_v1
func _associate() int32

//export watm_start_v1
func _start() int32</code>
</pre>
</div>
</div>
</details>

### 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._

<details>
<summary>Imports</summary>

<div class="highlighter-rouge">
<div class="highlight">
<pre class="highlight">
<code>// imports.wit
package env;

interface host {
water_dial: func(network_iovs: ciovec_array, addr_iovs: ciovec_array) -> (net_fd: s32);
water_dial_fixed: func() -> (net_fd: s32);
water_accept: func() -> (conf_fd: s32);
}

world host-world {
import host;
}</code>
</pre>
</div>
</div>
</details>

<details>
<summary>Exports</summary>

<div class="highlighter-rouge">
<div class="highlight">
<pre class="highlight">
<code>
// exports.wit
interface wasm {
watm_init_v1: func() -> (errno: s32);
watm_ctrlpipe_v1(ctrl_fd: s32) -> (errno: s32);
watm_dial_v1: func(internal_fd: s32) -> (net_fd: s32);
watm_dial_fixed_v1: func(internal_fd: s32) -> (net_fd: s32);
watm_accept_v1: func(internal_fd: s32) -> (net_fd: s32);
watm_associate_v1: func() -> (errno: s32);
watm_start_v1: func() -> (errno: s32);
}

world wasm-world {
export wasm;
}</code>
</pre>
</div>
</div>
</details>

0 comments on commit 475ed7a

Please sign in to comment.