Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions option/water.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@ type WATEROutboundOptions struct {
// DownloadTimeout specifies how much time the downloader should wait
// until it cancel and try to fetch from another URL
DownloadTimeout string `json:"download_timeout"`
// WASMStorageDir specifies which directory should store the WASM files
WASMStorageDir string `json:"water_dir"`
// WazeroCompilationCacheDir specifies which directory should be used for storing
// Wazero cache
WazeroCompilationCacheDir string `json:"wazero_compilation_cache_dir"`
// Dir specifies which directory we should use for storing WATER related
// files
Dir string `json:"water_dir"`
// Config is a optional config that will be sent to the WASM file.
Config map[string]any `json:"config,omitempty"`
// SkipHandshake is used when the WATER module deals with the handshake
Expand Down
17 changes: 8 additions & 9 deletions protocol/water/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net"
"net/http"
"os"
"path/filepath"
"strconv"
"sync"
"time"
Expand Down Expand Up @@ -55,22 +56,20 @@ func NewOutbound(ctx context.Context, router adapter.Router, logger log.ContextL
return nil, err
}

if options.WASMStorageDir == "" {
return nil, E.New("provided an empty storage directory for WASM files")
if options.Dir == "" {
return nil, E.New("provided an empty storage directory for WATER files")
}

if options.WazeroCompilationCacheDir == "" {
return nil, E.New("provided an empty storage directory for wazero compilation cache")
}

for _, dir := range []string{options.WASMStorageDir, options.WazeroCompilationCacheDir} {
wasmDir := filepath.Join(options.Dir, "wasm_files")
wazeroCompilationDir := filepath.Join(options.Dir, "wazero_compilation_cache")
for _, dir := range []string{wasmDir, wazeroCompilationDir} {
if err := os.MkdirAll(dir, 0755); err != nil {
return nil, err
}
}

slogLogger := slog.New(L.NewLogHandler(logger))
vc := waterVC.NewWaterVersionControl(options.WASMStorageDir, slogLogger)
vc := waterVC.NewWaterVersionControl(wasmDir, slogLogger)
d, err := waterDownloader.NewWASMDownloader(options.WASMAvailableAt, &http.Client{Timeout: timeout})
if err != nil {
return nil, E.New("failed to create WASM downloader", err)
Expand All @@ -95,7 +94,7 @@ func NewOutbound(ctx context.Context, router adapter.Router, logger log.ContextL

// We're creating the compilation cache dir and setting the global value so during runtime
// it won't need to create one at a temp directory
compilationCache, err := wazero.NewCompilationCacheWithDir(options.WazeroCompilationCacheDir)
compilationCache, err := wazero.NewCompilationCacheWithDir(wazeroCompilationDir)
if err != nil {
return nil, err
}
Expand Down
Loading