-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ca5cc83
Showing
9 changed files
with
790 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Loadbalanceeeer | ||
|
||
PoC local JSON-RPC load-balancer with opt-in anonymizer via Tor | ||
|
||
## Why | ||
|
||
Distribute RPC requests across different RPC providers and eventually use a proxy for privacy purposes | ||
|
||
## How use it | ||
|
||
- Install [Docker](https://docs.docker.com/get-docker/) | ||
|
||
- Clone the repo | ||
|
||
- Edit `rpc.txt` with your RPCs (currently some public examples from [Ethereum Nodes](https://ethereumnodes.com/)) | ||
|
||
- For only load balancing, run `docker-compose up -f docker-compose.yml` | ||
|
||
- For more privacy, run `docker-compose up -f docker-compose.yml -f docker-compose.proxy.yml` | ||
|
||
- You get your new RPC at `http://localhost:9545` | ||
|
||
## Architecture | ||
|
||
Only Load Balancing | ||
|
||
``` | ||
=> remote_rpc_1 | ||
| | ||
user => (localhost:9545) - ... | ||
| | ||
=> remote_rpc_N | ||
``` | ||
|
||
With Anonymizer/Proxy | ||
|
||
``` | ||
=> remote_rpc_1 | ||
| | ||
user => (localhost:9545) => (tor/proxy) - ... | ||
| | ||
=> remote_rpc_N | ||
``` | ||
|
||
## Disclaimer | ||
|
||
This is only to demonstrate how to load balance request across multiple providers and how tunnel them via a proxy for analysis, debugging (e.g. mitmproxy) and privacy purposes. | ||
|
||
Use at your own risks. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
services: | ||
tor-socks: | ||
image: peterdavehello/tor-socks-proxy:latest | ||
ports: | ||
- "9150:9150" | ||
lb: | ||
environment: | ||
- PROXY=socks5://tor-socks:9150 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
services: | ||
lb: | ||
image: lb | ||
build: ./lb | ||
ports: | ||
- "9545:5000" | ||
env_file: | ||
- rpc.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# syntax=docker/dockerfile:1 | ||
|
||
FROM python:3 | ||
|
||
WORKDIR /app | ||
|
||
COPY requirements.txt requirements.txt | ||
RUN pip3 install -r requirements.txt | ||
|
||
COPY . . | ||
|
||
CMD [ "python3", "-m" , "flask", "run", "--host=0.0.0.0"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from flask import Flask, request | ||
from flask_cors import CORS | ||
from requests import post | ||
import os | ||
import random | ||
import logging | ||
|
||
logging.basicConfig(level=logging.INFO) | ||
|
||
api = Flask(__name__) | ||
CORS(api) | ||
|
||
rpcs = os.environ['RPCS'].split(',') | ||
api.logger.info('RPCs: %s', rpcs) | ||
|
||
proxies = {} | ||
if "PROXY" in os.environ: | ||
proxies['http'] = os.environ['PROXY'] | ||
proxies['https'] = os.environ['PROXY'] | ||
|
||
api.logger.info('Proxies: %s', proxies) | ||
|
||
@api.route('/', methods=['POST']) | ||
def proxy(): | ||
random_rpc = random.choice(rpcs) | ||
api.logger.info('Used RPC: ' + random_rpc) | ||
proxy_req = post(random_rpc, json=request.json, proxies=proxies) | ||
print(proxy_req.text) | ||
return proxy_req.json() | ||
|
||
if __name__ == '__main__': | ||
api.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
requests | ||
pysocks | ||
flask | ||
flask-cors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
RPCS=https://eth-mainnet.nodereal.io/v1/1659dfb40aa24bbb8153a677b98064d7,https://cloudflare-eth.com/ |