Skip to content

Commit

Permalink
fix: receiving WASM as base64 and decoding before using it
Browse files Browse the repository at this point in the history
  • Loading branch information
WendelHime committed Jun 24, 2024
1 parent a340009 commit 5d88f5c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
13 changes: 2 additions & 11 deletions http-proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ var (
algenevaAddr = flag.String("algeneva-addr", "", "Address at which to listen for algenAddr connections.")

waterAddr = flag.String("water-addr", "", "Address at which to listen for WATER connections.")
waterWASM []byte
waterWASM = flag.String("water-wasm", "", "Base64 encoded WASM for WATER")

track = flag.String("track", "", "The track this proxy is running on")
)
Expand All @@ -197,15 +197,6 @@ const (
)

func main() {
flag.Func("water-wasm", "WATER WASM bytes.", func(s string) error {
if s == "" {
return nil
}

waterWASM = []byte(s)
return nil
})

iniflags.SetAllowUnknownFlags(true)
iniflags.Parse()
if *version {
Expand Down Expand Up @@ -482,7 +473,7 @@ func main() {
BroflakeKey: os.Getenv("BROFLAKE_KEY"),
AlgenevaAddr: *algenevaAddr,
WaterAddr: *waterAddr,
WaterWASM: waterWASM,
WaterWASM: *waterWASM,
}
if *maxmindLicenseKey != "" {
log.Debug("Will use Maxmind for geolocating clients")
Expand Down
2 changes: 1 addition & 1 deletion http_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ type Proxy struct {
AlgenevaAddr string

WaterAddr string
WaterWASM []byte
WaterWASM string

throttleConfig throttle.Config
instrument instrument.Instrument
Expand Down
11 changes: 9 additions & 2 deletions water/reverse.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package water

import (
"context"
"encoding/base64"
"net"
"sync"

Expand All @@ -21,9 +22,15 @@ type llistener struct {
closeError error
}

func NewReverseListener(ctx context.Context, address string, wasm []byte) (*llistener, error) {
func NewReverseListener(ctx context.Context, address string, wasm string) (*llistener, error) {
decodedWASM, err := base64.StdEncoding.DecodeString(wasm)
if err != nil {
log.Errorf("failed to decode WASM base64: %v", err)
return nil, err
}

cfg := &water.Config{
TransportModuleBin: wasm,
TransportModuleBin: decodedWASM,
}

waterListener, err := cfg.ListenContext(ctx, "tcp", address)
Expand Down
5 changes: 4 additions & 1 deletion water/reverse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package water
import (
"bytes"
"context"
"encoding/base64"
"net"
"os"
"testing"
Expand All @@ -20,13 +21,15 @@ func TestReverseListener(t *testing.T) {
wasm, err := os.ReadFile(wasmPath)
require.Nil(t, err)

b64WASM := base64.StdEncoding.EncodeToString(wasm)

ctx := context.Background()

cfg := &water.Config{
TransportModuleBin: wasm,
}

ll, err := NewReverseListener(ctx, addr, wasm)
ll, err := NewReverseListener(ctx, addr, b64WASM)
require.Nil(t, err)

messageRequest := "hello"
Expand Down

0 comments on commit 5d88f5c

Please sign in to comment.