diff options
author | terminaldweller <thabogre@gmail.com> | 2023-01-28 20:24:47 +0000 |
---|---|---|
committer | terminaldweller <thabogre@gmail.com> | 2023-01-28 20:24:47 +0000 |
commit | 49e73bd6db0d5947b49fab3f2c17f289b2a14f01 (patch) | |
tree | 37bb04532e33d49d1dbb02bdc5229d933eca7d14 /arbiter | |
parent | hived now caches results. just trying not to exceed our quotas. (diff) | |
download | hived-49e73bd6db0d5947b49fab3f2c17f289b2a14f01.tar.gz hived-49e73bd6db0d5947b49fab3f2c17f289b2a14f01.zip |
added socks5 support for arbiter
Diffstat (limited to 'arbiter')
-rw-r--r-- | arbiter/arbiter.go | 52 | ||||
-rw-r--r-- | arbiter/go.mod | 1 | ||||
-rw-r--r-- | arbiter/go.sum | 6 |
3 files changed, 55 insertions, 4 deletions
diff --git a/arbiter/arbiter.go b/arbiter/arbiter.go index 8fce2be..5168b3a 100644 --- a/arbiter/arbiter.go +++ b/arbiter/arbiter.go @@ -8,6 +8,7 @@ import ( "flag" "fmt" "io/ioutil" + "net" "net/http" "net/url" "os" @@ -20,6 +21,7 @@ import ( "github.com/gorilla/mux" "github.com/rs/zerolog" "github.com/rs/zerolog/log" + "golang.org/x/net/proxy" ) var ( @@ -74,6 +76,28 @@ type errorChanStruct struct { err error } +func GetProxiedClient() (*http.Client, error) { + proxyURL := os.Getenv("ALL_PROXY") + if proxyURL == "" { + proxyURL = os.Getenv("HTTPS_PROXY") + } + dialer, err := proxy.SOCKS5("tcp", proxyURL, nil, proxy.Direct) + if err != nil { + return nil, err + } + dialContext := func(ctx context.Context, network, address string) (net.Conn, error) { + return dialer.Dial(network, address) + } + + transport := &http.Transport{ + DialContext: dialContext, + DisableKeepAlives: true, + } + client := &http.Client{Transport: transport} + + return client, nil +} + // OWASP: https://cheatsheetseries.owasp.org/cheatsheets/REST_Security_Cheat_Sheet.html func addSecureHeaders(w *http.ResponseWriter) { (*w).Header().Set("Cache-Control", "no-store") @@ -84,7 +108,7 @@ func addSecureHeaders(w *http.ResponseWriter) { (*w).Header().Set("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS") } -//binance +// binance func getPriceFromBinance(name, unit string, wg *sync.WaitGroup, priceChan chan<- priceChanStruct, @@ -92,7 +116,7 @@ func getPriceFromBinance(name, unit string, } -//kucoin +// kucoin func getPriceFromKu(name, uni string, wg *sync.WaitGroup, priceChan chan<- priceChanStruct, @@ -111,11 +135,22 @@ func getPriceFromCoinGecko( "vs_currencies=" + url.QueryEscape(unit) path := coingeckoAPIURLv3 + params fmt.Println(path) - resp, err := http.Get(path) + // resp, err := http.Get(path) + client, err := GetProxiedClient() + if err != nil { + priceChan <- priceChanStruct{name: name, price: 0.} + errChan <- errorChanStruct{hasError: true, err: err} + log.Error().Err(err) + return + } + + resp, err := client.Get(path) if err != nil { priceChan <- priceChanStruct{name: name, price: 0.} errChan <- errorChanStruct{hasError: true, err: err} log.Error().Err(err) + fmt.Println(err) + return } defer resp.Body.Close() @@ -152,11 +187,20 @@ func getPriceFromCoinCap( params := "/assets/" + url.QueryEscape(name) path := coincapAPIURLv2 + params fmt.Println(path) - resp, err := http.Get(path) + client, err := GetProxiedClient() + if err != nil { + priceChan <- priceChanStruct{name: name, price: 0.} + errChan <- errorChanStruct{hasError: true, err: err} + log.Error().Err(err) + return + } + // resp, err := http.Get(path) + resp, err := client.Get(path) if err != nil { priceChan <- priceChanStruct{name: name, price: 0.} errChan <- errorChanStruct{hasError: true, err: err} log.Error().Err(err) + return } defer resp.Body.Close() diff --git a/arbiter/go.mod b/arbiter/go.mod index 57b26ac..a0027e0 100644 --- a/arbiter/go.mod +++ b/arbiter/go.mod @@ -6,6 +6,7 @@ require ( github.com/go-redis/redis/v8 v8.11.5 github.com/gorilla/mux v1.8.0 github.com/rs/zerolog v1.27.0 + golang.org/x/net v0.0.0-20210428140749-89ef3d95e781 ) require ( diff --git a/arbiter/go.sum b/arbiter/go.sum index d93030f..cc58061 100644 --- a/arbiter/go.sum +++ b/arbiter/go.sum @@ -21,10 +21,16 @@ github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.27.0 h1:1T7qCieN22GVc8S4Q2yuexzBb1EqjbgjSH9RohbMjKs= github.com/rs/zerolog v1.27.0/go.mod h1:7frBqO0oezxmnO7GF86FY++uy8I0Tk/If5ni1G9Qc0U= golang.org/x/net v0.0.0-20210428140749-89ef3d95e781 h1:DzZ89McO9/gWPsQXS/FVKAlG02ZjaQ6AlZRBimEYOd0= +golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= |