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

(OraklNode) Implement proxy for websocket fetchers #2206

Merged
merged 1 commit into from
Aug 23, 2024
Merged
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
19 changes: 18 additions & 1 deletion node/pkg/websocketfetcher/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package websocketfetcher
import (
"context"
"errors"
"fmt"
"os"
"sync"
"time"
Expand Down Expand Up @@ -106,14 +107,20 @@ type App struct {
chainReader *websocketchainreader.ChainReader
latestFeedDataMap *types.LatestFeedDataMap
feedDataDumpChannel chan *common.FeedData
proxies []types.Proxy
}

func New() *App {
return &App{}
}

func (a *App) Init(ctx context.Context, opts ...AppOption) error {
// TODO: Proxy support
proxies, err := db.QueryRows[types.Proxy](ctx, "SELECT * FROM proxies", nil)
if err != nil {
return err
}
a.proxies = proxies

cexFactories := map[string]func(context.Context, ...common.FetcherOption) (common.FetcherInterface, error){
"binance": binance.New,
"coinbase": coinbase.New,
Expand Down Expand Up @@ -195,7 +202,14 @@ func (a *App) initializeCex(ctx context.Context, appConfig AppConfig) error {
a.buffer = make(chan *common.FeedData, appConfig.BufferSize)
a.storeInterval = appConfig.StoreInterval

index := 0
for name, factory := range appConfig.CexFactories {
proxyUrl := ""
if len(a.proxies) != 0 {
proxy := a.proxies[index%len(a.proxies)]
proxyUrl = fmt.Sprintf("%s://%s:%d", proxy.Protocol, proxy.Host, proxy.Port)
}

if _, ok := feedMap[name]; !ok {
log.Warn().Msgf("no feeds for %s", name)
continue
Expand All @@ -204,12 +218,15 @@ func (a *App) initializeCex(ctx context.Context, appConfig AppConfig) error {
ctx,
common.WithFeedDataBuffer(a.buffer),
common.WithFeedMaps(feedMap[name]),
common.WithProxy(proxyUrl),
)
if err != nil {
log.Error().Err(err).Msgf("error in creating %s fetcher", name)
return err
}
a.fetchers = append(a.fetchers, fetcher)

index++
}
return nil
}
Expand Down