From a41166033f0d249a7e54f5b1eaa5118147436e7e Mon Sep 17 00:00:00 2001 From: WendelHime <6754291+WendelHime@users.noreply.github.com> Date: Tue, 8 Oct 2024 11:45:19 -0300 Subject: [PATCH 01/16] feat: adding support to downloading WATER WASM from a given list of URLs --- http-proxy/main.go | 10 ++- http_proxy.go | 37 ++++++++- water/downloader.go | 122 ++++++++++++++++++++++++++++++ water/downloader_test.go | 154 ++++++++++++++++++++++++++++++++++++++ water/https_downloader.go | 44 +++++++++++ water/listener.go | 16 ++-- water/listener_test.go | 5 +- water/mock_downloader.go | 55 ++++++++++++++ 8 files changed, 422 insertions(+), 21 deletions(-) create mode 100644 water/downloader.go create mode 100644 water/downloader_test.go create mode 100644 water/https_downloader.go create mode 100644 water/mock_downloader.go diff --git a/http-proxy/main.go b/http-proxy/main.go index 22e4dcef..aa5adf8b 100644 --- a/http-proxy/main.go +++ b/http-proxy/main.go @@ -186,9 +186,11 @@ 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 = flag.String("water-wasm", "", "Base64 encoded WASM for WATER") - waterTransport = flag.String("water-transport", "", "WATER based transport name") + waterAddr = flag.String("water-addr", "", "Address at which to listen for WATER connections.") + waterWASM = flag.String("water-wasm", "", "Base64 encoded WASM for WATER") + waterWASMAvailableAt = flag.String("water-wasm-available-at", "", "URLs where the WATER WASM is available") + waterWASMHashsum = flag.String("water-wasm-hashsum", "", "Hashsum of the WATER WASM") + waterTransport = flag.String("water-transport", "", "WATER based transport name") track = flag.String("track", "", "The track this proxy is running on") ) @@ -473,6 +475,8 @@ func main() { AlgenevaAddr: *algenevaAddr, WaterAddr: *waterAddr, WaterWASM: *waterWASM, + WaterWASMAvailableAt: *waterWASMAvailableAt, + WaterWASMHashsum: *waterWASMHashsum, WaterTransport: *waterTransport, } if *maxmindLicenseKey != "" { diff --git a/http_proxy.go b/http_proxy.go index c6ce452f..9d9e5c9d 100644 --- a/http_proxy.go +++ b/http_proxy.go @@ -1,8 +1,10 @@ package proxy import ( + "bytes" "context" "crypto/tls" + "encoding/base64" "encoding/json" "fmt" "net" @@ -185,9 +187,12 @@ type Proxy struct { AlgenevaAddr string - WaterAddr string - WaterWASM string - WaterTransport string + // deprecated: use WaterWASMAvailableAt + WaterWASM string + WaterWASMAvailableAt string + WaterWASMHashsum string + WaterTransport string + WaterAddr string throttleConfig throttle.Config instrument instrument.Instrument @@ -988,7 +993,31 @@ func (p *Proxy) listenAlgeneva(baseListen func(string) (net.Listener, error)) li // Currently water doesn't support customized TCP connections and we need to listen and receive requests directly from the WATER listener func (p *Proxy) listenWATER(addr string) (net.Listener, error) { ctx := context.Background() - waterListener, err := water.NewWATERListener(ctx, p.WaterTransport, addr, p.WaterWASM) + var wasm []byte + if p.WaterWASM != "" { + var err error + wasm, err = base64.StdEncoding.DecodeString(p.WaterWASM) + if err != nil { + log.Errorf("failed to decode WASM base64: %v", err) + return nil, err + } + } + + if p.WaterWASMAvailableAt != "" { + wasmBuffer := new(bytes.Buffer) + err := water.NewWASMDownloader( + water.WithURLs(strings.Split(p.WaterWASMAvailableAt, ",")), + water.WithExpectedHashsum(p.WaterWASMHashsum), + water.WithHTTPClient(&http.Client{Timeout: 10 * time.Second}), + ).DownloadWASM(wasmBuffer) + if err != nil { + return nil, fmt.Errorf("unable to download water wasm: %v", err) + } + wasm = wasmBuffer.Bytes() + } + + // currently the WATER listener doesn't accept a multiplexed connections, so we need to listen and accept connections directly from the listener + waterListener, err := water.NewWATERListener(ctx, nil, p.WaterTransport, addr, wasm) if err != nil { return nil, err } diff --git a/water/downloader.go b/water/downloader.go new file mode 100644 index 00000000..298129c7 --- /dev/null +++ b/water/downloader.go @@ -0,0 +1,122 @@ +package water + +import ( + "bytes" + "context" + "crypto/sha256" + "errors" + "fmt" + "io" + "net/http" + "strings" +) + +//go:generate mockgen -destination=mock_downloader.go -package=water . WASMDownloader + +type WASMDownloader interface { + DownloadWASM(context.Context, io.Writer) error +} + +type downloader struct { + urls []string + httpClient *http.Client + expectedHashSum string + httpDownloader WASMDownloader +} + +type DownloaderOption func(*downloader) + +func WithURLs(urls []string) DownloaderOption { + return func(d *downloader) { + d.urls = urls + } +} + +func WithHTTPClient(httpClient *http.Client) DownloaderOption { + return func(d *downloader) { + d.httpClient = httpClient + } +} + +func WithExpectedHashsum(hashsum string) DownloaderOption { + return func(d *downloader) { + d.expectedHashSum = hashsum + } +} + +func WithHTTPDownloader(httpDownloader WASMDownloader) DownloaderOption { + return func(d *downloader) { + d.httpDownloader = httpDownloader + } +} + +// NewWASMDownloader creates a new WASMDownloader instance. +func NewWASMDownloader(withOpts ...DownloaderOption) WASMDownloader { + downloader := new(downloader) + for _, opt := range withOpts { + opt(downloader) + } + return downloader +} + +// DownloadWASM downloads the WASM file from the given URLs, verifies the hash +// sum and writes the file to the given writer. +func (d *downloader) DownloadWASM(ctx context.Context, w io.Writer) error { + joinedErrs := errors.New("failed to download WASM from all URLs") + for _, url := range d.urls { + if strings.HasPrefix(url, "magnet:?") { + // Skip magnetic links for now + joinedErrs = errors.Join(joinedErrs, errors.New("magentic links are not supported")) + continue + } + tempBuffer := &bytes.Buffer{} + err := d.downloadWASM(ctx, tempBuffer, url) + if err != nil { + joinedErrs = errors.Join(joinedErrs, err) + continue + } + + err = d.verifyHashSum(tempBuffer.Bytes()) + if err != nil { + joinedErrs = errors.Join(joinedErrs, err) + continue + } + + _, err = tempBuffer.WriteTo(w) + if err != nil { + joinedErrs = errors.Join(joinedErrs, err) + continue + } + + return nil + } + return joinedErrs +} + +// downloadWASM checks what kind of URL was given and downloads the WASM file +// from the URL. It can be a HTTPS URL or a magnetic link. +func (d *downloader) downloadWASM(ctx context.Context, w io.Writer, url string) error { + switch { + case strings.HasPrefix(url, "http://"), strings.HasPrefix(url, "https://"): + if d.httpDownloader == nil { + d.httpDownloader = NewHTTPSDownloader(d.httpClient, url) + } + return d.httpDownloader.DownloadWASM(ctx, w) + default: + return fmt.Errorf("unsupported protocol: %s", url) + } +} + +var ErrFailedToVerifyHashSum = errors.New("failed to verify hash sum") + +func (d *downloader) verifyHashSum(data []byte) error { + sha256Hashsum := sha256.Sum256(data) + if d.expectedHashSum == "" { + return nil + } + + if d.expectedHashSum != fmt.Sprintf("%x", sha256Hashsum) { + return ErrFailedToVerifyHashSum + } + return nil +} diff --git a/water/downloader_test.go b/water/downloader_test.go new file mode 100644 index 00000000..aa2c5e0a --- /dev/null +++ b/water/downloader_test.go @@ -0,0 +1,154 @@ +package water + +import ( + "bytes" + "context" + "io" + "net/http" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + gomock "go.uber.org/mock/gomock" +) + +func TestDownloaderWithOptions(t *testing.T) { + var tests = []struct { + name string + givenOptions []DownloaderOption + assert func(*testing.T, *downloader) + }{ + { + name: "no options", + assert: func(t *testing.T, d *downloader) { + assert.Empty(t, d.urls) + assert.Nil(t, d.httpClient) + assert.Empty(t, d.expectedHashSum) + }, + }, + { + name: "with URLs", + givenOptions: []DownloaderOption{ + WithURLs([]string{"http://example.com"}), + }, + assert: func(t *testing.T, d *downloader) { + assert.Equal(t, []string{"http://example.com"}, d.urls) + assert.Nil(t, d.httpClient) + assert.Empty(t, d.expectedHashSum) + }, + }, + { + name: "with HTTP client", + givenOptions: []DownloaderOption{ + WithHTTPClient(http.DefaultClient), + }, + assert: func(t *testing.T, d *downloader) { + assert.Empty(t, d.urls) + assert.Equal(t, http.DefaultClient, d.httpClient) + assert.Empty(t, d.expectedHashSum) + }, + }, + { + name: "with expected hashsum", + givenOptions: []DownloaderOption{ + WithExpectedHashsum("hashsum"), + }, + assert: func(t *testing.T, d *downloader) { + assert.Empty(t, d.urls) + assert.Nil(t, d.httpClient) + assert.Equal(t, "hashsum", d.expectedHashSum) + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + tt.assert(t, NewWASMDownloader(tt.givenOptions...).(*downloader)) + }) + } +} + +func TestDownloadWASM(t *testing.T) { + ctx := context.Background() + var tests = []struct { + name string + givenHTTPClient *http.Client + givenURLs []string + givenExpectedHashSum string + givenWriter io.Writer + setupHTTPDownloader func(ctrl *gomock.Controller) WASMDownloader + assert func(*testing.T, io.Reader, error) + }{ + { + name: "no URLs", + assert: func(t *testing.T, r io.Reader, err error) { + b, berr := io.ReadAll(r) + require.NoError(t, berr) + assert.Empty(t, b) + assert.Error(t, err) + assert.ErrorContains(t, err, "failed to download WASM from all URLs") + }, + }, + { + name: "magnetic links are skipped", + givenURLs: []string{"magnet:?"}, + assert: func(t *testing.T, r io.Reader, err error) { + b, berr := io.ReadAll(r) + require.NoError(t, berr) + assert.Empty(t, b) + assert.Error(t, err) + assert.ErrorContains(t, err, "magentic links are not supported") + }, + }, + { + name: "udp urls are unsupported", + givenURLs: []string{ + "udp://example.com", + }, + assert: func(t *testing.T, r io.Reader, err error) { + b, berr := io.ReadAll(r) + require.NoError(t, berr) + assert.Empty(t, b) + assert.Error(t, err) + assert.ErrorContains(t, err, "unsupported protocol") + }, + }, + { + name: "http download error", + givenURLs: []string{ + "http://example.com", + }, + setupHTTPDownloader: func(ctrl *gomock.Controller) WASMDownloader { + httpDownloader := NewMockWASMDownloader(ctrl) + httpDownloader.EXPECT().DownloadWASM(ctx, gomock.Any()).Return(assert.AnError) + return httpDownloader + }, + assert: func(t *testing.T, r io.Reader, err error) { + b, berr := io.ReadAll(r) + require.NoError(t, berr) + assert.Empty(t, b) + assert.Error(t, err) + assert.ErrorContains(t, err, assert.AnError.Error()) + assert.ErrorContains(t, err, "failed to download WASM from all URLs") + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + var httpDownloader WASMDownloader + if tt.setupHTTPDownloader != nil { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + httpDownloader = tt.setupHTTPDownloader(ctrl) + } + + b := &bytes.Buffer{} + err := NewWASMDownloader( + WithExpectedHashsum(tt.givenExpectedHashSum), + WithHTTPClient(tt.givenHTTPClient), + WithURLs(tt.givenURLs), + WithHTTPDownloader(httpDownloader)). + DownloadWASM(ctx, b) + tt.assert(t, b, err) + }) + } +} diff --git a/water/https_downloader.go b/water/https_downloader.go new file mode 100644 index 00000000..63e8fdf4 --- /dev/null +++ b/water/https_downloader.go @@ -0,0 +1,44 @@ +package water + +import ( + "context" + "fmt" + "io" + "net/http" +) + +type httpsDownloader struct { + cli *http.Client + url string +} + +func NewHTTPSDownloader(client *http.Client, url string) WASMDownloader { + return &httpsDownloader{cli: client, url: url} +} + +func (d *httpsDownloader) DownloadWASM(ctx context.Context, w io.Writer) error { + if d.cli == nil { + d.cli = http.DefaultClient + } + + req, err := http.NewRequestWithContext(ctx, http.MethodGet, d.url, http.NoBody) + if err != nil { + return fmt.Errorf("failed to create a new HTTP request: %w", err) + } + resp, err := d.cli.Do(req) + if err != nil { + return fmt.Errorf("failed to send a HTTP request: %w", err) + } + defer resp.Body.Close() + + if resp.StatusCode != http.StatusOK { + return fmt.Errorf("failed to download WASM file: %s", resp.Status) + } + + _, err = io.Copy(w, resp.Body) + if err != nil { + return fmt.Errorf("failed to write the WASM file: %w", err) + } + + return nil +} diff --git a/water/listener.go b/water/listener.go index 3d6b86f7..71aa04ab 100644 --- a/water/listener.go +++ b/water/listener.go @@ -2,7 +2,6 @@ package water import ( "context" - "encoding/base64" "log/slog" "net" @@ -15,17 +14,14 @@ var log = golog.LoggerFor("water") // NewWATERListener creates a WATER listener // Currently water doesn't support customized TCP connections and we need to listen and receive requests directly from the WATER listener -func NewWATERListener(ctx context.Context, transport, address, wasm string) (net.Listener, error) { - decodedWASM, err := base64.StdEncoding.DecodeString(wasm) - if err != nil { - log.Errorf("failed to decode WASM base64: %v", err) - return nil, err +func NewWATERListener(ctx context.Context, baseListener net.Listener, transport, address string, wasm []byte) (net.Listener, error) { + cfg := &water.Config{ + TransportModuleBin: wasm, + OverrideLogger: slog.New(newLogHandler(log, transport)), } - cfg := &water.Config{ - TransportModuleBin: decodedWASM, - //NetworkListener: baseListener, - OverrideLogger: slog.New(newLogHandler(log, transport)), + if baseListener != nil { + cfg.NetworkListener = baseListener } waterListener, err := cfg.ListenContext(ctx, "tcp", address) diff --git a/water/listener_test.go b/water/listener_test.go index 26a997e1..e13544ee 100644 --- a/water/listener_test.go +++ b/water/listener_test.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "embed" - "encoding/base64" "io" "net" "testing" @@ -25,15 +24,13 @@ func TestWATERListener(t *testing.T) { wasm, err := io.ReadAll(f) require.Nil(t, err) - b64WASM := base64.StdEncoding.EncodeToString(wasm) - ctx := context.Background() cfg := &water.Config{ TransportModuleBin: wasm, } - ll, err := NewWATERListener(ctx, "reverse_v0", "127.0.0.1:3000", b64WASM) + ll, err := NewWATERListener(ctx, nil, "reverse_v0", "127.0.0.1:3000", wasm) require.Nil(t, err) messageRequest := "hello" diff --git a/water/mock_downloader.go b/water/mock_downloader.go new file mode 100644 index 00000000..42e69df1 --- /dev/null +++ b/water/mock_downloader.go @@ -0,0 +1,55 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/getlantern/http-proxy-lantern/v2/water (interfaces: WASMDownloader) +// +// Generated by this command: +// +// mockgen -destination=mock_downloader.go -package=water . WASMDownloader +// + +// Package water is a generated GoMock package. +package water + +import ( + context "context" + io "io" + reflect "reflect" + + gomock "go.uber.org/mock/gomock" +) + +// MockWASMDownloader is a mock of WASMDownloader interface. +type MockWASMDownloader struct { + ctrl *gomock.Controller + recorder *MockWASMDownloaderMockRecorder +} + +// MockWASMDownloaderMockRecorder is the mock recorder for MockWASMDownloader. +type MockWASMDownloaderMockRecorder struct { + mock *MockWASMDownloader +} + +// NewMockWASMDownloader creates a new mock instance. +func NewMockWASMDownloader(ctrl *gomock.Controller) *MockWASMDownloader { + mock := &MockWASMDownloader{ctrl: ctrl} + mock.recorder = &MockWASMDownloaderMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockWASMDownloader) EXPECT() *MockWASMDownloaderMockRecorder { + return m.recorder +} + +// DownloadWASM mocks base method. +func (m *MockWASMDownloader) DownloadWASM(arg0 context.Context, arg1 io.Writer) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DownloadWASM", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 +} + +// DownloadWASM indicates an expected call of DownloadWASM. +func (mr *MockWASMDownloaderMockRecorder) DownloadWASM(arg0, arg1 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DownloadWASM", reflect.TypeOf((*MockWASMDownloader)(nil).DownloadWASM), arg0, arg1) +} From 023f73970f0132f1353e11d9ba89bd52e5bb8295 Mon Sep 17 00:00:00 2001 From: WendelHime <6754291+WendelHime@users.noreply.github.com> Date: Tue, 8 Oct 2024 11:59:41 -0300 Subject: [PATCH 02/16] chore: adding more unit tests --- water/downloader.go | 6 +---- water/downloader_test.go | 50 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/water/downloader.go b/water/downloader.go index 298129c7..4036847a 100644 --- a/water/downloader.go +++ b/water/downloader.go @@ -111,11 +111,7 @@ var ErrFailedToVerifyHashSum = errors.New("failed to verify hash sum") func (d *downloader) verifyHashSum(data []byte) error { sha256Hashsum := sha256.Sum256(data) - if d.expectedHashSum == "" { - return nil - } - - if d.expectedHashSum != fmt.Sprintf("%x", sha256Hashsum) { + if d.expectedHashSum == "" || !bytes.Equal(sha256Hashsum[:], []byte(d.expectedHashSum)) { return ErrFailedToVerifyHashSum } return nil diff --git a/water/downloader_test.go b/water/downloader_test.go index aa2c5e0a..dac8aca9 100644 --- a/water/downloader_test.go +++ b/water/downloader_test.go @@ -3,6 +3,7 @@ package water import ( "bytes" "context" + "crypto/sha256" "io" "net/http" "testing" @@ -69,6 +70,10 @@ func TestDownloaderWithOptions(t *testing.T) { func TestDownloadWASM(t *testing.T) { ctx := context.Background() + + contentMessage := "content" + hashsum := sha256.Sum256([]byte("content")) + contentHashsum := string(hashsum[:]) var tests = []struct { name string givenHTTPClient *http.Client @@ -131,6 +136,51 @@ func TestDownloadWASM(t *testing.T) { assert.ErrorContains(t, err, "failed to download WASM from all URLs") }, }, + { + name: "hashsum verification error", + givenURLs: []string{ + "http://example.com", + }, + givenExpectedHashSum: "hashsum", + setupHTTPDownloader: func(ctrl *gomock.Controller) WASMDownloader { + httpDownloader := NewMockWASMDownloader(ctrl) + httpDownloader.EXPECT().DownloadWASM(ctx, gomock.Any()).DoAndReturn( + func(ctx context.Context, w io.Writer) error { + _, err := w.Write([]byte(contentMessage)) + return err + }) + return httpDownloader + }, + assert: func(t *testing.T, r io.Reader, err error) { + b, berr := io.ReadAll(r) + require.NoError(t, berr) + assert.Empty(t, b) + assert.Error(t, err) + assert.ErrorContains(t, err, "failed to verify hash sum") + }, + }, + { + name: "success", + givenURLs: []string{ + "http://example.com", + }, + givenExpectedHashSum: contentHashsum, + setupHTTPDownloader: func(ctrl *gomock.Controller) WASMDownloader { + httpDownloader := NewMockWASMDownloader(ctrl) + httpDownloader.EXPECT().DownloadWASM(ctx, gomock.Any()).DoAndReturn( + func(ctx context.Context, w io.Writer) error { + _, err := w.Write([]byte(contentMessage)) + return err + }) + return httpDownloader + }, + assert: func(t *testing.T, r io.Reader, err error) { + b, berr := io.ReadAll(r) + require.NoError(t, berr) + assert.NoError(t, err) + assert.Equal(t, contentMessage, string(b)) + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { From 3b85462b797468cafeb77fe95ce8efb4fcf2b755 Mon Sep 17 00:00:00 2001 From: WendelHime <6754291+WendelHime@users.noreply.github.com> Date: Tue, 8 Oct 2024 12:02:51 -0300 Subject: [PATCH 03/16] chore: adding forgotten ctx --- http_proxy.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/http_proxy.go b/http_proxy.go index 9d9e5c9d..cfdc666f 100644 --- a/http_proxy.go +++ b/http_proxy.go @@ -1009,7 +1009,7 @@ func (p *Proxy) listenWATER(addr string) (net.Listener, error) { water.WithURLs(strings.Split(p.WaterWASMAvailableAt, ",")), water.WithExpectedHashsum(p.WaterWASMHashsum), water.WithHTTPClient(&http.Client{Timeout: 10 * time.Second}), - ).DownloadWASM(wasmBuffer) + ).DownloadWASM(ctx, wasmBuffer) if err != nil { return nil, fmt.Errorf("unable to download water wasm: %v", err) } From 387e5d889714c1ae8d966899f2d4f36d135b5f4a Mon Sep 17 00:00:00 2001 From: WendelHime <6754291+WendelHime@users.noreply.github.com> Date: Tue, 8 Oct 2024 14:25:17 -0300 Subject: [PATCH 04/16] chore: adding http downloader test --- water/https_downloader_test.go | 90 ++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 water/https_downloader_test.go diff --git a/water/https_downloader_test.go b/water/https_downloader_test.go new file mode 100644 index 00000000..68bfb631 --- /dev/null +++ b/water/https_downloader_test.go @@ -0,0 +1,90 @@ +package water + +import ( + "bytes" + "context" + "io" + "net/http" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +type roundTripFunc struct { + f func(req *http.Request) (*http.Response, error) +} + +func (f *roundTripFunc) RoundTrip(req *http.Request) (*http.Response, error) { + return f.f(req) +} + +func TestHTTPSDownloadWASM(t *testing.T) { + ctx := context.Background() + var tests = []struct { + name string + givenHTTPClient *http.Client + givenURL string + assert func(*testing.T, io.Reader, error) + }{ + { + name: "sending request successfully", + givenHTTPClient: &http.Client{ + Transport: &roundTripFunc{ + f: func(req *http.Request) (*http.Response, error) { + return &http.Response{ + StatusCode: http.StatusOK, + Body: io.NopCloser(bytes.NewBufferString("wasm")), + }, nil + }, + }, + }, + givenURL: "https://example.com/wasm.wasm", + assert: func(t *testing.T, r io.Reader, err error) { + assert.NoError(t, err) + b, err := io.ReadAll(r) + require.NoError(t, err) + assert.Equal(t, "wasm", string(b)) + }, + }, + { + name: "when receiving an error from the HTTP client, it should return an error", + givenHTTPClient: &http.Client{ + Transport: &roundTripFunc{ + f: func(req *http.Request) (*http.Response, error) { + return nil, assert.AnError + }, + }, + }, + givenURL: "https://example.com/wasm.wasm", + assert: func(t *testing.T, r io.Reader, err error) { + assert.Error(t, err) + assert.Contains(t, err.Error(), "failed to send a HTTP request") + }, + }, + { + name: "when the HTTP status code is not 200, it should return an error", + givenHTTPClient: &http.Client{ + Transport: &roundTripFunc{ + f: func(req *http.Request) (*http.Response, error) { + return &http.Response{ + StatusCode: http.StatusNotFound, + }, nil + }, + }, + }, + givenURL: "https://example.com/wasm.wasm", + assert: func(t *testing.T, r io.Reader, err error) { + assert.Error(t, err) + assert.Contains(t, err.Error(), "failed to download WASM file") + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + b := new(bytes.Buffer) + err := NewHTTPSDownloader(tt.givenHTTPClient, tt.givenURL).DownloadWASM(ctx, b) + tt.assert(t, b, err) + }) + } +} From c308895ec22e4d5ceb6f490ec78e17b4a96eb454 Mon Sep 17 00:00:00 2001 From: WendelHime <6754291+WendelHime@users.noreply.github.com> Date: Wed, 9 Oct 2024 10:16:31 -0300 Subject: [PATCH 05/16] fix: replacing magnetic references by magnet --- water/downloader.go | 4 ++-- water/downloader_test.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/water/downloader.go b/water/downloader.go index 4036847a..17f578c1 100644 --- a/water/downloader.go +++ b/water/downloader.go @@ -65,7 +65,7 @@ func (d *downloader) DownloadWASM(ctx context.Context, w io.Writer) error { joinedErrs := errors.New("failed to download WASM from all URLs") for _, url := range d.urls { if strings.HasPrefix(url, "magnet:?") { - // Skip magnetic links for now + // Skip magnet links for now joinedErrs = errors.Join(joinedErrs, errors.New("magentic links are not supported")) continue } @@ -94,7 +94,7 @@ func (d *downloader) DownloadWASM(ctx context.Context, w io.Writer) error { } // downloadWASM checks what kind of URL was given and downloads the WASM file -// from the URL. It can be a HTTPS URL or a magnetic link. +// from the URL. It can be a HTTPS URL or a magnet link. func (d *downloader) downloadWASM(ctx context.Context, w io.Writer, url string) error { switch { case strings.HasPrefix(url, "http://"), strings.HasPrefix(url, "https://"): diff --git a/water/downloader_test.go b/water/downloader_test.go index dac8aca9..afbe2225 100644 --- a/water/downloader_test.go +++ b/water/downloader_test.go @@ -72,7 +72,7 @@ func TestDownloadWASM(t *testing.T) { ctx := context.Background() contentMessage := "content" - hashsum := sha256.Sum256([]byte("content")) + hashsum := sha256.Sum256([]byte(contentMessage)) contentHashsum := string(hashsum[:]) var tests = []struct { name string @@ -94,14 +94,14 @@ func TestDownloadWASM(t *testing.T) { }, }, { - name: "magnetic links are skipped", + name: "magnet links are skipped", givenURLs: []string{"magnet:?"}, assert: func(t *testing.T, r io.Reader, err error) { b, berr := io.ReadAll(r) require.NoError(t, berr) assert.Empty(t, b) assert.Error(t, err) - assert.ErrorContains(t, err, "magentic links are not supported") + assert.ErrorContains(t, err, "magnet links are not supported") }, }, { From 158d7dadca4a0c57b146c859925b0d21a325f1a7 Mon Sep 17 00:00:00 2001 From: WendelHime <6754291+WendelHime@users.noreply.github.com> Date: Wed, 9 Oct 2024 10:32:46 -0300 Subject: [PATCH 06/16] fix: replacing magnetic references by magnet --- water/downloader.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/water/downloader.go b/water/downloader.go index 17f578c1..7bb0fec0 100644 --- a/water/downloader.go +++ b/water/downloader.go @@ -66,7 +66,7 @@ func (d *downloader) DownloadWASM(ctx context.Context, w io.Writer) error { for _, url := range d.urls { if strings.HasPrefix(url, "magnet:?") { // Skip magnet links for now - joinedErrs = errors.Join(joinedErrs, errors.New("magentic links are not supported")) + joinedErrs = errors.Join(joinedErrs, errors.New("magent links are not supported")) continue } tempBuffer := &bytes.Buffer{} From c1e11455488e74b93262c3a95dd5de1bc060e220 Mon Sep 17 00:00:00 2001 From: WendelHime <6754291+WendelHime@users.noreply.github.com> Date: Wed, 9 Oct 2024 10:39:21 -0300 Subject: [PATCH 07/16] fix: typo --- water/downloader.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/water/downloader.go b/water/downloader.go index 7bb0fec0..5ed42d1e 100644 --- a/water/downloader.go +++ b/water/downloader.go @@ -66,7 +66,7 @@ func (d *downloader) DownloadWASM(ctx context.Context, w io.Writer) error { for _, url := range d.urls { if strings.HasPrefix(url, "magnet:?") { // Skip magnet links for now - joinedErrs = errors.Join(joinedErrs, errors.New("magent links are not supported")) + joinedErrs = errors.Join(joinedErrs, errors.New("magnet links are not supported")) continue } tempBuffer := &bytes.Buffer{} From fe2e519611c58c5c818a2e2be7d49bc1057ad6f9 Mon Sep 17 00:00:00 2001 From: WendelHime <6754291+WendelHime@users.noreply.github.com> Date: Wed, 9 Oct 2024 17:12:13 -0300 Subject: [PATCH 08/16] fix: updating the way we're comparing hashes --- water/downloader.go | 2 +- water/downloader_test.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/water/downloader.go b/water/downloader.go index 5ed42d1e..399ad081 100644 --- a/water/downloader.go +++ b/water/downloader.go @@ -111,7 +111,7 @@ var ErrFailedToVerifyHashSum = errors.New("failed to verify hash sum") func (d *downloader) verifyHashSum(data []byte) error { sha256Hashsum := sha256.Sum256(data) - if d.expectedHashSum == "" || !bytes.Equal(sha256Hashsum[:], []byte(d.expectedHashSum)) { + if d.expectedHashSum == "" || d.expectedHashSum != fmt.Sprintf("%x", sha256Hashsum[:]) { return ErrFailedToVerifyHashSum } return nil diff --git a/water/downloader_test.go b/water/downloader_test.go index afbe2225..a23b91e4 100644 --- a/water/downloader_test.go +++ b/water/downloader_test.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "crypto/sha256" + "fmt" "io" "net/http" "testing" @@ -73,7 +74,7 @@ func TestDownloadWASM(t *testing.T) { contentMessage := "content" hashsum := sha256.Sum256([]byte(contentMessage)) - contentHashsum := string(hashsum[:]) + contentHashsum := fmt.Sprintf("%x", hashsum[:]) var tests = []struct { name string givenHTTPClient *http.Client From 81d9b679d0918001aebd152b7bdff2cd33d51b59 Mon Sep 17 00:00:00 2001 From: WendelHime <6754291+WendelHime@users.noreply.github.com> Date: Thu, 10 Oct 2024 16:36:49 -0300 Subject: [PATCH 09/16] chore: increasing timeout for retrieving WASM --- http_proxy.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/http_proxy.go b/http_proxy.go index cfdc666f..640bf4db 100644 --- a/http_proxy.go +++ b/http_proxy.go @@ -1008,7 +1008,7 @@ func (p *Proxy) listenWATER(addr string) (net.Listener, error) { err := water.NewWASMDownloader( water.WithURLs(strings.Split(p.WaterWASMAvailableAt, ",")), water.WithExpectedHashsum(p.WaterWASMHashsum), - water.WithHTTPClient(&http.Client{Timeout: 10 * time.Second}), + water.WithHTTPClient(&http.Client{Timeout: 1 * time.Minute}), ).DownloadWASM(ctx, wasmBuffer) if err != nil { return nil, fmt.Errorf("unable to download water wasm: %v", err) From 45be0575dfb9d726f6dc52c009d4b6e5bada2580 Mon Sep 17 00:00:00 2001 From: WendelHime <6754291+WendelHime@users.noreply.github.com> Date: Wed, 16 Oct 2024 12:41:43 -0300 Subject: [PATCH 10/16] fix: replace fmt Errorf by log.Errorf and use %w instead of %v --- http_proxy.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/http_proxy.go b/http_proxy.go index 640bf4db..64bdd3ef 100644 --- a/http_proxy.go +++ b/http_proxy.go @@ -1011,7 +1011,7 @@ func (p *Proxy) listenWATER(addr string) (net.Listener, error) { water.WithHTTPClient(&http.Client{Timeout: 1 * time.Minute}), ).DownloadWASM(ctx, wasmBuffer) if err != nil { - return nil, fmt.Errorf("unable to download water wasm: %v", err) + return nil, log.Errorf("unable to download water wasm: %w", err) } wasm = wasmBuffer.Bytes() } @@ -1019,6 +1019,7 @@ func (p *Proxy) listenWATER(addr string) (net.Listener, error) { // currently the WATER listener doesn't accept a multiplexed connections, so we need to listen and accept connections directly from the listener waterListener, err := water.NewWATERListener(ctx, nil, p.WaterTransport, addr, wasm) if err != nil { + log.Errorf("failed to starte WATER listener: %w", err) return nil, err } From a6347048c509e7e48f3db5dae2369edb05cde61e Mon Sep 17 00:00:00 2001 From: WendelHime <6754291+WendelHime@users.noreply.github.com> Date: Wed, 16 Oct 2024 13:20:14 -0300 Subject: [PATCH 11/16] fix: create wasm downloader by receiving specified parameters instead of options --- water/downloader.go | 63 ++++---------------- water/downloader_test.go | 125 ++++++++++----------------------------- 2 files changed, 43 insertions(+), 145 deletions(-) diff --git a/water/downloader.go b/water/downloader.go index 399ad081..35f0e556 100644 --- a/water/downloader.go +++ b/water/downloader.go @@ -3,9 +3,7 @@ package water import ( "bytes" "context" - "crypto/sha256" "errors" - "fmt" "io" "net/http" "strings" @@ -18,45 +16,22 @@ type WASMDownloader interface { } type downloader struct { - urls []string - httpClient *http.Client - expectedHashSum string - httpDownloader WASMDownloader + urls []string + httpClient *http.Client + httpDownloader WASMDownloader } type DownloaderOption func(*downloader) -func WithURLs(urls []string) DownloaderOption { - return func(d *downloader) { - d.urls = urls - } -} - -func WithHTTPClient(httpClient *http.Client) DownloaderOption { - return func(d *downloader) { - d.httpClient = httpClient - } -} - -func WithExpectedHashsum(hashsum string) DownloaderOption { - return func(d *downloader) { - d.expectedHashSum = hashsum - } -} - -func WithHTTPDownloader(httpDownloader WASMDownloader) DownloaderOption { - return func(d *downloader) { - d.httpDownloader = httpDownloader - } -} - // NewWASMDownloader creates a new WASMDownloader instance. -func NewWASMDownloader(withOpts ...DownloaderOption) WASMDownloader { - downloader := new(downloader) - for _, opt := range withOpts { - opt(downloader) +func NewWASMDownloader(urls []string, client *http.Client) (WASMDownloader, error) { + if len(urls) == 0 { + return nil, log.Error("WASM downloader requires URLs to download but received empty list") } - return downloader + return &downloader{ + urls: urls, + httpClient: client, + }, nil } // DownloadWASM downloads the WASM file from the given URLs, verifies the hash @@ -76,12 +51,6 @@ func (d *downloader) DownloadWASM(ctx context.Context, w io.Writer) error { continue } - err = d.verifyHashSum(tempBuffer.Bytes()) - if err != nil { - joinedErrs = errors.Join(joinedErrs, err) - continue - } - _, err = tempBuffer.WriteTo(w) if err != nil { joinedErrs = errors.Join(joinedErrs, err) @@ -103,16 +72,6 @@ func (d *downloader) downloadWASM(ctx context.Context, w io.Writer, url string) } return d.httpDownloader.DownloadWASM(ctx, w) default: - return fmt.Errorf("unsupported protocol: %s", url) - } -} - -var ErrFailedToVerifyHashSum = errors.New("failed to verify hash sum") - -func (d *downloader) verifyHashSum(data []byte) error { - sha256Hashsum := sha256.Sum256(data) - if d.expectedHashSum == "" || d.expectedHashSum != fmt.Sprintf("%x", sha256Hashsum[:]) { - return ErrFailedToVerifyHashSum + return log.Errorf("unsupported protocol: %s", url) } - return nil } diff --git a/water/downloader_test.go b/water/downloader_test.go index a23b91e4..320c9d57 100644 --- a/water/downloader_test.go +++ b/water/downloader_test.go @@ -3,8 +3,6 @@ package water import ( "bytes" "context" - "crypto/sha256" - "fmt" "io" "net/http" "testing" @@ -14,57 +12,37 @@ import ( gomock "go.uber.org/mock/gomock" ) -func TestDownloaderWithOptions(t *testing.T) { +func TestNewWASMDownloader(t *testing.T) { var tests = []struct { - name string - givenOptions []DownloaderOption - assert func(*testing.T, *downloader) + name string + givenURLs []string + givenHTTPClient *http.Client + givenOptions []DownloaderOption + assert func(*testing.T, WASMDownloader, error) }{ { - name: "no options", - assert: func(t *testing.T, d *downloader) { - assert.Empty(t, d.urls) - assert.Nil(t, d.httpClient) - assert.Empty(t, d.expectedHashSum) + name: "it should return an error when providing an empty list of URLs", + assert: func(t *testing.T, d WASMDownloader, err error) { + assert.Error(t, err) + assert.Nil(t, d) }, }, { - name: "with URLs", - givenOptions: []DownloaderOption{ - WithURLs([]string{"http://example.com"}), - }, - assert: func(t *testing.T, d *downloader) { + name: "it should successfully return a wasm downloader", + givenURLs: []string{"http://example.com"}, + givenHTTPClient: http.DefaultClient, + assert: func(t *testing.T, wDownloader WASMDownloader, err error) { + assert.NoError(t, err) + d := wDownloader.(*downloader) assert.Equal(t, []string{"http://example.com"}, d.urls) - assert.Nil(t, d.httpClient) - assert.Empty(t, d.expectedHashSum) - }, - }, - { - name: "with HTTP client", - givenOptions: []DownloaderOption{ - WithHTTPClient(http.DefaultClient), - }, - assert: func(t *testing.T, d *downloader) { - assert.Empty(t, d.urls) assert.Equal(t, http.DefaultClient, d.httpClient) - assert.Empty(t, d.expectedHashSum) - }, - }, - { - name: "with expected hashsum", - givenOptions: []DownloaderOption{ - WithExpectedHashsum("hashsum"), - }, - assert: func(t *testing.T, d *downloader) { - assert.Empty(t, d.urls) - assert.Nil(t, d.httpClient) - assert.Equal(t, "hashsum", d.expectedHashSum) }, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - tt.assert(t, NewWASMDownloader(tt.givenOptions...).(*downloader)) + d, err := NewWASMDownloader(tt.givenURLs, tt.givenHTTPClient) + tt.assert(t, d, err) }) } } @@ -73,29 +51,16 @@ func TestDownloadWASM(t *testing.T) { ctx := context.Background() contentMessage := "content" - hashsum := sha256.Sum256([]byte(contentMessage)) - contentHashsum := fmt.Sprintf("%x", hashsum[:]) var tests = []struct { - name string - givenHTTPClient *http.Client - givenURLs []string - givenExpectedHashSum string - givenWriter io.Writer - setupHTTPDownloader func(ctrl *gomock.Controller) WASMDownloader - assert func(*testing.T, io.Reader, error) + name string + givenHTTPClient *http.Client + givenURLs []string + givenWriter io.Writer + setupHTTPDownloader func(ctrl *gomock.Controller) WASMDownloader + assert func(*testing.T, io.Reader, error) }{ { - name: "no URLs", - assert: func(t *testing.T, r io.Reader, err error) { - b, berr := io.ReadAll(r) - require.NoError(t, berr) - assert.Empty(t, b) - assert.Error(t, err) - assert.ErrorContains(t, err, "failed to download WASM from all URLs") - }, - }, - { - name: "magnet links are skipped", + name: "it should return an error telling magnet links are not supported", givenURLs: []string{"magnet:?"}, assert: func(t *testing.T, r io.Reader, err error) { b, berr := io.ReadAll(r) @@ -106,7 +71,7 @@ func TestDownloadWASM(t *testing.T) { }, }, { - name: "udp urls are unsupported", + name: "it should return an unupported protocol error when we provide an URL with not implemented downloader", givenURLs: []string{ "udp://example.com", }, @@ -119,7 +84,7 @@ func TestDownloadWASM(t *testing.T) { }, }, { - name: "http download error", + name: "it should return an error with the HTTP error", givenURLs: []string{ "http://example.com", }, @@ -138,34 +103,10 @@ func TestDownloadWASM(t *testing.T) { }, }, { - name: "hashsum verification error", - givenURLs: []string{ - "http://example.com", - }, - givenExpectedHashSum: "hashsum", - setupHTTPDownloader: func(ctrl *gomock.Controller) WASMDownloader { - httpDownloader := NewMockWASMDownloader(ctrl) - httpDownloader.EXPECT().DownloadWASM(ctx, gomock.Any()).DoAndReturn( - func(ctx context.Context, w io.Writer) error { - _, err := w.Write([]byte(contentMessage)) - return err - }) - return httpDownloader - }, - assert: func(t *testing.T, r io.Reader, err error) { - b, berr := io.ReadAll(r) - require.NoError(t, berr) - assert.Empty(t, b) - assert.Error(t, err) - assert.ErrorContains(t, err, "failed to verify hash sum") - }, - }, - { - name: "success", + name: "it should return an io.Reader with the expected content", givenURLs: []string{ "http://example.com", }, - givenExpectedHashSum: contentHashsum, setupHTTPDownloader: func(ctrl *gomock.Controller) WASMDownloader { httpDownloader := NewMockWASMDownloader(ctrl) httpDownloader.EXPECT().DownloadWASM(ctx, gomock.Any()).DoAndReturn( @@ -193,12 +134,10 @@ func TestDownloadWASM(t *testing.T) { } b := &bytes.Buffer{} - err := NewWASMDownloader( - WithExpectedHashsum(tt.givenExpectedHashSum), - WithHTTPClient(tt.givenHTTPClient), - WithURLs(tt.givenURLs), - WithHTTPDownloader(httpDownloader)). - DownloadWASM(ctx, b) + wDownloader, err := NewWASMDownloader(tt.givenURLs, tt.givenHTTPClient) + require.NoError(t, err) + wDownloader.(*downloader).httpDownloader = httpDownloader + err = wDownloader.DownloadWASM(ctx, b) tt.assert(t, b, err) }) } From a6b8c172678cd084070a0d9236165474830feca6 Mon Sep 17 00:00:00 2001 From: WendelHime <6754291+WendelHime@users.noreply.github.com> Date: Wed, 16 Oct 2024 13:22:09 -0300 Subject: [PATCH 12/16] fix: update wasm downloader reference --- http_proxy.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/http_proxy.go b/http_proxy.go index 64bdd3ef..c185388a 100644 --- a/http_proxy.go +++ b/http_proxy.go @@ -1005,11 +1005,12 @@ func (p *Proxy) listenWATER(addr string) (net.Listener, error) { if p.WaterWASMAvailableAt != "" { wasmBuffer := new(bytes.Buffer) - err := water.NewWASMDownloader( - water.WithURLs(strings.Split(p.WaterWASMAvailableAt, ",")), - water.WithExpectedHashsum(p.WaterWASMHashsum), - water.WithHTTPClient(&http.Client{Timeout: 1 * time.Minute}), - ).DownloadWASM(ctx, wasmBuffer) + d, err := water.NewWASMDownloader(strings.Split(p.WaterWASMAvailableAt, ","), &http.Client{Timeout: 1 * time.Minute}) + if err != nil { + return nil, log.Errorf("failed to create wasm downloader: %w", err) + } + + err = d.DownloadWASM(ctx, wasmBuffer) if err != nil { return nil, log.Errorf("unable to download water wasm: %w", err) } From e167a29aff52656799bc818c36399b067c17600c Mon Sep 17 00:00:00 2001 From: WendelHime <6754291+WendelHime@users.noreply.github.com> Date: Wed, 16 Oct 2024 13:25:56 -0300 Subject: [PATCH 13/16] fix: generate mocks at mocks_test.go --- water/downloader.go | 2 +- water/{mock_downloader.go => mocks_test.go} | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) rename water/{mock_downloader.go => mocks_test.go} (91%) diff --git a/water/downloader.go b/water/downloader.go index 35f0e556..278ce527 100644 --- a/water/downloader.go +++ b/water/downloader.go @@ -9,7 +9,7 @@ import ( "strings" ) -//go:generate mockgen -destination=mock_downloader.go -package=water . WASMDownloader +//go:generate mockgen -package=chained -destination=mocks_test.go . WASMDownloader type WASMDownloader interface { DownloadWASM(context.Context, io.Writer) error diff --git a/water/mock_downloader.go b/water/mocks_test.go similarity index 91% rename from water/mock_downloader.go rename to water/mocks_test.go index 42e69df1..db347e0f 100644 --- a/water/mock_downloader.go +++ b/water/mocks_test.go @@ -3,11 +3,11 @@ // // Generated by this command: // -// mockgen -destination=mock_downloader.go -package=water . WASMDownloader +// mockgen -package=chained -destination=mocks_test.go . WASMDownloader // -// Package water is a generated GoMock package. -package water +// Package chained is a generated GoMock package. +package chained import ( context "context" From 506230477421af533e91e6059f607b138951b907 Mon Sep 17 00:00:00 2001 From: WendelHime <6754291+WendelHime@users.noreply.github.com> Date: Wed, 16 Oct 2024 13:31:26 -0300 Subject: [PATCH 14/16] fix: update mocks package --- water/downloader.go | 2 +- water/mocks_test.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/water/downloader.go b/water/downloader.go index 278ce527..05b176b3 100644 --- a/water/downloader.go +++ b/water/downloader.go @@ -9,7 +9,7 @@ import ( "strings" ) -//go:generate mockgen -package=chained -destination=mocks_test.go . WASMDownloader +//go:generate mockgen -package=water -destination=mocks_test.go . WASMDownloader type WASMDownloader interface { DownloadWASM(context.Context, io.Writer) error diff --git a/water/mocks_test.go b/water/mocks_test.go index db347e0f..80635f90 100644 --- a/water/mocks_test.go +++ b/water/mocks_test.go @@ -3,11 +3,11 @@ // // Generated by this command: // -// mockgen -package=chained -destination=mocks_test.go . WASMDownloader +// mockgen -package=water -destination=mocks_test.go . WASMDownloader // -// Package chained is a generated GoMock package. -package chained +// Package water is a generated GoMock package. +package water import ( context "context" From a20bf5c38f22813f8ba5aafb38d183ff8ac22ed2 Mon Sep 17 00:00:00 2001 From: WendelHime <6754291+WendelHime@users.noreply.github.com> Date: Wed, 16 Oct 2024 13:38:50 -0300 Subject: [PATCH 15/16] fix: removing downloader options leftover --- water/downloader.go | 2 -- water/downloader_test.go | 1 - 2 files changed, 3 deletions(-) diff --git a/water/downloader.go b/water/downloader.go index 05b176b3..151ed7eb 100644 --- a/water/downloader.go +++ b/water/downloader.go @@ -21,8 +21,6 @@ type downloader struct { httpDownloader WASMDownloader } -type DownloaderOption func(*downloader) - // NewWASMDownloader creates a new WASMDownloader instance. func NewWASMDownloader(urls []string, client *http.Client) (WASMDownloader, error) { if len(urls) == 0 { diff --git a/water/downloader_test.go b/water/downloader_test.go index 320c9d57..94e1519a 100644 --- a/water/downloader_test.go +++ b/water/downloader_test.go @@ -17,7 +17,6 @@ func TestNewWASMDownloader(t *testing.T) { name string givenURLs []string givenHTTPClient *http.Client - givenOptions []DownloaderOption assert func(*testing.T, WASMDownloader, error) }{ { From 3b4cfb8bb727bb4a8b593106db45d5f231a6bc2e Mon Sep 17 00:00:00 2001 From: WendelHime <6754291+WendelHime@users.noreply.github.com> Date: Tue, 22 Oct 2024 10:17:53 -0300 Subject: [PATCH 16/16] chore: removing unused hashsum --- http-proxy/main.go | 2 -- http_proxy.go | 1 - 2 files changed, 3 deletions(-) diff --git a/http-proxy/main.go b/http-proxy/main.go index aa5adf8b..4697deb1 100644 --- a/http-proxy/main.go +++ b/http-proxy/main.go @@ -189,7 +189,6 @@ var ( waterAddr = flag.String("water-addr", "", "Address at which to listen for WATER connections.") waterWASM = flag.String("water-wasm", "", "Base64 encoded WASM for WATER") waterWASMAvailableAt = flag.String("water-wasm-available-at", "", "URLs where the WATER WASM is available") - waterWASMHashsum = flag.String("water-wasm-hashsum", "", "Hashsum of the WATER WASM") waterTransport = flag.String("water-transport", "", "WATER based transport name") track = flag.String("track", "", "The track this proxy is running on") @@ -476,7 +475,6 @@ func main() { WaterAddr: *waterAddr, WaterWASM: *waterWASM, WaterWASMAvailableAt: *waterWASMAvailableAt, - WaterWASMHashsum: *waterWASMHashsum, WaterTransport: *waterTransport, } if *maxmindLicenseKey != "" { diff --git a/http_proxy.go b/http_proxy.go index c185388a..47aa49a3 100644 --- a/http_proxy.go +++ b/http_proxy.go @@ -190,7 +190,6 @@ type Proxy struct { // deprecated: use WaterWASMAvailableAt WaterWASM string WaterWASMAvailableAt string - WaterWASMHashsum string WaterTransport string WaterAddr string