This commit is contained in:
emdee 2023-12-10 15:59:53 +00:00
parent aedf36cda2
commit d034bafd4a
3 changed files with 161 additions and 229 deletions

View File

@ -186,9 +186,7 @@ class Tox:
else:
LOG_DEBUG(f"tox.kill")
# -----------------------------------------------------------------------------------------------------------------
# Startup options
# -----------------------------------------------------------------------------------------------------------------
@staticmethod
def options_default(tox_options):
@ -240,9 +238,7 @@ class Tox:
LOG_DEBUG(f"tox.options_free")
Tox.libtoxcore.tox_options_free(tox_options)
# -----------------------------------------------------------------------------------------------------------------
# Creation and destruction
# -----------------------------------------------------------------------------------------------------------------
def get_savedata_size(self):
"""
@ -269,9 +265,7 @@ class Tox:
Tox.libtoxcore.tox_get_savedata(self._tox_pointer, savedata)
return savedata[:]
# -----------------------------------------------------------------------------------------------------------------
# Connection lifecycle and event loop
# -----------------------------------------------------------------------------------------------------------------
def bootstrap(self, address, port, public_key):
"""Sends a "get nodes" request to the given bootstrap node with IP, port, and public key to setup connections.
@ -414,9 +408,7 @@ class Tox:
else:
LOG_TRACE(f"iterate")
# -----------------------------------------------------------------------------------------------------------------
# Internal client information (Tox address/id)
# -----------------------------------------------------------------------------------------------------------------
def self_get_toxid(self, address=None):
return self.self_get_address(address)
@ -481,9 +473,7 @@ class Tox:
Tox.libtoxcore.tox_self_get_secret_key(self._tox_pointer, secret_key)
return bin_to_string(secret_key, TOX_SECRET_KEY_SIZE)
# -----------------------------------------------------------------------------------------------------------------
# User-visible client information (nickname/status)
# -----------------------------------------------------------------------------------------------------------------
def self_set_name(self, name):
"""
@ -620,9 +610,7 @@ class Tox:
result = Tox.libtoxcore.tox_self_get_status(self._tox_pointer)
return int(result)
# -----------------------------------------------------------------------------------------------------------------
# Friend list management
# -----------------------------------------------------------------------------------------------------------------
def friend_add(self, address, message):
"""Add a friend to the friend list and send a friend request.
@ -658,7 +646,7 @@ class Tox:
byref(tox_err_friend_add))
tox_err_friend_add = tox_err_friend_add.value
if tox_err_friend_add == TOX_ERR_FRIEND_ADD['OK']:
return result
return int(result)
if tox_err_friend_add == TOX_ERR_FRIEND_ADD['NULL']:
raise ArgumentError('One of the arguments to the function was NULL when it was not expected.')
@ -705,7 +693,7 @@ class Tox:
byref(tox_err_friend_add))
tox_err_friend_add = tox_err_friend_add.value
if tox_err_friend_add == TOX_ERR_FRIEND_ADD['OK']:
return result
return int(result)
if tox_err_friend_add == TOX_ERR_FRIEND_ADD['NULL']:
raise ArgumentError('One of the arguments to the function was NULL when it was not expected.')
if tox_err_friend_add == TOX_ERR_FRIEND_ADD['TOO_LONG']:
@ -747,9 +735,7 @@ class Tox:
elif tox_err_friend_delete == TOX_ERR_FRIEND_DELETE['FRIEND_NOT_FOUND']:
raise ArgumentError('There was no friend with the given friend number. No friends were deleted.')
# -----------------------------------------------------------------------------------------------------------------
# Friend list queries
# -----------------------------------------------------------------------------------------------------------------
def friend_by_public_key(self, public_key):
"""
@ -765,7 +751,7 @@ class Tox:
byref(tox_err_friend_by_public_key))
tox_err_friend_by_public_key = tox_err_friend_by_public_key.value
if tox_err_friend_by_public_key == TOX_ERR_FRIEND_BY_PUBLIC_KEY['OK']:
return result
return int(result)
if tox_err_friend_by_public_key == TOX_ERR_FRIEND_BY_PUBLIC_KEY['NULL']:
raise ArgumentError('One of the arguments to the function was NULL when it was not expected.')
if tox_err_friend_by_public_key == TOX_ERR_FRIEND_BY_PUBLIC_KEY['NOT_FOUND']:
@ -844,14 +830,12 @@ class Tox:
byref(tox_err_last_online))
tox_err_last_online = tox_err_last_online.value
if tox_err_last_online == TOX_ERR_FRIEND_GET_LAST_ONLINE['OK']:
return result
return int(result)
elif tox_err_last_online == TOX_ERR_FRIEND_GET_LAST_ONLINE['FRIEND_NOT_FOUND']:
raise ArgumentError('No friend with the given number exists on the friend list.')
raise ToxError('The function did not return OK')
# -----------------------------------------------------------------------------------------------------------------
# Friend-specific state queries (can also be received through callbacks)
# -----------------------------------------------------------------------------------------------------------------
def friend_get_name_size(self, friend_number):
"""
@ -866,7 +850,7 @@ class Tox:
byref(tox_err_friend_query))
tox_err_friend_query = tox_err_friend_query.value
if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']:
return result
return int(result)
elif tox_err_friend_query == TOX_ERR_FRIEND_QUERY['NULL']:
raise ArgumentError('The pointer parameter for storing the query result (name, message) was NULL. Unlike'
' the `_self_` variants of these functions, which have no effect when a parameter is'
@ -941,7 +925,7 @@ class Tox:
byref(tox_err_friend_query))
tox_err_friend_query = tox_err_friend_query.value
if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']:
return result
return int(result)
elif tox_err_friend_query == TOX_ERR_FRIEND_QUERY['NULL']:
raise ArgumentError('The pointer parameter for storing the query result (name, message) was NULL. Unlike'
' the `_self_` variants of these functions, which have no effect when a parameter is'
@ -1150,9 +1134,7 @@ class Tox:
LOG_DEBUG(f"tox.callback_friend_typing")
Tox.libtoxcore.tox_callback_friend_typing(self._tox_pointer, self.friend_typing_cb)
# -----------------------------------------------------------------------------------------------------------------
# Sending private messages
# -----------------------------------------------------------------------------------------------------------------
def self_set_typing(self, friend_number, typing):
"""
@ -1249,9 +1231,7 @@ class Tox:
Tox.libtoxcore.tox_callback_friend_read_receipt(self._tox_pointer,
self.friend_read_receipt_cb)
# -----------------------------------------------------------------------------------------------------------------
# Receiving private messages and friend requests
# -----------------------------------------------------------------------------------------------------------------
def callback_friend_request(self, callback):
"""
@ -1302,9 +1282,7 @@ class Tox:
LOG_DEBUG(f"tox.callback_friend_message")
Tox.libtoxcore.tox_callback_friend_message(self._tox_pointer, self.friend_message_cb)
# -----------------------------------------------------------------------------------------------------------------
# File transmission: common between sending and receiving
# -----------------------------------------------------------------------------------------------------------------
@staticmethod
def hash(data, hash=None):
@ -1454,9 +1432,7 @@ class Tox:
if err_val == TOX_ERR_FILE_GET['NOT_FOUND']:
raise ArgumentError('No file transfer with the given file number was found for the given friend.')
# -----------------------------------------------------------------------------------------------------------------
# File transmission: sending
# -----------------------------------------------------------------------------------------------------------------
def file_send(self, friend_number, kind, file_size, file_id, filename):
"""Send a file transmission request.
@ -1618,9 +1594,7 @@ class Tox:
self.file_chunk_request_cb = c_callback(callback)
self.libtoxcore.tox_callback_file_chunk_request(self._tox_pointer, self.file_chunk_request_cb)
# -----------------------------------------------------------------------------------------------------------------
# File transmission: receiving
# -----------------------------------------------------------------------------------------------------------------
def callback_file_recv(self, callback):
"""
@ -1687,9 +1661,7 @@ class Tox:
self.file_recv_chunk_cb = c_callback(callback)
self.libtoxcore.tox_callback_file_recv_chunk(self._tox_pointer, self.file_recv_chunk_cb)
# -----------------------------------------------------------------------------------------------------------------
# Low-level custom packet sending and receiving
# -----------------------------------------------------------------------------------------------------------------
def friend_send_lossy_packet(self, friend_number, data):
"""
@ -1811,9 +1783,7 @@ class Tox:
self.friend_lossless_packet_cb = c_callback(callback)
self.libtoxcore.tox_callback_friend_lossless_packet(self._tox_pointer, self.friend_lossless_packet_cb)
# -----------------------------------------------------------------------------------------------------------------
# Low-level network information
# -----------------------------------------------------------------------------------------------------------------
# def self_get_keys(self): pass
def self_get_dht_id(self, dht_id=None):
@ -1867,9 +1837,7 @@ class Tox:
raise ToxError('The instance was not bound to any port.')
raise ToxError('The function did not return OK')
# -----------------------------------------------------------------------------------------------------------------
# Group chat instance management
# -----------------------------------------------------------------------------------------------------------------
def group_new(self, privacy_state, group_name, nick, status=''):
"""Creates a new group chat.
@ -1918,7 +1886,7 @@ class Tox:
if error.value:
s = sGetError(error.value, TOX_ERR_GROUP_NEW)
LOG_ERROR(f"group_new {error.value} {s}")
raise ToxError(f"group_new {s} {error.value}")
raise ToxError(f"group_new {s} err={error.value}")
# TypeError: '<' not supported between instances of 'c_uint' and 'int'
return int(result)
@ -1999,7 +1967,7 @@ class Tox:
if error.value:
s = sGetError(error.value, TOX_ERR_GROUP_RECONNECT)
LOG_ERROR(f"group_new {error.value} {s}")
raise ToxError(f"group_new {s} {error.value}")
raise ToxError(f"group_new {s} err={error.value}")
return bool(result)
def group_is_connected(self, group_number):
@ -2025,7 +1993,7 @@ class Tox:
if error.value:
s = sGetError(error.value, TOX_ERR_GROUP_DISCONNECT)
LOG_ERROR(f"group_disconnect {error.value} {s}")
raise ToxError(f"group_disconnect {s} {error.value}")
raise ToxError(f"group_disconnect {s} err={error.value}")
return bool(result)
def group_leave(self, group_number, message=None):
@ -2055,13 +2023,11 @@ class Tox:
result = f(self._tox_pointer, c_uint32(group_number), message,
c_size_t(len(message)) if message else 0, byref(error))
if error.value:
LOG_ERROR(f"group_leave {error.value}")
raise ToxError("group_leave {error.value}")
LOG_ERROR(f"group_leave err={error.value}")
raise ToxError("group_leave err={error.value}")
return bool(result)
# -----------------------------------------------------------------------------------------------------------------
# Group user-visible client information (nickname/status/role/public key)
# -----------------------------------------------------------------------------------------------------------------
def group_self_set_name(self, group_number, name):
"""Set the client's nickname for the group instance designated by the given group number.
@ -2084,8 +2050,8 @@ class Tox:
LOG_DEBUG(f"tox.group_self_set_name")
result = Tox.libtoxcore.tox_group_self_set_name(self._tox_pointer, c_uint32(group_number), name, c_size_t(len(name)), byref(error))
if error.value:
LOG_ERROR(f"group_self_set_name {error.value}")
raise ToxError("group_self_set_name {error.value}")
LOG_ERROR(f"group_self_set_name err={error.value}")
raise ToxError("group_self_set_name err={error.value}")
return bool(result)
def group_self_get_name_size(self, group_number):
@ -2105,8 +2071,8 @@ class Tox:
c_uint32(group_number),
byref(error))
if error.value:
LOG_ERROR(f"group_self_get_name_size {error.value}")
raise ToxError("group_self_get_name_size {error.value}")
LOG_ERROR(f"group_self_get_name_size err={error.value}")
raise ToxError("group_self_get_name_size err={error.value}")
return int(result)
def group_self_get_name(self, group_number):
@ -2125,7 +2091,7 @@ class Tox:
raise ToxError(f"tox_group_ group_number < 0 {group_number}")
error = c_int()
size = self.group_self_get_name_size(c_uint32(group_number))
size = self.group_self_get_name_size(group_number)
name = create_string_buffer(size)
LOG_DEBUG(f"tox.group_self_get_name")
result = Tox.libtoxcore.tox_group_self_get_name(self._tox_pointer,
@ -2150,8 +2116,8 @@ class Tox:
LOG_DEBUG(f"tox.group_self_set_status")
result = Tox.libtoxcore.tox_group_self_set_status(self._tox_pointer, c_uint32(group_number), status, byref(error))
if error.value:
LOG_ERROR(f"group_self_set_status {error.value}")
raise ToxError("group_self_set_status {error.value}")
LOG_ERROR(f"group_self_set_status err={error.value}")
raise ToxError("group_self_set_status err={error.value}")
return bool(result)
def group_self_get_status(self, group_number):
@ -2166,7 +2132,7 @@ class Tox:
LOG_DEBUG(f"tox.group_self_get_status")
result = Tox.libtoxcore.tox_group_self_get_status(self._tox_pointer, c_uint32(group_number), byref(error))
if error.value:
LOG_ERROR(f"group_self_get_status {error.value}")
LOG_ERROR(f"group_self_get_status err={error.value}")
raise ToxError("group_self_get_status err={error.value}")
return int(result)
@ -2199,7 +2165,7 @@ class Tox:
result = Tox.libtoxcore.tox_group_self_get_peer_id(self._tox_pointer, c_uint32(group_number), byref(error))
if error.value:
LOG_ERROR(f"tox.group_self_get_peer_id err={error.value}")
raise ToxError("tox_group_self_get_peer_id {error.value}")
raise ToxError("tox_group_self_get_peer_id err={error.value}")
return int(result)
def group_self_get_public_key(self, group_number):
@ -2227,9 +2193,7 @@ class Tox:
raise ToxError(f"tox.group_self_get_public_key {TOX_ERR_FRIEND_GET_PUBLIC_KEY[error.value]}")
return bin_to_string(key, TOX_GROUP_PEER_PUBLIC_KEY_SIZE)
# -----------------------------------------------------------------------------------------------------------------
# Peer-specific group state queries.
# -----------------------------------------------------------------------------------------------------------------
def group_peer_get_name_size(self, group_number, peer_id):
"""
@ -2245,8 +2209,8 @@ class Tox:
error = c_int()
result = Tox.libtoxcore.tox_group_peer_get_name_size(self._tox_pointer, c_uint32(group_number), c_uint32(peer_id), byref(error))
if error.value:
LOG_ERROR(f" {error.value}")
raise ToxError(f" {error.value}")
LOG_ERROR(f" err={error.value}")
raise ToxError(f" err={error.value}")
LOG_TRACE(f"tox_group_peer_get_name_size")
return int(result)
@ -2300,9 +2264,10 @@ class Tox:
c_uint32(peer_id),
byref(error))
if error.value:
LOG_ERROR(f"tox.group_peer_get_status {error.value}")
raise ToxError(f"tox.group_peer_get_status {error.value}")
return result
# unwrapped
LOG_ERROR(f"tox.group_peer_get_status err={error.value}")
raise ToxError(f"tox.group_peer_get_status err={error.value}")
return int(result)
def group_peer_get_role(self, group_number, peer_id):
"""
@ -2318,12 +2283,12 @@ class Tox:
error = c_int()
LOG_DEBUG(f"tox.group_peer_get_role")
result = Tox.libtoxcore.tox_group_peer_get_role(self._tox_pointer,
c_uint32(group_number),
s c_uint32(group_number),
c_uint32(peer_id),
byref(error))
if error.value:
LOG_ERROR(f"tox.group_peer_get_role {error.value}")
raise ToxError(f"tox.group_peer_get_role {error.value}")
LOG_ERROR(f"tox.group_peer_get_role err={error.value}")
raise ToxError(f"tox.group_peer_get_role err={error.value}")
return int(result)
def group_peer_get_public_key(self, group_number, peer_id):
@ -2397,9 +2362,7 @@ class Tox:
LOG_WARN(f"callback_group_peer_status Exception {e}")
return None
# -----------------------------------------------------------------------------------------------------------------
# Group chat state queries and events.
# -----------------------------------------------------------------------------------------------------------------
def group_set_topic(self, group_number, topic):
"""Set the group topic and broadcast it to the rest of the group.
@ -2474,8 +2437,8 @@ class Tox:
LOG_DEBUG(f"tox.group_get_topic")
result = Tox.libtoxcore.tox_group_get_topic(self._tox_pointer, c_uint32(group_number), topic, byref(error))
if error.value:
LOG_ERROR(f" {error.value}")
raise ToxError(f" {error.value}")
LOG_ERROR(f" err={error.value}")
raise ToxError(f" err={error.value}")
return str(topic[:size], 'utf-8', errors='ignore')
def group_get_name_size(self, group_number):
@ -2490,8 +2453,8 @@ class Tox:
c_uint32(group_number),
byref(error))
if error.value:
LOG_ERROR(f" {error.value}")
raise ToxError(f" {error.value}")
LOG_ERROR(f" err={error.value}")
raise ToxError(f" err={error.value}")
LOG_TRACE(f"tox_group_get_name_size")
return int(result)
@ -2511,8 +2474,8 @@ class Tox:
result = Tox.libtoxcore.tox_group_get_name(self._tox_pointer, c_uint32(group_number),
name, byref(error))
if error.value:
LOG_ERROR(f" {error.value}")
raise ToxError(f" {error.value}")
LOG_ERROR(f"group_get_name err={error.value}")
raise ToxError(f"group_get_name err={error.value}")
return str(name[:size], 'utf-8', errors='ignore')
def group_get_chat_id(self, group_number):
@ -2587,8 +2550,8 @@ class Tox:
c_uint32(group_number),
byref(error))
if error.value:
LOG_ERROR(f"tox.group_get_privacy_state {error.value}")
raise ToxError(f"tox.group_get_privacy_state {error.value}")
LOG_ERROR(f"tox.group_get_privacy_state err={error.value}")
raise ToxError(f"tox.group_get_privacy_state err={error.value}")
return int(result)
def group_get_peer_limit(self, group_number):
@ -2610,8 +2573,8 @@ class Tox:
c_uint(group_number),
byref(error))
if error.value:
LOG_ERROR(f"tox.group_get_peer_limit {error.value}")
raise ToxError(f"tox.group_get_peer_limit {error.value}")
LOG_ERROR(f"tox.group_get_peer_limit err={error.value}")
raise ToxError(f"tox.group_get_peer_limit err={error.value}")
return int(result)
def group_get_password_size(self, group_number):
@ -2627,8 +2590,8 @@ class Tox:
result = Tox.libtoxcore.tox_group_get_password_size(self._tox_pointer,
c_uint(group_number), byref(error))
if error.value:
LOG_ERROR(f" {error.value}")
raise ToxError(f" {error.value}")
LOG_ERROR(f"group_get_password_size err={error.value}")
raise ToxError(f"group_get_password_size err={error.value}")
return result
def group_get_password(self, group_number):
@ -2654,8 +2617,8 @@ class Tox:
result = Tox.libtoxcore.tox_group_get_password(self._tox_pointer, c_uint(group_number),
password, byref(error))
if error.value:
LOG_ERROR(f" {error.value}")
raise ToxError(f" {error.value}")
LOG_ERROR(f"group_get_password err={error.value}")
raise ToxError(f"group_get_password err={error.value}")
return str(password[:size], 'utf-8', errors='ignore')
def callback_group_topic(self, callback, user_data):
@ -2734,9 +2697,7 @@ class Tox:
except Exception as e:
LOG_WARN(f"tox.callback_group_password Exception {e}")
# -----------------------------------------------------------------------------------------------------------------
# Group message sending
# -----------------------------------------------------------------------------------------------------------------
def group_send_custom_packet(self, group_number, lossless, data):
"""Send a custom packet to the group.
@ -2775,9 +2736,9 @@ class Tox:
c_size_t(len(data)),
byref(error))
if error.value:
LOG_ERROR(f" {error.value}")
raise ToxError(f" {error.value}")
return result
LOG_ERROR(f"group_send_custom_packet err={error.value}")
raise ToxError(f"group_send_custom_packet err={error.value}")
return bool(result)
def group_send_private_message(self, group_number, peer_id, message_type, message):
"""
@ -2814,7 +2775,7 @@ class Tox:
LOG_ERROR(f"group_send_private_message {error.value} {s}")
raise ToxError(f"group_send_private_message {error.value} {s}")
return result
return bool(result)
def group_send_message(self, group_number, type_, message):
"""
@ -2857,11 +2818,9 @@ class Tox:
LOG_ERROR(f"group_send_message {error.value} {s}")
raise ToxError(f"group_send_message {error.value} {s}")
return result
return bool(result)
# -----------------------------------------------------------------------------------------------------------------
# Group message receiving
# -----------------------------------------------------------------------------------------------------------------
def callback_group_message(self, callback, user_data):
"""
@ -2921,9 +2880,7 @@ class Tox:
LOG_DEBUG(f"tox.callback_group_custom_packet")
Tox.libtoxcore.tox_callback_group_custom_packet(self._tox_pointer, self.group_custom_packet_cb)
# -----------------------------------------------------------------------------------------------------------------
# Group chat inviting and join/part events
# -----------------------------------------------------------------------------------------------------------------
def group_invite_friend(self, group_number, friend_number):
"""
@ -2946,7 +2903,7 @@ class Tox:
s = sGetError(error.value, TOX_ERR_GROUP_INVITE_FRIEND)
LOG_ERROR(f"group_invite_friend {error.value} {s}")
raise ToxError(f"group_invite_friend {error.value} {s}")
return result
return bool(result)
# API change - this no longer exists
# @staticmethod
@ -3004,7 +2961,7 @@ class Tox:
if error.value:
s = sGetError(error.value, TOX_ERR_GROUP_INVITE_ACCEPT)
LOG_ERROR(f"group_invite_friend {error.value} {s}")
raise ToxError(f"group_invite_accept {s} {error.value}")
raise ToxError(f"group_invite_accept {s} err={error.value}")
return result
def callback_group_invite(self, callback, user_data):
@ -3139,9 +3096,7 @@ class Tox:
except Exception as e:
LOG_ERROR(f"tox.callback_group_join_fail {e}") # req
# -----------------------------------------------------------------------------------------------------------------
# Group chat founder controls (these only work for the group founder)
# -----------------------------------------------------------------------------------------------------------------
def group_founder_set_password(self, group_number, password):
"""
@ -3166,8 +3121,8 @@ class Tox:
if error.value:
s = sGetError(error.value, TOX_ERR_GROUP_FOUNDER_SET_PASSWORD)
LOG_ERROR(f"group_founder_set_password {error.value} {s}")
raise ToxError(f"group_founder_set_password {s} {error.value}")
return result
raise ToxError(f"group_founder_set_password {s} err={error.value}")
return bool(result)
def group_founder_set_privacy_state(self, group_number, privacy_state):
"""
@ -3192,9 +3147,9 @@ class Tox:
result = Tox.libtoxcore.tox_group_founder_set_privacy_state(self._tox_pointer, c_uint(group_number), privacy_state,
byref(error))
if error.value:
LOG_ERROR(f" {error.value}")
raise ToxError(f" {error.value}")
return result
LOG_ERROR(f"group_founder_set_privacy_state err={error.value}")
raise ToxError(f"group_founder_set_privacy_state err={error.value}")
return bool(result)
def group_founder_set_peer_limit(self, group_number, max_peers):
"""
@ -3218,13 +3173,11 @@ class Tox:
max_peers,
byref(error))
if error.value:
LOG_ERROR(f" {error.value}")
raise ToxError(f" {error.value}")
return result
LOG_ERROR(f"group_founder_set_peer_limit err={error.value}")
raise ToxError(f"group_founder_set_peer_limit err={error.value}")
return bool(result)
# -----------------------------------------------------------------------------------------------------------------
# Group chat moderation
# -----------------------------------------------------------------------------------------------------------------
def group_mod_set_role(self, group_number, peer_id, role):
"""
@ -3247,9 +3200,9 @@ class Tox:
LOG_DEBUG(f"tox.group_mod_set_role")
result = Tox.libtoxcore.tox_group_mod_set_role(self._tox_pointer, c_uint(group_number), c_uint32(peer_id), role, byref(error))
if error.value:
LOG_ERROR(f" {error.value}")
raise ToxError(f" {error.value}")
return result
LOG_ERROR(f"group_mod_set_role err={error.value}")
raise ToxError(f"group_mod_set_role err={error.value}")
return bool(result)
def callback_group_moderation(self, callback, user_data):
"""
@ -3301,6 +3254,6 @@ class Tox:
c_bool(ignore),
byref(error))
if error.value:
LOG_ERROR(f"tox.group_set_ignore {error.value}")
raise ToxError("tox_group_set_ignore {error.value}")
return result
LOG_ERROR(f"tox.group_set_ignore err={error.value}")
raise ToxError("tox_group_set_ignore err={error.value}")
return bool(result)

