Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gweidart committed Nov 25, 2022
0 parents commit ca5cc83
Show file tree
Hide file tree
Showing 9 changed files with 790 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions README.md
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.
8 changes: 8 additions & 0 deletions docker-compose.proxy.yml
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
8 changes: 8 additions & 0 deletions docker-compose.yml
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
12 changes: 12 additions & 0 deletions lb/Dockerfile
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"]
32 changes: 32 additions & 0 deletions lb/app.py
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()
4 changes: 4 additions & 0 deletions lb/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
requests
pysocks
flask
flask-cors
1 change: 1 addition & 0 deletions rpc.txt
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/

0 comments on commit ca5cc83

Please sign in to comment.