From f5cd0ebf154fd59347ebf4dca13dce4b137331ce Mon Sep 17 00:00:00 2001 From: lza_menace Date: Fri, 19 Nov 2021 15:29:38 -0800 Subject: [PATCH] setting up i2p option --- Dockerfile-i2pd | 15 +++++++++++++++ docker-compose.yaml | 8 ++++++++ xmrnodes/app.py | 8 +++++++- xmrnodes/config.example.py | 2 ++ xmrnodes/helpers.py | 12 ++++++++++++ xmrnodes/models.py | 1 + xmrnodes/static/images/i2p.svg | 3 +++ 7 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 Dockerfile-i2pd create mode 100644 xmrnodes/static/images/i2p.svg diff --git a/Dockerfile-i2pd b/Dockerfile-i2pd new file mode 100644 index 0000000..6acd111 --- /dev/null +++ b/Dockerfile-i2pd @@ -0,0 +1,15 @@ +FROM ubuntu:20.04 + +RUN apt-get update && apt-get install i2pd -y + +RUN mkdir -p /run/i2pd \ + && chown -R i2pd:i2pd /run/i2pd \ + && chmod 700 -R /run/i2pd + +USER i2pd + +EXPOSE 4447 +EXPOSE 11744 +EXPOSE 4444 + +ENTRYPOINT ["i2pd", "--socksproxy.address=0.0.0.0", "--httpproxy.address=0.0.0.0"] diff --git a/docker-compose.yaml b/docker-compose.yaml index 101f0c9..257d890 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -8,3 +8,11 @@ services: restart: unless-stopped ports: - 127.0.0.1:9050:9050 + i2pd: + container_name: i2p + build: + context: . + dockerfile: Dockerfile-i2pd + restart: unless-stopped + ports: + - 127.0.0.1:4447:4447 diff --git a/xmrnodes/app.py b/xmrnodes/app.py index f5cba84..ea50b43 100644 --- a/xmrnodes/app.py +++ b/xmrnodes/app.py @@ -14,7 +14,7 @@ from flask import Flask, request, redirect, jsonify from flask import render_template, flash, url_for from urllib.parse import urlparse -from xmrnodes.helpers import determine_crypto, is_onion, make_request +from xmrnodes.helpers import determine_crypto, is_onion, is_b32, make_request from xmrnodes.helpers import retrieve_peers, rw_cache from xmrnodes.forms import SubmitNode from xmrnodes.models import Node, HealthCheck, Peer @@ -36,6 +36,7 @@ def index(): nettype = request.args.get("nettype", "mainnet") crypto = request.args.get("crypto", "monero") onion = request.args.get("onion", False) + i2p = request.args.get("i2p", False) nodes = Node.select().where( Node.validated==True ).where( @@ -47,6 +48,8 @@ def index(): ) if onion: nodes = nodes.where(Node.is_tor==True) + if i2p: + nodes = nodes.where(Node.is_i2p==True) nodes = [n for n in nodes] shuffle(nodes) @@ -255,6 +258,7 @@ def validate(): node.datetime_checked = now node.crypto = crypto node.is_tor = is_onion(node.url) + node.is_i2p = is_b32(node.url) node.save() else: logging.info("unexpected nettype") @@ -272,6 +276,8 @@ def validate(): node.delete_instance() except Exception as e: logging.info("failed for reasons unknown") + if app.debug: + logging.info(e) node.delete_instance() @app.cli.command("export") diff --git a/xmrnodes/config.example.py b/xmrnodes/config.example.py index daa0ca7..146d376 100644 --- a/xmrnodes/config.example.py +++ b/xmrnodes/config.example.py @@ -6,3 +6,5 @@ TOR_HOST = os.environ.get('TOR_HOST', '127.0.0.1') TOR_PORT = os.environ.get('TOR_PORT', 9050) NODE_HOST = os.environ.get('NODE_HOST', '127.0.0.1') NODE_PORT = os.environ.get('NODE_PORT', 18080) +I2P_HOST = os.environ.get('I2P_HOST', '127.0.0.1') +I2P_PORT = os.environ.get('I2P_PORT', 4447) diff --git a/xmrnodes/helpers.py b/xmrnodes/helpers.py index 3a087e6..e8ea813 100644 --- a/xmrnodes/helpers.py +++ b/xmrnodes/helpers.py @@ -16,6 +16,9 @@ def make_request(url: str, path="/get_info", data=None): if is_onion(url): proxies = {"http": f"socks5h://{config.TOR_HOST}:{config.TOR_PORT}"} timeout = 18 + elif is_b32(url): + proxies = {"http": f"socks5h://{config.I2P_HOST}:{config.I2P_PORT}"} + timeout = 18 else: proxies = None timeout = 6 @@ -58,6 +61,15 @@ def is_onion(url: str): else: return False +def is_b32(url: str): + _split = url.split(":") + if len(_split) < 2: + return False + if _split[1].endswith(".i2p"): + return True + else: + return False + # Use hacky filesystem cache since i dont feel like shipping redis def rw_cache(key_name, data=None): pickle_file = path.join(config.DATA_DIR, f'{key_name}.pkl') diff --git a/xmrnodes/models.py b/xmrnodes/models.py index cabcd74..a3a8639 100644 --- a/xmrnodes/models.py +++ b/xmrnodes/models.py @@ -12,6 +12,7 @@ class Node(Model): id = AutoField() url = CharField(unique=True) is_tor = BooleanField(default=False) + is_i2p = BooleanField(default=False) available = BooleanField(default=False) validated = BooleanField(default=False) nettype = CharField(null=True) diff --git a/xmrnodes/static/images/i2p.svg b/xmrnodes/static/images/i2p.svg new file mode 100644 index 0000000..8ccc55a --- /dev/null +++ b/xmrnodes/static/images/i2p.svg @@ -0,0 +1,3 @@ +i2p icon + +