-
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.
update: rearrange doc structure and add WATM Spec in Go (#8)
* update: add spec in Go representation Signed-off-by: Gaukas Wang <[email protected]> * update: Go runtime doc in subdirectory Signed-off-by: Gaukas Wang <[email protected]> * update: remove unnecessary indentation Signed-off-by: Gaukas Wang <[email protected]> --------- Signed-off-by: Gaukas Wang <[email protected]>
- Loading branch information
Showing
4 changed files
with
152 additions
and
85 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
layout: default | ||
title: Troubleshooting (Go) | ||
grand_parent: Runtime Library | ||
parent: Runtime Library in Go | ||
nav_order: 2 | ||
--- | ||
# Troubleshooting | ||
|
||
## Enable `wazero` debug logs | ||
|
||
`wazero` is the WebAssembly runtime with WASI support that `water` uses. To enable debug logs from `wazero`, pass the values below via the `context.Context` | ||
|
||
```go | ||
// example of enabling FileSystem, Poll, and Sock logging scopes of wazero | ||
ctx = context.WithValue(ctx, experimental.FunctionListenerFactoryKey{}, | ||
logging.NewHostLoggingListenerFactory(os.Stderr, logging.LogScopeFilesystem|logging.LogScopePoll|logging.LogScopeSock)) | ||
``` |
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,65 @@ | ||
--- | ||
layout: default | ||
title: Usage (Go) | ||
grand_parent: Runtime Library | ||
parent: Runtime Library in Go | ||
nav_order: 3 | ||
--- | ||
# Usage | ||
|
||
## Importing `water` | ||
To use `water` in a Go project, simply import it as a module. | ||
|
||
By default, `water` does not recognize any transport modules as there can be many different | ||
specifications of transport modules. To use a specific transport module, import its implementation | ||
as well. | ||
|
||
```go | ||
import ( | ||
"github.com/refraction-networking/water" | ||
_ "github.com/refraction-networking/water/transport/v0" // import the v0 transport module spec | ||
) | ||
``` | ||
|
||
## Working Modes | ||
|
||
### Dialer | ||
Dialer acts like a client. It actively creates connections to a remote server (and usually is the one who sends the first message). | ||
|
||
```go | ||
// Load the WebAssembly binary into wasm as []byte. | ||
// The rest of the code on this page assumes that wasm is already loaded. | ||
wasm, _ := os.ReadFile("./examples/v0/plain/plain.wasm") | ||
|
||
config := &water.Config{ | ||
TransportModuleBin: wasm, | ||
} | ||
|
||
dialer, _ := water.NewDialerWithContext(context.Background(), config) | ||
conn, _ := dialer.DialContext(context.Background(),"tcp", remoteAddr) | ||
``` | ||
|
||
### Listener | ||
Listener acts like a server. It listens on a network address and wait for | ||
incoming connections to accept. | ||
|
||
```go | ||
lis, _ := config.ListenContext(context.Background(), "tcp", localAddr) | ||
defer lis.Close() | ||
log.Printf("Listening on %s", lis.Addr().String()) | ||
|
||
for { | ||
conn, err := lis.Accept() | ||
handleConn(conn) | ||
} | ||
``` | ||
|
||
### Relay | ||
A relay combines the functionalities of both a dialer and a listener. It works | ||
like a forward proxy, accepting connections from a client and forwarding them to a | ||
remote server by dialing a connection to the remote server. | ||
|
||
```go | ||
relay, _ := water.NewRelayWithContext(context.Background(), config) | ||
relay.ListenAndRelayTo("tcp", localAddr, "tcp", remoteAddr) // blocking | ||
``` |
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