From 89c0e16379c0059f4fd067054249414956736c90 Mon Sep 17 00:00:00 2001 From: Cyberes Date: Fri, 12 Apr 2024 18:34:47 -0600 Subject: [PATCH] update documentation --- .gitignore | 2 -- README.md | 25 ++++++++++++------------- loadbalancer.service | 5 ++--- src/proxy/handleConnect.go | 13 +++++++++---- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index 0bd7aa2..328e614 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,6 @@ config.py dist/ -test.go config.yml config.yaml @@ -167,4 +166,3 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ - diff --git a/README.md b/README.md index 37a03a5..12a56ac 100644 --- a/README.md +++ b/README.md @@ -2,27 +2,26 @@ _A round-robin load balancer for HTTP proxies._ -does not support downstream https servers. +This is a simple proxy load balancer that will route requests to a cluster of proxy backends in a round-robin fashion. +This makes it easy to connect your clients to a large number of proxy servers without worrying about implementing +anything special clientside. -This is a simple load balancer using [proxy.py](https://github.com/abhinavsingh/proxy.py) that will route requests to a -cluster of proxy backends in a round-robin fashion. This makes it easy to connect your clients to a large number of -proxy -servers without worrying about implementing anything special clientside. +HTTPS proxy servers are not supported. ## Install -1. `pip install -r requirements.txt` -2. Copy `proxy-skeleton/app/config.py.example` to `proxy-skeleton/app/config.py` and fill in your config details. -3. Deploy the `canihazip` https://git.evulid.cc/cyberes/canihazip and start it. +1. Download the latest release from [/releases](https://git.evulid.cc/cyberes/proxy-loadbalancer/releases) or run `./build.sh` to build the program locally. +2. `cp config.example.yml config.yml` +3. Edit the config. +4. Start the loadbalancer with `./proxy-loadbalancer --config [path to your config.yml]` -## Use +You can run your own "public IP delivery server" `canihazip` or use the default `api.ipify.org` -To start the load balancer server, navigate to `./proxy-skeleton` and run `python3 -m app`. The systemd service -`loadbalancer.service` is provided as a service example. +An example systemd service `loadbalancer.service` is provided. ## Special Headers The load balancer accepts special headers to control its behavior. -- `Smartproxy-Bypass`: don't use any SmartProxy endpoints. -- `Smartproxy-Disable-BV3HI`: don't filter SmartProxy endpoints by the 503 connect error. +- `Thirdparty-Bypass`: don't use any third-party endpoints for this request. +- `Thirdparty-Include-Broken`: use all online endpoints for this request, including third-party ones that failed the special test. diff --git a/loadbalancer.service b/loadbalancer.service index 545fd4c..f726559 100644 --- a/loadbalancer.service +++ b/loadbalancer.service @@ -1,13 +1,12 @@ [Unit] -Description=Proxy Load Distributor +Description=Proxy Load Balancer After=network.target [Service] SyslogIdentifier=proxy-loadbalancer User=loadbalancer Group=loadbalancer -WorkingDirectory=/srv/loadbalancer/proxy-loadbalancer/proxy-skeleton -ExecStart=/srv/loadbalancer/proxy-loadbalancer/venv/bin/python -m app +ExecStart=/srv/loadbalancer/proxy-loadbalancer --config /etc/proxy-loadbalancer/config.yml Restart=always [Install] diff --git a/src/proxy/handleConnect.go b/src/proxy/handleConnect.go index 6398a6c..fd752fa 100644 --- a/src/proxy/handleConnect.go +++ b/src/proxy/handleConnect.go @@ -13,6 +13,11 @@ import ( "slices" ) +var ( + HeaderThirdpartyIncludeBroken = "Thirdparty-Include-Broken" + HeaderThirdpartyBypass = "Thirdparty-Bypass" +) + func (p *ForwardProxyCluster) validateRequestAndGetProxy(w http.ResponseWriter, req *http.Request) (string, string, string, string, *url.URL, error) { if p.BalancerOnline.GetCount() != 0 { errStr := "balancer is not ready" @@ -29,10 +34,10 @@ func (p *ForwardProxyCluster) validateRequestAndGetProxy(w http.ResponseWriter, return "", "", "", "", nil, errors.New(errStr) } - headerIncludeBrokenThirdparty := req.Header.Get("Thirdparty-Include-Broken") - req.Header.Del("Thirdparty-Include-Broken") - headerBypassThirdparty := req.Header.Get("Thirdparty-Bypass") - req.Header.Del("Thirdparty-Bypass") + headerIncludeBrokenThirdparty := req.Header.Get(HeaderThirdpartyIncludeBroken) + req.Header.Del(HeaderThirdpartyIncludeBroken) + headerBypassThirdparty := req.Header.Get(HeaderThirdpartyBypass) + req.Header.Del(HeaderThirdpartyBypass) if headerBypassThirdparty != "" && headerIncludeBrokenThirdparty != "" { errStr := "duplicate options headers detected, rejecting request" http.Error(w, errStr, http.StatusBadRequest)