Added proxy support

Some IPv6 traffic still sending directly to instance
not sure why not
This commit is contained in:
farhan 2021-01-30 07:12:37 +00:00
parent 2f9e0f85e4
commit cd8ecce807
2 changed files with 20 additions and 1 deletions

View File

@ -26,6 +26,11 @@ func main() {
runninginstances = make(map[string]RunningInstance)
getSettings()
if len(settings.Proxies) > 0 {
for i := 0; i < len(settings.Proxies); i++ {
logInfo.Printf("Using proxy: %s:%d", settings.Proxies[i].Host, settings.Proxies[i].Port)
}
}
go startpprof()
pool = getDbPool()

View File

@ -4,9 +4,12 @@ import (
"encoding/json"
"io/ioutil"
"net/http"
"net/url"
"math/rand"
"strings"
"time"
"net"
"fmt"
)
func DoTries(o *RunningInstance, req *http.Request) (*http.Response, error) {
@ -28,7 +31,7 @@ func DoTries(o *RunningInstance, req *http.Request) (*http.Response, error) {
func BuildClient(endpoint string) http.Client {
tr := &http.Transport{
MaxIdleConns: 10,
MaxIdleConns: 2,
IdleConnTimeout: 3600 * time.Second,
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
@ -38,6 +41,17 @@ func BuildClient(endpoint string) http.Client {
}
client := http.Client{Transport: tr}
if len(settings.Proxies) >= 1 {
rand.Seed(time.Now().Unix())
ridx := rand.Intn(len(settings.Proxies))
proxyuri := fmt.Sprintf("socks5://%s:%d", settings.Proxies[ridx].Host, settings.Proxies[ridx].Port)
proxy, err := url.Parse(proxyuri)
if err != nil {
logFatal.Fatal("Error: ", err)
}
tr.Proxy = http.ProxyURL(proxy)
}
return client
}