Esempio n. 1
0
void setToxCallbacks(Tox* tox, void* userData)
{
    tox_callback_friend_request(tox, _friendReqCb,  userData);
    tox_callback_friend_message(tox, _friendMsgCb,  userData);
    tox_callback_friend_name   (tox, _friendNameCb, userData);
    tox_callback_friend_status_message(tox, _friendStatusCb, userData);
    tox_callback_friend_status (tox, _friendUserStatusCb, userData);
    tox_callback_friend_typing (tox, _friendTypingCb,     userData);
    tox_callback_friend_read_receipt(tox, _friendReadReceiptCb, userData);
    tox_callback_friend_connection_status(tox, _friendConnectionCb, userData);
    tox_callback_friend_lossy_packet(tox, _friendLossyPacketCb, userData);
    tox_callback_friend_lossless_packet(tox, _friendLosslessPacketCb, userData);

    return;
}
Esempio n. 2
0
static void test_lossy_packet(Tox **toxes, State *state)
{
    tox_callback_friend_lossy_packet(toxes[1], &handle_lossy_packet);
    uint8_t packet[TOX_MAX_CUSTOM_PACKET_SIZE + 1];
    memset(packet, LOSSY_PACKET_FILLER, sizeof(packet));

    bool ret = tox_friend_send_lossy_packet(toxes[0], 0, packet, sizeof(packet), nullptr);
    ck_assert_msg(ret == false, "should not be able to send custom packets this big %i", ret);

    ret = tox_friend_send_lossy_packet(toxes[0], 0, packet, TOX_MAX_CUSTOM_PACKET_SIZE, nullptr);
    ck_assert_msg(ret == true, "tox_friend_send_lossy_packet fail %i", ret);

    do {
        iterate_all_wait(2, toxes, state, ITERATION_INTERVAL);
    } while (!state[1].custom_packet_received);
}
Esempio n. 3
0
void Tox_Dispatcher::init_callbacks()
{
    // self callbacks
    tox_callback_self_connection_status(tox,
        &Tox_Dispatcher::self_connection_status, this);

    // friend callbacks
    tox_callback_friend_connection_status(tox,
        &Tox_Dispatcher::friend_connection_status, this);
    tox_callback_friend_lossless_packet(tox,
        &Tox_Dispatcher::friend_lossless_packet, this);
    tox_callback_friend_lossy_packet(tox,
        &Tox_Dispatcher::friend_lossy_packet, this);
    tox_callback_friend_message(tox, &Tox_Dispatcher::friend_message, this);
    tox_callback_friend_name(tox, &Tox_Dispatcher::friend_name, this);
    tox_callback_friend_read_receipt(tox,
        &Tox_Dispatcher::friend_read_receipt, this);
    tox_callback_friend_request(tox, &Tox_Dispatcher::friend_request, this);

    tox_callback_file_recv(tox, Tox_Dispatcher::file_recv, this);
}
Esempio n. 4
0
static int r2tox_connect() {
	if (tox) {
		printf ("Status: Online\n");
		print_tox_my_address (tox);
		return -1;
	}
	Tox *t = NULL;
	struct Tox_Options *options = tox_options_new(NULL);
	FILE *fd = fopen("tox.data", "rb");
	if (fd) {
		eprintf ("Using tox.data\n");
		size_t sz = fread (&data, 1, 4096, fd);
		fclose (fd);
		tox_options_set_savedata_length (options, sz);
		tox_options_set_savedata_type (options, TOX_SAVEDATA_TYPE_TOX_SAVE);
		tox_options_set_savedata_data (options, data, sz);
		t = tox_new (options, NULL);
		if (!t) {
			printf("cannot new\n");
			return 1;
		}
	} else {
		t = tox_new (NULL, NULL);
		if (!t) {
			eprintf ("cannot new\n");
			return 1;
		}
		// r2tox_save();
	}

	const char *username = "******";
	const char *status = "Available";
	tox_self_set_name (t, username, strlen(username), NULL);
	tox_self_set_status_message (t, status, strlen(status), NULL);

	tox_callback_friend_name(t, handle_friend_name);
	tox_callback_friend_request (t, handle_friend_request);
	tox_callback_friend_message (t, handle_friend_message);
	tox_callback_friend_lossy_packet (t, handle_friend_lossy_packet);
	tox_callback_friend_lossless_packet (t, handle_friend_lossless_packet);
	tox_callback_friend_read_receipt (t, handle_friend_read_receipt);
	tox_callback_conference_invite(t, handle_conference_invite);
	tox_callback_conference_message(t, handle_conference_message);
	tox_callback_conference_title(t, handle_conference_title);

	// bootstrap
	size_t i;
	for (i = 0; i < sizeof(nodes)/sizeof(DHT_node); i ++) {
		sodium_hex2bin(nodes[i].key_bin, sizeof(nodes[i].key_bin),
				nodes[i].key_hex, sizeof(nodes[i].key_hex)-1, NULL, NULL, NULL);
		tox_bootstrap(t, nodes[i].ip, nodes[i].port, nodes[i].key_bin, NULL);
	}

	print_tox_my_address (t);
	tox_callback_self_connection_status (t, self_connection_status_cb);

	tox = t;
	// thread here
	if (!thread) {
		thread = r_th_new (r2tox_mainloop, NULL, 1);
		r_th_start (thread, true);
	}
	return 0;
}