aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorterminaldweller <devi@terminaldweller.com>2023-05-09 19:47:26 +0000
committerterminaldweller <devi@terminaldweller.com>2023-05-09 19:47:26 +0000
commit057a0e1076068ebb20c987f2e9aebe96a8e550ec (patch)
tree03968aa21f735b791362e5b30fdd482de874f455
parentwe no longer need to change the cert names manually (diff)
downloadhived-057a0e1076068ebb20c987f2e9aebe96a8e550ec.tar.gz
hived-057a0e1076068ebb20c987f2e9aebe96a8e550ec.zip
using the simpler proxyfromenv function from the stdlib
Diffstat (limited to '')
-rw-r--r--arbiter/arbiter.go24
-rw-r--r--docker-compose-test.yaml6
-rw-r--r--hived/hived.go23
3 files changed, 5 insertions, 48 deletions
diff --git a/arbiter/arbiter.go b/arbiter/arbiter.go
index a9ce43d..8e2c999 100644
--- a/arbiter/arbiter.go
+++ b/arbiter/arbiter.go
@@ -6,9 +6,7 @@ import (
"encoding/json"
"errors"
"flag"
- "fmt"
"io"
- "net"
"net/http"
"net/url"
"os"
@@ -21,7 +19,6 @@ import (
"github.com/gorilla/mux"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
- "golang.org/x/net/proxy"
)
var (
@@ -87,28 +84,9 @@ type errorChanStruct struct {
}
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, fmt.Errorf("[GetProxiedClient] : %w", err)
- }
-
- dialContext := func(ctx context.Context, network, address string) (net.Conn, error) {
- netConn, err := dialer.Dial(network, address)
- if err == nil {
- return netConn, nil
- }
-
- return netConn, fmt.Errorf("[dialContext] : %w", err)
- }
-
transport := &http.Transport{
- DialContext: dialContext,
DisableKeepAlives: true,
+ Proxy: http.ProxyFromEnvironment,
}
client := &http.Client{
Transport: transport,
diff --git a/docker-compose-test.yaml b/docker-compose-test.yaml
index b0030bc..fa82a35 100644
--- a/docker-compose-test.yaml
+++ b/docker-compose-test.yaml
@@ -21,7 +21,7 @@ services:
- ALL
environment:
- SERVER_DEPLOYMENT_TYPE=test
- - ALL_PROXY=192.168.1.214:9995
+ - HTTPS_PROXY=socks5://192.168.1.214:9995
telebot:
image: telebot
build:
@@ -37,7 +37,7 @@ services:
- ALL
environment:
- SERVER_DEPLOYMENT_TYPE=test
- - ALL_PROXY=192.168.1.214:9995
+ - HTTPS_PROXY=socks5://192.168.1.214:9995
arbiter:
image: arbiter
build:
@@ -51,7 +51,7 @@ services:
- ALL
environment:
- SERVER_DEPLOYMENT_TYPE=test
- - ALL_PROXY=192.168.1.214:9995
+ - HTTPS_PROXY=socks5://192.168.1.214:9995
redis:
image: redis:6.2-alpine
networks:
diff --git a/hived/hived.go b/hived/hived.go
index fccefc7..99ebaa6 100644
--- a/hived/hived.go
+++ b/hived/hived.go
@@ -7,7 +7,6 @@ import (
"errors"
"flag"
"fmt"
- "net"
"net/http"
"net/url"
"os"
@@ -22,7 +21,6 @@ import (
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
pb "github.com/terminaldweller/grpc/telebot/v1"
- "golang.org/x/net/proxy"
"google.golang.org/grpc"
"google.golang.org/protobuf/types/known/timestamppb"
)
@@ -61,28 +59,9 @@ var (
)
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, fmt.Errorf("[GetProxiedClient] : %w", err)
- }
-
- dialContext := func(ctx context.Context, network, address string) (net.Conn, error) {
- netConn, err := dialer.Dial(network, address)
- if err == nil {
- return netConn, nil
- }
-
- return netConn, fmt.Errorf("[dialContext] : %w", err)
- }
-
transport := &http.Transport{
- DialContext: dialContext,
DisableKeepAlives: true,
+ Proxy: http.ProxyFromEnvironment,
}
client := &http.Client{
Transport: transport,