diff --git a/option/water.go b/option/water.go index 5af84c7..13e92c2 100644 --- a/option/water.go +++ b/option/water.go @@ -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 diff --git a/protocol/water/outbound.go b/protocol/water/outbound.go index 18c9c6c..9e18b12 100644 --- a/protocol/water/outbound.go +++ b/protocol/water/outbound.go @@ -7,6 +7,7 @@ import ( "net" "net/http" "os" + "path/filepath" "strconv" "sync" "time" @@ -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) @@ -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 }