Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ws proxy support #2308

Merged
merged 2 commits into from
Nov 2, 2024
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
5 changes: 4 additions & 1 deletion node/pkg/websocketfetcher/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion node/pkg/websocketfetcher/common/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const (
VolumeFetchTimeout = 6 * time.Second
)

type Proxy = types.Proxy
type Feed = types.Feed
type FeedData = types.FeedData

Expand Down
5 changes: 5 additions & 0 deletions node/pkg/wss/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"net/http"
"net/url"
"strings"
"time"

"bisonai.com/miko/node/pkg/utils/retrier"
Expand All @@ -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
Expand Down