Перевод прокси на multiprocessing и отделение их в proxy.py

main
none 9 months ago
parent 6c611068d5
commit a42b73aefa

@ -18,27 +18,16 @@ if len(argv) == 1:
exit() exit()
print("\nУспешно перезагружено!") print("\nУспешно перезагружено!")
# Порт для приёма всяких запросов
def reverse_proxy(dest, port = 8000):
if name == "posix":
system(f"./bore local {port} --to jetwork.404.mn --port {dest}")
elif name == "nt":
system(f"bore.exe local {port} --to jetwork.404.mn --port {dest}")
from proxy import *
# Стартуем проброс порта
# http сервер
global http_port
http_port = port_gen() http_port = port_gen()
rp_http = Thread(target = reverse_proxy, args=(http_port,)) rp_http = Thread(target = watch_http, args=(http_port,))
rp_http.start() rp_http.start()
print(f"Порт http сервера: {http_port}")
# сервер для пинга
serv_port = port_gen()
rp = Thread(target = reverse_proxy, args=(serv_port, 8001))
rp.start()
print(f"Порт сервера: {serv_port}")
serv_port = port_gen()
rp_serv = Thread(target = watch_serv, args=(serv_port,))
rp_serv.start()
# Стартуем сервисы # Стартуем сервисы

@ -0,0 +1,48 @@
from os import system, name
#from threading import Thread
from multiprocessing import Process
from time import sleep
global http_out ; http_out = None
def proxy_http(port):
global http_out
if name == "posix":
http_out = system(f"./bore local 8000 --to jetwork.404.mn --port {port}")
elif name == "nt":
http_out = system(f"bore local 8000 --to jetwork.404.mn --port {port}")
global serv_out ; serv_out = None
def proxy_serv(port):
global serv_out
if name == "posix":
http_out = system(f"./bore local 8001 --to jetwork.404.mn --port {port}")
elif name == "nt":
http_out = system(f"bore local 8001 --to jetwork.404.mn --port {port}")
def watch_http(port):
run = Process(target=proxy_http, args=(port,))
run.start()
global http_out
while True:
# Если команда вышла
if http_out:
run.terminate()
http_out = None
run = Process(target=proxy_http, args=(port,))
run.start()
sleep(1)
def watch_serv(port):
run = Process(target=proxy_serv, args=(port,))
run.start()
global serv_out
while True:
if serv_out:
run.terminate()
serv_out = None
run = Process(target=proxy_serv, args=(port,))
run.start()
sleep(1)
Loading…
Cancel
Save