Compare commits

..

No commits in common. "0b4eda648e1c59e0ffb2ce0a403c8ca192527799" and "c4a31b8a56bf03279ae1a16cf5e3c6f17b1e6be0" have entirely different histories.

3 changed files with 39 additions and 55 deletions

View File

@ -1892,8 +1892,7 @@ class Tox:
# -3 TOX_ERR_GROUP_NEW_INIT # -3 TOX_ERR_GROUP_NEW_INIT
# -4 TOX_ERR_GROUP_NEW_STATE # -4 TOX_ERR_GROUP_NEW_STATE
# -5 TOX_ERR_GROUP_NEW_ANNOUNCE # -5 TOX_ERR_GROUP_NEW_ANNOUNCE
if error.value in TOX_ERR_GROUP_NEW: LOG_ERROR(f"group_new {error.value} {TOX_ERR_GROUP_NEW[error.value]}")
LOG_ERROR(f"group_new {error.value} {TOX_ERR_GROUP_NEW[error.value]}")
raise ToxError(f"group_new {error.value}") raise ToxError(f"group_new {error.value}")
return result return result
@ -1979,7 +1978,7 @@ class Tox:
raise ToxError("group_disconnect {error.value}") raise ToxError("group_disconnect {error.value}")
return result return result
def group_leave(self, group_number, message=None): def group_leave(self, group_number, message=''):
"""Leaves a group. """Leaves a group.
This function sends a parting packet containing a custom This function sends a parting packet containing a custom
@ -2000,7 +1999,7 @@ class Tox:
f = Tox.libtoxcore.tox_group_leave f = Tox.libtoxcore.tox_group_leave
f.restype = c_bool f.restype = c_bool
result = f(self._tox_pointer, group_number, message, result = f(self._tox_pointer, group_number, message,
len(message) if message else 0, byref(error)) len(message) if message is not None else 0, byref(error))
if error.value: if error.value:
LOG_ERROR(f"group_leave {error.value}") LOG_ERROR(f"group_leave {error.value}")
raise ToxError("group_leave {error.value}") raise ToxError("group_leave {error.value}")
@ -2414,7 +2413,7 @@ class Tox:
if error.value == 1: if error.value == 1:
LOG_ERROR(f"tox_group_get_chat_id ERROR GROUP_STATE_QUERIES_GROUP_NOT_FOUND group_number={group_number}") LOG_ERROR(f"tox_group_get_chat_id ERROR GROUP_STATE_QUERIES_GROUP_NOT_FOUND group_number={group_number}")
else: else:
LOG_ERROR(f"tox_group_get_chat_id group_number={group_number} error={error.value}") LOG_ERROR(f"tox_group_get_chat_id group_number={group_number} {error.value}")
raise ToxError(f"tox_group_get_chat_id {error.value}") raise ToxError(f"tox_group_get_chat_id {error.value}")
# #
# QObject::setParent: Cannot set parent, new parent is in a different thread # QObject::setParent: Cannot set parent, new parent is in a different thread
@ -2787,7 +2786,7 @@ class Tox:
raise ToxError(f"group_invite_friend {error.value} {s}") raise ToxError(f"group_invite_friend {error.value} {s}")
return result return result
# API change - this no longer exists # API change
# @staticmethod # @staticmethod
# def group_self_peer_info_new(): # def group_self_peer_info_new():
# error = c_int() # error = c_int()
@ -2796,8 +2795,7 @@ class Tox:
# result = f(byref(error)) # result = f(byref(error))
# return result # return result
# status should be dropped def group_invite_accept(self, invite_data, friend_number, nick, password=None):
def group_invite_accept(self, invite_data, friend_number, nick, status='', password=None):
""" """
Accept an invite to a group chat that the client previously received from a friend. The invite Accept an invite to a group chat that the client previously received from a friend. The invite
is only valid while the inviter is present in the group. is only valid while the inviter is present in the group.
@ -2815,10 +2813,10 @@ class Tox:
except: except:
nick = b'' nick = b''
try: try:
if password is not None: if password is None: password = b''
password = bytes(password, 'utf-8') password = bytes(password, 'utf-8')
except: except:
password = None password = b''
invite_data = invite_data or b'' invite_data = invite_data or b''
if False: # API change if False: # API change
@ -2837,7 +2835,7 @@ class Tox:
byref(error)) byref(error))
except Exception as e: except Exception as e:
LOG_ERROR(f"group_invite_accept ERROR {e}") LOG_ERROR(f"group_invite_accept ERROR {e}")
raise ToxError(f"group_invite_accept ERROR {e}") raise
if error.value: if error.value:
# The invite data is not in the expected format. # The invite data is not in the expected format.
LOG_ERROR(f"group_invite_accept {TOX_ERR_GROUP_INVITE_ACCEPT[error.value]}") LOG_ERROR(f"group_invite_accept {TOX_ERR_GROUP_INVITE_ACCEPT[error.value]}")

