From c55612ebee3790e232bbe521b2492876e85de771 Mon Sep 17 00:00:00 2001 From: nick Date: Sat, 2 Nov 2024 12:46:46 +0900 Subject: [PATCH 1/2] feat: ws proxy --- node/pkg/websocketfetcher/app.go | 5 ++++- node/pkg/wss/utils.go | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/node/pkg/websocketfetcher/app.go b/node/pkg/websocketfetcher/app.go index ac9aa2cfb..a078decf4 100644 --- a/node/pkg/websocketfetcher/app.go +++ b/node/pkg/websocketfetcher/app.go @@ -115,7 +115,7 @@ func New() *App { } func (a *App) Init(ctx context.Context, opts ...AppOption) error { - // TODO: Proxy support + cexFactories := map[string]func(context.Context, ...common.FetcherOption) (common.FetcherInterface, error){ "binance": binance.New, "coinbase": coinbase.New, @@ -198,6 +198,8 @@ func (a *App) initializeCex(ctx context.Context, appConfig AppConfig) error { a.buffer = make(chan *common.FeedData, appConfig.BufferSize) a.storeInterval = appConfig.StoreInterval + wsProxy := os.Getenv("WS_PROXY") + for name, factory := range appConfig.CexFactories { if _, ok := feedMap[name]; !ok { log.Warn().Msgf("no feeds for %s", name) @@ -207,6 +209,7 @@ func (a *App) initializeCex(ctx context.Context, appConfig AppConfig) error { ctx, common.WithFeedDataBuffer(a.buffer), common.WithFeedMaps(feedMap[name]), + common.WithProxy(wsProxy), ) if err != nil { log.Error().Err(err).Msgf("error in creating %s fetcher", name) diff --git a/node/pkg/wss/utils.go b/node/pkg/wss/utils.go index 314b41a97..7e6970233 100644 --- a/node/pkg/wss/utils.go +++ b/node/pkg/wss/utils.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" "net/url" + "strings" "time" "bisonai.com/miko/node/pkg/utils/retrier" @@ -16,6 +17,10 @@ import ( func (ws *WebsocketHelper) Dial(ctx context.Context) error { dialOption := &websocket.DialOptions{} if ws.Proxy != "" { + if strings.HasPrefix(ws.Endpoint, "wss") { + ws.Endpoint = strings.Replace(ws.Endpoint, "wss", "ws", 1) + } + proxyURL, err := url.Parse(ws.Proxy) if err != nil { return err From 56b7ba5ecab71c0a0761b6f764e77beab54b4137 Mon Sep 17 00:00:00 2001 From: nick Date: Sat, 2 Nov 2024 12:50:08 +0900 Subject: [PATCH 2/2] fix: remove unused type --- node/pkg/websocketfetcher/common/type.go | 1 - 1 file changed, 1 deletion(-) diff --git a/node/pkg/websocketfetcher/common/type.go b/node/pkg/websocketfetcher/common/type.go index 9cce71e09..6fe3683a6 100644 --- a/node/pkg/websocketfetcher/common/type.go +++ b/node/pkg/websocketfetcher/common/type.go @@ -23,7 +23,6 @@ const ( VolumeFetchTimeout = 6 * time.Second ) -type Proxy = types.Proxy type Feed = types.Feed type FeedData = types.FeedData