fixes
This commit is contained in:
parent
99136cd4e3
commit
68f28fdac5
39 changed files with 219 additions and 285 deletions
|
|
@ -1,59 +1,25 @@
|
|||
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
||||
import user_data.settings
|
||||
import wrapper.tox
|
||||
import wrapper.toxcore_enums_and_consts as enums
|
||||
|
||||
import ctypes
|
||||
import traceback
|
||||
import os
|
||||
from ctypes import *
|
||||
|
||||
import user_data.settings
|
||||
import tox_wrapper.tox
|
||||
import tox_wrapper.toxcore_enums_and_consts as enums
|
||||
from tox_wrapper.tests import support_testing as ts
|
||||
# callbacks can be called in any thread so were being careful
|
||||
# tox.py can be called by callbacks
|
||||
from tox_wrapper.tests.support_testing import LOG_ERROR, LOG_WARN, LOG_INFO, LOG_DEBUG, LOG_TRACE
|
||||
|
||||
global LOG
|
||||
import logging
|
||||
LOG = logging.getLogger('app.'+'tox_factory')
|
||||
|
||||
from ctypes import *
|
||||
from utils import util
|
||||
from utils import ui as util_ui
|
||||
|
||||
# callbacks can be called in any thread so were being careful
|
||||
# tox.py can be called by callbacks
|
||||
def LOG_ERROR(a): print('EROR> '+a)
|
||||
def LOG_WARN(a): print('WARN> '+a)
|
||||
def LOG_INFO(a):
|
||||
bVERBOSE = hasattr(__builtins__, 'app') and app.oArgs.loglevel <= 20
|
||||
if bVERBOSE: print('INFO> '+a)
|
||||
def LOG_DEBUG(a):
|
||||
bVERBOSE = hasattr(__builtins__, 'app') and app.oArgs.loglevel <= 10
|
||||
if bVERBOSE: print('DBUG> '+a)
|
||||
def LOG_TRACE(a):
|
||||
bVERBOSE = hasattr(__builtins__, 'app') and app.oArgs.loglevel < 10
|
||||
if bVERBOSE: print('TRAC> '+a)
|
||||
def LOG_LOG(a): print('TRAC> '+a)
|
||||
|
||||
def tox_log_cb(iTox, level, file, line, func, message, *args):
|
||||
"""
|
||||
* @param level The severity of the log message.
|
||||
* @param file The source file from which the message originated.
|
||||
* @param line The source line from which the message originated.
|
||||
* @param func The function from which the message originated.
|
||||
* @param message The log message.
|
||||
* @param user_data The user data pointer passed to tox_new in options.
|
||||
"""
|
||||
try:
|
||||
file = str(file, 'UTF-8')
|
||||
# root WARNING 3network.c#944:b'send_packet'attempted to send message with network family 10 (probably IPv6) on IPv4 socket
|
||||
if file == 'network.c' and line in [944, 660]: return
|
||||
func = str(func, 'UTF-8')
|
||||
message = str(message, 'UTF-8')
|
||||
message = f"{file}#{line}:{func} {message}"
|
||||
LOG_LOG(message)
|
||||
except Exception as e:
|
||||
LOG_ERROR(f"tox_log_cb {e}")
|
||||
|
||||
#tox_log_handler (context=0x24763d0,
|
||||
# level=LOGGER_LEVEL_TRACE, file=0x7fffe599fb99 "TCP_common.c", line=203,
|
||||
# func=0x7fffe599fc50 <__func__.2> "read_TCP_packet",
|
||||
# message=0x7fffba7fabd0 "recv buffer has 0 bytes, but requested 10 bytes",
|
||||
# userdata=0x0) at /var/local/src/c-toxcore/toxcore/tox.c:78
|
||||
|
||||
def tox_factory(data=None, settings=None, args=None, app=None):
|
||||
"""
|
||||
|
|
@ -68,7 +34,7 @@ def tox_factory(data=None, settings=None, args=None, app=None):
|
|||
user_data.settings.clean_settings(settings)
|
||||
|
||||
try:
|
||||
tox_options = wrapper.tox.Tox.options_new()
|
||||
tox_options = tox_wrapper.tox.Tox.options_new()
|
||||
tox_options.contents.ipv6_enabled = settings['ipv6_enabled']
|
||||
tox_options.contents.udp_enabled = settings['udp_enabled']
|
||||
tox_options.contents.proxy_type = int(settings['proxy_type'])
|
||||
|
|
@ -99,27 +65,28 @@ def tox_factory(data=None, settings=None, args=None, app=None):
|
|||
tox_options.contents.ipv6_enabled = False
|
||||
tox_options.contents.hole_punching_enabled = False
|
||||
|
||||
LOG.debug("wrapper.tox.Tox settings: " +repr(settings))
|
||||
LOG.debug("tox_wrapper.tox.Tox settings: " +repr(settings))
|
||||
|
||||
if 'trace_enabled' in settings and settings['trace_enabled']:
|
||||
LOG_INFO("settings['trace_enabled' disabled" )
|
||||
if 'trace_enabled' in settings and not settings['trace_enabled']:
|
||||
LOG_DEBUG("settings['trace_enabled' disabled" )
|
||||
elif tox_options._options_pointer:
|
||||
c_callback = CFUNCTYPE(None, c_void_p, c_int, c_char_p, c_int, c_char_p, c_char_p, c_void_p)
|
||||
tox_options.self_logger_cb = c_callback(tox_log_cb)
|
||||
wrapper.tox.Tox.libtoxcore.tox_options_set_log_callback(
|
||||
tox_options.self_logger_cb = c_callback(ts.tox_log_cb)
|
||||
tox_wrapper.tox.Tox.libtoxcore.tox_options_set_log_callback(
|
||||
tox_options._options_pointer,
|
||||
tox_options.self_logger_cb)
|
||||
LOG_INFO("c-toxcore trace_enabled enabled" )
|
||||
else:
|
||||
LOG_WARN("No tox_options._options_pointer to add self_logger_cb" )
|
||||
|
||||
retval = wrapper.tox.Tox(tox_options)
|
||||
retval = tox_wrapper.tox.Tox(tox_options)
|
||||
except Exception as e:
|
||||
if app and hasattr(app, '_log'):
|
||||
pass
|
||||
LOG_ERROR(f"wrapper.tox.Tox failed: {e}")
|
||||
LOG_ERROR(f"tox_wrapper.tox.Tox failed: {e}")
|
||||
LOG_WARN(traceback.format_exc())
|
||||
raise
|
||||
|
||||
if app and hasattr(app, '_log'):
|
||||
app._log("DEBUG: wrapper.tox.Tox succeeded")
|
||||
app._log("DEBUG: tox_wrapper.tox.Tox succeeded")
|
||||
return retval
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue