Add use_tor boolean to envvars

This commit is contained in:
Reckless_Satoshi 2022-08-08 08:58:06 -07:00
parent d73b05f76c
commit 5281176e3c
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
5 changed files with 11 additions and 10 deletions

View File

@ -21,6 +21,7 @@ POSTGRES_HOST='127.0.0.1'
POSTGRES_PORT='5432'
# Tor proxy for remote calls (e.g. fetching prices or sending Telegram messages)
USE_TOR=True
TOR_PROXY='127.0.0.1:9050'
# Auto unlock LND password. Only used in development docker-compose environment.

View File

@ -1,6 +1,4 @@
from datetime import timedelta
from tkinter import N, ON
from tokenize import Octnumber
from django.utils import timezone
from api.lightning.node import LNNode
from django.db.models import Q, Sum

View File

@ -2,7 +2,7 @@ from django.core.management.base import BaseCommand, CommandError
from api.models import Profile
from api.messages import Telegram
from api.utils import get_tor_session
from api.utils import get_session
from decouple import config
import requests
import time
@ -15,7 +15,7 @@ class Command(BaseCommand):
bot_token = config('TELEGRAM_TOKEN')
updates_url = f'https://api.telegram.org/bot{bot_token}/getUpdates'
session = get_tor_session()
session = get_session()
telegram = Telegram()
def handle(self, *args, **options):
"""Infinite loop to check for telegram updates.

View File

@ -1,13 +1,13 @@
from decouple import config
from secrets import token_urlsafe
from api.models import Order
from api.utils import get_tor_session
from api.utils import get_session
import time
class Telegram():
''' Simple telegram messages by requesting to API'''
session = get_tor_session()
session = get_session()
def get_context(user):
"""returns context needed to enable TG notifications"""

View File

@ -10,10 +10,12 @@ from api.models import Order
logger = logging.getLogger('api.utils')
TOR_PROXY = config('TOR_PROXY', default='127.0.0.1:9050')
USE_TOR = config('USE_TOR', cast=bool, default=True)
def get_tor_session():
def get_session():
session = requests.session()
# Tor uses the 9050 port as the default socks port
if USE_TOR:
session.proxies = {'http': 'socks5://' + TOR_PROXY,
'https': 'socks5://' + TOR_PROXY}
return session
@ -70,7 +72,7 @@ def get_exchange_rates(currencies):
Returns the median price list.
"""
session = get_tor_session()
session = get_session()
APIS = config("MARKET_PRICE_APIS",
cast=lambda v: [s.strip() for s in v.split(",")])