Esempio n. 1
0
static void do_connection(Tox *m, ToxWindow *prompt)
{
    char msg[MAX_STR_SIZE] = {0};

    static int conn_err = 0;
    static bool was_connected = false;
    static uint64_t last_conn_try = 0;
    uint64_t curtime = get_unix_time();
    bool is_connected = tox_isconnected(m);

    if (was_connected && is_connected)
        return;

    if (!was_connected && is_connected) {
        was_connected = true;
        prompt_update_connectionstatus(prompt, was_connected);
        snprintf(msg, sizeof(msg), "DHT connected.");
    } else if (was_connected && !is_connected) {
        was_connected = false;
        prompt_update_connectionstatus(prompt, was_connected);
        snprintf(msg, sizeof(msg), "DHT disconnected. Attempting to reconnect.");
    } else if (!was_connected && !is_connected && timed_out(last_conn_try, curtime, TRY_CONNECT)) {
        /* if autoconnect has already failed there's no point in trying again */
        if (conn_err == 0) {
            last_conn_try = curtime;

            if ((conn_err = init_connection(m)) != 0)
                snprintf(msg, sizeof(msg), "Auto-connect failed with error code %d", conn_err);
        }
    }

    if (msg[0])
        line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
}
Esempio n. 2
0
File: main.c Progetto: stqism/toxic
static void do_connection(Tox *m, ToxWindow *prompt)
{
    uint8_t msg[MAX_STR_SIZE] = {0};

    static int conn_try = 0;
    static int conn_err = 0;
    static bool dht_on = false;

    bool is_connected = tox_isconnected(m);

    if (!dht_on && !is_connected && !(conn_try++ % 100)) {
        if (!conn_err) {
            if ((conn_err = init_connection(m))) {
                snprintf(msg, sizeof(msg), "\nAuto-connect failed with error code %d", conn_err);
            }
        }
    } else if (!dht_on && is_connected) {
        dht_on = true;
        prompt_update_connectionstatus(prompt, dht_on);
        snprintf(msg, sizeof(msg), "DHT connected.");
    } else if (dht_on && !is_connected) {
        dht_on = false;
        prompt_update_connectionstatus(prompt, dht_on);
        snprintf(msg, sizeof(msg), "\nDHT disconnected. Attempting to reconnect.");
    }

    if (msg[0])
        line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
}
Esempio n. 3
0
static void do_tox(Tox *m, ToxWindow *prompt)
{
    static int conn_try = 0;
    static int conn_err = 0;
    static bool dht_on = false;

    if (!dht_on && !tox_isconnected(m) && !(conn_try++ % 100)) {
        if (!conn_err) {
            conn_err = init_connection(m);
            wprintw(prompt->window, "\nEstablishing connection...\n");

            if (conn_err)
                wprintw(prompt->window, "\nAuto-connect failed with error code %d\n", conn_err);
        }
    } else if (!dht_on && tox_isconnected(m)) {
        dht_on = true;
        prompt_update_connectionstatus(prompt, dht_on);
        wprintw(prompt->window, "\nDHT connected.\n");
    } else if (dht_on && !tox_isconnected(m)) {
        dht_on = false;
        prompt_update_connectionstatus(prompt, dht_on);
        wprintw(prompt->window, "\nDHT disconnected. Attempting to reconnect.\n");
    }

    tox_do(m);
}