View File

@ -22,9 +22,7 @@ class ToxAV:
peers.
"""
# -----------------------------------------------------------------------------------------------------------------
# Creation and destruction
# -----------------------------------------------------------------------------------------------------------------
def __init__(self, tox_pointer):
"""
@ -69,9 +67,7 @@ class ToxAV:
self.libtoxav.toxav_get_tox.restype = POINTER(c_void_p)
return self.libtoxav.toxav_get_tox(self._toxav_pointer)
# -----------------------------------------------------------------------------------------------------------------
# A/V event loop
# -----------------------------------------------------------------------------------------------------------------
def iteration_interval(self):
"""
@ -89,9 +85,7 @@ class ToxAV:
"""
self.libtoxav.toxav_iterate(self._toxav_pointer)
# -----------------------------------------------------------------------------------------------------------------
# Call setup
# -----------------------------------------------------------------------------------------------------------------
def call(self, friend_number, audio_bit_rate, video_bit_rate):
"""
@ -181,9 +175,7 @@ class ToxAV:
elif toxav_err_answer == TOXAV_ERR_ANSWER['INVALID_BIT_RATE']:
raise ArgumentError('Audio or video bit rate is invalid.')
# -----------------------------------------------------------------------------------------------------------------
# Call state graph
# -----------------------------------------------------------------------------------------------------------------
def callback_call_state(self, callback, user_data):
"""
@ -208,9 +200,7 @@ class ToxAV:
self.call_state_cb = c_callback(callback)
self.libtoxav.toxav_callback_call_state(self._toxav_pointer, self.call_state_cb, user_data)
# -----------------------------------------------------------------------------------------------------------------
# Call control
# -----------------------------------------------------------------------------------------------------------------
def call_control(self, friend_number, control):
"""
@ -238,13 +228,9 @@ class ToxAV:
raise RuntimeError('Happens if user tried to pause an already paused call or if trying to resume a call '
'that is not paused.')
# -----------------------------------------------------------------------------------------------------------------
# TODO Controlling bit rates
# -----------------------------------------------------------------------------------------------------------------
# -----------------------------------------------------------------------------------------------------------------
# A/V sending
# -----------------------------------------------------------------------------------------------------------------
def audio_send_frame(self, friend_number, pcm, sample_count, channels, sampling_rate):
"""
@ -331,9 +317,7 @@ class ToxAV:
elif toxav_err_send_frame == TOXAV_ERR_SEND_FRAME['RTP_FAILED']:
RuntimeError('Failed to push frame through rtp interface.')
# -----------------------------------------------------------------------------------------------------------------
# A/V receiving
# -----------------------------------------------------------------------------------------------------------------
def callback_audio_receive_frame(self, callback, user_data):
"""

View File

@ -423,13 +423,13 @@ class ToxSuite(unittest.TestCase):
LOG.debug(f"call_bootstrap ts.bootstrap_tcp {len(lElts)}")
ts.bootstrap_tcp(lElts, lToxes)
def group_until_connected(self, group_number, num=None, iMax=THRESHOLD):
def group_until_connected(self, otox, group_number, num=None, iMax=THRESHOLD):
"""
"""
i = 0
bRet = None
while i <= iMax :
iRet = self.bob.group_is_connected(group_number)
iRet = otox.group_is_connected(group_number)
if iRet == True or iRet == 0:
bRet = True
break
@ -441,24 +441,24 @@ class ToxSuite(unittest.TestCase):
LOG.info(s+"group_until_connected " \
+" #" + str(i) \
+" iRet=" +repr(iRet) \
+f" BOBS={self.bob.mycon_status}" \
+f" last={int(self.bob.mycon_time)}" )
+f" BOBS={otox.mycon_status}" \
+f" last={int(otox.mycon_time)}" )
i += 1
self.loop(100)
else:
bRet = False
if bRet:
LOG.info(f"group_until_connected returning True {i}" \
LOG.info(f"group_until_connected True i={i}" \
+f" iMax={iMax}" \
+f" BOB={self.bob.self_get_connection_status()}" \
+f" last={int(self.bob.mycon_time)}" )
+f" BOB={otox.self_get_connection_status()}" \
+f" last={int(otox.mycon_time)}" )
return True
else:
LOG.warning(f"group_until_connected returning False {i}" \
LOG.warning(f"group_until_connected False i={i}" \
+f" iMax={iMax}" \
+f" BOB={self.bob.self_get_connection_status()}" \
+f" last={int(self.bob.mycon_time)}" )
+f" BOB={otox.self_get_connection_status()}" \
+f" last={int(otox.mycon_time)}" )
return False
def loop_until_connected(self, num=None):
@ -466,6 +466,7 @@ class ToxSuite(unittest.TestCase):
t:on_self_connection_status
t:self_get_connection_status
"""
global THRESHOLD
i = 0
bRet = None
while i <= THRESHOLD :
@ -509,6 +510,7 @@ class ToxSuite(unittest.TestCase):
+f" last={int(self.bob.mycon_time)}" )
return True
else:
THRESHOLD += 5
LOG.warning(f"loop_until_connected returning False {i}" \
+f" BOB={self.bob.self_get_connection_status()}" \
+f" ALICE={self.alice.self_get_connection_status()}" \
@ -516,6 +518,7 @@ class ToxSuite(unittest.TestCase):
return False
def wait_objs_attr(self, objs, attr):
global THRESHOLD
i = 0
while i <= THRESHOLD:
if i % 5 == 0:
@ -529,7 +532,8 @@ class ToxSuite(unittest.TestCase):
self.loop(100)
i += 1
else:
LOG.error(f"wait_objs_attr for {attr} i >= {THRESHOLD}")
THRESHOLD += 1
LOG.warn(f"wait_objs_attr for {attr} i >= {THRESHOLD}")
return all([getattr(obj, attr) is not None for obj in objs])
@ -830,7 +834,8 @@ class ToxSuite(unittest.TestCase):
assert otox.group_get_topic_size(iGrp) == len(topic)
name = otox.group_get_name(iGrp)
if type(name) == bytes: name = str(name, 'utf-8')
if type(name) == bytes:
name = str(name, 'utf-8')
assert name == group_name, name
assert otox.group_get_name_size(iGrp) == len(group_name)
@ -843,6 +848,60 @@ class ToxSuite(unittest.TestCase):
LOG.info(f"group pK={sPk} iGrp={iGrp} n={otox.group_get_number_groups()}")
return iGrp
def otox_verify_group(self, otox, iGrp):
"""
group_self_get_name
group_self_get_peer_id
group_self_get_public_key
group_self_get_role
group_self_get_status
"""
group_number = iGrp
assert type(iGrp) == int, "otox_test_groups_join iGrp not an int"
assert iGrp < UINT32_MAX, "otox_test_groups_join iGrp failure UINT32_MAX"
assert iGrp >= 0, f"otox_test_groups_join iGrp={iGrp} < 0"
sGrp = otox.group_get_chat_id(iGrp)
assert len(sGrp) == enums.TOX_GROUP_CHAT_ID_SIZE * 2, \
f"group sGrp={sGrp} {len(sGrp)} != {enums.TOX_GROUP_CHAT_ID_SIZE * 2}"
sPk = otox.group_self_get_public_key(iGrp)
LOG.info(f"otox_verify_group sPk={sPk} iGrp={iGrp} n={otox.group_get_number_groups()}")
sName = otox.group_self_get_name(iGrp)
iStat = otox.group_self_get_status(iGrp)
iId = otox.group_self_get_peer_id(iGrp)
iRole = otox.group_self_get_role(iGrp)
iStat = otox.group_self_get_status(iGrp)
LOG.info(f"otox_verify_group sName={sName} iStat={iStat} iId={iId} iRole={iRole} iStat={iStat}")
try:
bRet = otox.group_is_connected(iGrp)
except Exception as e:
LOG.warn(f"group_is_connected EXCEPTION {e}")
return -1
# chat->connection_state == CS_CONNECTED || chat->connection_state == CS_CONNECTING;
if not bRet:
LOG.warn(f"group_is_connected WARN not connected iGrp={iGrp} n={otox.group_get_number_groups()}")
else:
LOG.info(f"group_is_connected SUCCESS connected iGrp={iGrp} n={otox.group_get_number_groups()}")
try:
bRet = self.group_until_connected(otox, iGrp, iMax=2*THRESHOLD)
except Exception as e:
LOG.error(f"group_until_connected EXCEPTION {e}")
return -1
# chat->connection_state == CS_CONNECTED || chat->connection_state == CS_CONNECTING;
if bRet:
LOG.warn(f"group_until_connected WARN not connected iGrp={iGrp} n={otox.group_get_number_groups()}")
else:
LOG.info(f"group_until_connected SUCCESS connected iGrp={iGrp} n={otox.group_get_number_groups()}")
message = bytes('hello', 'utf-8')
bRet = otox.group_send_message(iGrp, TOX_MESSAGE_TYPE['NORMAL'], message)
if not bRet:
LOG.warn(f"group_send_message {bRet}")
else:
LOG.debug(f"group_send_message {bRet}")
# 360497DA684BCE2A500C1AF9B3A5CE949BBB9F6FB1F91589806FB04CA039E313
# 75D2163C19FEFFE51508046398202DDC321E6F9B6654E99BAE45FFEC134F05DE
def otox_test_groups_join(self, otox,
@ -854,43 +913,16 @@ class ToxSuite(unittest.TestCase):
password = ''
LOG.debug(f"group_join nick={nick} chat_id={chat_id}")
try:
group_number = otox.group_join(chat_id, password, nick, status)
LOG.info(f"otox_test_groups_join SUCCESS group_number={group_number} chat_id={chat_id}")
assert type(group_number) == int, "otox_test_groups_join group_number not an int"
assert group_number < UINT32_MAX, "otox_test_groups_join group_number failure UINT32_MAX"
assert group_number >= 0, f"otox_test_groups_join group_number={group_number} < 0"
iGrp = group_number
sPk = otox.group_self_get_public_key(iGrp)
LOG.info(f"otox_test_groups_join pK={sPk} iGrp={iGrp} n={otox.group_get_number_groups()}")
iGrp = otox.group_join(chat_id, password, nick, status)
LOG.info(f"otox_test_groups_join SUCCESS iGrp={iGrp} chat_id={chat_id}")
self.otox_verify_group(otox, iGrp)
except Exception as e:
# gui
LOG.error(f"otox_test_groups_join EXCEPTION {e}")
raise
try:
bRet = otox.group_is_connected(group_number)
except Exception as e:
LOG.error(f"group_is_connected EXCEPTION {e}")
return -1
# chat->connection_state == CS_CONNECTED || chat->connection_state == CS_CONNECTING;
if bRet:
LOG.warn(f"group_is_connected WARN not connected group_number={group_number} n={otox.group_get_number_groups()}")
else:
LOG.info(f"group_is_connected SUCCESS connected group_number={group_number} n={otox.group_get_number_groups()}")
try:
bRet = self.group_until_connected(group_number, iMax=2*THRESHOLD)
except Exception as e:
LOG.error(f"group_until_connected EXCEPTION {e}")
return -1
# chat->connection_state == CS_CONNECTED || chat->connection_state == CS_CONNECTING;
if bRet:
LOG.warn(f"group_until_connected WARN not connected group_number={group_number} n={otox.group_get_number_groups()}")
else:
LOG.info(f"group_until_connected SUCCESS connected group_number={group_number} n={otox.group_get_number_groups()}")
return group_number
return iGrp
def otox_test_groups(self,
otox,
@ -898,54 +930,13 @@ class ToxSuite(unittest.TestCase):
nick='test_nick',
topic='Test Topic', # str
):
try:
iGrp = self.otox_test_groups_create(otox, group_name, nick, topic)
sGrp = otox.group_get_chat_id(iGrp)
assert len(sGrp) == enums.TOX_GROUP_CHAT_ID_SIZE * 2, \
f"group sGrp={sGrp} {len(sGrp)} != {enums.TOX_GROUP_CHAT_ID_SIZE * 2}"
LOG.info(f"group sGrp={sGrp}")
if False:
# already joined
try:
iNum = otox.group_join(sGrp, None, nick)
# :return group_number on success, UINT32_MAX on failure.
self.otox_verify_group(otox, iGrp)
except Exception as e:
LOG.error(f"group_join ERROR {e}")
if str(e).find('2') >= 0:
iNum = iGrp
else:
LOG.debug('\n' + traceback.format_exc())
iNum = -1
if iNum < 0:
return iGrp
#?
group_number = iGrp
try:
bRet = otox.group_is_connected(group_number)
except Exception as e:
LOG.error(f"group_is_connected ERROR {e}")
return -1
try:
bRet = self.group_until_connected(group_number, iMax=2*THRESHOLD)
except Exception as e:
LOG.error(f"group_until_connected EXCEPTION {e}")
return -1
# chat->connection_state == CS_CONNECTED || chat->connection_state == CS_CONNECTING;
if bRet:
LOG.warn(f"group_until_connected WARN not connected group_number={group_number} n={otox.group_get_number_groups()}")
else:
LOG.info(f"group_until_connected SUCCESS connected group_number={group_number} n={otox.group_get_number_groups()}")
message = bytes('hello', 'utf-8')
try:
bRet = otox.group_send_message(group_number, TOX_MESSAGE_TYPE['NORMAL'], 'hello')
if not bRet:
LOG.warn(f"group_send_message {bRet}")
else:
LOG.debug(f"group_send_message {bRet}")
except Exception as e:
LOG.error(f"group_send_message ERROR {e}")
LOG.error(f"otox_test_groups ERROR {e}")
raise
# unfinished
# tox_group_peer_exit_cb
@ -1444,8 +1435,8 @@ class ToxSuite(unittest.TestCase):
LOG.error(f"bob.group_leave EXCEPTION {e}")
raise
@unittest.skip("double free or corruption (fasttop)")
# @expectedFail('fails') # assertion fails on == MSG
#? @unittest.skip("double free or corruption (fasttop)")
@expectedFail('fails') # assertion fails on == MSG
def test_on_friend_status_message(self): # fails
"""
t:self_set_status_message
@ -1472,9 +1463,12 @@ class ToxSuite(unittest.TestCase):
setattr(self.bob, sSlot, None)
try:
if bUSE_NOREQUEST:
assert self.both_add_as_friend_norequest()
assert self.bob_add_alice_as_friend_norequest()
# assert self.alice_add_bob_as_friend_norequest()
else:
assert self.both_add_as_friend()
# no not connected error
assert self.bob_add_alice_as_friend()
# assert self.alice_add_bob_as_friend_norequest()
self.bob.callback_friend_status_message(bob_on_friend_status_message)
self.warn_if_no_cb(self.bob, sSlot)
@ -1508,6 +1502,7 @@ class ToxSuite(unittest.TestCase):
t:on_friend_name
"""
try:
#: Test friend request
if bUSE_NOREQUEST:
assert self.bob_add_alice_as_friend_norequest()
@ -1515,8 +1510,8 @@ class ToxSuite(unittest.TestCase):
else:
# no not connected error
assert self.bob_add_alice_as_friend()
assert self.alice_add_bob_as_friend()
try:
assert self.alice_add_bob_as_friend_norequest()
a = self.alice.self_get_address()[:CLIENT_ID_SIZE]
assert self.bob.friend_get_public_key(self.baid) == a, \
LOG.error(f"test_friend BAID {a}")