Starting server and forwarding it to onion works

This commit is contained in:
BarsTiger
2023-06-26 00:12:17 +03:00
parent 5719f583bd
commit 3a68723877
18 changed files with 571 additions and 0 deletions

View File

@@ -0,0 +1 @@
pass

View File

@@ -0,0 +1,4 @@
import sys
portable = getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS')

View File

@@ -0,0 +1,61 @@
import os
import sys
import platform
from . import const
def dir_size(start_path):
total_size = 0
for dirpath, dirnames, filenames in os.walk(start_path):
for f in filenames:
fp = os.path.join(dirpath, f)
if not os.path.islink(fp):
total_size += os.path.getsize(fp)
return total_size
def get_resource_path(filename):
application_path = 'resources'
return os.path.join(application_path, filename)
def get_tor_paths():
from ..onion.tor_downloader import download_tor
if platform.system() in ["Linux", "Darwin"]:
tor_path = os.path.join(build_data_dir(), 'tor/tor')
elif platform.system() == "Windows":
tor_path = os.path.join(build_data_dir(), 'tor/tor.exe')
else:
raise "Platform not supported"
if not os.path.isfile(tor_path):
download_tor(dist=build_data_dir())
return tor_path
def build_data_dir():
dragonion_data_dir = 'data'
os.makedirs(dragonion_data_dir, exist_ok=True)
return dragonion_data_dir
def build_tmp_dir():
tmp_dir = os.path.join(build_data_dir(), "tmp")
os.makedirs(tmp_dir, exist_ok=True)
return tmp_dir
def build_persistent_dir():
persistent_dir = os.path.join(build_data_dir(), "persistent")
os.makedirs(persistent_dir, exist_ok=True)
return persistent_dir
def build_tor_data_dir():
tor_dir = os.path.join(build_data_dir(), "tor_data")
os.makedirs(tor_dir, exist_ok=True)
return tor_dir

View File

@@ -0,0 +1,52 @@
import os
import hashlib
import base64
import time
def random_string(num_bytes, output_len=None):
b = os.urandom(num_bytes)
h = hashlib.sha256(b).digest()[:16]
s = base64.b32encode(h).lower().replace(b"=", b"").decode("utf-8")
if not output_len:
return s
return s[:output_len]
def human_readable_filesize(b):
thresh = 1024.0
if b < thresh:
return "{:.1f} B".format(b)
units = ("KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB")
u = 0
b /= thresh
while b >= thresh:
b /= thresh
u += 1
return "{:.1f} {}".format(b, units[u])
def format_seconds(seconds):
days, seconds = divmod(seconds, 86400)
hours, seconds = divmod(seconds, 3600)
minutes, seconds = divmod(seconds, 60)
human_readable = []
if days:
human_readable.append("{:.0f}d".format(days))
if hours:
human_readable.append("{:.0f}h".format(hours))
if minutes:
human_readable.append("{:.0f}m".format(minutes))
if seconds or not human_readable:
human_readable.append("{:.0f}s".format(seconds))
return "".join(human_readable)
def estimated_time_remaining(bytes_downloaded, total_bytes, started):
now = time.time()
time_elapsed = now - started
download_rate = bytes_downloaded / time_elapsed
remaining_bytes = total_bytes - bytes_downloaded
eta = remaining_bytes / download_rate
return format_seconds(eta)