View File

@ -262,7 +262,7 @@ class ToxAV:
24000, or 48000. 24000, or 48000.
""" """
toxav_err_send_frame = c_int() toxav_err_send_frame = c_int()
LOG_TRACE(f"toxav_audio_send_frame") LOG_DEBUG(f"toxav_audio_send_frame")
assert sampling_rate in [8000, 12000, 16000, 24000, 48000] assert sampling_rate in [8000, 12000, 16000, 24000, 48000]
result = self.libtoxav.toxav_audio_send_frame(self._toxav_pointer, result = self.libtoxav.toxav_audio_send_frame(self._toxav_pointer,
c_uint32(friend_number), c_uint32(friend_number),
@ -305,7 +305,7 @@ class ToxAV:
:param v: V (Chroma) plane data. :param v: V (Chroma) plane data.
""" """
toxav_err_send_frame = c_int() toxav_err_send_frame = c_int()
LOG_TRACE(f"toxav_video_send_frame") LOG_DEBUG(f"toxav_video_send_frame")
result = self.libtoxav.toxav_video_send_frame(self._toxav_pointer, c_uint32(friend_number), c_uint16(width), result = self.libtoxav.toxav_video_send_frame(self._toxav_pointer, c_uint32(friend_number), c_uint16(width),
c_uint16(height), c_char_p(y), c_char_p(u), c_char_p(v), c_uint16(height), c_char_p(y), c_char_p(u), c_char_p(v),
byref(toxav_err_send_frame)) byref(toxav_err_send_frame))

View File

@ -27,10 +27,6 @@ try:
import stem import stem
except ImportError as e: except ImportError as e:
stem = False stem = False
try:
import nmap
except ImportError as e:
nmap = False
import wrapper import wrapper
from wrapper.toxcore_enums_and_consts import TOX_CONNECTION, TOX_USER_STATUS from wrapper.toxcore_enums_and_consts import TOX_CONNECTION, TOX_USER_STATUS
@ -778,8 +774,9 @@ def bootstrap_good(lelts, lToxes):
return bootstrap_udp(lelts, lToxes) return bootstrap_udp(lelts, lToxes)
def bootstrap_udp(lelts, lToxes): def bootstrap_udp(lelts, lToxes):
LOG.debug(f'DHT bootstraping {len(lelts)}')
for elt in lToxes: for elt in lToxes:
LOG.debug(f'DHT bootstraping {len(lelts)}')
for largs in sDNSClean(lelts): for largs in sDNSClean(lelts):
host, port, key = largs host, port, key = largs
if host in lDEAD_BS: continue if host in lDEAD_BS: continue
@ -842,52 +839,38 @@ def bootstrap_tcp(lelts, lToxes):
LOG.debug(f'bootstrap_tcp to {host} but not connected') LOG.debug(f'bootstrap_tcp to {host} but not connected')
pass pass
def iNmapInfoNmap(sProt, sHost, sPort, key=None, environ=None, cmd=''):
if sHost in ['-', 'NONE']: return 0
if not nmap: return 0
nmps = nmap.PortScanner
if sProt in ['socks', 'socks5', 'tcp4']:
prot = 'tcp'
cmd = f" -Pn -n -sT -p T:{sPort}"
else:
prot = 'udp'
cmd = f" -Pn -n -sU -p U:{sPort}"
LOG.debug(f"iNmapInfoNmap cmd={cmd}")
sys.stdout.flush()
o = nmps().scan(hosts=sHost, arguments=cmd)
aScan = o['scan']
ip = list(aScan.keys())[0]
state = aScam[ip][prot][iPort]['state']
LOG.info(f"iNmapInfoNmap: to {sHost} {state}")
return 0
def iNmapInfo(sProt, sHost, sPort, key=None, environ=None, cmd='nmap'): def iNmapInfo(sProt, sHost, sPort, key=None, environ=None, cmd='nmap'):
if sHost in ['-', 'NONE']: return 0 if sHost in ['-', 'NONE']: return 0
sFile = os.path.join("/tmp", f"{sHost}.{os.getpid()}.nmap") sFile = os.path.join("/tmp", f"{sHost}.{os.getpid()}.nmap")
if sProt in ['socks', 'socks5', 'tcp4']: if sProt in ['socks', 'socks5', 'tcp4']:
cmd += f" -Pn -n -sT -p T:{sPort} {sHost} | grep /tcp " cmd += f" -Pn -n -sT -p T:{sPort} {sHost} | grep /tcp >{sFile}"
else: else:
cmd += f" -Pn -n -sU -p U:{sPort} {sHost} | grep /udp " cmd += f" -Pn -n -sU -p U:{sPort} {sHost} | grep /tcp >{sFile}"
LOG.debug(f"iNmapInfo cmd={cmd}") iRet = os.system('sudo ' +cmd)
sys.stdout.flush() LOG.debug(f"iNmapInfo cmd={cmd} {iRet}")
iRet = os.system('sudo ' +cmd +f" >{sFile} 2>&1 ")
LOG.debug(f"iNmapInfo cmd={cmd} iRet={iRet}")
if iRet != 0: if iRet != 0:
return iRet return iRet
assert os.path.exists(sFile), sFile assert os.path.exists(sFile), sFile
with open(sFile, 'rt') as oFd: with open(sFile, 'rt') as oFd:
l = oFd.readlines() l = oFd.readlines()
assert len(l) assert len(l)
l = [line for line in l if line and not line.startswith('WARNING:')]
s = '\n'.join([s.strip() for s in l]) s = '\n'.join([s.strip() for s in l])
LOG.info(f"iNmapInfo: to {sHost}\n{s}") LOG.debug(f"iNmapInfo: {s}")
return 0 return 0
def bootstrap_iNmapInfo(lElts, oArgs, protocol="tcp4", bIS_LOCAL=False, iNODES=iNODES, cmd='nmap'): def bootstrap_iNmapInfo(lElts, oArgs, bIS_LOCAL=False, iNODES=iNODES, cmd='nmap'):
if not bIS_LOCAL and not bAreWeConnected(): if not bIS_LOCAL and not bAreWeConnected():
LOG.warn(f"bootstrap_iNmapInfo not local and NOT CONNECTED") LOG.warn(f"bootstrap_iNmapInfo not local and NOT CONNECTED")
return True return True
env = dict()
if oArgs.proxy_type == 2:
protocol='socks'
elif oArgs.proxy_type == 1:
protocol='https'
else:
protocol='ipv4'
env = os.environ
lRetval = [] lRetval = []
for elts in lElts[:iNODES]: for elts in lElts[:iNODES]:
host, port, key = elts host, port, key = elts
@ -895,23 +878,26 @@ def bootstrap_iNmapInfo(lElts, oArgs, protocol="tcp4", bIS_LOCAL=False, iNODES=i
if not ip: if not ip:
LOG.info('bootstrap_iNmapInfo to {host} did not resolve') LOG.info('bootstrap_iNmapInfo to {host} did not resolve')
continue continue
assert len(key) == 64, key
if type(port) == str: if type(port) == str:
port = int(port) port = int(port)
iRet = -1 iRet = -1
try: try:
if not nmap: iRet = iNmapInfo(protocol, ip, port, key, cmd=cmd)
iRet = iNmapInfo(protocol, ip, port, key, cmd=cmd)
else:
iRet = iNmapInfoNmap(protocol, ip, port, key)
if iRet != 0: if iRet != 0:
LOG.warn('iNmapInfo to ' +repr(host) +' retval=' +str(iRet)) LOG.warn('iNmapInfo to ' +repr(host) +' retval=' +str(iRet))
lRetval += [False] lRetval += [False]
else: else:
LOG.debug('iNmapInfo to ' +repr(host) +' retval=' +str(iRet)) LOG.info(f'bootstrap_iNmapInfo '
+f" net={oArgs.network}"
+f" prot={protocol}"
+f" proxy={oArgs.proxy_type}"
+f' {elts[:2]!r}'
)
lRetval += [True] lRetval += [True]
except Exception as e: except Exception as e:
LOG.exception('iNmapInfo to {host} : ' +str(e) LOG.error('iNmapInfo to {host} : ' +str(e) \
) +'\n' + traceback.format_exc())
lRetval += [False] lRetval += [False]
return any(lRetval) return any(lRetval)