ability to use nodes from tox.chat added
This commit is contained in:
parent
32055050ee
commit
55a127a820
@ -1,83 +1,75 @@
|
|||||||
import random
|
import random
|
||||||
|
import urllib.request
|
||||||
|
from util import log, curr_directory
|
||||||
|
import settings
|
||||||
|
from PyQt5 import QtNetwork, QtCore
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
class Node:
|
class Node:
|
||||||
|
|
||||||
def __init__(self, ip, port, tox_key, rand):
|
def __init__(self, node):
|
||||||
self._ip, self._port, self._tox_key, self.rand = ip, port, tox_key, rand
|
self._ip, self._port, self._tox_key = node['ipv4'], node['port'], node['public_key']
|
||||||
|
self._priority = random.randint(1, 1000000) if node['status_tcp'] and node['status_udp'] else 0
|
||||||
|
|
||||||
|
def get_priority(self):
|
||||||
|
return self._priority
|
||||||
|
|
||||||
|
priority = property(get_priority)
|
||||||
|
|
||||||
def get_data(self):
|
def get_data(self):
|
||||||
return bytes(self._ip, 'utf-8'), self._port, self._tox_key
|
return bytes(self._ip, 'utf-8'), self._port, self._tox_key
|
||||||
|
|
||||||
|
|
||||||
def node_generator():
|
def generate_nodes():
|
||||||
nodes = []
|
with open(curr_directory() + '/nodes.json', 'rt') as fl:
|
||||||
ips = [
|
json_nodes = json.loads(fl.read())['nodes']
|
||||||
"144.76.60.215", "23.226.230.47", "195.154.119.113", "biribiri.org",
|
nodes = map(lambda json_node: Node(json_node), json_nodes)
|
||||||
"46.38.239.179", "178.62.250.138", "130.133.110.14", "104.167.101.29",
|
sorted_nodes = sorted(nodes, key=lambda x: x.priority)[-4:]
|
||||||
"205.185.116.116", "198.98.51.198", "80.232.246.79", "108.61.165.198",
|
for node in sorted_nodes:
|
||||||
"212.71.252.109", "194.249.212.109", "185.25.116.107", "192.99.168.140",
|
yield node.get_data()
|
||||||
"46.101.197.175", "95.215.46.114", "5.189.176.217", "148.251.23.146",
|
|
||||||
"104.223.122.15", "78.47.114.252", "d4rk4.ru", "81.4.110.149",
|
|
||||||
"95.31.20.151", "104.233.104.126", "51.254.84.212", "home.vikingmakt.com.br",
|
def save_nodes(nodes):
|
||||||
"5.135.59.163", "185.58.206.164", "188.244.38.183", "mrflibble.c4.ee",
|
if not nodes:
|
||||||
"82.211.31.116", "128.199.199.197", "103.230.156.174", "91.121.66.124",
|
return
|
||||||
"92.54.84.70", "tox1.privacydragon.me"
|
print('Saving nodes...')
|
||||||
]
|
with open(curr_directory() + '/nodes.json', 'wb') as fl:
|
||||||
ports = [
|
fl.write(nodes)
|
||||||
33445, 33445, 33445, 33445,
|
|
||||||
33445, 33445, 33445, 33445,
|
|
||||||
33445, 33445, 33445, 33445,
|
def download_nodes_list():
|
||||||
33445, 33445, 33445, 33445,
|
url = 'https://nodes.tox.chat/json'
|
||||||
443, 33445, 5190, 2306,
|
s = settings.Settings.get_instance()
|
||||||
33445, 33445, 1813, 33445,
|
if not s['download_nodes_list']:
|
||||||
33445, 33445, 33445, 33445,
|
return
|
||||||
33445, 33445, 33445, 33445,
|
|
||||||
33445, 33445, 33445, 33445,
|
if not s['proxy_type']: # no proxy
|
||||||
33445, 33445
|
try:
|
||||||
]
|
req = urllib.request.Request(url)
|
||||||
ids = [
|
req.add_header('Content-Type', 'application/json')
|
||||||
"04119E835DF3E78BACF0F84235B300546AF8B936F035185E2A8E9E0A67C8924F",
|
response = urllib.request.urlopen(req)
|
||||||
"A09162D68618E742FFBCA1C2C70385E6679604B2D80EA6E84AD0996A1AC8A074",
|
result = response.read()
|
||||||
"E398A69646B8CEACA9F0B84F553726C1C49270558C57DF5F3C368F05A7D71354",
|
save_nodes(result)
|
||||||
"F404ABAA1C99A9D37D61AB54898F56793E1DEF8BD46B1038B9D822E8460FAB67",
|
except Exception as ex:
|
||||||
"F5A1A38EFB6BD3C2C8AF8B10D85F0F89E931704D349F1D0720C3C4059AF2440A",
|
log('TOX nodes loading error: ' + str(ex))
|
||||||
"788236D34978D1D5BD822F0A5BEBD2C53C64CC31CD3149350EE27D4D9A2F9B6B",
|
else: # proxy
|
||||||
"461FA3776EF0FA655F1A05477DF1B3B614F7D6B124F7DB1DD4FE3C08B03B640F",
|
netman = QtNetwork.QNetworkAccessManager()
|
||||||
"5918AC3C06955962A75AD7DF4F80A5D7C34F7DB9E1498D2E0495DE35B3FE8A57",
|
proxy = QtNetwork.QNetworkProxy()
|
||||||
"A179B09749AC826FF01F37A9613F6B57118AE014D4196A0E1105A98F93A54702",
|
proxy.setType(
|
||||||
"1D5A5F2F5D6233058BF0259B09622FB40B482E4FA0931EB8FD3AB8E7BF7DAF6F",
|
QtNetwork.QNetworkProxy.Socks5Proxy if s['proxy_type'] == 2 else QtNetwork.QNetworkProxy.HttpProxy)
|
||||||
"CF6CECA0A14A31717CC8501DA51BE27742B70746956E6676FF423A529F91ED5D",
|
proxy.setHostName(s['proxy_host'])
|
||||||
"8E7D0B859922EF569298B4D261A8CCB5FEA14FB91ED412A7603A585A25698832",
|
proxy.setPort(s['proxy_port'])
|
||||||
"C4CEB8C7AC607C6B374E2E782B3C00EA3A63B80D4910B8649CCACDD19F260819",
|
netman.setProxy(proxy)
|
||||||
"3CEE1F054081E7A011234883BC4FC39F661A55B73637A5AC293DDF1251D9432B",
|
try:
|
||||||
"DA4E4ED4B697F2E9B000EEFE3A34B554ACD3F45F5C96EAEA2516DD7FF9AF7B43",
|
request = QtNetwork.QNetworkRequest()
|
||||||
"6A4D0607A296838434A6A7DDF99F50EF9D60A2C510BBF31FE538A25CB6B4652F",
|
request.setUrl(QtCore.QUrl(url))
|
||||||
"CD133B521159541FB1D326DE9850F5E56A6C724B5B8E5EB5CD8D950408E95707",
|
reply = netman.get(request)
|
||||||
"5823FB947FF24CF83DDFAC3F3BAA18F96EA2018B16CC08429CB97FA502F40C23",
|
|
||||||
"2B2137E094F743AC8BD44652C55F41DFACC502F125E99E4FE24D40537489E32F",
|
while not reply.isFinished():
|
||||||
"7AED21F94D82B05774F697B209628CD5A9AD17E0C073D9329076A4C28ED28147",
|
QtCore.QThread.msleep(1)
|
||||||
"0FB96EEBFB1650DDB52E70CF773DDFCABE25A95CC3BB50FC251082E4B63EF82A",
|
QtCore.QCoreApplication.processEvents()
|
||||||
"1C5293AEF2114717547B39DA8EA6F1E331E5E358B35F9B6B5F19317911C5F976",
|
data = bytes(reply.readAll().data())
|
||||||
"53737F6D47FA6BD2808F378E339AF45BF86F39B64E79D6D491C53A1D522E7039",
|
save_nodes(data)
|
||||||
"9E7BD4793FFECA7F32238FA2361040C09025ED3333744483CA6F3039BFF0211E",
|
except Exception as ex:
|
||||||
"9CA69BB74DE7C056D1CC6B16AB8A0A38725C0349D187D8996766958584D39340",
|
log('TOX nodes loading error: ' + str(ex))
|
||||||
"EDEE8F2E839A57820DE3DA4156D88350E53D4161447068A3457EE8F59F362414",
|
|
||||||
"AEC204B9A4501412D5F0BB67D9C81B5DB3EE6ADA64122D32A3E9B093D544327D",
|
|
||||||
"188E072676404ED833A4E947DC1D223DF8EFEBE5F5258573A236573688FB9761",
|
|
||||||
"2D320F971EF2CA18004416C2AAE7BA52BF7949DB34EA8E2E21AF67BD367BE211",
|
|
||||||
"24156472041E5F220D1FA11D9DF32F7AD697D59845701CDD7BE7D1785EB9DB39",
|
|
||||||
"15A0F9684E2423F9F46CFA5A50B562AE42525580D840CC50E518192BF333EE38",
|
|
||||||
"FAAB17014F42F7F20949F61E55F66A73C230876812A9737F5F6D2DCE4D9E4207",
|
|
||||||
"AF97B76392A6474AF2FD269220FDCF4127D86A42EF3A242DF53A40A268A2CD7C",
|
|
||||||
"B05C8869DBB4EDDD308F43C1A974A20A725A36EACCA123862FDE9945BF9D3E09",
|
|
||||||
"5C4C7A60183D668E5BD8B3780D1288203E2F1BAE4EEF03278019E21F86174C1D",
|
|
||||||
"4E3F7D37295664BBD0741B6DBCB6431D6CD77FC4105338C2FC31567BF5C8224A",
|
|
||||||
"5625A62618CB4FCA70E147A71B29695F38CC65FF0CBD68AD46254585BE564802",
|
|
||||||
"31910C0497D347FF160D6F3A6C0E317BAFA71E8E03BC4CBB2A185C9D4FB8B31E"
|
|
||||||
]
|
|
||||||
for i in range(len(ips)):
|
|
||||||
nodes.append(Node(ips[i], ports[i], ids[i], random.randint(0, 1000000)))
|
|
||||||
arr = sorted(nodes, key=lambda x: x.rand)[:4]
|
|
||||||
for elem in arr:
|
|
||||||
yield elem.get_data()
|
|
||||||
|
@ -3,7 +3,7 @@ from loginscreen import LoginScreen
|
|||||||
import profile
|
import profile
|
||||||
from settings import *
|
from settings import *
|
||||||
from PyQt5 import QtCore, QtGui, QtWidgets
|
from PyQt5 import QtCore, QtGui, QtWidgets
|
||||||
from bootstrap import node_generator
|
from bootstrap import generate_nodes, download_nodes_list
|
||||||
from mainscreen import MainWindow
|
from mainscreen import MainWindow
|
||||||
from callbacks import init_callbacks, stop, start
|
from callbacks import init_callbacks, stop, start
|
||||||
from util import curr_directory, program_version, remove
|
from util import curr_directory, program_version, remove
|
||||||
@ -379,9 +379,11 @@ class Toxygen:
|
|||||||
def run(self):
|
def run(self):
|
||||||
# initializing callbacks
|
# initializing callbacks
|
||||||
init_callbacks(self.tox, self.ms, self.tray)
|
init_callbacks(self.tox, self.ms, self.tray)
|
||||||
|
# download list of nodes if needed
|
||||||
|
download_nodes_list()
|
||||||
# bootstrap
|
# bootstrap
|
||||||
try:
|
try:
|
||||||
for data in node_generator():
|
for data in generate_nodes():
|
||||||
if self.stop:
|
if self.stop:
|
||||||
return
|
return
|
||||||
self.tox.bootstrap(*data)
|
self.tox.bootstrap(*data)
|
||||||
@ -394,7 +396,7 @@ class Toxygen:
|
|||||||
self.msleep(1000)
|
self.msleep(1000)
|
||||||
while not self.tox.self_get_connection_status():
|
while not self.tox.self_get_connection_status():
|
||||||
try:
|
try:
|
||||||
for data in node_generator():
|
for data in generate_nodes():
|
||||||
if self.stop:
|
if self.stop:
|
||||||
return
|
return
|
||||||
self.tox.bootstrap(*data)
|
self.tox.bootstrap(*data)
|
||||||
|
@ -294,10 +294,10 @@ class NetworkSettings(CenteredWidget):
|
|||||||
|
|
||||||
def initUI(self):
|
def initUI(self):
|
||||||
self.setObjectName("NetworkSettings")
|
self.setObjectName("NetworkSettings")
|
||||||
self.resize(300, 330)
|
self.resize(300, 400)
|
||||||
self.setMinimumSize(QtCore.QSize(300, 330))
|
self.setMinimumSize(QtCore.QSize(300, 400))
|
||||||
self.setMaximumSize(QtCore.QSize(300, 330))
|
self.setMaximumSize(QtCore.QSize(300, 400))
|
||||||
self.setBaseSize(QtCore.QSize(300, 330))
|
self.setBaseSize(QtCore.QSize(300, 400))
|
||||||
self.ipv = QtWidgets.QCheckBox(self)
|
self.ipv = QtWidgets.QCheckBox(self)
|
||||||
self.ipv.setGeometry(QtCore.QRect(20, 10, 97, 22))
|
self.ipv.setGeometry(QtCore.QRect(20, 10, 97, 22))
|
||||||
self.ipv.setObjectName("ipv")
|
self.ipv.setObjectName("ipv")
|
||||||
@ -332,6 +332,9 @@ class NetworkSettings(CenteredWidget):
|
|||||||
self.warning = QtWidgets.QLabel(self)
|
self.warning = QtWidgets.QLabel(self)
|
||||||
self.warning.setGeometry(QtCore.QRect(5, 270, 290, 60))
|
self.warning.setGeometry(QtCore.QRect(5, 270, 290, 60))
|
||||||
self.warning.setStyleSheet('QLabel { color: #BC1C1C; }')
|
self.warning.setStyleSheet('QLabel { color: #BC1C1C; }')
|
||||||
|
self.nodes = QtWidgets.QCheckBox(self)
|
||||||
|
self.nodes.setGeometry(QtCore.QRect(20, 350, 270, 22))
|
||||||
|
self.nodes.setChecked(settings['download_nodes_list'])
|
||||||
self.retranslateUi()
|
self.retranslateUi()
|
||||||
self.proxy.stateChanged.connect(lambda x: self.activate())
|
self.proxy.stateChanged.connect(lambda x: self.activate())
|
||||||
self.activate()
|
self.activate()
|
||||||
@ -346,6 +349,7 @@ class NetworkSettings(CenteredWidget):
|
|||||||
self.label_2.setText(QtWidgets.QApplication.translate("Form", "Port:"))
|
self.label_2.setText(QtWidgets.QApplication.translate("Form", "Port:"))
|
||||||
self.reconnect.setText(QtWidgets.QApplication.translate("NetworkSettings", "Restart TOX core"))
|
self.reconnect.setText(QtWidgets.QApplication.translate("NetworkSettings", "Restart TOX core"))
|
||||||
self.http.setText(QtWidgets.QApplication.translate("Form", "HTTP"))
|
self.http.setText(QtWidgets.QApplication.translate("Form", "HTTP"))
|
||||||
|
self.nodes.setText(QtWidgets.QApplication.translate("Form", "Download nodes list from tox.chat"))
|
||||||
self.warning.setText(QtWidgets.QApplication.translate("Form", "WARNING:\nusing proxy with enabled UDP\ncan produce IP leak"))
|
self.warning.setText(QtWidgets.QApplication.translate("Form", "WARNING:\nusing proxy with enabled UDP\ncan produce IP leak"))
|
||||||
|
|
||||||
def activate(self):
|
def activate(self):
|
||||||
@ -362,6 +366,7 @@ class NetworkSettings(CenteredWidget):
|
|||||||
settings['proxy_type'] = 2 - int(self.http.isChecked()) if self.proxy.isChecked() else 0
|
settings['proxy_type'] = 2 - int(self.http.isChecked()) if self.proxy.isChecked() else 0
|
||||||
settings['proxy_host'] = str(self.proxyip.text())
|
settings['proxy_host'] = str(self.proxyip.text())
|
||||||
settings['proxy_port'] = int(self.proxyport.text())
|
settings['proxy_port'] = int(self.proxyport.text())
|
||||||
|
settings['download_nodes_list'] = self.nodes.isChecked()
|
||||||
settings.save()
|
settings.save()
|
||||||
# recreate tox instance
|
# recreate tox instance
|
||||||
Profile.get_instance().reset(self.reset)
|
Profile.get_instance().reset(self.reset)
|
||||||
|
1
toxygen/nodes.json
Normal file
1
toxygen/nodes.json
Normal file
File diff suppressed because one or more lines are too long
@ -145,7 +145,8 @@ class Settings(dict, Singleton):
|
|||||||
'close_to_tray': False,
|
'close_to_tray': False,
|
||||||
'font': 'Times New Roman',
|
'font': 'Times New Roman',
|
||||||
'update': 1,
|
'update': 1,
|
||||||
'group_notifications': True
|
'group_notifications': True,
|
||||||
|
'download_nodes_list': False
|
||||||
}
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
Loading…
Reference in New Issue
Block a user