void Core::process() { tox_do(tox); #ifdef DEBUG //we want to see the debug messages immediately fflush(stdout); #endif checkConnection(); timer->start(tox_do_interval(tox)); }
void Core::start() { const Settings &settings = Settings::getInstance(); Tox_Options options; options.ipv6enabled = settings.isIPv6Enabled(); options.proxy_type = TOX_PROXY_NONE; options.udp_disabled = 0; tox = tox_new(&options); // if failed to initialize -- try to fallback to ipv4 if (tox == nullptr && settings.isIPv6Enabled() && settings.isIPv4FallbackEnabled()) { options.ipv6enabled = 0; tox = tox_new(&options); } // if still didn't manage to initialize -- throw an error if (tox == nullptr) { emit failedToStart(); return; } loadConfiguration(); tox_callback_friend_request(tox, onFriendRequest, this); tox_callback_friend_message(tox, onFriendMessage, this); tox_callback_friend_action(tox, onAction, this); tox_callback_name_change(tox, onFriendNameChange, this); tox_callback_typing_change(tox, onFriendTypingChange, this); tox_callback_status_message(tox, onStatusMessageChanged, this); tox_callback_user_status(tox, onUserStatusChanged, this); tox_callback_connection_status(tox, onConnectionStatusChanged, this); uint8_t friendAddress[TOX_FRIEND_ADDRESS_SIZE]; tox_get_address(tox, friendAddress); emit friendAddressGenerated(CFriendAddress::toString(friendAddress)); CString cUsername(settings.getUsername()); tox_set_name(tox, cUsername.data(), cUsername.size()); CString cStatusMessage(settings.getStatusMessage()); tox_set_status_message(tox, cStatusMessage.data(), cStatusMessage.size()); bootstrapDht(); timer->start(tox_do_interval(tox)); }
int twc_do_timer_cb(void *data, int remaining_calls) { struct t_twc_profile *profile = data; tox_do(profile->tox); struct t_hook *hook = weechat_hook_timer(tox_do_interval(profile->tox), 0, 1, twc_do_timer_cb, profile); profile->tox_do_timer = hook; // check connection status int connected = tox_isconnected(profile->tox); twc_profile_set_online_status(profile, connected); return WEECHAT_RC_OK; }
void Core::process() { if (!tox) return; static int tolerance = CORE_DISCONNECT_TOLERANCE; tox_do(tox); #ifdef DEBUG //we want to see the debug messages immediately fflush(stdout); #endif if (checkConnection()) tolerance = CORE_DISCONNECT_TOLERANCE; else if (!(--tolerance)) { bootstrapDht(); } toxTimer->start(tox_do_interval(tox)); }
char timeout_getch(Tox *m) { char c; int slpval = tox_do_interval(m); fd_set fds; FD_ZERO(&fds); FD_SET(0, &fds); struct timeval tv; tv.tv_sec = 0; tv.tv_usec = slpval * 1000; c = ERR; int n = select(1, &fds, NULL, NULL, &tv); if (n < 0) { new_lines("select error: maybe interupted"); } else if (n == 0) { } else { c = getch(); } return c; }
void tox_thread(void *UNUSED(args)) { Tox *tox; ToxAv *av; uint8_t id[TOX_FRIEND_ADDRESS_SIZE]; TOP:; debug("new tox object ipv6: %u no_udp: %u proxy: %u %s %u\n", options.ipv6enabled, options.udp_disabled, options.proxy_enabled, options.proxy_address, options.proxy_port); if((tox = tox_new(&options)) == NULL) { debug("trying without proxy\n"); if(!options.proxy_enabled || (options.proxy_enabled = 0, (tox = tox_new(&options)) == NULL)) { debug("trying without ipv6\n"); if(!options.ipv6enabled || (options.ipv6enabled = 0, (tox = tox_new(&options)) == NULL)) { debug("tox_new() failed\n"); exit(1); } dropdown_ipv6.selected = dropdown_ipv6.over = 1; } dropdown_proxy.selected = dropdown_proxy.over = 0; } if(!load_save(tox)) { debug("No save file, using defaults\n"); load_defaults(tox); } edit_setstr(&edit_name, self.name, self.name_length); edit_setstr(&edit_status, self.statusmsg, self.statusmsg_length); tox_get_address(tox, id); id_to_string(self.id, id); debug("Tox ID: %.*s\n", (int)sizeof(self.id), self.id); set_callbacks(tox); do_bootstrap(tox); av = toxav_new(tox, MAX_CALLS); set_av_callbacks(av); global_av = av; tox_thread_init = 1; thread(audio_thread, av); thread(video_thread, av); thread(toxav_thread, av); _Bool connected = 0, reconfig; uint64_t last_save = get_time(), time; while(1) { tox_do(tox); if(tox_isconnected(tox) != connected) { connected = !connected; postmessage(DHT_CONNECTED, connected, 0, NULL); debug("Connected to DHT: %u\n", connected); } time = get_time(); if(time - last_save >= (uint64_t)10 * 1000 * 1000 * 1000) { last_save = time; if(!connected) { do_bootstrap(tox); } write_save(tox); } if(tox_thread_msg) { TOX_MSG *msg = &tox_msg; if(!msg->msg) { reconfig = msg->param1; tox_thread_msg = 0; break; } tox_thread_message(tox, av, time, msg->msg, msg->param1, msg->param2, msg->data); tox_thread_msg = 0; } utox_thread_work_for_transfers(tox, time); utox_thread_work_for_typing_notifications(tox, time); uint32_t interval = tox_do_interval(tox); yieldcpu((interval > 20) ? 20 : interval); } write_save(tox); while(audio_thread_init || video_thread_init || toxav_thread_init) { yieldcpu(1); } debug("av_thread exit, tox thread ending\n"); toxav_kill(av); tox_kill(tox); if(reconfig) { goto TOP; } tox_thread_init = 0; }
void Core::start() { // IPv6 needed for LAN discovery, but can crash some weird routers. On by default, can be disabled in options. bool enableIPv6 = Settings::getInstance().getEnableIPv6(); if (enableIPv6) qDebug() << "Core starting with IPv6 enabled"; else qWarning() << "Core starting with IPv6 disabled. LAN discovery may not work properly."; Tox_Options toxOptions; toxOptions.ipv6enabled = enableIPv6; toxOptions.udp_disabled = 0; toxOptions.proxy_enabled = false; toxOptions.proxy_address[0] = 0; toxOptions.proxy_port = 0; tox = tox_new(&toxOptions); if (tox == nullptr) { if (enableIPv6) // Fallback to IPv4 { toxOptions.ipv6enabled = false; tox = tox_new(&toxOptions); if (tox == nullptr) { qCritical() << "Tox core failed to start"; emit failedToStart(); return; } else qWarning() << "Core failed to start with IPv6, falling back to IPv4. LAN discovery may not work properly."; } else { qCritical() << "Tox core failed to start"; emit failedToStart(); return; } } toxav = toxav_new(tox, TOXAV_MAX_CALLS); if (toxav == nullptr) { qCritical() << "Toxav core failed to start"; emit failedToStart(); return; } qsrand(time(nullptr)); loadConfiguration(); tox_callback_friend_request(tox, onFriendRequest, this); tox_callback_friend_message(tox, onFriendMessage, this); tox_callback_friend_action(tox, onAction, this); tox_callback_name_change(tox, onFriendNameChange, this); tox_callback_typing_change(tox, onFriendTypingChange, this); tox_callback_status_message(tox, onStatusMessageChanged, this); tox_callback_user_status(tox, onUserStatusChanged, this); tox_callback_connection_status(tox, onConnectionStatusChanged, this); tox_callback_group_invite(tox, onGroupInvite, this); tox_callback_group_message(tox, onGroupMessage, this); tox_callback_group_namelist_change(tox, onGroupNamelistChange, this); tox_callback_file_send_request(tox, onFileSendRequestCallback, this); tox_callback_file_control(tox, onFileControlCallback, this); tox_callback_file_data(tox, onFileDataCallback, this); toxav_register_callstate_callback(toxav, onAvInvite, av_OnInvite, this); toxav_register_callstate_callback(toxav, onAvStart, av_OnStart, this); toxav_register_callstate_callback(toxav, onAvCancel, av_OnCancel, this); toxav_register_callstate_callback(toxav, onAvReject, av_OnReject, this); toxav_register_callstate_callback(toxav, onAvEnd, av_OnEnd, this); toxav_register_callstate_callback(toxav, onAvRinging, av_OnRinging, this); toxav_register_callstate_callback(toxav, onAvStarting, av_OnStarting, this); toxav_register_callstate_callback(toxav, onAvEnding, av_OnEnding, this); toxav_register_callstate_callback(toxav, onAvMediaChange, av_OnMediaChange, this); toxav_register_callstate_callback(toxav, onAvRequestTimeout, av_OnRequestTimeout, this); toxav_register_callstate_callback(toxav, onAvPeerTimeout, av_OnPeerTimeout, this); toxav_register_audio_recv_callback(toxav, playCallAudio, this); toxav_register_video_recv_callback(toxav, playCallVideo, this); uint8_t friendAddress[TOX_FRIEND_ADDRESS_SIZE]; tox_get_address(tox, friendAddress); emit friendAddressGenerated(CFriendAddress::toString(friendAddress)); bootstrapDht(); toxTimer->start(tox_do_interval(tox)); }