diff --git a/wrapper/libtox.py b/wrapper/libtox.py index 9255d28..bf39dd0 100644 --- a/wrapper/libtox.py +++ b/wrapper/libtox.py @@ -18,7 +18,7 @@ except ImportError: d = os.environ.get('TOXCORE_LIBS', '') if d and os.path.exists(d): sLIBS_DIR = d - if os.environ.get('DEBUG', ''): + if os.environ.get('DEBUG', ''): print ('DBUG: Setting TOXCORE_LIBS to ' +d) del d diff --git a/wrapper_tests/support_http.py b/wrapper_tests/support_http.py index f496d96..d60ccbf 100644 --- a/wrapper_tests/support_http.py +++ b/wrapper_tests/support_http.py @@ -22,7 +22,7 @@ except ImportError: lNO_PROXY = ['localhost', '127.0.0.1'] CONNECT_TIMEOUT = 20.0 -def bAreWeConnected(): +def bAreWeConnected(): # FixMe: Linux only sFile = f"/proc/{os.getpid()}/net/route" if not os.path.isfile(sFile): return None @@ -70,10 +70,10 @@ def pick_up_proxy_from_environ(): def download_url(url, settings=None): if not bAreWeConnected(): return '' - + if settings is None: settings = pick_up_proxy_from_environ() - + if pycurl: LOG.debug('Downloading with pycurl: ' + str(url)) buffer = BytesIO() @@ -161,4 +161,4 @@ def download_url(url, settings=None): return '' return '' - + diff --git a/wrapper_tests/support_onions.py b/wrapper_tests/support_onions.py index 0c463a1..6da6529 100644 --- a/wrapper_tests/support_onions.py +++ b/wrapper_tests/support_onions.py @@ -33,41 +33,41 @@ bHAVE_TORR = shutil.which('tor-resolve') # in the wild we'll keep a copy here so we can avoid restesting yKNOWN_NODNS = """ --- - - 0x0.is - - a9.wtf - - aklad5.com - - artikel5ev.de - - arvanode.net - - dodo.pm - - dra-family.github.io - - eraldonion.org - - erjan.net - - galtland.network - - ineapple.cx - - lonet.sh - - moneneis.de - - olonet.sh - - or-exit-2.aa78i2efsewr0neeknk.xyz - - or.wowplanet.de - - ormycloud.org - - plied-privacy.net - - rivacysvcs.net - - redacted.org - - rification-for-nusenu.net - - rofl.cat - - rsv.ch - - sv.ch + - heraldonion.org + - linkspartei.org + - pineapple.cx - thingtohide.nl - - tikel10.org - - tor.wowplanet.de - tor-exit-2.aa78i2efsewr0neeknk.xyz - tor-exit-3.aa78i2efsewr0neeknk.xyz - - torix-relays.org - - tse.com + - tor.dlecan.com - tuxli.org - - w.digidow.eu - - w.cccs.de + - verification-for-nusenu.net """ +# - 0x0.is +# - a9.wtf +# - aklad5.com +# - artikel5ev.de +# - arvanode.net +# - dodo.pm +# - erjan.net +# - galtland.network +# - lonet.sh +# - moneneis.de +# - olonet.sh +# - or-exit-2.aa78i2efsewr0neeknk.xyz +# - or.wowplanet.de +# - ormycloud.org +# - plied-privacy.net +# - rivacysvcs.net +# - redacted.org +# - rofl.cat +# - sv.ch +# - tikel10.org +# - tor.wowplanet.de +# - torix-relays.org +# - tse.com +# - w.digidow.eu +# - w.cccs.de def oMakeController(sSock='', port=9051): import getpass @@ -86,13 +86,15 @@ def oGetStemController(log_level=10, sock_or_pair='/run/tor/control'): global oSTEM_CONTROLER if oSTEM_CONTROLER: return oSTEM_CONTROLER import stem.util.log - stem.util.log.Runlevel = log_level + # stem.util.log.Runlevel = 'DEBUG' = 20 # log_level if os.path.exists(sock_or_pair): LOG.info(f"controller from socket {sock_or_pair}") controller = Controller.from_socket_file(path=sock_or_pair) else: - if ':' in sock_or_pair: + if type(sock_or_pair) == int: + port = sock_or_pair + elif ':' in sock_or_pair: port = sock_or_pair.split(':')[1] else: port = sock_or_pair diff --git a/wrapper_tests/support_testing.py b/wrapper_tests/support_testing.py index 3e90bca..0b515ff 100644 --- a/wrapper_tests/support_testing.py +++ b/wrapper_tests/support_testing.py @@ -2,6 +2,7 @@ import argparse import contextlib +import inspect import json import logging import os @@ -162,7 +163,7 @@ def clean_booleans(oArgs): setattr(oArgs, key, False) else: setattr(oArgs, key, True) - + def on_log(iTox, level, filename, line, func, message, *data): # LOG.debug(repr((level, filename, line, func, message,))) tox_log_cb(level, filename, line, func, message) @@ -210,7 +211,7 @@ def tox_log_cb(level, filename, line, func, message, *args): level = 30 # LOG.warn else: level = 20 # LOG.info - + o = LOG.makeRecord(filename, level, func, line, message, list(), None) # LOG.handle(o) LOG_TRACE(f"{level}: {func}{line} {message}") @@ -251,7 +252,7 @@ def get_audio(): with ignoreStderr(): import pyaudio oPyA = pyaudio.PyAudio() - + input_devices = output_devices = 0 for i in range(oPyA.get_device_count()): device = oPyA.get_device_info_by_index(i) @@ -333,7 +334,7 @@ def vSetupLogging(oArgs): if add or sub: oArgs.logfile = oArgs.logfile[1:] kwargs['filename'] = oArgs.logfile - + if coloredlogs: # https://pypi.org/project/coloredlogs/ aKw = dict(level=oArgs.loglevel, @@ -350,7 +351,7 @@ def vSetupLogging(oArgs): if add: oHandler = logging.StreamHandler(sys.stdout) LOG.addHandler(oHandler) - + LOG.info(f"Setting loglevel to {oArgs.loglevel!s}") @@ -517,7 +518,7 @@ def generate_nodes_from_file(sFile, I had a conversation with @irungentoo on IRC about whether we really need to call tox_bootstrap() when having UDP disabled and why. The answer is yes, because in addition to TCP relays (tox_add_tcp_relay()), toxcore also needs to know addresses of UDP onion nodes in order to work correctly. The DHT, however, is not used when UDP is disabled. tox_bootstrap() function resolves the address passed to it as argument and calls onion_add_bs_node_path() and DHT_bootstrap() functions. Although calling DHT_bootstrap() is not really necessary as DHT is not used, we still need to resolve the address of the DHT node in order to populate the onion routes with onion_add_bs_node_path() call. """ global aNODES_CACHE - + key = ipv key += ',0' if udp_not_tcp else ',1' if key in aNODES_CACHE: @@ -642,7 +643,7 @@ def sDNSLookup(host): ipv = 6 else: ipv = 4 - + if ipv > 0: # LOG.debug(f"{ipv} IP address {host}") return host @@ -652,10 +653,10 @@ def sDNSLookup(host): if False and stem: ip = sMapaddressResolv(host) if ip: return ip - + ip = sTorResolve(host) if ip: return ip - + if not bHAVE_TORR: LOG.warn(f"onion address skipped because no tor-resolve {host}") return '' @@ -680,7 +681,7 @@ def sDNSLookup(host): except: # drop through pass - + if ip == '': try: sout = f"/tmp/TR{os.getpid()}.log" @@ -701,7 +702,7 @@ def bootstrap_good(lelts, lToxes): def bootstrap_udp(lelts, lToxes): lelts = lDNSClean(lelts) - LOG.debug(f'DHT bootstraping {len(lelts)}') + LOG.debug(f'DHT bootstraping {len(lelts)}') for elt in lToxes: random.shuffle(lelts) for largs in lelts: @@ -710,7 +711,7 @@ def bootstrap_udp(lelts, lToxes): if not ip: LOG.warn(f'bootstrap_udp to {host} did not resolve') continue - + if type(port) == str: port = int(port) try: @@ -765,7 +766,7 @@ def bootstrap_tcp(lelts, lToxes): else: LOG.debug(f'bootstrap_tcp to {host} but not connected') pass - + def iNmapInfoNmap(sProt, sHost, sPort, key=None, environ=None, cmd=''): if sHost in ['-', 'NONE']: return 0 if not nmap: return 0 @@ -784,7 +785,7 @@ def iNmapInfoNmap(sProt, sHost, sPort, key=None, environ=None, cmd=''): state = aScan[ip][prot][sPort]['state'] LOG.info(f"iNmapInfoNmap: to {sHost} {state}") return 0 - + def iNmapInfo(sProt, sHost, sPort, key=None, environ=None, cmd='nmap'): if sHost in ['-', 'NONE']: return 0 sFile = os.path.join("/tmp", f"{sHost}.{os.getpid()}.nmap") @@ -811,7 +812,7 @@ def bootstrap_iNmapInfo(lElts, oArgs, protocol="tcp4", bIS_LOCAL=False, iNODES=i if not bIS_LOCAL and not bAreWeConnected(): LOG.warn(f"bootstrap_iNmapInfo not local and NOT CONNECTED") return True - + lRetval = [] for elts in lElts[:iNODES]: host, port, key = elts @@ -842,7 +843,7 @@ def bootstrap_iNmapInfo(lElts, oArgs, protocol="tcp4", bIS_LOCAL=False, iNODES=i def caseFactory(cases): """We want the tests run in order.""" if len(cases) > 1: - ordered_cases = sorted(cases, key=lambda f: findsource(f)[1]) + ordered_cases = sorted(cases, key=lambda f: inspect.findsource(f)[1]) else: ordered_cases = cases return ordered_cases diff --git a/wrapper_tests/tests_wrapper.py b/wrapper_tests/tests_wrapper.py index d1f0785..6561500 100644 --- a/wrapper_tests/tests_wrapper.py +++ b/wrapper_tests/tests_wrapper.py @@ -24,7 +24,7 @@ """Originaly from https://github.com/oxij/PyTox c-toxcore-02 branch which itself was forked from https://github.com/aitjcize/PyTox/ -Modified to work with +Modified to work with """ import ctypes @@ -215,7 +215,7 @@ class ToxSuite(unittest.TestCase): self.bob.oArgs = opts if not bIS_LOCAL and not ts.bAreWeConnected(): LOG.warn(f"prepare not local and NOT CONNECTED") - + self.lUdp = ts.generate_nodes( oArgs=oTOX_OARGS, nodes_count=8, @@ -309,7 +309,7 @@ class ToxSuite(unittest.TestCase): """ i = 0 bRet = None - + self.bob.mycon_status = False def bobs_on_self_connection_status(iTox, connection_state, *args): status = connection_state @@ -718,9 +718,9 @@ class ToxSuite(unittest.TestCase): o2 = self.bob.self_get_dht_id() assert len(o2) == 64 - if o1 != o2: + if o1 != o2: LOG.warn(f"bootstrap_local DHT NOT same {o1} {o2} iStatus={iStatus}") - + iStatus = self.bob.self_get_connection_status() if iStatus != TOX_CONNECTION['NONE']: LOG.info(f"bootstrap_local connected iStatus={iStatus}") @@ -731,7 +731,7 @@ class ToxSuite(unittest.TestCase): return True LOG.warn(f"bootstrap_local NOT CONNECTED iStatus={iStatus}") return False - + def test_bootstrap_iNmapInfo(self): # works if oTOX_OARGS.network in ['new', 'newlocal', 'localnew']: lElts = self.lUdp @@ -741,7 +741,7 @@ class ToxSuite(unittest.TestCase): lElts = self.lUdp lRetval = [] random.shuffle(lElts) - # assert + # assert ts.bootstrap_iNmapInfo(lElts, oTOX_OARGS, bIS_LOCAL, iNODES=8) def test_self_get_secret_key(self): # works @@ -927,7 +927,7 @@ class ToxSuite(unittest.TestCase): """ MSG = 'Happy' sSlot = 'friend_status_message' - + if oTOX_OARGS.bIS_LOCAL: iRet = self.bob_add_alice_as_friend_norequest() if iRet < 0: @@ -1120,7 +1120,7 @@ class ToxSuite(unittest.TestCase): AID = self.baid #: Test friend name NEWNAME = 'Jenny' - + setattr(self.bob, sSlot, False) def bobs_on_friend_name(iTox, fid, newname, iNameSize, *largs): LOG_INFO(sSlot +" " +repr(fid)) @@ -1277,7 +1277,7 @@ class ToxSuite(unittest.TestCase): setattr(self.bob, sSlot, False) sSlot = 'friend_read_receipt' setattr(self.alice, sSlot, False) - + self.alice.callback_friend_read_receipt(alices_on_read_reciept) #was alices_on_friend_action assert self.wait_ensure_exec(self.bob.friend_send_message, (self.baid, @@ -1381,7 +1381,7 @@ class ToxSuite(unittest.TestCase): self.bob_add_alice_as_friend_norequest() self.baid = self.bob.friend_by_public_key(self.alice._address) BID = self.baid - + FRIEND_NUMBER = self.baid FILE_NUMBER = 1 FILE = os.urandom(1024 * 1024) @@ -1445,7 +1445,7 @@ class ToxSuite(unittest.TestCase): self.alice.completed = True self.alice.file_control(fid, file_number, TOX_FILE_CONTROL['CANCEL']) return - + CONTEXT['FILE'] += data CONTEXT['RECEIVED'] += len(data) # if CONTEXT['RECEIVED'] < FILE_SIZE: @@ -1481,7 +1481,7 @@ class ToxSuite(unittest.TestCase): return data = FILE[position:(position + length)] self.bob.file_send_chunk(fid, file_number, position, data) - + sSlot = 'file_recv_control' self.bob.callback_file_recv_control(bob_on_file_recv_control2) self.bob.callback_file_chunk_request(bob_on_file_chunk_request) @@ -1489,12 +1489,12 @@ class ToxSuite(unittest.TestCase): # was FILE_ID = FILE_NAME FILE_ID = 32*'1' # FILE_NAME = b'test.in' - + assert self.loop_until_connected() if not self.get_connection_status(): LOG.warn(f"test_file_transfer NOT CONNECTED") raise RuntimeError("not connected") - + i = 0 iKind = 0 while i < 2: @@ -1513,7 +1513,7 @@ class ToxSuite(unittest.TestCase): else: LOG.error(f"test_file_transfer bob.file_send 2") raise RuntimeError(f"test_file_transfer bob.file_send {THRESHOLD // 2}") - + # UINT32_MAX FID = self.bob.file_get_file_id(self.baid, FN) hexFID = "".join([hex(ord(c))[2:].zfill(2) for c in FILE_NAME]) @@ -1527,12 +1527,12 @@ class ToxSuite(unittest.TestCase): # ValueError: non-hexadecimal number found in fromhex() arg at position 0 LOG_ERROR(f"test_file_transfer: {e}") raise - + except Exception as e: LOG_ERROR(f"test_file_transfer:: {e}") LOG_DEBUG('\n' + traceback.format_exc()) raise - + finally: self.alice.callback_file_recv(None) self.alice.callback_file_recv_control(None) @@ -1554,11 +1554,11 @@ class ToxSuite(unittest.TestCase): assert data is not None addr = self.alice.self_get_address() # self._address - + try: self.alice.kill() except: pass - + oArgs = oTOX_OARGS opts = oToxygenToxOptions(oArgs) opts.savedata_data = data @@ -1570,11 +1570,11 @@ class ToxSuite(unittest.TestCase): f"{addr} != {self.alice.self_get_address()}") else: LOG.info("passed test_tox_savedata") - + def vOargsToxPreamble(oArgs, Tox, ToxTest): ts.vSetupLogging() - + methods = set([x for x in dir(Tox) if not x[0].isupper() and not x[0] == '_']) docs = "".join([getattr(ToxTest, x).__doc__ for x in dir(ToxTest)