bugfixes
This commit is contained in:
parent
bccd262a68
commit
4e44a559e7
@ -2657,8 +2657,8 @@ class Tox:
|
||||
message_type, message,
|
||||
len(message), byref(error))
|
||||
if error.value:
|
||||
LOG_ERROR(f" {error.value}")
|
||||
raise ToxError(f" {error.value}")
|
||||
LOG_ERROR(f"group_send_private_message {TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE[error.value]}")
|
||||
raise ToxError(f"group_send_private_message {TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE[error.value]}")
|
||||
return result
|
||||
|
||||
def group_send_message(self, group_number, type, message):
|
||||
|
@ -7,6 +7,7 @@ import re
|
||||
import logging
|
||||
import shutil
|
||||
import json
|
||||
import socket
|
||||
from ctypes import *
|
||||
import time, contextlib
|
||||
import unittest
|
||||
@ -92,7 +93,7 @@ lDEAD_BS = [
|
||||
# at 3 different places. Giving up.
|
||||
'104.244.74.69',
|
||||
'172.93.52.70',
|
||||
'tox2.abilinski.com',
|
||||
'tox.abilinski.com',
|
||||
# Failed to resolve "tox3.plastiras.org".
|
||||
"tox3.plastiras.org",
|
||||
]
|
||||
@ -368,15 +369,21 @@ def _get_nodes_path(oArgs=None):
|
||||
|
||||
DEFAULT_NODES_COUNT = 8
|
||||
|
||||
def generate_nodes(
|
||||
oArgs=None,
|
||||
global aNODES
|
||||
aNODES = {}
|
||||
def generate_nodes(oArgs=None,
|
||||
nodes_count=DEFAULT_NODES_COUNT,
|
||||
ipv='ipv4',
|
||||
udp_not_tcp=True):
|
||||
global aNODES
|
||||
sKey = ipv
|
||||
sKey += ',0' if udp_not_tcp else ',1'
|
||||
if sKey in aNODES: return aNODES[sKey]
|
||||
sFile = _get_nodes_path(oArgs=oArgs)
|
||||
return generate_nodes_from_file(sFile,
|
||||
nodes_count=nodes_count,
|
||||
ipv=ipv, udp_not_tcp=udp_not_tcp)
|
||||
aNODES[sKey] = generate_nodes_from_file(sFile,
|
||||
nodes_count=nodes_count,
|
||||
ipv=ipv, udp_not_tcp=udp_not_tcp)
|
||||
return aNODES[sKey]
|
||||
|
||||
aNODES_CACHE = {}
|
||||
def generate_nodes_from_file(sFile,
|
||||
@ -457,23 +464,28 @@ def bootstrap_good(lelts, lToxes):
|
||||
for largs in lelts:
|
||||
host, port, key = largs
|
||||
if largs[0] in lDEAD_BS: continue
|
||||
try:
|
||||
host = socket.gethostbyname(largs[0])
|
||||
except:
|
||||
continue
|
||||
assert len(key) == 64, key
|
||||
if type(port) == str:
|
||||
port = int(port)
|
||||
try:
|
||||
oRet = elt.bootstrap(largs[0],
|
||||
oRet = elt.bootstrap(host,
|
||||
port,
|
||||
largs[2])
|
||||
except Exception as e:
|
||||
LOG.error('bootstrap to ' +largs[0] +':' +str(largs[1]) \
|
||||
LOG.error('bootstrap to ' +host +':' +str(largs[1]) \
|
||||
+' ' +str(e))
|
||||
continue
|
||||
if not oRet:
|
||||
LOG.warn('bootstrap failed to ' +largs[0] +' : ' +str(oRet))
|
||||
LOG.warn('bootstrap failed to ' +host +' : ' +str(oRet))
|
||||
elif elt.self_get_connection_status() != TOX_CONNECTION['NONE']:
|
||||
LOG.info('bootstrap to ' +host +' connected')
|
||||
break
|
||||
else:
|
||||
if elt.self_get_connection_status() != TOX_CONNECTION['NONE']:
|
||||
LOG.debug('bootstrap to ' +largs[0] +' connected')
|
||||
return
|
||||
LOG.debug('bootstrap to ' +host +' not connected')
|
||||
|
||||
def bootstrap_tcp(lelts, lToxes):
|
||||
LOG.info('bootstraping tcp')
|
||||
@ -481,7 +493,11 @@ def bootstrap_tcp(lelts, lToxes):
|
||||
for largs in lelts:
|
||||
if largs[0] in lDEAD_BS: continue
|
||||
try:
|
||||
oRet = elt.add_tcp_relay(largs[0],
|
||||
host = socket.gethostbyname(largs[0])
|
||||
except:
|
||||
continue
|
||||
try:
|
||||
oRet = elt.add_tcp_relay(host,
|
||||
int(largs[1]),
|
||||
largs[2])
|
||||
except Exception as e:
|
||||
@ -489,10 +505,11 @@ def bootstrap_tcp(lelts, lToxes):
|
||||
continue
|
||||
if not oRet:
|
||||
LOG.warn('bootstrap_tcp failed to ' +largs[0] +' : ' +str(oRet))
|
||||
elif elt.self_get_connection_status() != TOX_CONNECTION['NONE']:
|
||||
LOG.info('bootstrap_tcp to ' +largs[0] +' connected')
|
||||
break
|
||||
else:
|
||||
if elt.self_get_connection_status() != TOX_CONNECTION['NONE']:
|
||||
LOG.debug('bootstrap_tcp to ' +largs[0] +' connected')
|
||||
break
|
||||
LOG.debug('bootstrap_tcp to ' +largs[0] +' not connected')
|
||||
|
||||
def setup_logging(oArgs):
|
||||
global LOG
|
||||
|
@ -122,14 +122,14 @@ if not hasattr(unittest, 'skip'):
|
||||
return _wrap1
|
||||
unittest.skip = unittest_skip
|
||||
|
||||
def iNodeInfo(sProt, sHost, sPort, key=None, environ=None, bTest=False):
|
||||
def iNmapInfo(sProt, sHost, sPort, key=None, environ=None, bTest=False):
|
||||
sFile = os.path.join("/tmp", f"{sHost}.{os.getpid()}.nmap")
|
||||
if sProt in ['socks', 'socks5', 'tcp4']:
|
||||
cmd = f"nmap -Pn -n -sT -p T:{sPort} {sHost} | grep /tcp >{sFile}"
|
||||
else:
|
||||
cmd = f"nmap -Pn -n -sU -p U:{sPort} {sHost} | grep /tcp >{sFile}"
|
||||
iRet = os.system(cmd)
|
||||
LOG.debug(f"iNodeInfo cmd={cmd} {iRet}")
|
||||
LOG.debug(f"iNmapInfo cmd={cmd} {iRet}")
|
||||
if iRet != 0:
|
||||
return iRet
|
||||
assert os.path.exists(sFile), sFile
|
||||
@ -137,12 +137,12 @@ def iNodeInfo(sProt, sHost, sPort, key=None, environ=None, bTest=False):
|
||||
l = oFd.readlines()
|
||||
assert len(l)
|
||||
s = '\n'.join([s.strip() for s in l])
|
||||
LOG.debug(f"iNodeInfo: {s}")
|
||||
LOG.debug(f"iNmapInfo: {s}")
|
||||
return 0
|
||||
|
||||
def bootstrap_iNodeInfo(lElts):
|
||||
def bootstrap_iNmapInfo(lElts):
|
||||
if not bIS_LOCAL and not ts.bAreWeConnected():
|
||||
LOG.warn(f"bootstrap_iNodeInfo not local and NOT CONNECTED")
|
||||
LOG.warn(f"bootstrap_iNmapInfo not local and NOT CONNECTED")
|
||||
return True
|
||||
env = dict()
|
||||
if oTOX_OARGS.proxy_type == 2:
|
||||
@ -157,12 +157,12 @@ def bootstrap_iNodeInfo(lElts):
|
||||
if elts[0] in ts.lDEAD_BS: continue
|
||||
iRet = -1
|
||||
try:
|
||||
iRet = iNodeInfo(protocol, *elts)
|
||||
iRet = iNmapInfo(protocol, *elts)
|
||||
if iRet != 0:
|
||||
LOG.warn('iNodeInfo to ' +repr(elts[0]) +' retval=' +str(iRet))
|
||||
LOG.warn('iNmapInfo to ' +repr(elts[0]) +' retval=' +str(iRet))
|
||||
lRetval += [False]
|
||||
else:
|
||||
LOG.info(f'bootstrap_iNodeInfo '
|
||||
LOG.info(f'bootstrap_iNmapInfo '
|
||||
+f" net={oTOX_OARGS.network}"
|
||||
+f" prot={protocol}"
|
||||
+f" proxy={oTOX_OARGS.proxy_type}"
|
||||
@ -170,7 +170,7 @@ def bootstrap_iNodeInfo(lElts):
|
||||
)
|
||||
lRetval += [True]
|
||||
except Exception as e:
|
||||
LOG.error('iNodeInfo to ' +repr(elts[0]) +' : ' +str(e) \
|
||||
LOG.error('iNmapInfo to ' +repr(elts[0]) +' : ' +str(e) \
|
||||
+'\n' + traceback.format_exc())
|
||||
lRetval += [False]
|
||||
return any(lRetval)
|
||||
@ -806,7 +806,7 @@ class ToxSuite(unittest.TestCase):
|
||||
LOG.warn(f"bootstrap_local NOT CONNECTED iStatus={iStatus}")
|
||||
return False
|
||||
|
||||
def test_bootstrap_iNodeInfo(self): # works
|
||||
def test_bootstrap_iNmapInfo(self): # works
|
||||
if oTOX_OARGS.network in ['new', 'newlocal', 'localnew']:
|
||||
lElts = self.lUdp
|
||||
elif oTOX_OARGS.proxy_port > 0:
|
||||
@ -816,7 +816,7 @@ class ToxSuite(unittest.TestCase):
|
||||
lRetval = []
|
||||
random.shuffle(lElts)
|
||||
# assert
|
||||
bootstrap_iNodeInfo(lElts)
|
||||
bootstrap_iNmapInfo(lElts)
|
||||
|
||||
def test_self_get_secret_key(self): # works
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user