├── .gitignore ├── .travis.yml ├── COPYING ├── DONATORS ├── INSTALL.md ├── Makefile.am ├── README.md ├── auto_tests ├── Makefile.inc ├── TCP_test.c ├── assoc_test.c ├── crypto_test.c ├── dht_test.c ├── encryptsave_test.c ├── friends_test.c ├── helpers.h ├── messenger_test.c ├── network_test.c ├── onion_test.c ├── skeleton_test.c ├── tox_test.c ├── toxav_basic_test.c └── toxav_many_test.c ├── autogen.sh ├── build └── Makefile.am ├── configure.ac ├── dist-build ├── android-arm.sh ├── android-armv7.sh ├── android-build.sh ├── android-mips.sh └── android-x86.sh ├── docs ├── Group-Chats.md ├── Hardening.txt ├── Hardening_docs.txt ├── Prevent_Tracking.txt ├── TCP_Network.txt ├── TODO.md ├── Tox_middle_level_network_protocol.txt ├── av_api.md └── updates │ ├── Crypto.md │ ├── DHT.md │ ├── Spam-Prevention.md │ └── Symmetric-NAT-Transversal.md ├── libtoxav.pc.in ├── libtoxcore.pc.in ├── m4 ├── ax_have_epoll.m4 ├── ax_pthread.m4 └── pkg.m4 ├── other ├── DHT_bootstrap.c ├── DHTnodes ├── Makefile.inc ├── apidsl │ ├── README.md │ ├── tox.in.h │ └── toxav.in.h ├── astyle │ ├── README.md │ ├── astylerc │ └── pre-commit ├── bootstrap_daemon │ ├── README.md │ ├── docker │ │ ├── Dockerfile │ │ └── get-nodes.py │ ├── src │ │ ├── Makefile.inc │ │ ├── command_line_arguments.c │ │ ├── command_line_arguments.h │ │ ├── config.c │ │ ├── config.h │ │ ├── config_defaults.h │ │ ├── global.h │ │ ├── log.c │ │ ├── log.h │ │ └── tox-bootstrapd.c │ ├── tox-bootstrapd.conf │ ├── tox-bootstrapd.service │ └── tox-bootstrapd.sh ├── bootstrap_node_packets.c ├── bootstrap_node_packets.h ├── fun │ ├── bootstrap_node_info.py │ ├── cracker.c │ ├── make-funny-savefile.py │ ├── sign.c │ └── strkey.c ├── osx_build_script_toxcore.sh └── tox.png ├── super_donators ├── LittleVulpix ├── grencez_tok5.c └── sir@cmpwn.com ├── testing ├── DHT_test.c ├── Makefile.inc ├── Messenger_test.c ├── av_test.c ├── dns3_test.c ├── irc_syncbot.c ├── misc_tools.c ├── nTox.c ├── nTox.h ├── tox_shell.c └── tox_sync.c ├── tox.spec.in ├── toxav ├── Makefile.inc ├── audio.c ├── audio.h ├── bwcontroller.c ├── bwcontroller.h ├── group.c ├── group.h ├── msi.c ├── msi.h ├── rtp.c ├── rtp.h ├── toxav.c ├── toxav.h ├── toxav_old.c ├── video.c └── video.h ├── toxcore ├── DHT.c ├── DHT.h ├── LAN_discovery.c ├── LAN_discovery.h ├── Makefile.inc ├── Messenger.c ├── Messenger.h ├── TCP_client.c ├── TCP_client.h ├── TCP_connection.c ├── TCP_connection.h ├── TCP_server.c ├── TCP_server.h ├── assoc.c ├── assoc.h ├── crypto_core.c ├── crypto_core.h ├── friend_connection.c ├── friend_connection.h ├── friend_requests.c ├── friend_requests.h ├── group.c ├── group.h ├── list.c ├── list.h ├── logger.c ├── logger.h ├── misc_tools.h ├── net_crypto.c ├── net_crypto.h ├── network.c ├── network.h ├── onion.c ├── onion.h ├── onion_announce.c ├── onion_announce.h ├── onion_client.c ├── onion_client.h ├── ping.c ├── ping.h ├── ping_array.c ├── ping_array.h ├── tox.c ├── tox.h ├── tox_old.h ├── tox_old_code.h ├── util.c └── util.h ├── toxdns ├── Makefile.inc ├── toxdns.c └── toxdns.h └── toxencryptsave ├── Makefile.inc ├── crypto_pwhash_scryptsalsa208sha256 ├── crypto_pwhash_scryptsalsa208sha256.h ├── crypto_scrypt-common.c ├── crypto_scrypt.h ├── export.h ├── nosse │ └── pwhash_scryptsalsa208sha256_nosse.c ├── note_to_maintainers.txt ├── pbkdf2-sha256.c ├── pbkdf2-sha256.h ├── pwhash_scryptsalsa208sha256.c ├── runtime.c ├── runtime.h ├── scrypt_platform.c ├── sse │ └── pwhash_scryptsalsa208sha256_sse.c ├── sysendian.h ├── utils.c └── utils.h ├── defines.h ├── toxencryptsave.c └── toxencryptsave.h /.gitignore: -------------------------------------------------------------------------------- 1 | # OS files 2 | .DS_Store 3 | .DS_Store? 4 | ._* 5 | .Spotlight-V100 6 | .Trash* 7 | Icon? 8 | ethumbs.db 9 | Thumbs.db 10 | *.tmp 11 | 12 | # Make 13 | CMakeCache.txt 14 | CMakeFiles 15 | Makefile 16 | cmake_install.cmake 17 | install_manifest.txt 18 | tags 19 | Makefile.in 20 | 21 | # Testing 22 | testing/data 23 | *~ 24 | 25 | # Vim 26 | *.swp 27 | 28 | # Object files 29 | *.o 30 | *.lo 31 | *.a 32 | 33 | # Executables 34 | *.exe 35 | *.out 36 | *.app 37 | *.la 38 | 39 | # Misc (?) 40 | m4/* 41 | configure 42 | configure_aux 43 | !m4/pkg.m4 44 | aclocal.m4 45 | config.h* 46 | config.log 47 | config.status 48 | stamp-h1 49 | autom4te.cache 50 | libtoxcore.pc 51 | libtoxav.pc 52 | libtool 53 | .deps 54 | .libs 55 | .dirstamp 56 | build/ 57 | 58 | #kdevelop 59 | .kdev/ 60 | *.kdev* 61 | 62 | # Netbeans 63 | nbproject 64 | 65 | # astyle 66 | *.orig 67 | 68 | # Android buildscript 69 | android-toolchain-* 70 | toxcore-android-* 71 | 72 | # cscope files list 73 | cscope.files 74 | 75 | # rpm 76 | tox.spec 77 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | dist: trusty 3 | language: c 4 | compiler: 5 | - gcc 6 | - clang 7 | 8 | before_script: 9 | - sudo add-apt-repository ppa:avsm/ocaml42+opam12 -y 10 | - sudo apt-get update -qq 11 | - sudo apt-get install ocaml opam astyle -qq 12 | - sudo apt-get install libconfig-dev libvpx-dev libopus-dev check -qq 13 | # build apidsl 14 | - git clone https://github.com/iphydf/apidsl 15 | - cd apidsl 16 | - export OPAMYES=1 17 | - opam init 18 | - opam install ocamlfind ppx_deriving menhir 19 | - eval `opam config env` 20 | - make -j3 21 | - cd .. 22 | # install sodium, as it's not in Ubuntu Trusty 23 | - git clone git://github.com/jedisct1/libsodium.git 24 | - cd libsodium 25 | - git checkout tags/1.0.8 26 | - ./autogen.sh 27 | - ./configure 28 | - make -j3 29 | - sudo make install 30 | - cd .. 31 | - sudo ldconfig 32 | 33 | script: 34 | # check if toxcore.h and toxav.h match apidsl tox.in.h and toxav.in.h 35 | # tox.h 36 | - ./apidsl/_build/apigen.native ./other/apidsl/tox.in.h > tox.h 37 | - astyle --options=./other/astyle/astylerc tox.h 38 | - diff -u tox.h ./toxcore/tox.h 39 | # toxav.h 40 | - ./apidsl/_build/apigen.native ./other/apidsl/toxav.in.h > toxav.h 41 | - astyle --options=./other/astyle/astylerc toxav.h 42 | - diff -u toxav.h ./toxav/toxav.h 43 | # build toxcore and run tests 44 | - ./autogen.sh 45 | - CFLAGS="-Ofast -Wall -Wextra" ./configure --enable-daemon --enable-ntox 46 | - make 47 | - make check 48 | - cat build/test-suite.log 49 | - make dist 50 | 51 | notifications: 52 | email: false 53 | 54 | irc: 55 | channels: 56 | - "chat.freenode.net#tox-dev" 57 | on_success: always 58 | on_failure: always 59 | -------------------------------------------------------------------------------- /DONATORS: -------------------------------------------------------------------------------- 1 | Minnesota > Florida 2 | vdo 3 | Spitfire is best technicolor horse. 4 | if bad people don't hate you, you're doing something wrong 5 | Pinkie Pie is best pony. 6 | JRS was here 7 | qTox is so bloated it doesn't even fit in a 64-bit address space 8 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = build 2 | 3 | ACLOCAL_AMFLAGS = -I m4 4 | 5 | pkgconfigdir = $(libdir)/pkgconfig 6 | 7 | 8 | pkgconfig_DATA = $(top_builddir)/libtoxcore.pc 9 | BUILT_SOURCES = $(top_builddir)/libtoxcore.pc 10 | CLEANFILES = $(top_builddir)/libtoxcore.pc 11 | 12 | 13 | EXTRA_DIST = \ 14 | README.md \ 15 | libtoxcore.pc.in \ 16 | tox.spec \ 17 | dist-build/android-arm.sh \ 18 | dist-build/android-armv7.sh \ 19 | dist-build/android-x86.sh \ 20 | dist-build/android-mips.sh \ 21 | dist-build/android-build.sh \ 22 | $(top_srcdir)/docs/updates/Crypto.md \ 23 | $(top_srcdir)/docs/updates/Spam-Prevention.md \ 24 | $(top_srcdir)/docs/updates/Symmetric-NAT-Transversal.md \ 25 | $(top_srcdir)/other/astyle/README.md \ 26 | $(top_srcdir)/other/astyle/astylerc \ 27 | $(top_srcdir)/other/astyle/pre-commit 28 | 29 | if BUILD_AV 30 | 31 | pkgconfig_DATA += $(top_builddir)/libtoxav.pc 32 | BUILT_SOURCES += $(top_builddir)/libtoxav.pc 33 | CLEANFILES += $(top_builddir)/libtoxav.pc 34 | 35 | EXTRA_DIST += libtoxav.pc.in 36 | 37 | endif 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Project Tox](https://raw.github.com/irungentoo/toxcore/master/other/tox.png "Project Tox") 2 | *** 3 | 4 | With the rise of government surveillance programs, Tox, a FOSS initiative, aims to be an easy to use, all-in-one communication platform that ensures full privacy and secure message delivery.

5 | 6 | [**Website**](https://tox.chat) **|** [**Wiki**](https://wiki.tox.chat/) **|** [**Blog**](https://blog.tox.chat/) **|** [**FAQ**](https://wiki.tox.chat/doku.php?id=users:faq) **|** [**Binaries/Downloads**](https://wiki.tox.chat/Binaries) **|** [**Clients**](https://wiki.tox.chat/doku.php?id=clients) **|** [**Compiling**](/INSTALL.md) 7 | 8 | **IRC Channels:** [#tox@freenode](https://webchat.freenode.net/?channels=tox), [#tox-dev@freenode](https://webchat.freenode.net/?channels=tox-dev) 9 | 10 | 11 | ## The Complex Stuff: 12 | ### UDP vs. TCP 13 | Tox must use UDP simply because [hole punching](https://en.wikipedia.org/wiki/UDP_hole_punching) with TCP is not as reliable. 14 | However, Tox does use [TCP relays](/docs/TCP_Network.txt) as a fallback if it encounters a firewall that prevents UDP hole punching. 15 | 16 | ### Connecting & Communicating 17 | Every peer is represented as a [byte string](https://en.wikipedia.org/wiki/String_(computer_science)) (the public key [Tox ID] of the peer). By using torrent-style DHT, peers can find the IP of other peers by using their Tox ID. Once the IP is obtained, peers can initiate a [secure](/docs/updates/Crypto.md) connection with each other. Once the connection is made, peers can exchange messages, send files, start video chats, etc. using encrypted communications. 18 | 19 | 20 | **Current build status:** [![Build Status](https://travis-ci.org/irungentoo/toxcore.png?branch=master)](https://travis-ci.org/irungentoo/toxcore) 21 | 22 | 23 | ## Q&A: 24 | 25 | ### What are your goals with Tox? 26 | 27 | We want Tox to be as simple as possible while remaining as secure as possible. 28 | 29 | ### Why are you doing this? There are already a bunch of free Skype alternatives. 30 | The goal of this project is to create a configuration-free P2P Skype replacement. “Configuration-free” means that the user will simply have to open the program and will be capable of adding people and communicating with them without having to set up an account. There are many so-called Skype replacements, but all of them are either hard to configure for the normal user or suffer from being way too centralized. 31 | 32 | ## TODO: 33 | - [TODO](/docs/TODO.md) 34 | 35 | 36 | ## Documentation: 37 | 38 | - [Compiling](/INSTALL.md) 39 | - [DHT Protocol](/docs/updates/DHT.md)
40 | - [Crypto](/docs/updates/Crypto.md)
41 | -------------------------------------------------------------------------------- /auto_tests/Makefile.inc: -------------------------------------------------------------------------------- 1 | if BUILD_TESTS 2 | 3 | TESTS = encryptsave_test messenger_autotest crypto_test network_test assoc_test onion_test TCP_test tox_test dht_autotest 4 | check_PROGRAMS = encryptsave_test messenger_autotest crypto_test network_test assoc_test onion_test TCP_test tox_test dht_autotest 5 | 6 | AUTOTEST_CFLAGS = \ 7 | $(LIBSODIUM_CFLAGS) \ 8 | $(NACL_CFLAGS) \ 9 | $(CHECK_CFLAGS) 10 | 11 | AUTOTEST_LDADD = \ 12 | $(LIBSODIUM_LDFLAGS) \ 13 | $(NACL_LDFLAGS) \ 14 | libtoxcore.la \ 15 | libtoxencryptsave.la \ 16 | $(LIBSODIUM_LIBS) \ 17 | $(NACL_OBJECTS) \ 18 | $(NACL_LIBS) \ 19 | $(CHECK_LIBS) 20 | 21 | 22 | 23 | if BUILD_AV 24 | TESTS += toxav_basic_test toxav_many_test 25 | check_PROGRAMS += toxav_basic_test toxav_many_test 26 | AUTOTEST_LDADD += libtoxav.la 27 | endif 28 | 29 | messenger_autotest_SOURCES = ../auto_tests/messenger_test.c 30 | 31 | messenger_autotest_CFLAGS = $(AUTOTEST_CFLAGS) 32 | 33 | messenger_autotest_LDADD = $(AUTOTEST_LDADD) 34 | 35 | 36 | crypto_test_SOURCES = ../auto_tests/crypto_test.c 37 | 38 | crypto_test_CFLAGS = $(AUTOTEST_CFLAGS) 39 | 40 | crypto_test_LDADD = $(AUTOTEST_LDADD) 41 | 42 | 43 | network_test_SOURCES = ../auto_tests/network_test.c 44 | 45 | network_test_CFLAGS = $(AUTOTEST_CFLAGS) 46 | 47 | network_test_LDADD = $(AUTOTEST_LDADD) 48 | 49 | 50 | assoc_test_SOURCES = ../auto_tests/assoc_test.c 51 | 52 | assoc_test_CFLAGS = $(AUTOTEST_CFLAGS) 53 | 54 | assoc_test_LDADD = $(AUTOTEST_LDADD) 55 | 56 | 57 | onion_test_SOURCES = ../auto_tests/onion_test.c 58 | 59 | onion_test_CFLAGS = $(AUTOTEST_CFLAGS) 60 | 61 | onion_test_LDADD = $(AUTOTEST_LDADD) 62 | 63 | 64 | TCP_test_SOURCES = ../auto_tests/TCP_test.c 65 | 66 | TCP_test_CFLAGS = $(AUTOTEST_CFLAGS) 67 | 68 | TCP_test_LDADD = $(AUTOTEST_LDADD) 69 | 70 | 71 | tox_test_SOURCES = ../auto_tests/tox_test.c 72 | 73 | tox_test_CFLAGS = $(AUTOTEST_CFLAGS) 74 | 75 | tox_test_LDADD = $(AUTOTEST_LDADD) 76 | 77 | 78 | dht_autotest_SOURCES = ../auto_tests/dht_test.c 79 | 80 | dht_autotest_CFLAGS = $(AUTOTEST_CFLAGS) 81 | 82 | dht_autotest_LDADD = $(AUTOTEST_LDADD) 83 | 84 | 85 | if BUILD_AV 86 | toxav_basic_test_SOURCES = ../auto_tests/toxav_basic_test.c 87 | 88 | toxav_basic_test_CFLAGS = $(AUTOTEST_CFLAGS) 89 | 90 | toxav_basic_test_LDADD = $(AUTOTEST_LDADD) $(AV_LIBS) 91 | 92 | 93 | toxav_many_test_SOURCES = ../auto_tests/toxav_many_test.c 94 | 95 | toxav_many_test_CFLAGS = $(AUTOTEST_CFLAGS) 96 | 97 | toxav_many_test_LDADD = $(AUTOTEST_LDADD) 98 | endif 99 | 100 | endif 101 | 102 | 103 | encryptsave_test_SOURCES = ../auto_tests/encryptsave_test.c 104 | 105 | encryptsave_test_CFLAGS = $(AUTOTEST_CFLAGS) 106 | 107 | encryptsave_test_LDADD = $(AUTOTEST_LDADD) 108 | 109 | 110 | EXTRA_DIST += $(top_srcdir)/auto_tests/friends_test.c \ 111 | $(top_srcdir)/auto_tests/helpers.h 112 | -------------------------------------------------------------------------------- /auto_tests/assoc_test.c: -------------------------------------------------------------------------------- 1 | #ifdef HAVE_CONFIG_H 2 | #include "config.h" 3 | #endif 4 | 5 | #define AUTO_TEST 6 | #include "../toxcore/DHT.h" 7 | #include "../toxcore/assoc.h" 8 | #include "../toxcore/util.h" 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | #include "helpers.h" 17 | 18 | START_TEST(test_basics) 19 | { 20 | /* TODO: real test */ 21 | uint8_t id[crypto_box_PUBLICKEYBYTES]; 22 | Assoc *assoc = new_Assoc_default(id); 23 | ck_assert_msg(assoc != NULL, "failed to create default assoc"); 24 | 25 | kill_Assoc(assoc); 26 | assoc = new_Assoc(17, 4, id); /* results in an assoc of 16/3 */ 27 | ck_assert_msg(assoc != NULL, "failed to create customized assoc"); 28 | 29 | IP_Port ipp; 30 | ipp.ip.family = AF_INET; 31 | ipp.ip.ip4.uint8[0] = 1; 32 | ipp.port = htons(12345); 33 | 34 | IPPTs ippts_send; 35 | ippts_send.ip_port = ipp; 36 | ippts_send.timestamp = unix_time(); 37 | IP_Port ipp_recv = ipp; 38 | 39 | uint8_t res = Assoc_add_entry(assoc, id, &ippts_send, &ipp_recv, 0); 40 | ck_assert_msg(res == 0, "stored self as entry: expected %u, got %u", 0, res); 41 | 42 | id[0]++; 43 | 44 | res = Assoc_add_entry(assoc, id, &ippts_send, &ipp_recv, 0); 45 | ck_assert_msg(res == 1, "failed to store entry: expected %u, got %u", 1, res); 46 | 47 | Assoc_close_entries close_entries; 48 | memset(&close_entries, 0, sizeof(close_entries)); 49 | close_entries.count = 4; 50 | close_entries.count_good = 2; 51 | close_entries.wanted_id = id; 52 | 53 | Client_data *entries[close_entries.count]; 54 | close_entries.result = entries; 55 | 56 | uint8_t found = Assoc_get_close_entries(assoc, &close_entries); 57 | ck_assert_msg(found == 1, "get_close_entries(): expected %u, got %u", 1, found); 58 | kill_Assoc(assoc); 59 | } 60 | END_TEST 61 | 62 | START_TEST(test_fillup) 63 | { 64 | /* TODO: real test */ 65 | int i, j; 66 | uint8_t id[crypto_box_PUBLICKEYBYTES]; 67 | //uint32_t a = current_time(); 68 | uint32_t a = 2710106197; 69 | srand(a); 70 | 71 | for (i = 0; i < crypto_box_PUBLICKEYBYTES; ++i) { 72 | id[i] = rand(); 73 | } 74 | 75 | Assoc *assoc = new_Assoc(6, 15, id); 76 | ck_assert_msg(assoc != NULL, "failed to create default assoc"); 77 | struct entry { 78 | uint8_t id[crypto_box_PUBLICKEYBYTES]; 79 | IPPTs ippts_send; 80 | IP_Port ipp_recv; 81 | }; 82 | unsigned int fail = 0; 83 | struct entry entries[128]; 84 | struct entry closest[8]; 85 | 86 | for (j = 0; j < 128; ++j) { 87 | 88 | for (i = 0; i < crypto_box_PUBLICKEYBYTES; ++i) { 89 | entries[j].id[i] = rand(); 90 | } 91 | 92 | IP_Port ipp; 93 | ipp.ip.family = AF_INET; 94 | ipp.ip.ip4.uint32 = rand(); 95 | ipp.port = rand(); 96 | entries[j].ippts_send.ip_port = ipp; 97 | entries[j].ippts_send.timestamp = unix_time(); 98 | ipp.ip.ip4.uint32 = rand(); 99 | ipp.port = rand(); 100 | entries[j].ipp_recv = ipp; 101 | 102 | if (j % 16 == 0) { 103 | memcpy(entries[j].id, id, crypto_box_PUBLICKEYBYTES - 30); 104 | memcpy(&closest[j / 16], &entries[j], sizeof(struct entry)); 105 | 106 | } 107 | 108 | uint8_t res = Assoc_add_entry(assoc, entries[j].id, &entries[j].ippts_send, &entries[j].ipp_recv, 1); 109 | ck_assert_msg(res == 1, "failed to store entry: expected %u, got %u, j = %u", 1, res, j); 110 | } 111 | 112 | int good = 0; 113 | Assoc_close_entries close_entries; 114 | memset(&close_entries, 0, sizeof(close_entries)); 115 | close_entries.count = 8; 116 | close_entries.count_good = 8; 117 | close_entries.wanted_id = id; 118 | 119 | Client_data *entri[close_entries.count]; 120 | close_entries.result = entri; 121 | 122 | uint8_t found = Assoc_get_close_entries(assoc, &close_entries); 123 | ck_assert_msg(found == 8, "get_close_entries(): expected %u, got %u", 1, found); 124 | 125 | for (i = 0; i < 8; ++i) { 126 | for (j = 0; j < 8; ++j) { 127 | if (id_equal(entri[j]->public_key, closest[i].id)) 128 | ++good; 129 | } 130 | } 131 | 132 | ck_assert_msg(good == 8, "Entries found were not the closest ones. Only %u/8 were.", good); 133 | //printf("good: %u %u %u\n", good, a, ((uint32_t)current_time() - a)); 134 | kill_Assoc(assoc); 135 | } 136 | END_TEST 137 | 138 | Suite *Assoc_suite(void) 139 | { 140 | Suite *s = suite_create("Assoc"); 141 | 142 | DEFTESTCASE(basics); 143 | DEFTESTCASE(fillup); 144 | return s; 145 | } 146 | 147 | int main(int argc, char *argv[]) 148 | { 149 | unix_time_update(); 150 | Suite *Assoc = Assoc_suite(); 151 | SRunner *test_runner = srunner_create(Assoc); 152 | 153 | srunner_set_fork_status(test_runner, CK_NOFORK); 154 | 155 | srunner_run_all(test_runner, CK_NORMAL); 156 | 157 | int number_failed = srunner_ntests_failed(test_runner); 158 | 159 | srunner_free(test_runner); 160 | 161 | return number_failed; 162 | } 163 | -------------------------------------------------------------------------------- /auto_tests/helpers.h: -------------------------------------------------------------------------------- 1 | #ifndef TOXCORE_TEST_HELPERS_H 2 | #define TOXCORE_TEST_HELPERS_H 3 | 4 | #include 5 | 6 | #define DEFTESTCASE(NAME) \ 7 | TCase *tc_##NAME = tcase_create(#NAME); \ 8 | tcase_add_test(tc_##NAME, test_##NAME); \ 9 | suite_add_tcase(s, tc_##NAME); 10 | 11 | #define DEFTESTCASE_SLOW(NAME, TIMEOUT) \ 12 | DEFTESTCASE(NAME) \ 13 | tcase_set_timeout(tc_##NAME, TIMEOUT); 14 | 15 | #endif // TOXCORE_TEST_HELPERS_H 16 | -------------------------------------------------------------------------------- /auto_tests/skeleton_test.c: -------------------------------------------------------------------------------- 1 | #ifdef HAVE_CONFIG_H 2 | #include "config.h" 3 | #endif 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "helpers.h" 13 | 14 | /* 15 | #include "../" 16 | */ 17 | 18 | START_TEST(test_creativetestnamegoeshere) 19 | { 20 | uint8_t test = 0; 21 | ck_assert_msg(test == 0, "test: expected result 0, got %u.", test); 22 | } 23 | END_TEST 24 | 25 | Suite *creativesuitenamegoeshere_suite(void) 26 | { 27 | Suite *s = suite_create("creativesuitedescritptiongoeshere"); 28 | 29 | DEFTESTCASE(/* remove test_ from test function names */ creativetestnamegoeshere); 30 | 31 | return s; 32 | } 33 | 34 | int main(int argc, char *argv[]) 35 | { 36 | srand((unsigned int) time(NULL)); 37 | 38 | Suite *creativesuitenamegoeshere = creativesuitenamegoeshere_suite(); 39 | SRunner *test_runner = srunner_create(creativesuitenamegoeshere); 40 | 41 | int number_failed = 0; 42 | srunner_run_all(test_runner, CK_NORMAL); 43 | number_failed = srunner_ntests_failed(test_runner); 44 | 45 | srunner_free(test_runner); 46 | 47 | return number_failed; 48 | } 49 | 50 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | 3 | echo 'Running autoreconf -if...' 4 | ( 5 | autoreconf -if 6 | ) 7 | -------------------------------------------------------------------------------- /build/Makefile.am: -------------------------------------------------------------------------------- 1 | bin_PROGRAMS = 2 | noinst_PROGRAMS = 3 | lib_LTLIBRARIES = 4 | noinst_bindir = $(top_builddir)/build 5 | EXTRA_DIST= 6 | 7 | include ../toxcore/Makefile.inc 8 | include ../toxdns/Makefile.inc 9 | include ../toxencryptsave/Makefile.inc 10 | include ../toxav/Makefile.inc 11 | include ../other/Makefile.inc 12 | include ../testing/Makefile.inc 13 | include ../other/bootstrap_daemon/src/Makefile.inc 14 | include ../auto_tests/Makefile.inc 15 | -------------------------------------------------------------------------------- /dist-build/android-arm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | export CFLAGS="-Ofast -mthumb -marm -march=armv6" 3 | TARGET_ARCH=arm TOOLCHAIN_NAME=arm-linux-androideabi-4.8 HOST_COMPILER=arm-linux-androideabi "$(dirname "$0")/android-build.sh" 4 | -------------------------------------------------------------------------------- /dist-build/android-armv7.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | export CFLAGS="-Ofast -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -marm -march=armv7-a" 3 | TARGET_ARCH=armv7 TOOLCHAIN_NAME=arm-linux-androideabi-4.8 HOST_COMPILER=arm-linux-androideabi "$(dirname "$0")/android-build.sh" 4 | -------------------------------------------------------------------------------- /dist-build/android-build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ -z "$ANDROID_NDK_HOME" ]; then 4 | echo "You should probably set ANDROID_NDK_HOME to the directory containing" 5 | echo "the Android NDK" 6 | exit 7 | fi 8 | 9 | if [ -z "$SODIUM_HOME" ]; then 10 | echo "You should probably set SODIUM_HOME to the directory containing root sodium sources" 11 | exit 12 | fi 13 | 14 | if [[ -z $TARGET_ARCH ]] || [[ -z $HOST_COMPILER ]]; then 15 | echo "You shouldn't use android-build.sh directly, use android-[arch].sh instead" 16 | exit 1 17 | fi 18 | 19 | if [ ! -f ./configure ]; then 20 | echo "Can't find ./configure. Wrong directory or haven't run autogen.sh?" 21 | exit 1 22 | fi 23 | 24 | if [ -z "$TOOLCHAIN_DIR" ]; then 25 | export TOOLCHAIN_DIR="$(pwd)/android-toolchain-${TARGET_ARCH}" 26 | export MAKE_TOOLCHAIN="${ANDROID_NDK_HOME}/build/tools/make-standalone-toolchain.sh" 27 | 28 | if [ -z "$MAKE_TOOLCHAIN" ]; then 29 | echo "Cannot find a make-standalone-toolchain.sh in ndk dir, interrupt..." 30 | exit 1 31 | fi 32 | 33 | $MAKE_TOOLCHAIN --platform="${NDK_PLATFORM:-android-14}" \ 34 | --arch="${TARGET_ARCH}" \ 35 | --toolchain="${TOOLCHAIN_NAME:-arm-linux-androideabi-4.8}" \ 36 | --install-dir="${TOOLCHAIN_DIR}" 37 | fi 38 | 39 | export PREFIX="$(pwd)/toxcore-android-${TARGET_ARCH}" 40 | export SYSROOT="${TOOLCHAIN_DIR}/sysroot" 41 | export PATH="${PATH}:${TOOLCHAIN_DIR}/bin" 42 | 43 | # Clean up before build 44 | rm -rf "${PREFIX}" 45 | 46 | export CFLAGS="${CFLAGS} --sysroot=${SYSROOT} -I${SYSROOT}/usr/include" 47 | export CPPFLAGS="${CFLAGS}" 48 | export LDFLAGS="${LDFLAGS} -L${SYSROOT}/usr/lib" 49 | 50 | ./configure --host="${HOST_COMPILER}" \ 51 | --with-sysroot="${SYSROOT}" \ 52 | --with-libsodium-headers="${SODIUM_HOME}/libsodium-android-${TARGET_ARCH}/include" \ 53 | --with-libsodium-libs="${SODIUM_HOME}/libsodium-android-${TARGET_ARCH}/lib" \ 54 | --disable-av \ 55 | --prefix="${PREFIX}" && \ 56 | 57 | make clean && \ 58 | make -j3 install && \ 59 | echo "libtoxcore has been installed into ${PREFIX}" 60 | -------------------------------------------------------------------------------- /dist-build/android-mips.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | export CFLAGS="-Ofast" 3 | TARGET_ARCH=mips TOOLCHAIN_NAME=mipsel-linux-android-4.8 HOST_COMPILER=mipsel-linux-android "$(dirname "$0")/android-build.sh" 4 | -------------------------------------------------------------------------------- /dist-build/android-x86.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | export CFLAGS="-Ofast" 3 | TARGET_ARCH=x86 TOOLCHAIN_NAME=x86-4.8 HOST_COMPILER=i686-linux-android "$(dirname "$0")/android-build.sh" 4 | -------------------------------------------------------------------------------- /docs/Group-Chats.md: -------------------------------------------------------------------------------- 1 | Group chats. 2 | 3 | Note: we assume everyone in the chat trusts each other. 4 | 5 | These group chats work by temporarily adding the 4 "closest" people defined by a distance function 6 | in group.c in order to form a circle of connected peers. These peers then relay messages to each other. 7 | 8 | A friend invites another friend to a group chat by sending them an invite packet. The friend either ignores 9 | the invite or responds with a response packet if he wants to join the chat. The friend invite contains the type 10 | of groupchat (text only, A/V) the friend is being invited to. 11 | 12 | 13 | TODO: write more of this. 14 | 15 | ## Protocol 16 | 17 | Invite packets: 18 | Invite packet: 19 | [uint8_t id 96][uint8_t id 0][uint16_t group chat number][33 bytes group chat identifier[1 byte type][32 bytes id]] 20 | 21 | Response packet 22 | [uint8_t id 96][uint8_t id 1][uint16_t group chat number(local)][uint16_t group chat number to join][33 bytes group chat identifier[1 byte type][32 bytes id]] 23 | 24 | 25 | Peer online packet: 26 | [uint8_t id 97][uint16_t group chat number (local)][33 bytes group chat identifier[1 byte type][32 bytes id]] 27 | 28 | Peer leave packet: 29 | [uint8_t id 98][uint16_t group chat number][uint8_t id 1] 30 | 31 | Peer query packet: 32 | [uint8_t id 98][uint16_t group chat number][uint8_t id 8] 33 | 34 | Peer response packet: 35 | [uint8_t id 98][uint16_t group chat number][uint8_t id 9][Repeated times number of peers: [uint16_t peer num][uint8_t 32bytes real public key][uint8_t 32bytes temp DHT public key][uint8_t name length][name]] 36 | 37 | Title response packet: 38 | [uint8_t id 98][uint16_t group chat number][uint8_t id 10][title] 39 | 40 | Message packets: 41 | [uint8_t id 99][uint16_t group chat number][uint16_t peer number][uint32_t message number][uint8_t with a value representing id of message][data] 42 | 43 | Lossy Message packets: 44 | [uint8_t id 199][uint16_t group chat number][uint16_t peer number][uint16_t message number][uint8_t with a value representing id of message][data] 45 | 46 | Group chat types: 47 | 0: text 48 | 1: AV 49 | 50 | 51 | Note: the message number is increased by 1 for each sent message. 52 | 53 | message ids: 54 | 0 - ping 55 | sent every ~60 seconds by every peer. 56 | No data. 57 | 58 | 16 - new_peer 59 | Tell everyone about a new peer in the chat. 60 | [uint16_t peer_num][uint8_t 32bytes real public key][uint8_t 32bytes temp DHT public key] 61 | 62 | 17 - kill_peer 63 | [uint16_t peer_num] 64 | 65 | 48 - name change 66 | [uint8_t name[namelen]] 67 | 68 | 49 - groupchat title change 69 | [uint8_t title[titlelen]] 70 | 71 | 64 - chat message 72 | [uint8_t message[messagelen]] 73 | 74 | 65 - action (/me) 75 | [uint8_t message[messagelen]] 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /docs/Hardening.txt: -------------------------------------------------------------------------------- 1 | Currently an attacker with sufficient resources could launch a large scale 2 | denial of service type attack by flooding the Tox network with a bunch of nodes 3 | that do not act like real nodes to prevent people from finding each other. 4 | 5 | Due to the design of Tox, this is the worst thing an attacker can do to disrupt 6 | the network. 7 | 8 | This solution's goal is to make these denial of service attack very very hard 9 | to accomplish. 10 | 11 | For the network to work every Tox node must: 12 | 1. Respond to ping requests. 13 | 2. Respond to get node requests with the ids of nodes closest to a queried id 14 | (It is assumed each nodes know at least the 32 nodes closest to them.) 15 | 3. Properly send crypto request packets to their intended destination. 16 | 17 | Currently the only thing a node needs to do to be part of the network is 18 | respond correctly to ping requests. 19 | 20 | The only people we really trust on the network are the nodes in our friends 21 | list. 22 | 23 | 24 | The behavior of each Tox node is easily predictable. This means that it possible 25 | for Tox nodes to test the nodes that they are connected to to see if they 26 | behave like normal Tox nodes and only send nodes that are confirmed to behave 27 | like real Tox nodes as part of send node replies when other nodes query them. 28 | 29 | If correctly done, this means that to poison the network an attacker can only 30 | infiltrate the network if his "fake" nodes behave exactly like real nodes 31 | completely defeating the purpose of the attack. Of course nodes must be 32 | rechecked regularly to defeat an attack where someone floods the network with 33 | many good nodes then suddenly turns them all bad. 34 | 35 | This also prevents someone from accidentally killing the tox network with a bad 36 | implementation of the protocol. 37 | 38 | Implementation ideas (In Progress): 39 | 40 | 1. Use our friends to check if the nodes in our close list are good. 41 | 42 | EX: If our friend queries a node close to us and it correctly returns our 43 | ip/port and then sends a crypto request packet to it and it routes it correctly 44 | to us then it is good. 45 | 46 | Problems with this: People don't always have at least one online friend. 47 | 48 | 2. Pick random nodes (add ourselves some random (fake) friends to increase the 49 | pool of available nodes) and make then send requests to other nodes, the 50 | response is then relayed back to us and compared to how the node should have 51 | behaved. If the node is found to be behaving correctly, it is set as trusted. 52 | Only trusted nodes are sent in send node packets, that is unless the exact node 53 | being queried for in the getnode packet is present, it will be sent in the 54 | sendnode packet even if it is not trusted. 55 | 56 | The hypothesis is that if to be part of the network nodes have to behave 57 | correctly it should prevent disruption from nodes that behave incorrectly. 58 | 59 | (This idea is currently being implemented in the harden branch.) 60 | ... 61 | -------------------------------------------------------------------------------- /docs/Hardening_docs.txt: -------------------------------------------------------------------------------- 1 | Hardening request packets are sent as crypto request packets (see crypto docs.) 2 | NOTE: currently only get nodes requests are tested in the code which is why 3 | there is only one test (more will be added soon.) 4 | 5 | All hardening requests must contain exactly 768 bytes of data. (The data sent 6 | must be padded with zeros if it is smaller than that.) 7 | 8 | 1. Get the information (IP_port, client_id) of the node we want to test. 9 | 2. Find a couple random nodes that is not that node (one for each test.) 10 | 3. Send crypto request packets to each of these random nodes with the data being: 11 | 12 | [byte with value: 02 (get nodes test request)][struct Node_format (the node to 13 | test.)][client_id(32 bytes) the id to query the node with.][padding] 14 | 15 | 4. The random node receives a packet. 16 | -The packet is a get nodes test request: 17 | send a get_node request to that node with the id to query in the request. 18 | when a send_node response is received, send the following response to the 19 | person who sent us the get nodes test request packet: 20 | [byte with value: 03 (get nodes test response)][client_id(32 bytes): 21 | the id of the tested node][The list of nodes it responded with in IPv6 22 | Node format (struct Node_Format)] 23 | PROTIP: (get node requests and response contain an encrypted part that you 24 | can use to store information so that you don't 25 | have to store in your memory where/if to send back the response from the 26 | send node) 27 | 28 | 5. Receive the test responses. 29 | -If the test(s) pass (the nodes behave in a satisfactory manner), make these 30 | nodes have priority over those who don't pass the test(s). 31 | -------------------------------------------------------------------------------- /docs/TODO.md: -------------------------------------------------------------------------------- 1 | # Toxcore todo list. 2 | Welcome to the Toxcore todo list, this is very likely out of date, but either way it's a good jumping off point if 3 | you're looking to see where core is going, or where it could use a little love. 4 | 5 | There are 3 sections; In Progress, TODO, and Done. These tasks are somewhat sorted by priority, but that shouldn't be 6 | taken to mean that this is the order tasks will (or should) be completed in. 7 | 8 | ## In Progress 9 | - [ ] [IN PROGRESS] Audio/Video 10 | - [X] [DONE] encoding/streaming/decoding 11 | - [X] [DONE] Call initiation 12 | - [X] [DONE] Encryption 13 | - [ ] [NEEDS TESTING] Video packet splitting. 14 | - [ ] [IN PROGRESS] Auditing. 15 | - [ ] [IN PROGRESS] Prevent audio skew (seems to be easily solvable client side.) 16 | - [ ] [IN PROGRESS] Group chats, audio done. 17 | - [ ] Networking: 18 | - [ ] [NEEDS TESTING] UPnP port forwarding. ([#969](https://github.com/irungentoo/toxcore/pull/969)) 19 | - [ ] [TODO] NAT-PMP port forwarding. 20 | - [ ] DHT: 21 | - [ ] [ALMOST DONE] Metadata collection prevention. (docs/Prevent_Tracking.txt) 22 | - [ ] [IN PROGRESS] Hardening against attacks. 23 | - [ ] [IN PROGRESS] Optimizing the code. 24 | - [ ] [DONE] Friend only group chats 25 | - [X] [DONE] Networking base. 26 | - [X] [MOSTLY DONE] Syncing chat state between clients (nicknames, list of who is in chat, etc...) 27 | - [ ] [TODO] Group private messages. (and adding friends from group chats using those private messages.) 28 | - [ ] [TODO] Group file transfers. 29 | - [ ] [IN PROGRESS] Friends list syncing 30 | - [ ] [IN PROGRESS] Make toxcore thread safe. 31 | - [ ] [MOSTLY DONE] A way for people to connect to people on Tox if they are behind a bad NAT that blocks UDP (or is 32 | just unpunchable) ([docs/TCP_Network.txt](TCP_Network.txt)) (Current way doesn't scale very well.) 33 | 34 | ## TODO 35 | - [ ] [TODO] Make the core save/datafile portable across client versions/different processor architectures. 36 | - [ ] [TODO] Friend_requests.c: 37 | - [ ] [TODO] What happens when a friend request is received needs to be changed. 38 | - [ ] [DONE?] Add multiple nospam functionality. ([#1317](https://github.com/irungentoo/toxcore/pull/1317)) 39 | 40 | - [ ] [TODO] Offline messaging 41 | - [ ] [TODO] Security audit from professionals 42 | 43 | ## Done 44 | - [X] [DONE] File transfers 45 | - [X] [DONE] IPV6 support 46 | - [X] [DONE] Encrypted Saves. (see: toxencryptsave) 47 | -------------------------------------------------------------------------------- /docs/updates/Crypto.md: -------------------------------------------------------------------------------- 1 | Encryption library used: http://nacl.cr.yp.to/ 2 | 3 | 4 | When running the program for the first time the crypto_box_keypair() function is used to 5 | generate the users public-private key pair. (32 bytes each) 6 | 7 | The generated public key is set as the client_id of the peer. 8 | 9 | Adding a friend 10 | --------------- 11 | 12 | Alice adds Bob to her friend list by adding his 32 byte public key (client_id) to her friend list. 13 | 2 cases: 14 | case 1: Alice adds the public key of Bob, then Bob waits for Alice to attempt to connect to him. 15 | case 2: Bob and Alice add their respective public keys to their friend lists at the same time. 16 | 17 | case 1: 18 | Alice sends an onion data (see: Prevent_tracking.txt) packet to Bob with the encrypted part containing the friend request like so: 19 | ``` 20 | [char with a value of 32][nospam number (4 bytes)][Message] 21 | ``` 22 | 23 | Ex message: hello Bob it's me Alice -_- add me pl0x. 24 | 25 | For more info on the nospam see: Spam_Prevention.txt 26 | 27 | Bob receives the request and decrypts the message using the function crypto_box_open() 28 | 29 | If the message decrypts successfully: 30 | If Alice is already in Bob's friend list: case 2 31 | If Alice is not in Bob's friend list and the nospam is good: Bob is prompt to add Alice and is shown the message from her. 32 | If Bob accepts Alice friend request he adds her public key to his friend list. 33 | 34 | case 2: 35 | Bob and Alice both have the others public key in their friend list, they are ready for the next step: Connecting to an already added friend 36 | 37 | In the next step only crypto_box() is used for encryption and only crypto_box_open() for decryption (just like in the last step.) 38 | 39 | 40 | Connecting to an already added friend 41 | ------------------------------------- 42 | 43 | see: Tox_middle_level_network_protocol.txt 44 | 45 | Crypto request packets 46 | -------------------------------------- 47 | 48 | ``` 49 | [char with a value of 32][Bob (The reciever's) Public key (client_id) (32 bytes))][Alice's (The sender's) Public key (client_id) (32 bytes)][Random nonce (24 bytes)][Encrypted message] 50 | ``` 51 | 52 | The encrypted message is encrypted with crypto_box() (using Bob's public key, Alice's private key and the nonce (randomly generated 24 bytes)) and is a message from Alice in which she tells Bob who she is. 53 | 54 | Each node can route the request to the receiver if they are connected to him. This is to bypass bad NATs. 55 | -------------------------------------------------------------------------------- /docs/updates/Spam-Prevention.md: -------------------------------------------------------------------------------- 1 | 2 | Situation 1: 3 | Someone randomly goes around the DHT sending friend requests to everyone. 4 | 5 | Prevented by: 6 | Every friend address: 7 | [client_id (32 bytes)][nospam number (4 bytes)][checksum (2 bytes)] 8 | contains a number (nospam). 9 | 10 | The nospam in every friend request to that friend must be that number. 11 | 12 | If not it is rejected. 13 | -------------------------------------------------------------------------------- /docs/updates/Symmetric-NAT-Transversal.md: -------------------------------------------------------------------------------- 1 | Notes: 2 | 3 | Friend requests need to be routed. 4 | 5 | The current DHT should be capable of punching all NATs except symmetric ones. 6 | 7 | ###### 8 | 9 | Symmetric NAT hole punching: 10 | 11 | If we are not connected to the friend and if the DHT is queried and ips 12 | returned for the friend are the same but the port is different, the friend is 13 | assumed to be behind a symmetric NAT. 14 | 15 | Before attempting the procedure we first send a routed ping request to the 16 | friend. This request is to be routed through the nodes who returned the ip of 17 | the peer. 18 | 19 | As soon as we receive one routed ping request from the other peer, we respond 20 | with a ping response. 21 | 22 | Ping request/response packet: 23 | See: Crypto request packets in [[Crypto]] 24 | 25 | Message: 26 | For the ping request: 27 | [char with a value of 254][char with 0][8 byte random number] 28 | 29 | For the ping response: 30 | [char with a value of 254][char with 1][8 byte random number (The same that was sent in the request)] 31 | 32 | As soon as we get a proper ping response from the other we run the different 33 | ports returned by the DHT through our port guessing algorithm. 34 | 35 | ###### 36 | 37 | Port guessing algorithm: 38 | 39 | Right now it just tries all the ports directly beside the known ports.(A better one is needed) 40 | 41 | ###### 42 | 43 | We send DHT ping requests to all the guessed ports, only a couple at a time. 44 | -------------------------------------------------------------------------------- /libtoxav.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libtoxav 7 | Description: Tox A/V library 8 | Requires: libtoxcore 9 | Version: @PACKAGE_VERSION@ 10 | Libs: -L${libdir} -ltoxav @AV_LIBS@ 11 | Cflags: -I${includedir} 12 | -------------------------------------------------------------------------------- /libtoxcore.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libtoxcore 7 | Description: Tox protocol library 8 | Requires: 9 | Version: @PACKAGE_VERSION@ 10 | Libs: @NACL_OBJECTS_PKGCONFIG@ -L${libdir} @NACL_LDFLAGS@ -ltoxdns -ltoxencryptsave -ltoxcore @NACL_LIBS@ @LIBS@ @MATH_LDFLAGS@ @PTHREAD_LDFLAGS@ 11 | Cflags: -I${includedir} 12 | -------------------------------------------------------------------------------- /m4/ax_have_epoll.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # http://www.gnu.org/software/autoconf-archive/ax_have_epoll.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_HAVE_EPOLL([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) 8 | # AX_HAVE_EPOLL_PWAIT([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) 9 | # 10 | # DESCRIPTION 11 | # 12 | # This macro determines whether the system supports the epoll I/O event 13 | # interface. A neat usage example would be: 14 | # 15 | # AX_HAVE_EPOLL( 16 | # [AX_CONFIG_FEATURE_ENABLE(epoll)], 17 | # [AX_CONFIG_FEATURE_DISABLE(epoll)]) 18 | # AX_CONFIG_FEATURE( 19 | # [epoll], [This platform supports epoll(7)], 20 | # [HAVE_EPOLL], [This platform supports epoll(7).]) 21 | # 22 | # The epoll interface was added to the Linux kernel in version 2.5.45, and 23 | # the macro verifies that a kernel newer than this is installed. This 24 | # check is somewhat unreliable if doesn't match the 25 | # running kernel, but it is necessary regardless, because glibc comes with 26 | # stubs for the epoll_create(), epoll_wait(), etc. that allow programs to 27 | # compile and link even if the kernel is too old; the problem would then 28 | # be detected only at runtime. 29 | # 30 | # Linux kernel version 2.6.19 adds the epoll_pwait() call in addition to 31 | # epoll_wait(). The availability of that function can be tested with the 32 | # second macro. Generally speaking, it is safe to assume that 33 | # AX_HAVE_EPOLL would succeed if AX_HAVE_EPOLL_PWAIT has, but not the 34 | # other way round. 35 | # 36 | # LICENSE 37 | # 38 | # Copyright (c) 2008 Peter Simons 39 | # 40 | # Copying and distribution of this file, with or without modification, are 41 | # permitted in any medium without royalty provided the copyright notice 42 | # and this notice are preserved. This file is offered as-is, without any 43 | # warranty. 44 | 45 | #serial 10 46 | 47 | AC_DEFUN([AX_HAVE_EPOLL], [dnl 48 | ax_have_epoll_cppflags="${CPPFLAGS}" 49 | AC_CHECK_HEADER([linux/version.h], [CPPFLAGS="${CPPFLAGS} -DHAVE_LINUX_VERSION_H"]) 50 | AC_MSG_CHECKING([for Linux epoll(7) interface]) 51 | AC_CACHE_VAL([ax_cv_have_epoll], [dnl 52 | AC_LINK_IFELSE([dnl 53 | AC_LANG_PROGRAM([dnl 54 | #include 55 | #ifdef HAVE_LINUX_VERSION_H 56 | # include 57 | # if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,45) 58 | # error linux kernel version is too old to have epoll 59 | # endif 60 | #endif 61 | ], [dnl 62 | int fd, rc; 63 | struct epoll_event ev; 64 | fd = epoll_create(128); 65 | rc = epoll_wait(fd, &ev, 1, 0);])], 66 | [ax_cv_have_epoll=yes], 67 | [ax_cv_have_epoll=no])]) 68 | CPPFLAGS="${ax_have_epoll_cppflags}" 69 | AS_IF([test "${ax_cv_have_epoll}" = "yes"], 70 | [AC_MSG_RESULT([yes]) 71 | $1],[AC_MSG_RESULT([no]) 72 | $2]) 73 | ])dnl 74 | 75 | AC_DEFUN([AX_HAVE_EPOLL_PWAIT], [dnl 76 | ax_have_epoll_cppflags="${CPPFLAGS}" 77 | AC_CHECK_HEADER([linux/version.h], 78 | [CPPFLAGS="${CPPFLAGS} -DHAVE_LINUX_VERSION_H"]) 79 | AC_MSG_CHECKING([for Linux epoll(7) interface with signals extension]) 80 | AC_CACHE_VAL([ax_cv_have_epoll_pwait], [dnl 81 | AC_LINK_IFELSE([dnl 82 | AC_LANG_PROGRAM([dnl 83 | #ifdef HAVE_LINUX_VERSION_H 84 | # include 85 | # if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19) 86 | # error linux kernel version is too old to have epoll_pwait 87 | # endif 88 | #endif 89 | #include 90 | #include 91 | ], [dnl 92 | int fd, rc; 93 | struct epoll_event ev; 94 | fd = epoll_create(128); 95 | rc = epoll_wait(fd, &ev, 1, 0); 96 | rc = epoll_pwait(fd, &ev, 1, 0, (sigset_t const *)(0));])], 97 | [ax_cv_have_epoll_pwait=yes], 98 | [ax_cv_have_epoll_pwait=no])]) 99 | CPPFLAGS="${ax_have_epoll_cppflags}" 100 | AS_IF([test "${ax_cv_have_epoll_pwait}" = "yes"], 101 | [AC_MSG_RESULT([yes]) 102 | $1],[AC_MSG_RESULT([no]) 103 | $2]) 104 | ])dnl 105 | -------------------------------------------------------------------------------- /other/DHTnodes: -------------------------------------------------------------------------------- 1 | As maintaining 2 separate lists of the same information seemed redundant, this list has been phased out. 2 | 3 | For a current DHT node list please visit https://wiki.tox.chat/doku.php?id=users:nodes 4 | -------------------------------------------------------------------------------- /other/Makefile.inc: -------------------------------------------------------------------------------- 1 | bin_PROGRAMS += DHT_bootstrap 2 | 3 | DHT_bootstrap_SOURCES = ../other/DHT_bootstrap.c \ 4 | ../toxcore/DHT.h \ 5 | ../toxcore/friend_requests.h \ 6 | ../other/bootstrap_node_packets.h \ 7 | ../other/bootstrap_node_packets.c 8 | 9 | DHT_bootstrap_CFLAGS = -I$(top_srcdir)/other \ 10 | $(LIBSODIUM_CFLAGS) \ 11 | $(NACL_CFLAGS) 12 | 13 | DHT_bootstrap_LDADD = $(LIBSODIUM_LDFLAGS) \ 14 | $(NACL_LDFLAGS) \ 15 | libtoxcore.la \ 16 | $(LIBSODIUM_LIBS) \ 17 | $(NACL_OBJECTS) \ 18 | $(NACL_LIBS) \ 19 | $(WINSOCK2_LIBS) 20 | 21 | EXTRA_DIST += $(top_srcdir)/other/DHTnodes \ 22 | $(top_srcdir)/other/tox.png 23 | -------------------------------------------------------------------------------- /other/apidsl/README.md: -------------------------------------------------------------------------------- 1 | This folder contains the input file (``tox.in.h``) that has to be used to generate the ``tox.h`` api with: https://github.com/iphydf/apidsl 2 | 3 | # Minimal requirements 4 | 5 | There are some minimal requirements to contribute to ``tox.h``: 6 | * unix environment 7 | * ``astyle`` ``>=2.03`` 8 | * [``apidsl``](https://github.com/iphydf/apidsl) (you can use provided service with curl instead) 9 | 10 | ## Quick way 11 | 12 | If you want to do it quickly and you don't have time for anything other than copypasting commands, you should have ``curl`` installed. 13 | 14 | 15 | 1. Make sure that you have ``curl`` and ``>=astyle-2.03`` installed 16 | 2. Modify [``tox.in.h``](/other/apidsl/tox.in.h) 17 | 3. Run command below ↓ 18 | 19 | Command to run from ``toxcore`` directory (quick way, involves using curl): 20 | ```bash 21 | rm toxcore/tox.h && \ 22 | ( curl -X POST --data-binary @- https://criticism.herokuapp.com/apidsl < ./other/apidsl/tox.in.h > ./toxcore/tox.h ) && \ 23 | astyle --options=./other/astyle/astylerc ./toxcore/tox.h 24 | ``` 25 | 26 | When formatting will be complete, you should see output like: 27 | ``` 28 | Formatted ./toxcore/tox.h 29 | ``` 30 | 31 | You may want to make sure with ``git diff`` that changes made in ``tox.h`` reflect changes in ``tox.in.h``. 32 | 33 | And you're done. 34 | 35 | 36 | ## Manually 37 | 38 | If you prefer to have more control over what is happening, there are steps below: 39 | 40 | 1. Install [``apidsl``](https://github.com/iphydf/apidsl) 41 | 2. Install ``astyle``, version 2.03 or later. 42 | 3. Modify [``tox.in.h``](/other/apidsl/tox.in.h) 43 | 4. Use ``apidsl`` ``??`` 44 | 5. Parse generated ``tox.h`` with astyle, minimal command for it would be: 45 | ```bash 46 | astyle --options=./other/astyle/astylerc ./toxcore/tox.h 47 | ``` 48 | 49 | **Always pass output from ``apidsl`` through astyle.** -------------------------------------------------------------------------------- /other/astyle/README.md: -------------------------------------------------------------------------------- 1 | This directory can house various tools and utilities. 2 | 3 | # How to use astyle 4 | 5 | ## Manually 6 | 7 | ### For all files 8 | 9 | Run from ``toxcore`` directory: 10 | ```bash 11 | astyle --options=./other/astyle/astylerc ./toxcore/*.c ./toxcore/*.h ./toxdns/*.c ./toxdns/*.h ./testing/*.c ./toxav/*.c ./toxav/*.h ./other/*.c ./other/bootstrap_daemon/*.c ./toxencryptsave/*.c ./toxencryptsave/*.h ./auto_tests/*.c 12 | ``` 13 | 14 | ### For selected file 15 | 16 | Run from ``toxcore`` directory, e.g. for [``tox.h``](/toxcore/tox.h) file: 17 | ```bash 18 | astyle --options=./other/astyle/astylerc ./toxcore/tox.h 19 | ``` 20 | 21 | 22 | ## Automatically, as pre-commit hook (*NIX only) 23 | 24 | Copy [``astylerc``](/other/astyle/astylerc) to ``toxcore/.git/hooks`` 25 | 26 | 27 | 28 | # Why 29 | 30 | ``astylerc`` - this file can be used in the pre-commit hook to try its best at making the code conform to the coding style of toxcore. 31 | 32 | Furthermore, it is being used to format ``tox.h`` after using [``apidsl``](/other/apidsl) to generate it. -------------------------------------------------------------------------------- /other/astyle/astylerc: -------------------------------------------------------------------------------- 1 | --style=kr 2 | --pad-header 3 | --max-code-length=120 4 | --convert-tabs 5 | --indent-switches 6 | --pad-oper 7 | --align-pointer=name 8 | --align-reference=name 9 | --preserve-date 10 | --lineend=linux 11 | --break-blocks -------------------------------------------------------------------------------- /other/astyle/pre-commit: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | # 3 | # An example hook script to verify what is about to be committed. 4 | # Called by "git commit" with no arguments. The hook should 5 | # exit with non-zero status after issuing an appropriate message if 6 | # it wants to stop the commit. 7 | # 8 | # To enable this hook, rename this file to "pre-commit". 9 | 10 | for file in `git diff-index --diff-filter=ACMR --name-only HEAD`; do 11 | if [[ $file == *.c || $file == *.h ]] 12 | then 13 | echo $file 14 | `which astyle` $file --options=tools/astylerc 15 | git add $file 16 | fi 17 | done -------------------------------------------------------------------------------- /other/bootstrap_daemon/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:jessie 2 | 3 | WORKDIR /tmp/tox 4 | 5 | RUN export BUILD_PACKAGES="\ 6 | build-essential \ 7 | libtool \ 8 | autotools-dev \ 9 | automake \ 10 | checkinstall \ 11 | check \ 12 | git \ 13 | yasm \ 14 | libsodium-dev \ 15 | libconfig-dev \ 16 | python3" && \ 17 | export RUNTIME_PACKAGES="\ 18 | libconfig9 \ 19 | libsodium13" && \ 20 | # get all deps 21 | apt-get update && apt-get install -y $BUILD_PACKAGES $RUNTIME_PACKAGES && \ 22 | # install toxcore and daemon 23 | git clone https://github.com/irungentoo/toxcore && \ 24 | cd toxcore && \ 25 | ./autogen.sh && \ 26 | ./configure --enable-daemon && \ 27 | make -j`nproc` && \ 28 | make install -j`nproc` && \ 29 | ldconfig && \ 30 | # add new user 31 | useradd --home-dir /var/lib/tox-bootstrapd --create-home \ 32 | --system --shell /sbin/nologin \ 33 | --comment "Account to run Tox's DHT bootstrap daemon" \ 34 | --user-group tox-bootstrapd && \ 35 | chmod 700 /var/lib/tox-bootstrapd && \ 36 | cp other/bootstrap_daemon/tox-bootstrapd.conf /etc/tox-bootstrapd.conf && \ 37 | # remove all the example bootstrap nodes from the config file 38 | sed -i '/^bootstrap_nodes = /,$d' /etc/tox-bootstrapd.conf && \ 39 | # add bootstrap nodes from https://nodes.tox.chat/ 40 | python3 other/bootstrap_daemon/docker/get-nodes.py >> /etc/tox-bootstrapd.conf && \ 41 | # perform cleanup 42 | export AUTO_ADDED_PACKAGES="$(apt-mark showauto)" && \ 43 | apt-get remove --purge -y $BUILD_PACKAGES $AUTO_ADDED_PACKAGES && \ 44 | apt-get clean && \ 45 | rm -rf /var/lib/apt/lists/* && \ 46 | cd / && \ 47 | rm -rf /tmp/* 48 | 49 | WORKDIR /var/lib/tox-bootstrapd 50 | 51 | USER tox-bootstrapd 52 | 53 | ENTRYPOINT /usr/local/bin/tox-bootstrapd \ 54 | --config /etc/tox-bootstrapd.conf \ 55 | --log-backend stdout \ 56 | --foreground 57 | 58 | EXPOSE 443/tcp 3389/tcp 33445/tcp 33445/udp 59 | -------------------------------------------------------------------------------- /other/bootstrap_daemon/docker/get-nodes.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | """ 3 | Copyright (c) 2016 by nurupo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | """ 23 | 24 | # Gets a list of nodes from https://nodes.tox.chat/json and prints them out 25 | # in the format of tox-bootstrapd config file. 26 | 27 | import urllib.request 28 | import json 29 | 30 | response = urllib.request.urlopen('https://nodes.tox.chat/json') 31 | raw_json = response.read().decode('ascii', 'ignore') 32 | nodes = json.loads(raw_json)['nodes'] 33 | 34 | output = 'bootstrap_nodes = (\n' 35 | 36 | for node in nodes: 37 | node_output = ' { // ' + node['maintainer'] + '\n' 38 | node_output += ' public_key = "' + node['public_key'] + '"\n' 39 | node_output += ' port = ' + str(node['port']) + '\n' 40 | node_output += ' address = "' 41 | if len(node['ipv4']) > 4: 42 | output += node_output + node['ipv4'] + '"\n },\n' 43 | if len(node['ipv6']) > 4: 44 | output += node_output + node['ipv6'] + '"\n },\n' 45 | 46 | # remove last comma 47 | output = output[:-2] + '\n)\n' 48 | 49 | print(output) 50 | -------------------------------------------------------------------------------- /other/bootstrap_daemon/src/Makefile.inc: -------------------------------------------------------------------------------- 1 | if BUILD_DHT_BOOTSTRAP_DAEMON 2 | 3 | bin_PROGRAMS += tox-bootstrapd 4 | 5 | tox_bootstrapd_SOURCES = \ 6 | ../other/bootstrap_daemon/src/command_line_arguments.c \ 7 | ../other/bootstrap_daemon/src/command_line_arguments.h \ 8 | ../other/bootstrap_daemon/src/config.c \ 9 | ../other/bootstrap_daemon/src/config_defaults.h \ 10 | ../other/bootstrap_daemon/src/config.h \ 11 | ../other/bootstrap_daemon/src/log.c \ 12 | ../other/bootstrap_daemon/src/log.h \ 13 | ../other/bootstrap_daemon/src/tox-bootstrapd.c \ 14 | ../other/bootstrap_daemon/src/global.h \ 15 | ../other/bootstrap_node_packets.c \ 16 | ../other/bootstrap_node_packets.h 17 | 18 | 19 | tox_bootstrapd_CFLAGS = \ 20 | -I$(top_srcdir)/other/bootstrap_daemon \ 21 | $(LIBSODIUM_CFLAGS) \ 22 | $(NACL_CFLAGS) \ 23 | $(LIBCONFIG_CFLAGS) 24 | 25 | tox_bootstrapd_LDADD = \ 26 | $(LIBSODIUM_LDFLAGS) \ 27 | $(NACL_LDFLAGS) \ 28 | libtoxcore.la \ 29 | $(LIBCONFIG_LIBS) \ 30 | $(LIBSODIUM_LIBS) \ 31 | $(NACL_LIBS) 32 | 33 | endif 34 | 35 | EXTRA_DIST += \ 36 | $(top_srcdir)/other/bootstrap_daemon/tox-bootstrapd.conf \ 37 | $(top_srcdir)/other/bootstrap_daemon/tox-bootstrapd.service \ 38 | $(top_srcdir)/other/bootstrap_daemon/tox-bootstrapd.sh 39 | 40 | -------------------------------------------------------------------------------- /other/bootstrap_daemon/src/command_line_arguments.c: -------------------------------------------------------------------------------- 1 | /* command_line_arguments.c 2 | * 3 | * Tox DHT bootstrap daemon. 4 | * Command line argument handling. 5 | * 6 | * Copyright (C) 2015-2016 Tox project All Rights Reserved. 7 | * 8 | * This file is part of Tox. 9 | * 10 | * Tox is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * Tox is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with Tox. If not, see . 22 | * 23 | */ 24 | 25 | #include "command_line_arguments.h" 26 | 27 | #include "global.h" 28 | 29 | #include 30 | 31 | #include 32 | #include 33 | 34 | 35 | /** 36 | * Prints --help message 37 | */ 38 | void print_help() 39 | { 40 | // 2 space ident 41 | // make sure all lines fit into 80 columns 42 | // make sure options are listed in alphabetical order 43 | write_log(LOG_LEVEL_INFO, 44 | "Usage: tox-bootstrapd [OPTION]... --config=FILE_PATH\n" 45 | "\n" 46 | "Options:\n" 47 | " --config=FILE_PATH Specify path to the config file.\n" 48 | " This is a required option.\n" 49 | " Set FILE_PATH to a path to an empty file in order to\n" 50 | " use default settings.\n" 51 | " --foreground Run the daemon in foreground. The daemon won't fork\n" 52 | " (detach from the terminal) and won't use the PID file.\n" 53 | " --help Print this help message.\n" 54 | " --log-backend=BACKEND Specify which logging backend to use.\n" 55 | " Valid BACKEND values (case sensetive):\n" 56 | " syslog Writes log messages to syslog.\n" 57 | " Default option when no --log-backend is\n" 58 | " specified.\n" 59 | " stdout Writes log messages to stdout/stderr.\n" 60 | " --version Print version information.\n"); 61 | } 62 | 63 | void handle_command_line_arguments(int argc, char *argv[], char **cfg_file_path, LOG_BACKEND *log_backend, 64 | bool *run_in_foreground) 65 | { 66 | if (argc < 2) { 67 | write_log(LOG_LEVEL_ERROR, "Error: No arguments provided.\n\n"); 68 | print_help(); 69 | exit(1); 70 | } 71 | 72 | opterr = 0; 73 | 74 | static struct option long_options[] = { 75 | {"config", required_argument, 0, 'c'}, // required option 76 | {"foreground", no_argument, 0, 'f'}, 77 | {"help", no_argument, 0, 'h'}, 78 | {"log-backend", required_argument, 0, 'l'}, // optional, defaults to syslog 79 | {"version", no_argument, 0, 'v'}, 80 | {0, 0, 0, 0 } 81 | }; 82 | 83 | bool cfg_file_path_set = false; 84 | bool log_backend_set = false; 85 | 86 | *run_in_foreground = false; 87 | 88 | int opt; 89 | 90 | while ((opt = getopt_long(argc, argv, ":", long_options, NULL)) != -1) { 91 | 92 | switch (opt) { 93 | 94 | case 'c': 95 | *cfg_file_path = optarg; 96 | cfg_file_path_set = true; 97 | break; 98 | 99 | case 'f': 100 | *run_in_foreground = true; 101 | break; 102 | 103 | case 'h': 104 | print_help(); 105 | exit(0); 106 | 107 | case 'l': 108 | if (strcmp(optarg, "syslog") == 0) { 109 | *log_backend = LOG_BACKEND_SYSLOG; 110 | log_backend_set = true; 111 | } else if (strcmp(optarg, "stdout") == 0) { 112 | *log_backend = LOG_BACKEND_STDOUT; 113 | log_backend_set = true; 114 | } else { 115 | write_log(LOG_LEVEL_ERROR, "Error: Invalid BACKEND value for --log-backend option passed: %s\n\n", optarg); 116 | print_help(); 117 | exit(1); 118 | } 119 | 120 | break; 121 | 122 | case 'v': 123 | write_log(LOG_LEVEL_INFO, "Version: %lu\n", DAEMON_VERSION_NUMBER); 124 | exit(0); 125 | 126 | case '?': 127 | write_log(LOG_LEVEL_ERROR, "Error: Unrecognized option %s\n\n", argv[optind - 1]); 128 | print_help(); 129 | exit(1); 130 | 131 | case ':': 132 | write_log(LOG_LEVEL_ERROR, "Error: No argument provided for option %s\n\n", argv[optind - 1]); 133 | print_help(); 134 | exit(1); 135 | } 136 | } 137 | 138 | if (!log_backend_set) { 139 | *log_backend = LOG_BACKEND_SYSLOG; 140 | } 141 | 142 | if (!cfg_file_path_set) { 143 | write_log(LOG_LEVEL_ERROR, "Error: The required --config option wasn't specified\n\n"); 144 | print_help(); 145 | exit(1); 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /other/bootstrap_daemon/src/command_line_arguments.h: -------------------------------------------------------------------------------- 1 | /* command_line_arguments.h 2 | * 3 | * Tox DHT bootstrap daemon. 4 | * Command line argument handling. 5 | * 6 | * Copyright (C) 2015-2016 Tox project All Rights Reserved. 7 | * 8 | * This file is part of Tox. 9 | * 10 | * Tox is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * Tox is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with Tox. If not, see . 22 | * 23 | */ 24 | 25 | #ifndef COMMAND_LINE_ARGUMENTS_H 26 | #define COMMAND_LINE_ARGUMENTS_H 27 | 28 | #include "log.h" 29 | 30 | /** 31 | * Handles command line arguments, setting cfg_file_path and log_backend. 32 | * Terminates the application if incorrect arguments are specified. 33 | * 34 | * @param argc Argc passed into main(). 35 | * @param argv Argv passed into main(). 36 | * @param cfg_file_path Sets to the provided by the user config file path. 37 | * @param log_backend Sets to the provided by the user log backend option. 38 | * @param run_in_foreground Sets to the provided by the user foreground option. 39 | */ 40 | void handle_command_line_arguments(int argc, char *argv[], char **cfg_file_path, LOG_BACKEND *log_backend, bool *run_in_foreground); 41 | 42 | #endif // COMMAND_LINE_ARGUMENTS_H 43 | -------------------------------------------------------------------------------- /other/bootstrap_daemon/src/config.h: -------------------------------------------------------------------------------- 1 | /* config.h 2 | * 3 | * Tox DHT bootstrap daemon. 4 | * Functionality related to dealing with the config file. 5 | * 6 | * Copyright (C) 2014-2016 Tox project All Rights Reserved. 7 | * 8 | * This file is part of Tox. 9 | * 10 | * Tox is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * Tox is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with Tox. If not, see . 22 | * 23 | */ 24 | 25 | #ifndef CONFIG_H 26 | #define CONFIG_H 27 | 28 | #include "../../../toxcore/DHT.h" 29 | 30 | /** 31 | * Gets general config options from the config file. 32 | * 33 | * Important: You are responsible for freeing `pid_file_path` and `keys_file_path` 34 | * also, iff `tcp_relay_ports_count` > 0, then you are responsible for freeing `tcp_relay_ports` 35 | * and also `motd` iff `enable_motd` is set. 36 | * 37 | * @return 1 on success, 38 | * 0 on failure, doesn't modify any data pointed by arguments. 39 | */ 40 | int get_general_config(const char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port, int *enable_ipv6, 41 | int *enable_ipv4_fallback, int *enable_lan_discovery, int *enable_tcp_relay, uint16_t **tcp_relay_ports, 42 | int *tcp_relay_port_count, int *enable_motd, char **motd); 43 | 44 | /** 45 | * Bootstraps off nodes listed in the config file. 46 | * 47 | * @return 1 on success, some or no bootstrap nodes were added 48 | * 0 on failure, a error accured while parsing config file. 49 | */ 50 | int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6); 51 | 52 | #endif // CONFIG_H 53 | -------------------------------------------------------------------------------- /other/bootstrap_daemon/src/config_defaults.h: -------------------------------------------------------------------------------- 1 | /* config_defaults.h 2 | * 3 | * Tox DHT bootstrap daemon. 4 | * Default config options for when they are missing in the config file. 5 | * 6 | * Copyright (C) 2014-2016 Tox project All Rights Reserved. 7 | * 8 | * This file is part of Tox. 9 | * 10 | * Tox is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * Tox is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with Tox. If not, see . 22 | * 23 | */ 24 | 25 | #ifndef CONFIG_DEFAULTS_H 26 | #define CONFIG_DEFAULTS_H 27 | 28 | #include "global.h" 29 | 30 | #define DEFAULT_PID_FILE_PATH "tox-bootstrapd.pid" 31 | #define DEFAULT_KEYS_FILE_PATH "tox-bootstrapd.keys" 32 | #define DEFAULT_PORT 33445 33 | #define DEFAULT_ENABLE_IPV6 1 // 1 - true, 0 - false 34 | #define DEFAULT_ENABLE_IPV4_FALLBACK 1 // 1 - true, 0 - false 35 | #define DEFAULT_ENABLE_LAN_DISCOVERY 1 // 1 - true, 0 - false 36 | #define DEFAULT_ENABLE_TCP_RELAY 1 // 1 - true, 0 - false 37 | #define DEFAULT_TCP_RELAY_PORTS 443, 3389, 33445 // comma-separated list of ports. make sure to adjust DEFAULT_TCP_RELAY_PORTS_COUNT accordingly 38 | #define DEFAULT_TCP_RELAY_PORTS_COUNT 3 39 | #define DEFAULT_ENABLE_MOTD 1 // 1 - true, 0 - false 40 | #define DEFAULT_MOTD DAEMON_NAME 41 | 42 | #endif // CONFIG_DEFAULTS_H 43 | -------------------------------------------------------------------------------- /other/bootstrap_daemon/src/global.h: -------------------------------------------------------------------------------- 1 | /* global.h 2 | * 3 | * Tox DHT bootstrap daemon. 4 | * Globally used defines. 5 | * 6 | * Copyright (C) 2014-2016 Tox project All Rights Reserved. 7 | * 8 | * This file is part of Tox. 9 | * 10 | * Tox is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * Tox is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with Tox. If not, see . 22 | * 23 | */ 24 | 25 | #ifndef GLOBAL_H 26 | #define GLOBAL_H 27 | 28 | #define DAEMON_NAME "tox-bootstrapd" 29 | #define DAEMON_VERSION_NUMBER 2016010100UL // yyyymmmddvv format: yyyy year, mm month, dd day, vv version change count for that day 30 | 31 | #define MIN_ALLOWED_PORT 1 32 | #define MAX_ALLOWED_PORT 65535 33 | 34 | #endif // GLOBAL_H 35 | -------------------------------------------------------------------------------- /other/bootstrap_daemon/src/log.c: -------------------------------------------------------------------------------- 1 | /* log.c 2 | * 3 | * Tox DHT bootstrap daemon. 4 | * Logging utility with support of multipel logging backends. 5 | * 6 | * Copyright (C) 2015-2016 Tox project All Rights Reserved. 7 | * 8 | * This file is part of Tox. 9 | * 10 | * Tox is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * Tox is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with Tox. If not, see . 22 | * 23 | */ 24 | 25 | #include "log.h" 26 | 27 | #include "global.h" 28 | 29 | #include 30 | 31 | #include 32 | #include 33 | 34 | LOG_BACKEND current_backend = -1; 35 | 36 | bool open_log(LOG_BACKEND backend) 37 | { 38 | if (current_backend != -1) { 39 | return false; 40 | } 41 | 42 | if (backend == LOG_BACKEND_SYSLOG) { 43 | openlog(DAEMON_NAME, LOG_NOWAIT | LOG_PID, LOG_DAEMON); 44 | } 45 | 46 | current_backend = backend; 47 | 48 | return true; 49 | } 50 | 51 | bool close_log() 52 | { 53 | if (current_backend == -1) { 54 | return false; 55 | } 56 | 57 | if (current_backend == LOG_BACKEND_SYSLOG) { 58 | closelog(); 59 | } 60 | 61 | current_backend = -1; 62 | 63 | return true; 64 | } 65 | 66 | int level_syslog(LOG_LEVEL level) 67 | { 68 | switch (level) { 69 | case LOG_LEVEL_INFO: 70 | return LOG_INFO; 71 | 72 | case LOG_LEVEL_WARNING: 73 | return LOG_WARNING; 74 | 75 | case LOG_LEVEL_ERROR: 76 | return LOG_ERR; 77 | } 78 | 79 | return LOG_INFO; 80 | } 81 | 82 | void log_syslog(LOG_LEVEL level, const char *format, va_list args) 83 | { 84 | vsyslog(level_syslog(level), format, args); 85 | } 86 | 87 | FILE *level_stdout(LOG_LEVEL level) 88 | { 89 | switch (level) { 90 | case LOG_LEVEL_INFO: 91 | return stdout; 92 | 93 | case LOG_LEVEL_WARNING: // intentional fallthrough 94 | case LOG_LEVEL_ERROR: 95 | return stderr; 96 | } 97 | 98 | return stdout; 99 | } 100 | 101 | void log_stdout(LOG_LEVEL level, const char *format, va_list args) 102 | { 103 | vfprintf(level_stdout(level), format, args); 104 | fflush(level_stdout(level)); 105 | } 106 | 107 | bool write_log(LOG_LEVEL level, const char *format, ...) 108 | { 109 | va_list args; 110 | va_start(args, format); 111 | 112 | switch (current_backend) { 113 | case LOG_BACKEND_SYSLOG: 114 | log_syslog(level, format, args); 115 | break; 116 | 117 | case LOG_BACKEND_STDOUT: 118 | log_stdout(level, format, args); 119 | break; 120 | } 121 | 122 | va_end(args); 123 | 124 | return current_backend != -1; 125 | } 126 | -------------------------------------------------------------------------------- /other/bootstrap_daemon/src/log.h: -------------------------------------------------------------------------------- 1 | /* log.h 2 | * 3 | * Tox DHT bootstrap daemon. 4 | * Logging utility with support of multipel logging backends. 5 | * 6 | * Copyright (C) 2015-2016 Tox project All Rights Reserved. 7 | * 8 | * This file is part of Tox. 9 | * 10 | * Tox is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * Tox is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with Tox. If not, see . 22 | * 23 | */ 24 | 25 | #ifndef LOG_H 26 | #define LOG_H 27 | 28 | #include 29 | 30 | typedef enum LOG_BACKEND { 31 | LOG_BACKEND_SYSLOG, 32 | LOG_BACKEND_STDOUT 33 | } LOG_BACKEND; 34 | 35 | typedef enum LOG_LEVEL { 36 | LOG_LEVEL_INFO, 37 | LOG_LEVEL_WARNING, 38 | LOG_LEVEL_ERROR 39 | } LOG_LEVEL; 40 | 41 | /** 42 | * Initializes logger. 43 | * @param backend Specifies which backend to use. 44 | * @return true on success, flase if log is already opened. 45 | */ 46 | bool open_log(LOG_BACKEND backend); 47 | 48 | /** 49 | * Releases all used resources by the logger. 50 | * @return true on success, flase if log is already closed. 51 | */ 52 | bool close_log(); 53 | 54 | /** 55 | * Writes a message to the log. 56 | * @param level Log level to use. 57 | * @param format printf-like format string. 58 | * @param ... Zero or more arguments, similar to printf function. 59 | * @return true on success, flase if log is closed. 60 | */ 61 | bool write_log(LOG_LEVEL level, const char *format, ...); 62 | 63 | 64 | #endif // LOG_H 65 | -------------------------------------------------------------------------------- /other/bootstrap_daemon/tox-bootstrapd.conf: -------------------------------------------------------------------------------- 1 | // Tox DHT bootstrap daemon configuration file. 2 | 3 | // Listening port (UDP). 4 | port = 33445 5 | 6 | // A key file is like a password, so keep it where no one can read it. 7 | // If there is no key file, a new one will be generated. 8 | // The daemon should have permission to read/write it. 9 | keys_file_path = "/var/lib/tox-bootstrapd/keys" 10 | 11 | // The PID file written to by the daemon. 12 | // Make sure that the user that daemon runs as has permissions to write to the 13 | // PID file. 14 | pid_file_path = "/var/run/tox-bootstrapd/tox-bootstrapd.pid" 15 | 16 | // Enable IPv6. 17 | enable_ipv6 = true 18 | 19 | // Fallback to IPv4 in case IPv6 fails. 20 | enable_ipv4_fallback = true 21 | 22 | // Automatically bootstrap with nodes on local area network. 23 | enable_lan_discovery = true 24 | 25 | enable_tcp_relay = true 26 | 27 | // While Tox uses 33445 port by default, 443 (https) and 3389 (rdp) ports are very 28 | // common among nodes, so it's encouraged to keep them in place. 29 | tcp_relay_ports = [443, 3389, 33445] 30 | 31 | // Reply to MOTD (Message Of The Day) requests. 32 | enable_motd = true 33 | 34 | // Just a message that is sent when someone requests MOTD. 35 | // Put anything you want, but note that it will be trimmed to fit into 255 bytes. 36 | motd = "tox-bootstrapd" 37 | 38 | // Any number of nodes the daemon will bootstrap itself off. 39 | // 40 | // Remember to replace the provided example with your own node list. 41 | // There is a maintained list of bootstrap nodes on Tox's wiki, if you need it 42 | // (https://wiki.tox.chat/doku.php?id=users:nodes). 43 | // 44 | // You may leave the list empty or remove "bootstrap_nodes" completely, 45 | // in both cases this will be interpreted as if you don't want to bootstrap 46 | // from anyone. 47 | // 48 | // address = any IPv4 or IPv6 address and also any US-ASCII domain name. 49 | bootstrap_nodes = ( 50 | { // Example Node 1 (IPv4) 51 | address = "127.0.0.1" 52 | port = 33445 53 | public_key = "728925473812C7AAC482BE7250BCCAD0B8CB9F737BF3D42ABD34459C1768F854" 54 | }, 55 | { // Example Node 2 (IPv6) 56 | address = "::1/128" 57 | port = 33445 58 | public_key = "3E78BACF0F84235B30054B54898F56793E1DEF8BD46B1038B9D822E8460FAB67" 59 | }, 60 | { // Example Node 3 (US-ASCII domain name) 61 | address = "example.org" 62 | port = 33445 63 | public_key = "8CD5A9BF0A6CE358BA36F7A653F99FA6B258FF756E490F52C1F98CC420F78858" 64 | } 65 | ) -------------------------------------------------------------------------------- /other/bootstrap_daemon/tox-bootstrapd.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Tox DHT Bootstrap Daemon 3 | After=network.target 4 | 5 | [Service] 6 | Type=forking 7 | RuntimeDirectory=tox-bootstrapd 8 | RuntimeDirectoryMode=750 9 | PIDFile=/var/run/tox-bootstrapd/tox-bootstrapd.pid 10 | WorkingDirectory=/var/lib/tox-bootstrapd 11 | ExecStart=/usr/local/bin/tox-bootstrapd --config /etc/tox-bootstrapd.conf 12 | User=tox-bootstrapd 13 | Group=tox-bootstrapd 14 | #CapabilityBoundingSet=CAP_NET_BIND_SERVICE 15 | 16 | [Install] 17 | WantedBy=multi-user.target 18 | -------------------------------------------------------------------------------- /other/bootstrap_daemon/tox-bootstrapd.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | ### BEGIN INIT INFO 3 | # Provides: tox-bootstrapd 4 | # Required-Start: $remote_fs $syslog 5 | # Required-Stop: $remote_fs $syslog 6 | # Default-Start: 2 3 4 5 7 | # Default-Stop: 0 1 6 8 | # Short-Description: Starts the Tox DHT bootstrapping server daemon 9 | # Description: Starts the Tox DHT bootstrapping server daemon 10 | ### END INIT INFO 11 | 12 | # PATH should only include /usr/* if it runs after the mountnfs.sh script 13 | PATH=/sbin:/usr/sbin:/bin:/usr/bin 14 | DESC="Tox DHT bootstrap daemon" 15 | NAME=tox-bootstrapd 16 | DAEMON=/usr/local/bin/$NAME 17 | CFGFILE=/etc/$NAME.conf 18 | DAEMON_ARGS="--config $CFGFILE" 19 | PIDDIR=/var/run/$NAME 20 | PIDFILE=$PIDDIR/$NAME.pid 21 | SCRIPTNAME=/etc/init.d/$NAME 22 | USER=tox-bootstrapd 23 | GROUP=tox-bootstrapd 24 | 25 | # Exit if the package is not installed 26 | [ -x "$DAEMON" ] || exit 0 27 | 28 | # Load the VERBOSE setting and other rcS variables 29 | . /lib/init/vars.sh 30 | 31 | # Define LSB log_* functions. 32 | # Depend on lsb-base (>= 3.2-14) to ensure that this file is present 33 | # and status_of_proc is working. 34 | . /lib/lsb/init-functions 35 | 36 | # 37 | # Function that starts the daemon/service 38 | # 39 | do_start() 40 | { 41 | # Return 42 | # 0 if daemon has been started 43 | # 1 if daemon was already running 44 | # 2 if daemon could not be started 45 | if [ ! -d $PIDDIR ] 46 | then 47 | mkdir $PIDDIR 48 | fi 49 | chown $USER:$GROUP $PIDDIR 50 | start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test --chuid $USER > /dev/null || return 1 51 | start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --chuid $USER -- $DAEMON_ARGS || return 2 52 | } 53 | 54 | # 55 | # Function that stops the daemon/service 56 | # 57 | do_stop() 58 | { 59 | # Return 60 | # 0 if daemon has been stopped 61 | # 1 if daemon was already stopped 62 | # 2 if daemon could not be stopped 63 | # other if a failure occurred 64 | start-stop-daemon --stop --quiet --retry 5 --pidfile $PIDFILE --name $NAME --chuid $USER 65 | RETVAL="$?" 66 | [ "$RETVAL" = 2 ] && return 2 67 | # Many daemons don't delete their pidfiles when they exit. 68 | rm -f $PIDFILE 69 | return "$RETVAL" 70 | } 71 | 72 | case "$1" in 73 | start) 74 | [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" 75 | do_start 76 | case "$?" in 77 | 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; 78 | 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; 79 | esac 80 | ;; 81 | stop) 82 | [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" 83 | do_stop 84 | case "$?" in 85 | 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; 86 | 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; 87 | esac 88 | ;; 89 | status) 90 | status_of_proc -p $PIDFILE "$DAEMON" "$NAME" && exit 0 || exit $? 91 | ;; 92 | 93 | restart) 94 | log_daemon_msg "Restarting $DESC" "$NAME" 95 | do_stop 96 | case "$?" in 97 | 0|1) 98 | do_start 99 | case "$?" in 100 | 0) log_end_msg 0 ;; 101 | 1) log_end_msg 1 ;; # Old process is still running 102 | *) log_end_msg 1 ;; # Failed to start 103 | esac 104 | ;; 105 | *) 106 | # Failed to stop 107 | log_end_msg 1 108 | ;; 109 | esac 110 | ;; 111 | *) 112 | echo "Usage: $SCRIPTNAME {start|stop|status|restart}" >&2 113 | exit 3 114 | ;; 115 | esac 116 | exit 0 -------------------------------------------------------------------------------- /other/bootstrap_node_packets.c: -------------------------------------------------------------------------------- 1 | /* bootstrap_node_packets.c 2 | * 3 | * Special bootstrap node only packets. 4 | * 5 | * Include it in your bootstrap node and use: bootstrap_set_callbacks() to enable. 6 | * 7 | * Copyright (C) 2013 Tox project All Rights Reserved. 8 | * 9 | * This file is part of Tox. 10 | * 11 | * Tox is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * Tox is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with Tox. If not, see . 23 | * 24 | */ 25 | 26 | #include "bootstrap_node_packets.h" 27 | 28 | #define INFO_REQUEST_PACKET_LENGTH 78 29 | 30 | static uint32_t bootstrap_version; 31 | static uint8_t bootstrap_motd[MAX_MOTD_LENGTH]; 32 | static uint16_t bootstrap_motd_length; 33 | 34 | /* To request this packet just send a packet of length INFO_REQUEST_PACKET_LENGTH 35 | * with the first byte being BOOTSTRAP_INFO_PACKET_ID 36 | */ 37 | static int handle_info_request(void *object, IP_Port source, const uint8_t *packet, uint16_t length) 38 | { 39 | if (length != INFO_REQUEST_PACKET_LENGTH) 40 | return 1; 41 | 42 | uint8_t data[1 + sizeof(bootstrap_version) + MAX_MOTD_LENGTH]; 43 | data[0] = BOOTSTRAP_INFO_PACKET_ID; 44 | memcpy(data + 1, &bootstrap_version, sizeof(bootstrap_version)); 45 | uint16_t len = 1 + sizeof(bootstrap_version) + bootstrap_motd_length; 46 | memcpy(data + 1 + sizeof(bootstrap_version), bootstrap_motd, bootstrap_motd_length); 47 | 48 | if (sendpacket(object, source, data, len) == len) 49 | return 0; 50 | 51 | return 1; 52 | } 53 | 54 | int bootstrap_set_callbacks(Networking_Core *net, uint32_t version, uint8_t *motd, uint16_t motd_length) 55 | { 56 | if (motd_length > MAX_MOTD_LENGTH) 57 | return -1; 58 | 59 | bootstrap_version = htonl(version); 60 | memcpy(bootstrap_motd, motd, motd_length); 61 | bootstrap_motd_length = motd_length; 62 | 63 | networking_registerhandler(net, BOOTSTRAP_INFO_PACKET_ID, &handle_info_request, net); 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /other/bootstrap_node_packets.h: -------------------------------------------------------------------------------- 1 | /* bootstrap_node_packets.h 2 | * 3 | * Special bootstrap node only packets. 4 | * 5 | * Include it in your bootstrap node and use: bootstrap_set_callbacks() to enable. 6 | * 7 | * Copyright (C) 2015 Tox project All Rights Reserved. 8 | * 9 | * This file is part of Tox. 10 | * 11 | * Tox is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * Tox is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with Tox. If not, see . 23 | * 24 | */ 25 | 26 | #ifndef BOOTSTRAP_NODE_PACKETS_H 27 | #define BOOTSTRAP_NODE_PACKETS_H 28 | 29 | #include "../toxcore/network.h" 30 | 31 | #define MAX_MOTD_LENGTH 256 /* I recommend you use a maximum of 96 bytes. The hard maximum is this though. */ 32 | 33 | int bootstrap_set_callbacks(Networking_Core *net, uint32_t version, uint8_t *motd, uint16_t motd_length); 34 | 35 | #endif // BOOTSTRAP_NODE_PACKETS_H 36 | -------------------------------------------------------------------------------- /other/fun/bootstrap_node_info.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Copyright (c) 2014 by nurupo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | """ 23 | 24 | from socket import * 25 | import sys 26 | 27 | if sys.version_info[0] == 2: 28 | print("This script requires Python 3+ in order to run.") 29 | sys.exit(1) 30 | 31 | def printHelp(): 32 | print("Usage: " + sys.argv[0] + " ") 33 | print(" Example: " + sys.argv[0] + " ipv4 192.210.149.121 33445") 34 | print(" Example: " + sys.argv[0] + " ipv4 23.226.230.47 33445") 35 | print(" Example: " + sys.argv[0] + " ipv4 biribiri.org 33445") 36 | print(" Example: " + sys.argv[0] + " ipv4 cerberus.zodiaclabs.org 33445") 37 | print(" Example: " + sys.argv[0] + " ipv6 2604:180:1::3ded:b280 33445") 38 | print("") 39 | print("Return values:") 40 | print(" 0 - received info reply from a node") 41 | print(" 1 - incorrect command line arguments") 42 | print(" 2 - didn't receive any reply from a node") 43 | print(" 3 - received a malformed/unexpected reply") 44 | 45 | if len(sys.argv) != 4: 46 | printHelp() 47 | sys.exit(1) 48 | 49 | protocol = sys.argv[1] 50 | ip = sys.argv[2] 51 | port = int(sys.argv[3]) 52 | 53 | INFO_PACKET_ID = b"\xF0" # https://github.com/irungentoo/toxcore/blob/4940c4c62b6014d1f0586aa6aca7bf6e4ecfcf29/toxcore/network.h#L128 54 | INFO_REQUEST_PACKET_LENGTH = 78 # https://github.com/irungentoo/toxcore/blob/881b2d900d1998981fb6b9938ec66012d049635f/other/bootstrap_node_packets.c#L28 55 | # first byte is INFO_REQUEST_ID, other bytes don't matter as long as reqest's length matches INFO_REQUEST_LENGTH 56 | INFO_REQUEST_PACKET = INFO_PACKET_ID + ( b"0" * (INFO_REQUEST_PACKET_LENGTH - len(INFO_PACKET_ID)) ) 57 | 58 | PACKET_ID_LENGTH = len(INFO_PACKET_ID) 59 | VERSION_LENGTH = 4 # https://github.com/irungentoo/toxcore/blob/881b2d900d1998981fb6b9938ec66012d049635f/other/bootstrap_node_packets.c#L44 60 | MAX_MOTD_LENGTH = 256 # https://github.com/irungentoo/toxcore/blob/881b2d900d1998981fb6b9938ec66012d049635f/other/bootstrap_node_packets.c#L26 61 | 62 | MAX_INFO_RESPONSE_PACKET_LENGTH = PACKET_ID_LENGTH + VERSION_LENGTH + MAX_MOTD_LENGTH 63 | 64 | SOCK_TIMEOUT_SECONDS = 1.0 65 | 66 | sock = None 67 | 68 | if protocol == "ipv4": 69 | sock = socket(AF_INET, SOCK_DGRAM) 70 | elif protocol == "ipv6": 71 | sock = socket(AF_INET6, SOCK_DGRAM) 72 | else: 73 | print("Invalid first argument") 74 | printHelp() 75 | sys.exit(1) 76 | 77 | sock.sendto(INFO_REQUEST_PACKET, (ip, port)) 78 | 79 | sock.settimeout(SOCK_TIMEOUT_SECONDS) 80 | 81 | try: 82 | data, addr = sock.recvfrom(MAX_INFO_RESPONSE_PACKET_LENGTH) 83 | except timeout: 84 | print("The DHT bootstrap node didn't reply in " + str(SOCK_TIMEOUT_SECONDS) + " sec.") 85 | print("The likely reason for that is that the DHT bootstrap node is either offline or has no info set.") 86 | sys.exit(2) 87 | 88 | packetId = data[:PACKET_ID_LENGTH] 89 | if packetId != INFO_PACKET_ID: 90 | print("Bad response, first byte should be", INFO_PACKET_ID, "but got", packetId, "(", data, ")") 91 | print("Are you sure that you are pointing the script at a Tox DHT bootstrap node and that the script is up to date?") 92 | sys.exit(3) 93 | 94 | version = int.from_bytes(data[PACKET_ID_LENGTH:PACKET_ID_LENGTH + VERSION_LENGTH], byteorder='big') 95 | motd = data[PACKET_ID_LENGTH + VERSION_LENGTH:].decode("utf-8") 96 | print("Version: " + str(version)) 97 | print("MOTD: " + motd) 98 | sys.exit(0) -------------------------------------------------------------------------------- /other/fun/cracker.c: -------------------------------------------------------------------------------- 1 | /* Public key cracker. 2 | * 3 | * Can be used to find public keys starting with specific hex (ABCD) for example. 4 | * 5 | * NOTE: There's probably a way to make this faster. 6 | * 7 | * Usage: ./cracker ABCDEF 8 | * 9 | * Will try to find a public key starting with: ABCDEF 10 | */ 11 | 12 | #include "../../testing/misc_tools.c" 13 | #include 14 | 15 | /* NaCl includes*/ 16 | #include 17 | #include 18 | 19 | /* Sodium include*/ 20 | //#include 21 | 22 | void print_key(uint8_t *client_id) 23 | { 24 | uint32_t j; 25 | 26 | for (j = 0; j < 32; j++) { 27 | printf("%02hhX", client_id[j]); 28 | } 29 | } 30 | 31 | 32 | int main(int argc, char *argv[]) 33 | { 34 | if (argc < 2) { 35 | printf("usage: ./cracker public_key(or beginning of one in hex format)\n"); 36 | return 0; 37 | } 38 | 39 | long long unsigned int num_tries = 0; 40 | 41 | uint32_t len = strlen(argv[1]) / 2; 42 | unsigned char *key = hex_string_to_bin(argv[1]); 43 | uint8_t pub_key[32], priv_key[32], c_key[32]; 44 | 45 | if (len > 32) 46 | len = 32; 47 | 48 | memcpy(c_key, key, len); 49 | free(key); 50 | randombytes(priv_key, 32); 51 | 52 | while (1) { 53 | crypto_scalarmult_curve25519_base(pub_key, priv_key); 54 | uint32_t i; 55 | 56 | if (memcmp(c_key, pub_key, len) == 0) 57 | break; 58 | 59 | for (i = 32; i != 0; --i) { 60 | priv_key[i - 1] += 1; 61 | 62 | if (priv_key[i - 1] != 0) 63 | break; 64 | } 65 | 66 | ++num_tries; 67 | } 68 | 69 | printf("Public key:\n"); 70 | print_key(pub_key); 71 | printf("\nPrivate key:\n"); 72 | print_key(priv_key); 73 | printf("\n %llu keys tried\n", num_tries); 74 | return 0; 75 | } 76 | -------------------------------------------------------------------------------- /other/fun/make-funny-savefile.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | """ 4 | Generate a new (and empty) save file with predefined keys. Used to play 5 | with externally generated keys. 6 | 7 | (c) 2015 Alexandre Erwin Ittner 8 | 9 | Distributed under the GNU GPL v3 or later, WITHOUT ANY WARRANTY. See the 10 | file "COPYING" for license information. 11 | 12 | 13 | Usage: 14 | 15 | ./make-funny-savefile.py 16 | 17 | The new user profile will be saved to . 18 | 19 | The keys must be an hex-encoded valid key pair generated by any means 20 | (eg. strkey.c); username may be anything. A random nospam value will be 21 | generated. 22 | 23 | Once the savefile is done, load it in your favorite client to get some 24 | DHT nodes, set status and status messages, add friends, etc. 25 | 26 | 27 | Example (of course, do not try using this key for anything real): 28 | 29 | ./make-funny-savefile.py 123411DC8B1A4760B648E0C7243B65F01069E4858F45C612CE1A6F673B603830 CC39440CFC063E4A95B7F2FB2580210558BE5C073AFC1C9604D431CCA3132238 "Test user" test.tox 30 | 31 | 32 | """ 33 | 34 | 35 | PUBLIC_KEY_LENGTH = 32 36 | PRIVATE_KEY_LENGTH = 32 37 | 38 | # Constants taken from messenger.c 39 | MESSENGER_STATE_COOKIE_GLOBAL = 0x15ed1b1f 40 | MESSENGER_STATE_COOKIE_TYPE = 0x01ce 41 | MESSENGER_STATE_TYPE_NOSPAMKEYS = 1 42 | MESSENGER_STATE_TYPE_DHT = 2 43 | MESSENGER_STATE_TYPE_FRIENDS = 3 44 | MESSENGER_STATE_TYPE_NAME = 4 45 | MESSENGER_STATE_TYPE_STATUSMESSAGE = 5 46 | MESSENGER_STATE_TYPE_STATUS = 6 47 | MESSENGER_STATE_TYPE_TCP_RELAY = 10 48 | MESSENGER_STATE_TYPE_PATH_NODE = 11 49 | 50 | STATUS_MESSAGE = "New user".encode("utf-8") 51 | 52 | 53 | 54 | import sys 55 | import struct 56 | import os 57 | 58 | def abort(msg): 59 | print(msg) 60 | exit(1) 61 | 62 | 63 | 64 | if len(sys.argv) != 5: 65 | abort("Usage: %s " % (sys.argv[0])) 66 | 67 | try: 68 | public_key = sys.argv[1].decode("hex") 69 | except: 70 | abort("Bad public key") 71 | 72 | try: 73 | private_key = sys.argv[2].decode("hex") 74 | except: 75 | abort("Bad private key") 76 | 77 | if len(public_key) != PUBLIC_KEY_LENGTH: 78 | abort("Public key with wrong length") 79 | 80 | if len(private_key) != PRIVATE_KEY_LENGTH: 81 | abort("Private key with wrong length") 82 | 83 | user_name = sys.argv[3].encode("utf-8") 84 | 85 | if len(user_name) > 32: 86 | abort("User name too long (for this script, at least)") 87 | 88 | out_file_name = sys.argv[4] 89 | nospam = os.urandom(4) 90 | 91 | 92 | def make_subheader(h_type, h_length): 93 | return ( 94 | struct.pack(" 19 | #include 20 | #include "../../testing/misc_tools.c" // hex_string_to_bin 21 | 22 | int load_file(char *filename, char **result) 23 | { 24 | int size = 0; 25 | FILE *f = fopen(filename, "rb"); 26 | 27 | if (f == NULL) { 28 | *result = NULL; 29 | return -1; // -1 means file opening fail 30 | } 31 | 32 | fseek(f, 0, SEEK_END); 33 | size = ftell(f); 34 | fseek(f, 0, SEEK_SET); 35 | *result = (char *)malloc(size + 1); 36 | 37 | if (size != fread(*result, sizeof(char), size, f)) { 38 | free(*result); 39 | fclose(f); 40 | return -2; // -2 means file reading fail 41 | } 42 | 43 | fclose(f); 44 | (*result)[size] = 0; 45 | return size; 46 | } 47 | 48 | int main(int argc, char *argv[]) 49 | { 50 | unsigned char pk[crypto_sign_ed25519_PUBLICKEYBYTES]; 51 | unsigned char sk[crypto_sign_ed25519_SECRETKEYBYTES]; 52 | 53 | if (argc == 2 && argv[1][0] == 'g') { 54 | crypto_sign_ed25519_keypair(pk, sk); 55 | printf("Public key:\n"); 56 | int i; 57 | 58 | for (i = 0; i < crypto_sign_ed25519_PUBLICKEYBYTES; i++) { 59 | printf("%02hhX", pk[i]); 60 | } 61 | 62 | printf("\nSecret key:\n"); 63 | 64 | for (i = 0; i < crypto_sign_ed25519_SECRETKEYBYTES; i++) { 65 | printf("%02hhX", sk[i]); 66 | } 67 | 68 | printf("\n"); 69 | } 70 | 71 | if (argc == 5 && argv[1][0] == 's') { 72 | unsigned char *secret_key = hex_string_to_bin(argv[2]); 73 | char *data; 74 | int size = load_file(argv[3], &data); 75 | 76 | if (size < 0) 77 | goto fail; 78 | 79 | unsigned long long smlen; 80 | char *sm = malloc(size + crypto_sign_ed25519_BYTES * 2); 81 | crypto_sign_ed25519(sm, &smlen, data, size, secret_key); 82 | free(secret_key); 83 | 84 | if (smlen - size != crypto_sign_ed25519_BYTES) 85 | goto fail; 86 | 87 | FILE *f = fopen(argv[4], "wb"); 88 | 89 | if (f == NULL) 90 | goto fail; 91 | 92 | memcpy(sm + smlen, sm, crypto_sign_ed25519_BYTES); // Move signature from beginning to end of file. 93 | 94 | if (fwrite(sm + (smlen - size), 1, smlen, f) != smlen) 95 | goto fail; 96 | 97 | fclose(f); 98 | printf("Signed successfully.\n"); 99 | } 100 | 101 | if (argc == 4 && argv[1][0] == 'c') { 102 | unsigned char *public_key = hex_string_to_bin(argv[2]); 103 | char *data; 104 | int size = load_file(argv[3], &data); 105 | 106 | if (size < 0) 107 | goto fail; 108 | 109 | char *signe = malloc(size + crypto_sign_ed25519_BYTES); 110 | memcpy(signe, data + size - crypto_sign_ed25519_BYTES, 111 | crypto_sign_ed25519_BYTES); // Move signature from end to beginning of file. 112 | memcpy(signe + crypto_sign_ed25519_BYTES, data, size - crypto_sign_ed25519_BYTES); 113 | unsigned long long smlen; 114 | char *m = malloc(size); 115 | unsigned long long mlen; 116 | 117 | if (crypto_sign_ed25519_open(m, &mlen, signe, size, public_key) == -1) { 118 | printf("Failed checking sig.\n"); 119 | goto fail; 120 | } 121 | 122 | printf("Checked successfully.\n"); 123 | } 124 | 125 | return 0; 126 | 127 | fail: 128 | printf("FAIL\n"); 129 | return 1; 130 | } 131 | -------------------------------------------------------------------------------- /other/fun/strkey.c: -------------------------------------------------------------------------------- 1 | /* strkey -- String in Public Key 2 | * 3 | * Generates Tox's key pairs, checking if a certain string is in the public key. 4 | * 5 | * Requires sodium or nacl library. 6 | * 7 | * There seem to be some problems with the code working on Windows -- it works 8 | * when built in debug mode with MinGW 4.8, but it doesn't work correctly when 9 | * built in release. 10 | * 11 | * Usage: strkey 12 | * 13 | * Offset - an integer specifying exact byte offset position of the string you 14 | * are looking for within a public key. When offset is negative, the program 15 | * just looks for the desired string being somewhere, doesn't matter where, in 16 | * the public key. 17 | * 18 | * String - a hex string that you want to have in your public key. It must have 19 | * an even number of letters, since every two hexes map to a single byte of 20 | * the public key. 21 | * 22 | * Examples: 23 | * strkey 0 0123 24 | * Looks for a public key that begins with "0123". 25 | * 26 | * strkey 1 0123 27 | * Looks for a public key that has "0123" starting at its second byte, i.e. "XX0123...". 28 | * 29 | * strkey 2 0123 30 | * Looks for a public key that has "0123" starting at its third byte, i.e. "XXXX0123...". 31 | * (each two hexes represent a single byte of a public key) 32 | * 33 | * strkey -1 AF57CC 34 | * Looks for a public key that contains "AF57CC", regardless of its position. 35 | * 36 | * To compile with gcc and sodium: gcc strkey.c -o strkey -lsodium 37 | */ 38 | 39 | #include 40 | #include 41 | 42 | #include 43 | 44 | #define PRINT_TRIES_COUNT 45 | 46 | void print_key(unsigned char *key) 47 | { 48 | size_t i; 49 | for (i = 0; i < crypto_box_PUBLICKEYBYTES; i++) { 50 | if (key[i] < 16) { 51 | fprintf(stdout, "0"); 52 | } 53 | 54 | fprintf(stdout, "%hhX", key[i]); 55 | } 56 | } 57 | 58 | int main(int argc, char *argv[]) 59 | { 60 | unsigned char public_key[crypto_box_PUBLICKEYBYTES]; // null terminator 61 | unsigned char secret_key[crypto_box_SECRETKEYBYTES]; 62 | int offset = 0; 63 | size_t len; 64 | unsigned char desired_bin[crypto_box_PUBLICKEYBYTES]; // null terminator 65 | 66 | if (argc == 3) { 67 | offset = atoi(argv[1]); 68 | char *desired_hex = argv[2]; 69 | len = strlen(desired_hex); 70 | if (len % 2 != 0) { 71 | fprintf(stderr, "Desired key should have an even number of letters\n"); 72 | exit(1); 73 | } 74 | size_t block_length = (offset < 0 ? 0 : offset) + len/2; 75 | if (block_length > crypto_box_PUBLICKEYBYTES) { 76 | fprintf(stderr, "The given key with the given offset exceed public key's length\n"); 77 | exit(1); 78 | } 79 | 80 | // convert hex to bin 81 | char *pos = desired_hex; 82 | size_t i; 83 | for (i = 0; i < len; pos += 2) { 84 | sscanf(pos, "%2hhx", &desired_bin[i]); 85 | ++i; 86 | } 87 | } else { 88 | fprintf(stdout, "Usage: executable \n"); 89 | exit(1); 90 | } 91 | 92 | len /= 2; 93 | 94 | #ifdef PRINT_TRIES_COUNT 95 | long long unsigned int tries = 0; 96 | #endif 97 | 98 | if (offset < 0) { 99 | int found = 0; 100 | do { 101 | #ifdef PRINT_TRIES_COUNT 102 | tries ++; 103 | #endif 104 | crypto_box_keypair(public_key, secret_key); 105 | int i; 106 | for (i = 0; i <= crypto_box_PUBLICKEYBYTES - len; i ++) { 107 | if (memcmp(public_key + i, desired_bin, len) == 0) { 108 | found = 1; 109 | break; 110 | } 111 | } 112 | } while (!found); 113 | } else { 114 | unsigned char *p = public_key + offset; 115 | 116 | do { 117 | #ifdef PRINT_TRIES_COUNT 118 | tries ++; 119 | #endif 120 | crypto_box_keypair(public_key, secret_key); 121 | } while (memcmp(p, desired_bin, len) != 0); 122 | } 123 | 124 | fprintf(stdout, "Public key: "); 125 | print_key(public_key); 126 | fprintf(stdout, "\n"); 127 | 128 | fprintf(stdout, "Private key: "); 129 | print_key(secret_key); 130 | fprintf(stdout, "\n"); 131 | 132 | #ifdef PRINT_TRIES_COUNT 133 | fprintf(stdout, "Found the key pair on %llu try.\n", tries); 134 | #endif 135 | 136 | return 0; 137 | } 138 | -------------------------------------------------------------------------------- /other/osx_build_script_toxcore.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # written by Lubo Diakov 3 | # hard coded toxcore directory, replace with other path or variable as needed 4 | cd ~/Downloads/toxcore 5 | echo "Now working in:"`pwd` 6 | 7 | # must have working git binary, and have done git clone at least once before 8 | git pull 9 | echo "If git pull responds: Already up-to-date. you can cancel the build" 10 | echo "by typing anything except y or Y below" 11 | read -p "Continue with build? (enter y to continue): " Last_Chance 12 | 13 | # blah blah 14 | if [[ $Last_Chance = [Yy] ]]; then echo "Continuing!"; 15 | else echo "Aborted!"; exit 16 | fi 17 | sleep 3 18 | 19 | # if libsodium is built with macports, link it from /opt/local/ to /usr/local 20 | if [ ! -L "/usr/local/lib/libsodium.dylib" ]; then 21 | # Control will enter here if $DIRECTORY doesn't exist. 22 | ln -s /opt/local/lib/libsodium.dylib /usr/local/lib/libsodium.dylib 23 | fi 24 | echo "The symlink /usr/local/lib/libsodium.dylib exists." 25 | sleep 3 26 | 27 | # replace ppc, i386 as needed. 28 | ./configure CC="gcc -arch ppc -arch i386" CXX="g++ -arch ppc -arch i386" CPP="gcc -E" CXXCPP="g++ -E" 29 | 30 | # get rid of prior builds, start clean 31 | make clean 32 | make 33 | echo "" 34 | echo "Sudo is required for make install only, all other steps run without it." 35 | echo "Please type your sudo password below for make install:" 36 | sudo make install 37 | 38 | exit 39 | -------------------------------------------------------------------------------- /other/tox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/irungentoo/toxcore/bf69b54f64003d160d759068f4816b2d9b2e1e21/other/tox.png -------------------------------------------------------------------------------- /super_donators/LittleVulpix: -------------------------------------------------------------------------------- 1 | Thank you to all the tox-devs for the idea of a privacy-oriented chat protocol. 2 | Thank you for seeing it through so that we have tox in its current state. It has ways to go, but it's already pretty good! 3 | It is my dream that it will one day be as popular (or even more so) than the other protocols. 4 | Thank you to everyone who is actively participating in maintaining and fixing things to make tox better today than it was yesterday! 5 | And finally a big thanks to the community that stayed together even through semi-tough times and united to fund the campaign! 6 | 7 | Working filetransfers are my 'gift' to you all! Thanks to irungentoo for making it happen. 8 | 9 | "I'm commander Shepard and this is my favourite chat protocol on the Internet." 10 | 11 | @LittleVulpix, 2015. 12 | -------------------------------------------------------------------------------- /super_donators/grencez_tok5.c: -------------------------------------------------------------------------------- 1 | /* Though it may look bleak at times, 2 | * this ring will stabilize to have one token, 3 | * and Tox will be the one true chat protocol! 4 | * -- Alex P. Klinkhamer (grencez) 5 | */ 6 | #include 7 | #include 8 | #include 9 | int main(int i, char** msg) 10 | { 11 | int j, fd[4], xpd, xid; 12 | if (--i<1) return 1; 13 | srand(getpid()); 14 | pipe(fd); 15 | while (xid=rand()%5, --i>0) { 16 | pipe(&fd[2]); 17 | j = (0==fork() ? 0 : 1); 18 | close(fd[j]); 19 | fd[j] = fd[j+2]; 20 | close(fd[3-j]); 21 | if (j==0) break; 22 | } 23 | #define SendSc() write(fd[1], &xid, sizeof(xid)) 24 | #define RecvPd() read(fd[0], &xpd, sizeof(xpd)) 25 | #define A(g,v) if (g) {xid=v; puts(msg[i+1]); fflush(stdout); SendSc();} 26 | SendSc(); 27 | while (RecvPd(), 1) { 28 | sleep(1); 29 | if (i==0) { 30 | A( xpd==0 && xid==0 , 1 ); 31 | A( xpd==1 && xid<=1 , 2 ); 32 | A( xpd> 1 && xid> 1 , 0 ); 33 | continue; 34 | } 35 | A( xpd==0 && xid> 1 , xid/4 ); 36 | A( xpd==1 && xid!=1 , 1 ); 37 | A( xpd==2 && xid<=1 , 2+xid ); 38 | A( xpd>=3 && xid<=1 , 4 ); 39 | } 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /super_donators/sir@cmpwn.com: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Run ./sir@cmpwn.com 3 | # Arrow keys or wasd to move 4 | 5 | c=`tput cols`;L=`tput lines` 6 | let x=$c/2;let y=$L/2;d=0;le=3;t="$y;$x";i=0;j=0;S=0 7 | A(){ let i=($RANDOM%$c);let j=($RANDOM%$L);};A 8 | B(){ printf $*;};C(){ B "\x1B[$1";};D(){ C "$1H";} 9 | F(){ D "0;0";C 2J;C "?25h";printf "GAME OVER\nSCORE: $S\n";exit;};trap F INT 10 | C ?25l;C 2J;da(){ D "$j;$i";echo "$1";} 11 | G() { for n in $t; do D "$n";echo "$1";done;} 12 | mt(){ t=`echo "$t"|cut -d' ' -f2-`;} 13 | sc(){ D "0;0";echo "Score: $S"; } 14 | gt() { t+=" $y;$x";};ct() { for n in $t; do [ "$y;$x" == "$n" ]&&F;done;} 15 | M() { case $d in 0)let y--;;1)let x--;;2)let y++;;3)let x++;;esac 16 | let x%=$c;let y%=$L;ct;[ "$y$x" == "$j$i" ]&&{ let le++;A;let S++;} 17 | l=`tr -dc ' '<<<"$t"|wc -c`;gt;[ $l -gt $le ]&&mt;} 18 | ky() { k=$1;read -sN1 -t 0.01 k1;read -sN1 -t 0.01 k2;read -sN1 -t 0.01 k3 19 | k+=${k1}${k2}${k3};case $k in w|$'\e[A'|$'\e0A')d=0;;a|$'\e[D'|$'\e0D')d=1;; 20 | s|$'\e[B'|$'\e0B')d=2;;d|$'\e[C'|$'\e0C')d=3;;esac;} 21 | while :;do da ' ';G ' ';M;da "@";G "#";sc;read -s -n 1 -t 0.1 k && ky "$k";done 22 | -------------------------------------------------------------------------------- /testing/Makefile.inc: -------------------------------------------------------------------------------- 1 | if BUILD_NTOX 2 | 3 | bin_PROGRAMS += nTox 4 | 5 | nTox_SOURCES = ../testing/nTox.h \ 6 | ../testing/nTox.c 7 | 8 | nTox_CFLAGS = $(LIBSODIUM_CFLAGS) \ 9 | $(NACL_CFLAGS) \ 10 | $(NCURSES_CFLAGS) 11 | 12 | nTox_LDADD = $(LIBSODIUM_LDFLAGS) \ 13 | $(NAC_LDFLAGS) \ 14 | libtoxcore.la \ 15 | $(LIBSODIUM_LIBS) \ 16 | $(NACL_OBJECTS) \ 17 | $(NACL_LIBS) \ 18 | $(NCURSES_LIBS) \ 19 | $(WINSOCK2_LIBS) 20 | endif 21 | 22 | 23 | if BUILD_TESTING 24 | 25 | noinst_PROGRAMS += DHT_test \ 26 | Messenger_test \ 27 | dns3_test 28 | 29 | DHT_test_SOURCES = ../testing/DHT_test.c 30 | 31 | DHT_test_CFLAGS = $(LIBSODIUM_CFLAGS) \ 32 | $(NACL_CFLAGS) 33 | 34 | DHT_test_LDADD = $(LIBSODIUM_LDFLAGS) \ 35 | $(NACL_LDFLAGS) \ 36 | libtoxcore.la \ 37 | $(LIBSODIUM_LIBS) \ 38 | $(NACL_OBJECTS) \ 39 | $(NACL_LIBS) \ 40 | $(WINSOCK2_LIBS) 41 | 42 | 43 | Messenger_test_SOURCES = \ 44 | ../testing/Messenger_test.c 45 | 46 | Messenger_test_CFLAGS = $(LIBSODIUM_CFLAGS) \ 47 | $(NACL_CFLAGS) 48 | 49 | Messenger_test_LDADD = $(LIBSODIUM_LDFLAGS) \ 50 | $(NACL_LDFLAGS) \ 51 | libtoxcore.la \ 52 | $(LIBSODIUM_LIBS) \ 53 | $(NACL_OBJECTS) \ 54 | $(NACL_LIBS) \ 55 | $(WINSOCK2_LIBS) 56 | 57 | 58 | 59 | dns3_test_SOURCES = \ 60 | ../testing/dns3_test.c 61 | 62 | dns3_test_CFLAGS = \ 63 | $(LIBSODIUM_CFLAGS) \ 64 | $(NACL_CFLAGS) 65 | 66 | dns3_test_LDADD = \ 67 | $(LIBSODIUM_LDFLAGS) \ 68 | $(NACL_LDFLAGS) \ 69 | libtoxdns.la \ 70 | libtoxcore.la \ 71 | $(LIBSODIUM_LIBS) \ 72 | $(NACL_OBJECTS) \ 73 | $(NACL_LIBS) \ 74 | $(WINSOCK2_LIBS) 75 | 76 | if !WIN32 77 | 78 | noinst_PROGRAMS += tox_sync 79 | 80 | tox_sync_SOURCES = ../testing/tox_sync.c 81 | 82 | tox_sync_CFLAGS = $(LIBSODIUM_CFLAGS) \ 83 | $(NACL_CFLAGS) 84 | 85 | tox_sync_LDADD = $(LIBSODIUM_LDFLAGS) \ 86 | $(NACL_LDFLAGS) \ 87 | libtoxcore.la \ 88 | $(LIBSODIUM_LIBS) \ 89 | $(NACL_OBJECTS) \ 90 | $(NACL_LIBS) 91 | 92 | 93 | noinst_PROGRAMS += tox_shell 94 | 95 | tox_shell_SOURCES = ../testing/tox_shell.c 96 | 97 | tox_shell_CFLAGS = $(LIBSODIUM_CFLAGS) \ 98 | $(NACL_CFLAGS) 99 | 100 | tox_shell_LDADD = $(LIBSODIUM_LDFLAGS) \ 101 | $(NACL_LDFLAGS) \ 102 | libtoxcore.la \ 103 | $(LIBSODIUM_LIBS) \ 104 | $(NACL_OBJECTS) \ 105 | $(NACL_LIBS) \ 106 | -lutil 107 | 108 | 109 | noinst_PROGRAMS += irc_syncbot 110 | 111 | irc_syncbot_SOURCES = ../testing/irc_syncbot.c 112 | 113 | irc_syncbot_CFLAGS = $(LIBSODIUM_CFLAGS) \ 114 | $(NACL_CFLAGS) 115 | 116 | irc_syncbot_LDADD = $(LIBSODIUM_LDFLAGS) \ 117 | $(NACL_LDFLAGS) \ 118 | libtoxcore.la \ 119 | $(LIBSODIUM_LIBS) \ 120 | $(NACL_OBJECTS) \ 121 | $(NACL_LIBS) 122 | endif 123 | 124 | EXTRA_DIST += $(top_srcdir)/testing/misc_tools.c 125 | 126 | endif 127 | -------------------------------------------------------------------------------- /testing/dns3_test.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "../toxdns/toxdns.h" 4 | #include "../toxcore/tox.h" 5 | #include "../toxcore/network.h" 6 | #include "misc_tools.c" 7 | 8 | #if defined(_WIN32) || defined(__WIN32__) || defined (WIN32) 9 | 10 | #define c_sleep(x) Sleep(1*x) 11 | 12 | #else 13 | #define c_sleep(x) usleep(1000*x) 14 | 15 | #endif 16 | 17 | uint32_t create_packet(uint8_t *packet, uint8_t *string, uint8_t str_len, uint8_t id) 18 | { 19 | memset(packet, 0, str_len + 13 + 16); 20 | packet[0] = id; 21 | packet[1] = rand(); 22 | packet[5] = 1; 23 | packet[11] = 1; 24 | packet[12] = '.'; 25 | memcpy(packet + 13, string, str_len); 26 | uint32_t i, c = 0; 27 | 28 | for (i = str_len + 12; i != 11; --i) { 29 | if (packet[i] == '.') { 30 | packet[i] = c; 31 | c = 0; 32 | } else { 33 | ++c; 34 | } 35 | } 36 | 37 | packet[str_len + 13 + 2] = 16; 38 | packet[str_len + 13 + 4] = 1; 39 | packet[str_len + 13 + 7] = 0x29; 40 | packet[str_len + 13 + 8] = 16; 41 | packet[str_len + 13 + 12] = 0x80; 42 | return str_len + 13 + 16; 43 | } 44 | 45 | int main(int argc, char *argv[]) 46 | { 47 | if (argc < 4) { 48 | printf("Usage: %s domain domain_public_key queried_username\nEX: %s utox.org D3154F65D28A5B41A05D4AC7E4B39C6B1C233CC857FB365C56E8392737462A12 username\n", 49 | argv[0], argv[0]); 50 | exit(0); 51 | } 52 | 53 | IP ip = {0}; 54 | ip.family = AF_INET; 55 | sock_t sock = socket(ip.family, SOCK_DGRAM, IPPROTO_UDP); 56 | 57 | if (!sock_valid(sock)) 58 | return -1; 59 | 60 | if (!addr_resolve_or_parse_ip(argv[1], &ip, 0)) 61 | return -1; 62 | 63 | struct sockaddr_in target; 64 | size_t addrsize = sizeof(struct sockaddr_in); 65 | target.sin_family = AF_INET; 66 | target.sin_addr = ip.ip4.in_addr; 67 | target.sin_port = htons(53); 68 | 69 | uint8_t string[1024] = {0}; 70 | void *d = tox_dns3_new(hex_string_to_bin(argv[2])); 71 | unsigned int i; 72 | uint32_t request_id; 73 | /* 74 | for (i = 0; i < 255; ++i) { 75 | tox_generate_dns3_string(d, string, sizeof(string), &request_id, string, i); 76 | printf("%s\n", string); 77 | }*/ 78 | int len = tox_generate_dns3_string(d, string + 1, sizeof(string) - 1, &request_id, (uint8_t *)argv[3], strlen(argv[3])); 79 | 80 | if (len == -1) 81 | return -1; 82 | 83 | string[0] = '_'; 84 | memcpy(string + len + 1, "._tox.", sizeof("._tox.")); 85 | memcpy((char *)(string + len + 1 + sizeof("._tox.") - 1), argv[1], strlen(argv[1])); 86 | uint8_t packet[512]; 87 | uint8_t id = rand(); 88 | uint32_t p_len = create_packet(packet, string, strlen((char *)string), id); 89 | 90 | if (sendto(sock, (char *) packet, p_len, 0, (struct sockaddr *)&target, addrsize) != p_len) 91 | return -1; 92 | 93 | uint8_t buffer[512] = {}; 94 | int r_len = recv(sock, buffer, sizeof(buffer), 0); 95 | 96 | if (r_len < (int)p_len) 97 | return -1; 98 | 99 | for (i = r_len - 1; i != 0 && buffer[i] != '='; --i); 100 | 101 | uint8_t tox_id[TOX_ADDRESS_SIZE]; 102 | 103 | if (tox_decrypt_dns3_TXT(d, tox_id, buffer + i + 1, r_len - (i + 1), request_id) != 0) 104 | return -1; 105 | 106 | printf("The Tox id for username %s is:\n", argv[3]); 107 | 108 | //unsigned int i; 109 | for (i = 0; i < TOX_ADDRESS_SIZE; ++i) { 110 | printf("%02hhX", tox_id[i]); 111 | } 112 | 113 | printf("\n"); 114 | return 0; 115 | } 116 | -------------------------------------------------------------------------------- /testing/misc_tools.c: -------------------------------------------------------------------------------- 1 | /* misc_tools.c 2 | * 3 | * Miscellaneous functions and data structures for doing random things. 4 | * 5 | * Copyright (C) 2013 Tox project All Rights Reserved. 6 | * 7 | * This file is part of Tox. 8 | * 9 | * Tox is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * Tox is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with Tox. If not, see . 21 | * 22 | */ 23 | 24 | #ifdef HAVE_CONFIG_H 25 | #include "config.h" 26 | #endif 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #ifdef DEBUG 34 | #include 35 | #endif // DEBUG 36 | 37 | // You are responsible for freeing the return value! 38 | uint8_t *hex_string_to_bin(char *hex_string) 39 | { 40 | // byte is represented by exactly 2 hex digits, so lenth of binary string 41 | // is half of that of the hex one. only hex string with even length 42 | // valid. the more proper implementation would be to check if strlen(hex_string) 43 | // is odd and return error code if it is. we assume strlen is even. if it's not 44 | // then the last byte just won't be written in 'ret'. 45 | size_t i, len = strlen(hex_string) / 2; 46 | uint8_t *ret = malloc(len); 47 | char *pos = hex_string; 48 | 49 | for (i = 0; i < len; ++i, pos += 2) 50 | sscanf(pos, "%2hhx", &ret[i]); 51 | 52 | return ret; 53 | } 54 | 55 | int cmdline_parsefor_ipv46(int argc, char **argv, uint8_t *ipv6enabled) 56 | { 57 | int argvoffset = 0, argi; 58 | 59 | for (argi = 1; argi < argc; argi++) 60 | if (!strncasecmp(argv[argi], "--ipv", 5)) { 61 | if (argv[argi][5] && !argv[argi][6]) { 62 | char c = argv[argi][5]; 63 | 64 | if (c == '4') 65 | *ipv6enabled = 0; 66 | else if (c == '6') 67 | *ipv6enabled = 1; 68 | else { 69 | printf("Invalid argument: %s. Try --ipv4 or --ipv6!\n", argv[argi]); 70 | return -1; 71 | } 72 | } else { 73 | printf("Invalid argument: %s. Try --ipv4 or --ipv6!\n", argv[argi]); 74 | return -1; 75 | } 76 | 77 | if (argvoffset != argi - 1) { 78 | printf("Argument must come first: %s.\n", argv[argi]); 79 | return -1; 80 | } 81 | 82 | argvoffset++; 83 | } 84 | 85 | return argvoffset; 86 | }; 87 | -------------------------------------------------------------------------------- /testing/nTox.h: -------------------------------------------------------------------------------- 1 | /* nTox.h 2 | * 3 | *Textual frontend for Tox. 4 | * 5 | * Copyright (C) 2013 Tox project All Rights Reserved. 6 | * 7 | * This file is part of Tox. 8 | * 9 | * Tox is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * Tox is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with Tox. If not, see . 21 | * 22 | */ 23 | 24 | #ifndef NTOX_H 25 | #define NTOX_H 26 | 27 | /* 28 | * module actually exports nothing for the outside 29 | */ 30 | 31 | #include 32 | #include 33 | 34 | #include "../toxcore/tox.h" 35 | 36 | #define STRING_LENGTH 256 37 | #define HISTORY 50 38 | 39 | void new_lines(char *line); 40 | void do_refresh(); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /testing/tox_shell.c: -------------------------------------------------------------------------------- 1 | /* Tox Shell 2 | * 3 | * Proof of concept ssh like server software using tox. 4 | * 5 | * Command line arguments are the ip, port and public_key of a node (for bootstrapping). 6 | * 7 | * EX: ./test 127.0.0.1 33445 CDCFD319CE3460824B33BE58FD86B8941C9585181D8FBD7C79C5721D7C2E9F7C 8 | * 9 | * 10 | * Copyright (C) 2014 Tox project All Rights Reserved. 11 | * 12 | * This file is part of Tox. 13 | * 14 | * Tox is free software: you can redistribute it and/or modify 15 | * it under the terms of the GNU General Public License as published by 16 | * the Free Software Foundation, either version 3 of the License, or 17 | * (at your option) any later version. 18 | * 19 | * Tox is distributed in the hope that it will be useful, 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | * GNU General Public License for more details. 23 | * 24 | * You should have received a copy of the GNU General Public License 25 | * along with Tox. If not, see . 26 | * 27 | */ 28 | 29 | #ifdef HAVE_CONFIG_H 30 | #include "config.h" 31 | #endif 32 | 33 | #include "../toxcore/tox.h" 34 | #include "misc_tools.c" 35 | 36 | #if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) 37 | #include 38 | #elif defined(__FreeBSD__) || defined(__DragonFly__) 39 | #include 40 | #else 41 | #include 42 | #endif 43 | #include 44 | #include 45 | 46 | #define c_sleep(x) usleep(1000*x) 47 | 48 | void print_online(Tox *tox, uint32_t friendnumber, TOX_CONNECTION status, void *userdata) 49 | { 50 | if (status) 51 | printf("\nOther went online.\n"); 52 | else 53 | printf("\nOther went offline.\n"); 54 | } 55 | 56 | void print_message(Tox *tox, uint32_t friendnumber, TOX_MESSAGE_TYPE type, const uint8_t *string, size_t length, 57 | void *userdata) 58 | { 59 | int master = *((int *)userdata); 60 | write(master, string, length); 61 | write(master, "\n", 1); 62 | } 63 | 64 | int main(int argc, char *argv[]) 65 | { 66 | uint8_t ipv6enabled = 1; /* x */ 67 | int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled); 68 | 69 | if (argvoffset < 0) 70 | exit(1); 71 | 72 | /* with optional --ipvx, now it can be 1-4 arguments... */ 73 | if ((argc != argvoffset + 2) && (argc != argvoffset + 4)) { 74 | printf("Usage: %s [--ipv4|--ipv6] ip port public_key (of the DHT bootstrap node)\n", argv[0]); 75 | exit(0); 76 | } 77 | 78 | int *master = malloc(sizeof(int)); 79 | int ret = forkpty(master, NULL, NULL, NULL); 80 | 81 | if (ret == -1) { 82 | printf("fork failed\n"); 83 | return 1; 84 | } 85 | 86 | if (ret == 0) { 87 | execl("/bin/sh", "sh", NULL); 88 | return 0; 89 | } 90 | 91 | int flags = fcntl(*master, F_GETFL, 0); 92 | int r = fcntl(*master, F_SETFL, flags | O_NONBLOCK); 93 | 94 | if (r < 0) { 95 | printf("error setting flags\n"); 96 | } 97 | 98 | Tox *tox = tox_new(0, 0); 99 | tox_callback_friend_connection_status(tox, print_online, NULL); 100 | tox_callback_friend_message(tox, print_message, master); 101 | 102 | 103 | uint16_t port = atoi(argv[argvoffset + 2]); 104 | unsigned char *binary_string = hex_string_to_bin(argv[argvoffset + 3]); 105 | int res = tox_bootstrap(tox, argv[argvoffset + 1], port, binary_string, 0); 106 | free(binary_string); 107 | 108 | if (!res) { 109 | printf("Failed to convert \"%s\" into an IP address. Exiting...\n", argv[argvoffset + 1]); 110 | exit(1); 111 | } 112 | 113 | uint8_t address[TOX_ADDRESS_SIZE]; 114 | tox_self_get_address(tox, address); 115 | uint32_t i; 116 | 117 | for (i = 0; i < TOX_ADDRESS_SIZE; i++) { 118 | printf("%02X", address[i]); 119 | } 120 | 121 | char temp_id[128]; 122 | printf("\nEnter the address of the other id you want to sync with (38 bytes HEX format):\n"); 123 | 124 | if (scanf("%s", temp_id) != 1) { 125 | return 1; 126 | } 127 | 128 | uint8_t *bin_id = hex_string_to_bin(temp_id); 129 | uint32_t num = tox_friend_add(tox, bin_id, (uint8_t *)"Install Gentoo", sizeof("Install Gentoo"), 0); 130 | free(bin_id); 131 | 132 | if (num == UINT32_MAX) { 133 | printf("\nSomething went wrong when adding friend.\n"); 134 | return 1; 135 | } 136 | 137 | uint8_t notconnected = 1; 138 | 139 | while (1) { 140 | if (tox_self_get_connection_status(tox) && notconnected) { 141 | printf("\nDHT connected.\n"); 142 | notconnected = 0; 143 | } 144 | 145 | while (tox_friend_get_connection_status(tox, num, 0)) { 146 | uint8_t buf[TOX_MAX_MESSAGE_LENGTH]; 147 | ret = read(*master, buf, sizeof(buf)); 148 | 149 | if (ret <= 0) 150 | break; 151 | 152 | tox_friend_send_message(tox, num, TOX_MESSAGE_TYPE_NORMAL, buf, ret, 0); 153 | } 154 | 155 | tox_iterate(tox); 156 | c_sleep(1); 157 | } 158 | 159 | return 0; 160 | } 161 | -------------------------------------------------------------------------------- /tox.spec.in: -------------------------------------------------------------------------------- 1 | Name: @PACKAGE_NAME@ 2 | Version: @VERSION@ 3 | Release: 1%{?dist} 4 | Summary: All-in-one secure communication platform 5 | 6 | License: GPLv3 7 | URL: https://github.com/irungentoo/toxcore 8 | Source0: https://github.com/irungentoo/toxcore/releases/tox-%{version}.tar.gz 9 | 10 | BuildRequires: autoconf automake libtool libvpx-devel opus-devel 11 | BuildRequires: libsodium-devel libconfig-devel 12 | 13 | %description 14 | With the rise of governmental monitoring programs, Tox, a FOSS initiative, aims to be an easy to use, all-in-one communication platform that ensures their users full privacy and secure message delivery. 15 | 16 | %package devel 17 | Summary: Development files for @PACKAGE_NAME@ 18 | Requires: %{name} = %{version}-%{release} 19 | 20 | %description devel 21 | Development package for @PACKAGE_NAME@ 22 | 23 | %prep 24 | %setup -q 25 | 26 | 27 | %build 28 | %configure \ 29 | --enable-shared \ 30 | --disable-static \ 31 | --enable-av \ 32 | --disable-ntox \ 33 | --disable-daemon \ 34 | --disable-testing 35 | 36 | make %{?_smp_mflags} 37 | 38 | 39 | %install 40 | %make_install 41 | 42 | # remove la files 43 | find %{buildroot} -name '*.la' -delete -print 44 | 45 | # not handling DHT_bootstrap yet 46 | rm -f %{buildroot}%{_bindir}/DHT_bootstrap 47 | 48 | %post 49 | /sbin/ldconfig 50 | 51 | %postun 52 | /sbin/ldconfig 53 | 54 | %files 55 | %defattr(-,root,root) 56 | %doc COPYING README.md 57 | %{_libdir}/libtox*.so.* 58 | 59 | %files devel 60 | %defattr(-, root, root) 61 | %{_includedir}/tox/ 62 | %{_libdir}/libtox*.so 63 | %{_libdir}/pkgconfig/libtox*.pc 64 | 65 | %changelog 66 | * Tue Mar 3 2015 Sergey 'Jin' Bostandzhyan - 0.0.0-1 67 | - initial package 68 | -------------------------------------------------------------------------------- /toxav/Makefile.inc: -------------------------------------------------------------------------------- 1 | if BUILD_AV 2 | 3 | lib_LTLIBRARIES += libtoxav.la 4 | libtoxav_la_include_HEADERS = ../toxav/toxav.h 5 | libtoxav_la_includedir = $(includedir)/tox 6 | 7 | libtoxav_la_SOURCES = ../toxav/rtp.h \ 8 | ../toxav/rtp.c \ 9 | ../toxav/msi.h \ 10 | ../toxav/msi.c \ 11 | ../toxav/group.h \ 12 | ../toxav/group.c \ 13 | ../toxav/audio.h \ 14 | ../toxav/audio.c \ 15 | ../toxav/video.h \ 16 | ../toxav/video.c \ 17 | ../toxav/bwcontroller.h \ 18 | ../toxav/bwcontroller.c \ 19 | ../toxav/toxav.h \ 20 | ../toxav/toxav.c \ 21 | ../toxav/toxav_old.c 22 | 23 | libtoxav_la_CFLAGS = -I../toxcore \ 24 | -I../toxav \ 25 | $(LIBSODIUM_CFLAGS) \ 26 | $(NACL_CFLAGS) \ 27 | $(AV_CFLAGS) \ 28 | $(PTHREAD_CFLAGS) 29 | 30 | libtoxav_la_LDFLAGS = $(TOXAV_LT_LDFLAGS) \ 31 | $(LIBSODIUM_LDFLAGS) \ 32 | $(NACL_LDFLAGS) \ 33 | $(EXTRA_LT_LDFLAGS) \ 34 | $(WINSOCK2_LIBS) 35 | 36 | libtoxav_la_LIBADD = libtoxcore.la \ 37 | $(LIBSODIUM_LIBS) \ 38 | $(NACL_LIBS) \ 39 | $(PTHREAD_LIBS) \ 40 | $(AV_LIBS) 41 | 42 | endif -------------------------------------------------------------------------------- /toxav/audio.h: -------------------------------------------------------------------------------- 1 | /** audio.h 2 | * 3 | * Copyright (C) 2013-2015 Tox project All Rights Reserved. 4 | * 5 | * This file is part of Tox. 6 | * 7 | * Tox is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * Tox is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with Tox. If not, see . 19 | * 20 | */ 21 | 22 | #ifndef AUDIO_H 23 | #define AUDIO_H 24 | 25 | #include 26 | #include 27 | 28 | #include "toxav.h" 29 | 30 | #include "../toxcore/util.h" 31 | 32 | struct RTPMessage; 33 | 34 | typedef struct ACSession_s { 35 | /* encoding */ 36 | OpusEncoder *encoder; 37 | int32_t le_sample_rate; /* Last encoder sample rate */ 38 | int32_t le_channel_count; /* Last encoder channel count */ 39 | int32_t le_bit_rate; /* Last encoder bit rate */ 40 | 41 | /* decoding */ 42 | OpusDecoder *decoder; 43 | int32_t lp_channel_count; /* Last packet channel count */ 44 | int32_t lp_sampling_rate; /* Last packet sample rate */ 45 | int32_t lp_frame_duration; /* Last packet frame duration */ 46 | int32_t ld_sample_rate; /* Last decoder sample rate */ 47 | int32_t ld_channel_count; /* Last decoder channel count */ 48 | uint64_t ldrts; /* Last decoder reconfiguration time stamp */ 49 | void *j_buf; 50 | 51 | pthread_mutex_t queue_mutex[1]; 52 | 53 | ToxAV *av; 54 | uint32_t friend_number; 55 | PAIR(toxav_audio_receive_frame_cb *, void *) acb; /* Audio frame receive callback */ 56 | } ACSession; 57 | 58 | ACSession *ac_new(ToxAV *av, uint32_t friend_number, toxav_audio_receive_frame_cb *cb, void *cb_data); 59 | void ac_kill(ACSession *ac); 60 | void ac_iterate(ACSession *ac); 61 | int ac_queue_message(void *acp, struct RTPMessage *msg); 62 | int ac_reconfigure_encoder(ACSession *ac, int32_t bit_rate, int32_t sampling_rate, uint8_t channels); 63 | 64 | #endif /* AUDIO_H */ 65 | -------------------------------------------------------------------------------- /toxav/bwcontroller.h: -------------------------------------------------------------------------------- 1 | /** bwcontroller.h 2 | * 3 | * Copyright (C) 2013-2015 Tox project All Rights Reserved. 4 | * 5 | * This file is part of Tox. 6 | * 7 | * Tox is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * Tox is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with Tox. If not, see . 19 | * 20 | */ 21 | 22 | #ifndef BWCONROLER_H 23 | #define BWCONROLER_H 24 | #include "../toxcore/Messenger.h" 25 | 26 | typedef struct BWController_s BWController; 27 | 28 | BWController *bwc_new(Messenger *m, uint32_t friendnumber, 29 | void (*mcb) (BWController *, uint32_t, float, void *), 30 | void *udata); 31 | void bwc_kill(BWController *bwc); 32 | 33 | void bwc_feed_avg(BWController *bwc, uint32_t bytes); 34 | void bwc_add_lost(BWController *bwc, uint32_t bytes); 35 | void bwc_add_recv(BWController *bwc, uint32_t bytes); 36 | 37 | #endif /* BWCONROLER_H */ 38 | -------------------------------------------------------------------------------- /toxav/group.h: -------------------------------------------------------------------------------- 1 | /** groupav.c 2 | * 3 | * Copyright (C) 2014 Tox project All Rights Reserved. 4 | * 5 | * This file is part of Tox. 6 | * 7 | * Tox is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * Tox is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with Tox. If not, see . 19 | */ 20 | 21 | /* Audio encoding/decoding */ 22 | #include 23 | 24 | #include "../toxcore/group.h" 25 | 26 | #define GROUP_AUDIO_PACKET_ID 192 27 | 28 | /* Create a new toxav group. 29 | * 30 | * return group number on success. 31 | * return -1 on failure. 32 | */ 33 | int add_av_groupchat(Group_Chats *g_c, void (*audio_callback)(Messenger *, int, int, const int16_t *, unsigned int, 34 | uint8_t, unsigned int, void *), void *userdata); 35 | 36 | /* Join a AV group (you need to have been invited first.) 37 | * 38 | * returns group number on success 39 | * returns -1 on failure. 40 | */ 41 | int join_av_groupchat(Group_Chats *g_c, int32_t friendnumber, const uint8_t *data, uint16_t length, 42 | void (*audio_callback)(Messenger *, int, int, const int16_t *, unsigned int, uint8_t, unsigned int, void *), 43 | void *userdata); 44 | 45 | 46 | /* Send audio to the group chat. 47 | * 48 | * return 0 on success. 49 | * return -1 on failure. 50 | */ 51 | int group_send_audio(Group_Chats *g_c, int groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels, 52 | unsigned int sample_rate); 53 | 54 | -------------------------------------------------------------------------------- /toxav/msi.h: -------------------------------------------------------------------------------- 1 | /** msi.h 2 | * 3 | * Copyright (C) 2013-2015 Tox project All Rights Reserved. 4 | * 5 | * This file is part of Tox. 6 | * 7 | * Tox is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * Tox is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with Tox. If not, see . 19 | * 20 | */ 21 | 22 | #ifndef MSI_H 23 | #define MSI_H 24 | 25 | #include 26 | #include 27 | 28 | #include "audio.h" 29 | #include "video.h" 30 | #include "../toxcore/Messenger.h" 31 | 32 | /** 33 | * Error codes. 34 | */ 35 | typedef enum { 36 | msi_ENone, 37 | msi_EInvalidMessage, 38 | msi_EInvalidParam, 39 | msi_EInvalidState, 40 | msi_EStrayMessage, 41 | msi_ESystem, 42 | msi_EHandle, 43 | msi_EUndisclosed, /* NOTE: must be last enum otherwise parsing will not work */ 44 | } MSIError; 45 | 46 | /** 47 | * Supported capabilities 48 | */ 49 | typedef enum { 50 | msi_CapSAudio = 4, /* sending audio */ 51 | msi_CapSVideo = 8, /* sending video */ 52 | msi_CapRAudio = 16, /* receiving audio */ 53 | msi_CapRVideo = 32, /* receiving video */ 54 | } MSICapabilities; 55 | 56 | 57 | /** 58 | * Call state identifiers. 59 | */ 60 | typedef enum { 61 | msi_CallInactive, /* Default */ 62 | msi_CallActive, 63 | msi_CallRequesting, /* when sending call invite */ 64 | msi_CallRequested, /* when getting call invite */ 65 | } MSICallState; 66 | 67 | /** 68 | * Callbacks ids that handle the states 69 | */ 70 | typedef enum { 71 | msi_OnInvite, /* Incoming call */ 72 | msi_OnStart, /* Call (RTP transmission) started */ 73 | msi_OnEnd, /* Call that was active ended */ 74 | msi_OnError, /* On protocol error */ 75 | msi_OnPeerTimeout, /* Peer timed out; stop the call */ 76 | msi_OnCapabilities, /* Peer requested capabilities change */ 77 | } MSICallbackID; 78 | 79 | /** 80 | * The call struct. Please do not modify outside msi.c 81 | */ 82 | typedef struct MSICall_s { 83 | struct MSISession_s *session; /* Session pointer */ 84 | 85 | MSICallState state; 86 | uint8_t peer_capabilities; /* Peer capabilities */ 87 | uint8_t self_capabilities; /* Self capabilities */ 88 | uint16_t peer_vfpsz; /* Video frame piece size */ 89 | uint32_t friend_number; /* Index of this call in MSISession */ 90 | MSIError error; /* Last error */ 91 | 92 | void *av_call; /* Pointer to av call handler */ 93 | 94 | struct MSICall_s *next; 95 | struct MSICall_s *prev; 96 | } MSICall; 97 | 98 | 99 | /** 100 | * Expected return on success is 0, if any other number is 101 | * returned the call is considered errored and will be handled 102 | * as such which means it will be terminated without any notice. 103 | */ 104 | typedef int msi_action_cb (void *av, MSICall *call); 105 | 106 | /** 107 | * Control session struct. Please do not modify outside msi.c 108 | */ 109 | typedef struct MSISession_s { 110 | /* Call handlers */ 111 | MSICall **calls; 112 | uint32_t calls_tail; 113 | uint32_t calls_head; 114 | 115 | void *av; 116 | Messenger *messenger; 117 | 118 | pthread_mutex_t mutex[1]; 119 | msi_action_cb *callbacks[7]; 120 | } MSISession; 121 | 122 | /** 123 | * Start the control session. 124 | */ 125 | MSISession *msi_new(Messenger *m); 126 | /** 127 | * Terminate control session. NOTE: all calls will be freed 128 | */ 129 | int msi_kill(MSISession *session); 130 | /** 131 | * Callback setter. 132 | */ 133 | void msi_register_callback(MSISession *session, msi_action_cb *callback, MSICallbackID id); 134 | /** 135 | * Send invite request to friend_number. 136 | */ 137 | int msi_invite(MSISession *session, MSICall **call, uint32_t friend_number, uint8_t capabilities); 138 | /** 139 | * Hangup call. NOTE: 'call' will be freed 140 | */ 141 | int msi_hangup(MSICall *call); 142 | /** 143 | * Answer call request. 144 | */ 145 | int msi_answer(MSICall *call, uint8_t capabilities); 146 | /** 147 | * Change capabilities of the call. 148 | */ 149 | int msi_change_capabilities(MSICall *call, uint8_t capabilities); 150 | 151 | #endif /* MSI_H */ 152 | -------------------------------------------------------------------------------- /toxav/rtp.h: -------------------------------------------------------------------------------- 1 | /** rtp.h 2 | * 3 | * Copyright (C) 2013-2015 Tox project All Rights Reserved. 4 | * 5 | * This file is part of Tox. 6 | * 7 | * Tox is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * Tox is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with Tox. If not, see . 19 | * 20 | */ 21 | 22 | #ifndef RTP_H 23 | #define RTP_H 24 | 25 | #include "bwcontroller.h" 26 | #include "../toxcore/Messenger.h" 27 | #include "stdbool.h" 28 | 29 | /** 30 | * Payload type identifier. Also used as rtp callback prefix. 31 | */ 32 | enum { 33 | rtp_TypeAudio = 192, 34 | rtp_TypeVideo, 35 | }; 36 | 37 | struct RTPHeader { 38 | /* Standard RTP header */ 39 | #ifndef WORDS_BIGENDIAN 40 | uint16_t cc: 4; /* Contributing sources count */ 41 | uint16_t xe: 1; /* Extra header */ 42 | uint16_t pe: 1; /* Padding */ 43 | uint16_t ve: 2; /* Version */ 44 | 45 | uint16_t pt: 7; /* Payload type */ 46 | uint16_t ma: 1; /* Marker */ 47 | #else 48 | uint16_t ve: 2; /* Version */ 49 | uint16_t pe: 1; /* Padding */ 50 | uint16_t xe: 1; /* Extra header */ 51 | uint16_t cc: 4; /* Contributing sources count */ 52 | 53 | uint16_t ma: 1; /* Marker */ 54 | uint16_t pt: 7; /* Payload type */ 55 | #endif 56 | 57 | uint16_t sequnum; 58 | uint32_t timestamp; 59 | uint32_t ssrc; 60 | uint32_t csrc[16]; 61 | 62 | /* Non-standard TOX-specific fields */ 63 | uint16_t cpart;/* Data offset of the current part */ 64 | uint16_t tlen; /* Total message lenght */ 65 | } __attribute__ ((packed)); 66 | 67 | /* Check alignment */ 68 | typedef char __fail_if_misaligned_1 [ sizeof(struct RTPHeader) == 80 ? 1 : -1 ]; 69 | 70 | struct RTPMessage { 71 | uint16_t len; 72 | 73 | struct RTPHeader header; 74 | uint8_t data[]; 75 | } __attribute__ ((packed)); 76 | 77 | /* Check alignment */ 78 | typedef char __fail_if_misaligned_2 [ sizeof(struct RTPMessage) == 82 ? 1 : -1 ]; 79 | 80 | /** 81 | * RTP control session. 82 | */ 83 | typedef struct { 84 | uint8_t payload_type; 85 | uint16_t sequnum; /* Sending sequence number */ 86 | uint16_t rsequnum; /* Receiving sequence number */ 87 | uint32_t rtimestamp; 88 | uint32_t ssrc; 89 | 90 | struct RTPMessage *mp; /* Expected parted message */ 91 | 92 | Messenger *m; 93 | uint32_t friend_number; 94 | 95 | BWController *bwc; 96 | void *cs; 97 | int (*mcb) (void *, struct RTPMessage *msg); 98 | } RTPSession; 99 | 100 | 101 | RTPSession *rtp_new (int payload_type, Messenger *m, uint32_t friend_num, 102 | BWController *bwc, void *cs, 103 | int (*mcb) (void *, struct RTPMessage *)); 104 | void rtp_kill (RTPSession *session); 105 | int rtp_allow_receiving (RTPSession *session); 106 | int rtp_stop_receiving (RTPSession *session); 107 | int rtp_send_data (RTPSession *session, const uint8_t *data, uint16_t length); 108 | 109 | #endif /* RTP_H */ 110 | -------------------------------------------------------------------------------- /toxav/toxav_old.c: -------------------------------------------------------------------------------- 1 | /* toxav_old.h 2 | * 3 | * Copyright (C) 2013-2015 Tox project All Rights Reserved. 4 | * 5 | * This file is part of Tox. 6 | * 7 | * Tox is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * Tox is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with Tox. If not, see . 19 | * 20 | */ 21 | /** 22 | * This file contains the group chats code for the backwards compatibility. 23 | */ 24 | 25 | #include "toxav.h" 26 | #include "group.h" 27 | 28 | /* Create a new toxav group. 29 | * 30 | * return group number on success. 31 | * return -1 on failure. 32 | * 33 | * Audio data callback format: 34 | * audio_callback(Tox *tox, int groupnumber, int peernumber, const int16_t *pcm, unsigned int samples, uint8_t channels, unsigned int sample_rate, void *userdata) 35 | * 36 | * Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)). 37 | */ 38 | int toxav_add_av_groupchat(struct Tox *tox, void (*audio_callback)(void *, int, int, const int16_t *, unsigned int, 39 | uint8_t, unsigned int, void *), void *userdata) 40 | { 41 | Messenger *m = (Messenger *)tox; 42 | return add_av_groupchat(m->group_chat_object, audio_callback, userdata); 43 | } 44 | 45 | /* Join a AV group (you need to have been invited first.) 46 | * 47 | * returns group number on success 48 | * returns -1 on failure. 49 | * 50 | * Audio data callback format (same as the one for toxav_add_av_groupchat()): 51 | * audio_callback(Tox *tox, int groupnumber, int peernumber, const int16_t *pcm, unsigned int samples, uint8_t channels, unsigned int sample_rate, void *userdata) 52 | * 53 | * Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)). 54 | */ 55 | int toxav_join_av_groupchat(struct Tox *tox, int32_t friendnumber, const uint8_t *data, uint16_t length, 56 | void (*audio_callback)(void *, int, int, const int16_t *, unsigned int, uint8_t, unsigned int, void *), 57 | void *userdata) 58 | { 59 | Messenger *m = (Messenger *)tox; 60 | return join_av_groupchat(m->group_chat_object, friendnumber, data, length, audio_callback, userdata); 61 | } 62 | 63 | /* Send audio to the group chat. 64 | * 65 | * return 0 on success. 66 | * return -1 on failure. 67 | * 68 | * Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)). 69 | * 70 | * Valid number of samples are ((sample rate) * (audio length (Valid ones are: 2.5, 5, 10, 20, 40 or 60 ms)) / 1000) 71 | * Valid number of channels are 1 or 2. 72 | * Valid sample rates are 8000, 12000, 16000, 24000, or 48000. 73 | * 74 | * Recommended values are: samples = 960, channels = 1, sample_rate = 48000 75 | */ 76 | int toxav_group_send_audio(struct Tox *tox, int groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels, 77 | unsigned int sample_rate) 78 | { 79 | Messenger *m = (Messenger *)tox; 80 | return group_send_audio(m->group_chat_object, groupnumber, pcm, samples, channels, sample_rate); 81 | } -------------------------------------------------------------------------------- /toxav/video.h: -------------------------------------------------------------------------------- 1 | /** video.h 2 | * 3 | * Copyright (C) 2013-2015 Tox project All Rights Reserved. 4 | * 5 | * This file is part of Tox. 6 | * 7 | * Tox is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * Tox is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with Tox. If not, see . 19 | * 20 | */ 21 | 22 | #ifndef VIDEO_H 23 | #define VIDEO_H 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #define VIDEO_CODEC_DECODER_INTERFACE (vpx_codec_vp8_dx()) 31 | #define VIDEO_CODEC_ENCODER_INTERFACE (vpx_codec_vp8_cx()) 32 | 33 | #include 34 | 35 | #include "toxav.h" 36 | 37 | #include "../toxcore/util.h" 38 | 39 | struct RTPMessage; 40 | 41 | typedef struct VCSession_s { 42 | /* encoding */ 43 | vpx_codec_ctx_t encoder[1]; 44 | uint32_t frame_counter; 45 | 46 | /* decoding */ 47 | vpx_codec_ctx_t decoder[1]; 48 | void *vbuf_raw; /* Un-decoded data */ 49 | 50 | uint64_t linfts; /* Last received frame time stamp */ 51 | uint32_t lcfd; /* Last calculated frame duration for incoming video payload */ 52 | 53 | ToxAV *av; 54 | uint32_t friend_number; 55 | 56 | PAIR(toxav_video_receive_frame_cb *, void *) vcb; /* Video frame receive callback */ 57 | 58 | pthread_mutex_t queue_mutex[1]; 59 | } VCSession; 60 | 61 | VCSession *vc_new(ToxAV *av, uint32_t friend_number, toxav_video_receive_frame_cb *cb, void *cb_data); 62 | void vc_kill(VCSession *vc); 63 | void vc_iterate(VCSession *vc); 64 | int vc_queue_message(void *vcp, struct RTPMessage *msg); 65 | int vc_reconfigure_encoder(VCSession *vc, uint32_t bit_rate, uint16_t width, uint16_t height); 66 | 67 | #endif /* VIDEO_H */ 68 | -------------------------------------------------------------------------------- /toxcore/LAN_discovery.h: -------------------------------------------------------------------------------- 1 | /* LAN_discovery.h 2 | * 3 | * LAN discovery implementation. 4 | * 5 | * Copyright (C) 2013 Tox project All Rights Reserved. 6 | * 7 | * This file is part of Tox. 8 | * 9 | * Tox is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * Tox is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with Tox. If not, see . 21 | * 22 | */ 23 | 24 | 25 | #ifndef LAN_DISCOVERY_H 26 | #define LAN_DISCOVERY_H 27 | 28 | 29 | #include "DHT.h" 30 | 31 | /* Interval in seconds between LAN discovery packet sending. */ 32 | #define LAN_DISCOVERY_INTERVAL 10 33 | 34 | /* Send a LAN discovery pcaket to the broadcast address with port port. */ 35 | int send_LANdiscovery(uint16_t port, DHT *dht); 36 | 37 | /* Sets up packet handlers. */ 38 | void LANdiscovery_init(DHT *dht); 39 | 40 | /* Clear packet handlers. */ 41 | void LANdiscovery_kill(DHT *dht); 42 | 43 | /* Is IP a local ip or not. */ 44 | _Bool Local_ip(IP ip); 45 | 46 | /* checks if a given IP isn't routable 47 | * 48 | * return 0 if ip is a LAN ip. 49 | * return -1 if it is not. 50 | */ 51 | int LAN_ip(IP ip); 52 | 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /toxcore/Makefile.inc: -------------------------------------------------------------------------------- 1 | lib_LTLIBRARIES += libtoxcore.la 2 | 3 | libtoxcore_la_include_HEADERS = \ 4 | ../toxcore/tox.h \ 5 | ../toxcore/tox_old.h 6 | 7 | libtoxcore_la_includedir = $(includedir)/tox 8 | 9 | libtoxcore_la_SOURCES = ../toxcore/DHT.h \ 10 | ../toxcore/DHT.c \ 11 | ../toxcore/network.h \ 12 | ../toxcore/network.c \ 13 | ../toxcore/crypto_core.h \ 14 | ../toxcore/crypto_core.c \ 15 | ../toxcore/ping_array.h \ 16 | ../toxcore/ping_array.c \ 17 | ../toxcore/net_crypto.h \ 18 | ../toxcore/net_crypto.c \ 19 | ../toxcore/friend_requests.h \ 20 | ../toxcore/friend_requests.c \ 21 | ../toxcore/LAN_discovery.h \ 22 | ../toxcore/LAN_discovery.c \ 23 | ../toxcore/friend_connection.h \ 24 | ../toxcore/friend_connection.c \ 25 | ../toxcore/Messenger.h \ 26 | ../toxcore/Messenger.c \ 27 | ../toxcore/ping.h \ 28 | ../toxcore/ping.c \ 29 | ../toxcore/tox.h \ 30 | ../toxcore/tox.c \ 31 | ../toxcore/util.h \ 32 | ../toxcore/util.c \ 33 | ../toxcore/group.h \ 34 | ../toxcore/group.c \ 35 | ../toxcore/assoc.h \ 36 | ../toxcore/assoc.c \ 37 | ../toxcore/onion.h \ 38 | ../toxcore/onion.c \ 39 | ../toxcore/logger.h \ 40 | ../toxcore/logger.c \ 41 | ../toxcore/onion_announce.h \ 42 | ../toxcore/onion_announce.c \ 43 | ../toxcore/onion_client.h \ 44 | ../toxcore/onion_client.c \ 45 | ../toxcore/TCP_client.h \ 46 | ../toxcore/TCP_client.c \ 47 | ../toxcore/TCP_server.h \ 48 | ../toxcore/TCP_server.c \ 49 | ../toxcore/TCP_connection.h \ 50 | ../toxcore/TCP_connection.c \ 51 | ../toxcore/list.c \ 52 | ../toxcore/list.h \ 53 | ../toxcore/misc_tools.h \ 54 | ../toxcore/tox_old_code.h 55 | 56 | libtoxcore_la_CFLAGS = -I$(top_srcdir) \ 57 | -I$(top_srcdir)/toxcore \ 58 | $(LIBSODIUM_CFLAGS) \ 59 | $(NACL_CFLAGS) \ 60 | $(PTHREAD_CFLAGS) 61 | 62 | libtoxcore_la_LDFLAGS = $(TOXCORE_LT_LDFLAGS) \ 63 | $(EXTRA_LT_LDFLAGS) \ 64 | $(LIBSODIUM_LDFLAGS) \ 65 | $(NACL_LDFLAGS) \ 66 | $(MATH_LDFLAGS) \ 67 | $(RT_LIBS) \ 68 | $(WINSOCK2_LIBS) 69 | 70 | libtoxcore_la_LIBADD = $(LIBSODIUM_LIBS) \ 71 | $(NACL_OBJECTS) \ 72 | $(NAC_LIBS) \ 73 | $(PTHREAD_LIBS) 74 | -------------------------------------------------------------------------------- /toxcore/assoc.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __ASSOC_H__ 3 | #define __ASSOC_H__ 4 | 5 | /* used by rendezvous */ 6 | #define ASSOC_AVAILABLE 7 | 8 | /* For the legalese parts, see tox.h. */ 9 | 10 | /* enumerated lists are superior to magic numbers */ 11 | enum NODE_STATUS { BAD, SEENB_HEARDG, SEENG, USED }; 12 | 13 | /* 14 | * Module to store currently unused ID <=> IP associations 15 | * for a potential future use 16 | */ 17 | 18 | typedef struct Assoc Assoc; 19 | 20 | /*****************************************************************************/ 21 | 22 | /* custom distance handler, if it's not ID-distance based 23 | * return values exactly like id_closest() */ 24 | typedef int (*Assoc_distance_relative_callback)(const Assoc *assoc, void *callback_data, const uint8_t *client_id, 25 | const uint8_t *client_id1, const uint8_t *client_id2); 26 | 27 | #define DISTANCE_INDEX_DISTANCE_BITS 44 28 | 29 | /* absolute distance: can be same for different client_id_check values 30 | * return value should have DISTANCE_INDEX_DISTANCE_BITS valid bits */ 31 | typedef uint64_t (*Assoc_distance_absolute_callback)(const Assoc *assoc, void *callback_data, 32 | const uint8_t *client_id_ref, const uint8_t *client_id_check); 33 | 34 | /*****************************************************************************/ 35 | 36 | /* Central entry point for new associations: add a new candidate to the cache 37 | * returns 1 if entry is stored, 2 if existing entry was updated, 0 else */ 38 | uint8_t Assoc_add_entry(Assoc *assoc, const uint8_t *id, const IPPTs *ippts_send, const IP_Port *ipp_recv, 39 | uint8_t used); 40 | 41 | /*****************************************************************************/ 42 | 43 | typedef enum AssocCloseEntriesFlags { 44 | ProtoIPv4 = 1, 45 | ProtoIPv6 = 2, 46 | LANOk = 4, 47 | } AssocCloseEntriesFlags; 48 | 49 | typedef struct Assoc_close_entries { 50 | void *custom_data; /* given to distance functions */ 51 | uint8_t *wanted_id; /* the target client_id */ 52 | uint8_t flags; /* additional flags */ 53 | 54 | Assoc_distance_relative_callback distance_relative_func; 55 | Assoc_distance_absolute_callback distance_absolute_func; 56 | 57 | uint8_t count_good; /* that many should be "good" w.r.t. timeout */ 58 | uint8_t count; /* allocated number of close_indices */ 59 | Client_data **result; 60 | } Assoc_close_entries; 61 | 62 | /* find up to close_count nodes to put into close_nodes_used of ID_Nodes 63 | * the distance functions can be NULL, then standard distance functions will be used 64 | * the caller is responsible for allocating close_indices of sufficient size 65 | * 66 | * returns 0 on error 67 | * returns the number of found nodes and the list of indices usable by Assoc_client() 68 | * the caller is assumed to be registered from Assoc_register_callback() 69 | * if they aren't, they should copy the Client_data and call Assoc_client_drop() 70 | */ 71 | uint8_t Assoc_get_close_entries(Assoc *assoc, Assoc_close_entries *close_entries); 72 | 73 | /*****************************************************************************/ 74 | 75 | /* create: default sizes (6, 5 => 320 entries) */ 76 | Assoc *new_Assoc_default(const uint8_t *public_id); 77 | 78 | /* create: customized sizes 79 | * total is (2^bits) * entries 80 | * bits should be between 2 and 15 (else it's trimmed) 81 | * entries will be reduced to the closest prime smaller or equal 82 | * 83 | * preferably bits should be large and entries small to ensure spread 84 | * in the search space (e. g. 5, 5 is preferable to 2, 41) */ 85 | Assoc *new_Assoc(size_t bits, size_t entries, const uint8_t *public_id); 86 | 87 | /* public_id changed (loaded), update which entry isn't stored */ 88 | void Assoc_self_client_id_changed(Assoc *assoc, const uint8_t *public_id); 89 | 90 | /* every 45s send out a getnodes() for a "random" bucket */ 91 | #define ASSOC_BUCKET_REFRESH 45 92 | 93 | /* refresh bucket's data from time to time 94 | * this must be called only from DHT */ 95 | void do_Assoc(Assoc *assoc, DHT *dht); 96 | 97 | /* destroy */ 98 | void kill_Assoc(Assoc *assoc); 99 | 100 | #ifdef TOX_LOGGER 101 | void Assoc_status(const Assoc *assoc); 102 | #endif /* TOX_LOGGER */ 103 | 104 | #endif /* !__ASSOC_H__ */ 105 | -------------------------------------------------------------------------------- /toxcore/friend_requests.c: -------------------------------------------------------------------------------- 1 | /* friend_requests.c 2 | * 3 | * Handle friend requests. 4 | * 5 | * Copyright (C) 2013 Tox project All Rights Reserved. 6 | * 7 | * This file is part of Tox. 8 | * 9 | * Tox is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * Tox is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with Tox. If not, see . 21 | * 22 | */ 23 | 24 | #ifdef HAVE_CONFIG_H 25 | #include "config.h" 26 | #endif 27 | 28 | #include "friend_requests.h" 29 | #include "util.h" 30 | 31 | 32 | /* Set and get the nospam variable used to prevent one type of friend request spam. */ 33 | void set_nospam(Friend_Requests *fr, uint32_t num) 34 | { 35 | fr->nospam = num; 36 | } 37 | 38 | uint32_t get_nospam(const Friend_Requests *fr) 39 | { 40 | return fr->nospam; 41 | } 42 | 43 | 44 | /* Set the function that will be executed when a friend request is received. */ 45 | void callback_friendrequest(Friend_Requests *fr, void (*function)(void *, const uint8_t *, const uint8_t *, size_t, 46 | void *), void *object, void *userdata) 47 | { 48 | fr->handle_friendrequest = function; 49 | fr->handle_friendrequest_isset = 1; 50 | fr->handle_friendrequest_object = object; 51 | fr->handle_friendrequest_userdata = userdata; 52 | } 53 | /* Set the function used to check if a friend request should be displayed to the user or not. */ 54 | void set_filter_function(Friend_Requests *fr, int (*function)(const uint8_t *, void *), void *userdata) 55 | { 56 | fr->filter_function = function; 57 | fr->filter_function_userdata = userdata; 58 | } 59 | 60 | /* Add to list of received friend requests. */ 61 | static void addto_receivedlist(Friend_Requests *fr, const uint8_t *real_pk) 62 | { 63 | if (fr->received_requests_index >= MAX_RECEIVED_STORED) 64 | fr->received_requests_index = 0; 65 | 66 | id_copy(fr->received_requests[fr->received_requests_index], real_pk); 67 | ++fr->received_requests_index; 68 | } 69 | 70 | /* Check if a friend request was already received. 71 | * 72 | * return 0 if it did not. 73 | * return 1 if it did. 74 | */ 75 | static int request_received(Friend_Requests *fr, const uint8_t *real_pk) 76 | { 77 | uint32_t i; 78 | 79 | for (i = 0; i < MAX_RECEIVED_STORED; ++i) 80 | if (id_equal(fr->received_requests[i], real_pk)) 81 | return 1; 82 | 83 | return 0; 84 | } 85 | 86 | /* Remove real pk from received_requests list. 87 | * 88 | * return 0 if it removed it successfully. 89 | * return -1 if it didn't find it. 90 | */ 91 | int remove_request_received(Friend_Requests *fr, const uint8_t *real_pk) 92 | { 93 | uint32_t i; 94 | 95 | for (i = 0; i < MAX_RECEIVED_STORED; ++i) { 96 | if (id_equal(fr->received_requests[i], real_pk)) { 97 | sodium_memzero(fr->received_requests[i], crypto_box_PUBLICKEYBYTES); 98 | return 0; 99 | } 100 | } 101 | 102 | return -1; 103 | } 104 | 105 | 106 | static int friendreq_handlepacket(void *object, const uint8_t *source_pubkey, const uint8_t *packet, uint16_t length) 107 | { 108 | Friend_Requests *fr = object; 109 | 110 | if (length <= 1 + sizeof(fr->nospam) || length > ONION_CLIENT_MAX_DATA_SIZE) 111 | return 1; 112 | 113 | ++packet; 114 | --length; 115 | 116 | if (fr->handle_friendrequest_isset == 0) 117 | return 1; 118 | 119 | if (request_received(fr, source_pubkey)) 120 | return 1; 121 | 122 | if (memcmp(packet, &fr->nospam, sizeof(fr->nospam)) != 0) 123 | return 1; 124 | 125 | if (fr->filter_function) 126 | if ((*fr->filter_function)(source_pubkey, fr->filter_function_userdata) != 0) 127 | return 1; 128 | 129 | addto_receivedlist(fr, source_pubkey); 130 | 131 | uint32_t message_len = length - sizeof(fr->nospam); 132 | uint8_t message[message_len + 1]; 133 | memcpy(message, packet + sizeof(fr->nospam), message_len); 134 | message[sizeof(message) - 1] = 0; /* Be sure the message is null terminated. */ 135 | 136 | (*fr->handle_friendrequest)(fr->handle_friendrequest_object, source_pubkey, message, message_len, 137 | fr->handle_friendrequest_userdata); 138 | return 0; 139 | } 140 | 141 | void friendreq_init(Friend_Requests *fr, Friend_Connections *fr_c) 142 | { 143 | set_friend_request_callback(fr_c, &friendreq_handlepacket, fr); 144 | } 145 | -------------------------------------------------------------------------------- /toxcore/friend_requests.h: -------------------------------------------------------------------------------- 1 | /* friend_requests.h 2 | * 3 | * Handle friend requests. 4 | * 5 | * Copyright (C) 2013 Tox project All Rights Reserved. 6 | * 7 | * This file is part of Tox. 8 | * 9 | * Tox is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * Tox is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with Tox. If not, see . 21 | * 22 | */ 23 | 24 | #ifndef FRIEND_REQUESTS_H 25 | #define FRIEND_REQUESTS_H 26 | 27 | #include "friend_connection.h" 28 | 29 | #define MAX_FRIEND_REQUEST_DATA_SIZE (ONION_CLIENT_MAX_DATA_SIZE - (1 + sizeof(uint32_t))) 30 | 31 | typedef struct { 32 | uint32_t nospam; 33 | void (*handle_friendrequest)(void *, const uint8_t *, const uint8_t *, size_t, void *); 34 | uint8_t handle_friendrequest_isset; 35 | void *handle_friendrequest_object; 36 | void *handle_friendrequest_userdata; 37 | 38 | int (*filter_function)(const uint8_t *, void *); 39 | void *filter_function_userdata; 40 | /* NOTE: The following is just a temporary fix for the multiple friend requests received at the same time problem. 41 | * TODO: Make this better (This will most likely tie in with the way we will handle spam.) 42 | */ 43 | 44 | #define MAX_RECEIVED_STORED 32 45 | 46 | uint8_t received_requests[MAX_RECEIVED_STORED][crypto_box_PUBLICKEYBYTES]; 47 | uint16_t received_requests_index; 48 | } Friend_Requests; 49 | 50 | /* Set and get the nospam variable used to prevent one type of friend request spam. */ 51 | void set_nospam(Friend_Requests *fr, uint32_t num); 52 | uint32_t get_nospam(const Friend_Requests *fr); 53 | 54 | /* Remove real_pk from received_requests list. 55 | * 56 | * return 0 if it removed it successfully. 57 | * return -1 if it didn't find it. 58 | */ 59 | int remove_request_received(Friend_Requests *fr, const uint8_t *real_pk); 60 | 61 | /* Set the function that will be executed when a friend request for us is received. 62 | * Function format is function(uint8_t * public_key, uint8_t * data, size_t length, void * userdata) 63 | */ 64 | void callback_friendrequest(Friend_Requests *fr, void (*function)(void *, const uint8_t *, const uint8_t *, size_t, 65 | void *), void *object, void *userdata); 66 | 67 | /* Set the function used to check if a friend request should be displayed to the user or not. 68 | * Function format is int function(uint8_t * public_key, void * userdata) 69 | * It must return 0 if the request is ok (anything else if it is bad.) 70 | */ 71 | void set_filter_function(Friend_Requests *fr, int (*function)(const uint8_t *, void *), void *userdata); 72 | 73 | /* Sets up friendreq packet handlers. */ 74 | void friendreq_init(Friend_Requests *fr, Friend_Connections *fr_c); 75 | 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /toxcore/list.h: -------------------------------------------------------------------------------- 1 | /* list.h 2 | * 3 | * Simple struct with functions to create a list which associates ids with data 4 | * -Allows for finding ids associated with data such as IPs or public keys in a short time 5 | * -Should only be used if there are relatively few add/remove calls to the list 6 | * 7 | * Copyright (C) 2014 Tox project All Rights Reserved. 8 | * 9 | * This file is part of Tox. 10 | * 11 | * Tox is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * Tox is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with Tox. If not, see . 23 | * 24 | */ 25 | 26 | #ifndef LIST_H 27 | #define LIST_H 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | typedef struct { 34 | uint32_t n; //number of elements 35 | uint32_t capacity; //number of elements memory is allocated for 36 | uint32_t element_size; //size of the elements 37 | uint8_t *data; //array of elements 38 | int *ids; //array of element ids 39 | } BS_LIST; 40 | 41 | /* Initialize a list, element_size is the size of the elements in the list and 42 | * initial_capacity is the number of elements the memory will be initially allocated for 43 | * 44 | * return value: 45 | * 1 : success 46 | * 0 : failure 47 | */ 48 | int bs_list_init(BS_LIST *list, uint32_t element_size, uint32_t initial_capacity); 49 | 50 | /* Free a list initiated with list_init */ 51 | void bs_list_free(BS_LIST *list); 52 | 53 | /* Retrieve the id of an element in the list 54 | * 55 | * return value: 56 | * >= 0 : id associated with data 57 | * -1 : failure 58 | */ 59 | int bs_list_find(const BS_LIST *list, const uint8_t *data); 60 | 61 | /* Add an element with associated id to the list 62 | * 63 | * return value: 64 | * 1 : success 65 | * 0 : failure (data already in list) 66 | */ 67 | int bs_list_add(BS_LIST *list, const uint8_t *data, int id); 68 | 69 | /* Remove element from the list 70 | * 71 | * return value: 72 | * 1 : success 73 | * 0 : failure (element not found or id does not match) 74 | */ 75 | int bs_list_remove(BS_LIST *list, const uint8_t *data, int id); 76 | 77 | /* Removes the memory overhead 78 | * 79 | * return value: 80 | * 1 : success 81 | * 0 : failure 82 | */ 83 | int bs_list_trim(BS_LIST *list); 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /toxcore/logger.h: -------------------------------------------------------------------------------- 1 | /* logger.h 2 | * 3 | * Copyright (C) 2013 Tox project All Rights Reserved. 4 | * 5 | * This file is part of Tox. 6 | * 7 | * Tox is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * Tox is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with Tox. If not, see . 19 | * 20 | */ 21 | 22 | 23 | #ifndef TOXLOGGER_H 24 | #define TOXLOGGER_H 25 | 26 | #include 27 | 28 | /* In case these are undefined; define 'empty' */ 29 | #ifndef LOGGER_OUTPUT_FILE 30 | # define LOGGER_OUTPUT_FILE "" 31 | #endif 32 | 33 | #ifndef LOGGER_LEVEL 34 | # define LOGGER_LEVEL LOG_ERROR 35 | #endif 36 | 37 | 38 | typedef enum { 39 | LOG_TRACE, 40 | LOG_DEBUG, 41 | LOG_INFO, 42 | LOG_WARNING, 43 | LOG_ERROR 44 | } LOG_LEVEL; 45 | 46 | typedef struct Logger Logger; 47 | 48 | /** 49 | * Set 'level' as the lowest printable level. If id == NULL, random number is used. 50 | */ 51 | Logger *logger_new (const char *file_name, LOG_LEVEL level, const char *id); 52 | 53 | void logger_kill (Logger *log); 54 | void logger_kill_global (void); 55 | 56 | /** 57 | * Global logger setter and getter. 58 | */ 59 | void logger_set_global (Logger *log); 60 | Logger *logger_get_global (void); 61 | 62 | /** 63 | * Main write function. If logging disabled does nothing. If log == NULL uses global logger. 64 | */ 65 | void logger_write (Logger *log, LOG_LEVEL level, const char *file, int line, const char *format, ...); 66 | 67 | 68 | /* To do some checks or similar only when logging, use this */ 69 | #ifdef TOX_LOGGER 70 | # define LOGGER_SCOPE(__SCOPE_DO__) do { __SCOPE_DO__ } while(0) 71 | # define LOGGER_WRITE(log, level, format, ...) \ 72 | logger_write(log, level, __FILE__, __LINE__, format, ##__VA_ARGS__) 73 | #else 74 | /* # warning "Logging disabled" */ 75 | # define LOGGER_SCOPE(__SCOPE_DO__) do {} while(0) 76 | # define LOGGER_WRITE(log, level, format, ...) do {} while(0) 77 | #endif /* TOX_LOGGER */ 78 | 79 | /* To log with an logger */ 80 | #define LOGGER_TRACE_(log, format, ...) LOGGER_WRITE(log, LOG_TRACE, format, ##__VA_ARGS__) 81 | #define LOGGER_DEBUG_(log, format, ...) LOGGER_WRITE(log, LOG_DEBUG, format, ##__VA_ARGS__) 82 | #define LOGGER_INFO_(log, format, ...) LOGGER_WRITE(log, LOG_INFO, format, ##__VA_ARGS__) 83 | #define LOGGER_WARNING_(log, format, ...) LOGGER_WRITE(log, LOG_WARNING, format, ##__VA_ARGS__) 84 | #define LOGGER_ERROR_(log, format, ...) LOGGER_WRITE(log, LOG_ERROR, format, ##__VA_ARGS__) 85 | 86 | /* To log with the global logger */ 87 | #define LOGGER_TRACE(format, ...) LOGGER_TRACE_(NULL, format, ##__VA_ARGS__) 88 | #define LOGGER_DEBUG(format, ...) LOGGER_DEBUG_(NULL, format, ##__VA_ARGS__) 89 | #define LOGGER_INFO(format, ...) LOGGER_INFO_(NULL, format, ##__VA_ARGS__) 90 | #define LOGGER_WARNING(format, ...) LOGGER_WARNING_(NULL, format, ##__VA_ARGS__) 91 | #define LOGGER_ERROR(format, ...) LOGGER_ERROR_(NULL, format, ##__VA_ARGS__) 92 | 93 | 94 | #endif /* TOXLOGGER_H */ 95 | -------------------------------------------------------------------------------- /toxcore/misc_tools.h: -------------------------------------------------------------------------------- 1 | /* misc_tools.h 2 | * 3 | * Miscellaneous functions and data structures for doing random things. 4 | * 5 | * Copyright (C) 2013 Tox project All Rights Reserved. 6 | * 7 | * This file is part of Tox. 8 | * 9 | * Tox is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * Tox is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with Tox. If not, see . 21 | * 22 | */ 23 | 24 | #ifndef MISC_TOOLS_H 25 | #define MISC_TOOLS_H 26 | 27 | /****************************Algorithms*************************** 28 | * Macro/generic definitions for useful algorithms 29 | *****************************************************************/ 30 | 31 | /* Creates a new quick_sort implementation for arrays of the specified type. 32 | * For a type T (eg: int, char), creates a function named T_quick_sort. 33 | * 34 | * Quick Sort: Complexity O(nlogn) 35 | * arr - the array to sort 36 | * n - the sort index (should be called with n = length(arr)) 37 | * cmpfn - a function that compares two values of type type. 38 | * Must return -1, 0, 1 for a < b, a == b, and a > b respectively. 39 | */ 40 | /* Must be called in the header file. */ 41 | #define declare_quick_sort(type) \ 42 | void type##_quick_sort(type *arr, int n, int (*cmpfn)(type, type)); 43 | 44 | /* Must be called in the C file. */ 45 | #define make_quick_sort(type) \ 46 | void type##_quick_sort(type *arr, int n, int (*cmpfn)(type, type)) \ 47 | { \ 48 | if ((n) < 2) \ 49 | return; \ 50 | type _p_ = (arr)[(n) / 2]; \ 51 | type *_l_ = (arr); \ 52 | type *_r_ = (arr) + n - 1; \ 53 | while (_l_ <= _r_) { \ 54 | if (cmpfn(*_l_, _p_) == -1) { \ 55 | ++_l_; \ 56 | continue; \ 57 | } \ 58 | if (cmpfn(*_r_, _p_) == 1) { \ 59 | --_r_; \ 60 | continue; \ 61 | } \ 62 | type _t_ = *_l_; \ 63 | *_l_++ = *_r_; \ 64 | *_r_-- = _t_; \ 65 | } \ 66 | type##_quick_sort((arr), _r_ - (arr) + 1, cmpfn); \ 67 | type##_quick_sort(_l_, (arr) + n - _l_, cmpfn); \ 68 | } 69 | 70 | #endif // MISC_TOOLS_H 71 | -------------------------------------------------------------------------------- /toxcore/ping.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ping.h -- Buffered pinging using cyclic arrays. 3 | * 4 | * This file is donated to the Tox Project. 5 | * Copyright 2013 plutooo 6 | * 7 | * Copyright (C) 2013 Tox project All Rights Reserved. 8 | * 9 | * This file is part of Tox. 10 | * 11 | * Tox is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * Tox is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with Tox. If not, see . 23 | */ 24 | #ifndef __PING_H__ 25 | #define __PING_H__ 26 | 27 | typedef struct PING PING; 28 | 29 | /* Add nodes to the to_ping list. 30 | * All nodes in this list are pinged every TIME_TOPING seconds 31 | * and are then removed from the list. 32 | * If the list is full the nodes farthest from our public_key are replaced. 33 | * The purpose of this list is to enable quick integration of new nodes into the 34 | * network while preventing amplification attacks. 35 | * 36 | * return 0 if node was added. 37 | * return -1 if node was not added. 38 | */ 39 | int add_to_ping(PING *ping, const uint8_t *public_key, IP_Port ip_port); 40 | void do_to_ping(PING *ping); 41 | 42 | PING *new_ping(DHT *dht); 43 | void kill_ping(PING *ping); 44 | 45 | int send_ping_request(PING *ping, IP_Port ipp, const uint8_t *public_key); 46 | 47 | #endif /* __PING_H__ */ 48 | -------------------------------------------------------------------------------- /toxcore/ping_array.c: -------------------------------------------------------------------------------- 1 | /* ping_array.c 2 | * 3 | * Implementation of an efficient array to store that we pinged something. 4 | * 5 | * 6 | * Copyright (C) 2014 Tox project All Rights Reserved. 7 | * 8 | * This file is part of Tox. 9 | * 10 | * Tox is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * Tox is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with Tox. If not, see . 22 | * 23 | */ 24 | 25 | #ifdef HAVE_CONFIG_H 26 | #include "config.h" 27 | #endif 28 | 29 | #include "ping_array.h" 30 | #include "crypto_core.h" 31 | #include "util.h" 32 | 33 | static void clear_entry(Ping_Array *array, uint32_t index) 34 | { 35 | free(array->entries[index].data); 36 | array->entries[index].data = NULL; 37 | array->entries[index].length = 38 | array->entries[index].time = 39 | array->entries[index].ping_id = 0; 40 | } 41 | 42 | /* Clear timed out entries. 43 | */ 44 | static void ping_array_clear_timedout(Ping_Array *array) 45 | { 46 | while (array->last_deleted != array->last_added) { 47 | uint32_t index = array->last_deleted % array->total_size; 48 | 49 | if (!is_timeout(array->entries[index].time, array->timeout)) 50 | break; 51 | 52 | clear_entry(array, index); 53 | ++array->last_deleted; 54 | } 55 | } 56 | 57 | /* Add a data with length to the Ping_Array list and return a ping_id. 58 | * 59 | * return ping_id on success. 60 | * return 0 on failure. 61 | */ 62 | uint64_t ping_array_add(Ping_Array *array, const uint8_t *data, uint32_t length) 63 | { 64 | ping_array_clear_timedout(array); 65 | uint32_t index = array->last_added % array->total_size; 66 | 67 | if (array->entries[index].data != NULL) { 68 | array->last_deleted = array->last_added - array->total_size; 69 | clear_entry(array, index); 70 | } 71 | 72 | array->entries[index].data = malloc(length); 73 | 74 | if (array->entries[index].data == NULL) 75 | return 0; 76 | 77 | memcpy(array->entries[index].data, data, length); 78 | array->entries[index].length = length; 79 | array->entries[index].time = unix_time(); 80 | ++array->last_added; 81 | uint64_t ping_id = random_64b(); 82 | ping_id /= array->total_size; 83 | ping_id *= array->total_size; 84 | ping_id += index; 85 | 86 | if (ping_id == 0) 87 | ping_id += array->total_size; 88 | 89 | array->entries[index].ping_id = ping_id; 90 | return ping_id; 91 | } 92 | 93 | 94 | /* Check if ping_id is valid and not timed out. 95 | * 96 | * On success, copies the data into data of length, 97 | * 98 | * return length of data copied on success. 99 | * return -1 on failure. 100 | */ 101 | int ping_array_check(uint8_t *data, uint32_t length, Ping_Array *array, uint64_t ping_id) 102 | { 103 | if (ping_id == 0) 104 | return -1; 105 | 106 | uint32_t index = ping_id % array->total_size; 107 | 108 | if (array->entries[index].ping_id != ping_id) 109 | return -1; 110 | 111 | if (is_timeout(array->entries[index].time, array->timeout)) 112 | return -1; 113 | 114 | if (array->entries[index].length > length) 115 | return -1; 116 | 117 | if (array->entries[index].data == NULL) 118 | return -1; 119 | 120 | memcpy(data, array->entries[index].data, array->entries[index].length); 121 | uint32_t len = array->entries[index].length; 122 | clear_entry(array, index); 123 | return len; 124 | } 125 | 126 | /* Initialize a Ping_Array. 127 | * size represents the total size of the array and should be a power of 2. 128 | * timeout represents the maximum timeout in seconds for the entry. 129 | * 130 | * return 0 on success. 131 | * return -1 on failure. 132 | */ 133 | int ping_array_init(Ping_Array *empty_array, uint32_t size, uint32_t timeout) 134 | { 135 | if (size == 0 || timeout == 0 || empty_array == NULL) 136 | return -1; 137 | 138 | empty_array->entries = calloc(size, sizeof(Ping_Array_Entry)); 139 | 140 | if (empty_array->entries == NULL) 141 | return -1; 142 | 143 | empty_array->last_deleted = empty_array->last_added = 0; 144 | empty_array->total_size = size; 145 | empty_array->timeout = timeout; 146 | return 0; 147 | } 148 | 149 | /* Free all the allocated memory in a Ping_Array. 150 | */ 151 | void ping_array_free_all(Ping_Array *array) 152 | { 153 | while (array->last_deleted != array->last_added) { 154 | uint32_t index = array->last_deleted % array->total_size; 155 | clear_entry(array, index); 156 | ++array->last_deleted; 157 | } 158 | 159 | free(array->entries); 160 | array->entries = NULL; 161 | } 162 | 163 | -------------------------------------------------------------------------------- /toxcore/ping_array.h: -------------------------------------------------------------------------------- 1 | /* ping_array.h 2 | * 3 | * Implementation of an efficient array to store that we pinged something. 4 | * 5 | * Copyright (C) 2013 Tox project All Rights Reserved. 6 | * 7 | * This file is part of Tox. 8 | * 9 | * Tox is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * Tox is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with Tox. If not, see . 21 | * 22 | */ 23 | #ifndef PING_ARRAY_H 24 | #define PING_ARRAY_H 25 | 26 | #include "network.h" 27 | 28 | typedef struct { 29 | void *data; 30 | uint32_t length; 31 | uint64_t time; 32 | uint64_t ping_id; 33 | } Ping_Array_Entry; 34 | 35 | 36 | typedef struct { 37 | Ping_Array_Entry *entries; 38 | 39 | uint32_t last_deleted; /* number representing the next entry to be deleted. */ 40 | uint32_t last_added; /* number representing the last entry to be added. */ 41 | uint32_t total_size; /* The length of entries */ 42 | uint32_t timeout; /* The timeout after which entries are cleared. */ 43 | } Ping_Array; 44 | 45 | 46 | /* Add a data with length to the Ping_Array list and return a ping_id. 47 | * 48 | * return ping_id on success. 49 | * return 0 on failure. 50 | */ 51 | uint64_t ping_array_add(Ping_Array *array, const uint8_t *data, uint32_t length); 52 | 53 | /* Check if ping_id is valid and not timed out. 54 | * 55 | * On success, copies the data into data of length, 56 | * 57 | * return length of data copied on success. 58 | * return -1 on failure. 59 | */ 60 | int ping_array_check(uint8_t *data, uint32_t length, Ping_Array *array, uint64_t ping_id); 61 | 62 | /* Initialize a Ping_Array. 63 | * size represents the total size of the array and should be a power of 2. 64 | * timeout represents the maximum timeout in seconds for the entry. 65 | * 66 | * return 0 on success. 67 | * return -1 on failure. 68 | */ 69 | int ping_array_init(Ping_Array *empty_array, uint32_t size, uint32_t timeout); 70 | 71 | /* Free all the allocated memory in a Ping_Array. 72 | */ 73 | void ping_array_free_all(Ping_Array *array); 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /toxcore/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * util.h -- Utilities. 3 | * 4 | * This file is donated to the Tox Project. 5 | * Copyright 2013 plutooo 6 | * 7 | * Copyright (C) 2013 Tox project All Rights Reserved. 8 | * 9 | * This file is part of Tox. 10 | * 11 | * Tox is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * Tox is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with Tox. If not, see . 23 | */ 24 | 25 | #ifndef __UTIL_H__ 26 | #define __UTIL_H__ 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #define MIN(a,b) (((a)<(b))?(a):(b)) 33 | #define PAIR(TYPE1__, TYPE2__) struct { TYPE1__ first; TYPE2__ second; } 34 | 35 | void unix_time_update(); 36 | uint64_t unix_time(); 37 | int is_timeout(uint64_t timestamp, uint64_t timeout); 38 | 39 | 40 | /* id functions */ 41 | bool id_equal(const uint8_t *dest, const uint8_t *src); 42 | uint32_t id_copy(uint8_t *dest, const uint8_t *src); /* return value is CLIENT_ID_SIZE */ 43 | 44 | void host_to_net(uint8_t *num, uint16_t numbytes); 45 | #define net_to_host(x, y) host_to_net(x, y) 46 | 47 | uint16_t lendian_to_host16(uint16_t lendian); 48 | #define host_tolendian16(x) lendian_to_host16(x) 49 | 50 | void host_to_lendian32(uint8_t *dest, uint32_t num); 51 | void lendian_to_host32(uint32_t *dest, const uint8_t *lendian); 52 | 53 | /* state load/save */ 54 | typedef int (*load_state_callback_func)(void *outer, const uint8_t *data, uint32_t len, uint16_t type); 55 | int load_state(load_state_callback_func load_state_callback, void *outer, 56 | const uint8_t *data, uint32_t length, uint16_t cookie_inner); 57 | 58 | /* Returns -1 if failed or 0 if success */ 59 | int create_recursive_mutex(pthread_mutex_t *mutex); 60 | 61 | /* Ring buffer */ 62 | typedef struct RingBuffer RingBuffer; 63 | bool rb_full(const RingBuffer *b); 64 | bool rb_empty(const RingBuffer *b); 65 | void *rb_write(RingBuffer *b, void *p); 66 | bool rb_read(RingBuffer *b, void **p); 67 | RingBuffer *rb_new(int size); 68 | void rb_kill(RingBuffer *b); 69 | uint16_t rb_size(const RingBuffer *b); 70 | uint16_t rb_data(const RingBuffer *b, void **dest); 71 | 72 | #endif /* __UTIL_H__ */ 73 | -------------------------------------------------------------------------------- /toxdns/Makefile.inc: -------------------------------------------------------------------------------- 1 | lib_LTLIBRARIES += libtoxdns.la 2 | 3 | libtoxdns_la_include_HEADERS = \ 4 | ../toxdns/toxdns.h 5 | 6 | libtoxdns_la_includedir = $(includedir)/tox 7 | 8 | libtoxdns_la_SOURCES = ../toxdns/toxdns.h \ 9 | ../toxdns/toxdns.c 10 | 11 | libtoxdns_la_CFLAGS = -I$(top_srcdir) \ 12 | -I$(top_srcdir)/toxcore \ 13 | $(LIBSODIUM_CFLAGS) \ 14 | $(NACL_CFLAGS) \ 15 | $(PTHREAD_CFLAGS) 16 | 17 | libtoxdns_la_LDFLAGS = $(TOXCORE_LT_LDFLAGS) \ 18 | $(EXTRA_LT_LDFLAGS) \ 19 | $(LIBSODIUM_LDFLAGS) \ 20 | $(NACL_LDFLAGS) \ 21 | $(MATH_LDFLAGS) \ 22 | $(RT_LIBS) \ 23 | $(WINSOCK2_LIBS) 24 | 25 | libtoxdns_la_LIBADD = $(LIBSODIUM_LIBS) \ 26 | $(NACL_OBJECTS) \ 27 | $(NAC_LIBS) \ 28 | $(PTHREAD_LIBS) \ 29 | libtoxcore.la 30 | -------------------------------------------------------------------------------- /toxdns/toxdns.h: -------------------------------------------------------------------------------- 1 | /* toxdns.h 2 | * 3 | * Tox secure username DNS toxid resolving functions. 4 | * 5 | * Copyright (C) 2014 Tox project All Rights Reserved. 6 | * 7 | * This file is part of Tox. 8 | * 9 | * Tox is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * Tox is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with Tox. If not, see . 21 | * 22 | */ 23 | 24 | #ifndef TOXDNS_H 25 | #define TOXDNS_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | #include 32 | 33 | /* Clients are encouraged to set this as the maximum length names can have. */ 34 | #define TOXDNS_MAX_RECOMMENDED_NAME_LENGTH 32 35 | 36 | /* How to use this api to make secure tox dns3 requests: 37 | * 38 | * 1. Get the public key of a server that supports tox dns3. 39 | * 2. use tox_dns3_new() to create a new object to create DNS requests 40 | * and handle responses for that server. 41 | * 3. Use tox_generate_dns3_string() to generate a string based on the name we want to query and a request_id 42 | * that must be stored somewhere for when we want to decrypt the response. 43 | * 4. take the string and use it for your DNS request like this: 44 | * _4haaaaipr1o3mz0bxweox541airydbovqlbju51mb4p0ebxq.rlqdj4kkisbep2ks3fj2nvtmk4daduqiueabmexqva1jc._tox.utox.org 45 | * 5. The TXT in the DNS you receive should look like this: 46 | * v=tox3;id=2vgcxuycbuctvauik3plsv3d3aadv4zfjfhi3thaizwxinelrvigchv0ah3qjcsx5qhmaksb2lv2hm5cwbtx0yp 47 | * 6. Take the id string and use it with tox_decrypt_dns3_TXT() and the request_id corresponding to the 48 | * request we stored earlier to get the Tox id returned by the DNS server. 49 | */ 50 | 51 | /* Create a new tox_dns3 object for server with server_public_key of size TOX_CLIENT_ID_SIZE. 52 | * 53 | * return Null on failure. 54 | * return pointer object on success. 55 | */ 56 | void *tox_dns3_new(uint8_t *server_public_key); 57 | 58 | /* Destroy the tox dns3 object. 59 | */ 60 | void tox_dns3_kill(void *dns3_object); 61 | 62 | /* Generate a dns3 string of string_max_len used to query the dns server referred to by to 63 | * dns3_object for a tox id registered to user with name of name_len. 64 | * 65 | * the uint32_t pointed by request_id will be set to the request id which must be passed to 66 | * tox_decrypt_dns3_TXT() to correctly decode the response. 67 | * 68 | * This is what the string returned looks like: 69 | * 4haaaaipr1o3mz0bxweox541airydbovqlbju51mb4p0ebxq.rlqdj4kkisbep2ks3fj2nvtmk4daduqiueabmexqva1jc 70 | * 71 | * returns length of string on success. 72 | * returns -1 on failure. 73 | */ 74 | int tox_generate_dns3_string(void *dns3_object, uint8_t *string, uint16_t string_max_len, uint32_t *request_id, 75 | uint8_t *name, uint8_t name_len); 76 | 77 | /* Decode and decrypt the id_record returned of length id_record_len into 78 | * tox_id (needs to be at least TOX_FRIEND_ADDRESS_SIZE). 79 | * 80 | * request_id is the request id given by tox_generate_dns3_string() when creating the request. 81 | * 82 | * the id_record passed to this function should look somewhat like this: 83 | * 2vgcxuycbuctvauik3plsv3d3aadv4zfjfhi3thaizwxinelrvigchv0ah3qjcsx5qhmaksb2lv2hm5cwbtx0yp 84 | * 85 | * returns -1 on failure. 86 | * returns 0 on success. 87 | * 88 | */ 89 | int tox_decrypt_dns3_TXT(void *dns3_object, uint8_t *tox_id, uint8_t *id_record, uint32_t id_record_len, 90 | uint32_t request_id); 91 | 92 | #ifdef __cplusplus 93 | } 94 | #endif 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /toxencryptsave/Makefile.inc: -------------------------------------------------------------------------------- 1 | lib_LTLIBRARIES += libtoxencryptsave.la 2 | 3 | libtoxencryptsave_la_include_HEADERS = \ 4 | ../toxencryptsave/toxencryptsave.h 5 | 6 | libtoxencryptsave_la_includedir = $(includedir)/tox 7 | 8 | libtoxencryptsave_la_SOURCES = ../toxencryptsave/toxencryptsave.h \ 9 | ../toxencryptsave/toxencryptsave.c \ 10 | ../toxencryptsave/defines.h 11 | 12 | 13 | if WITH_NACL 14 | libtoxencryptsave_la_SOURCES += ../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/crypto_pwhash_scryptsalsa208sha256.h \ 15 | ../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/crypto_scrypt.h \ 16 | ../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/pbkdf2-sha256.c \ 17 | ../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c \ 18 | ../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/runtime.h \ 19 | ../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/utils.c \ 20 | ../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/crypto_scrypt-common.c \ 21 | ../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/export.h \ 22 | ../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/pbkdf2-sha256.h \ 23 | ../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/runtime.c \ 24 | ../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/scrypt_platform.c \ 25 | ../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/sysendian.h \ 26 | ../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/utils.h \ 27 | ../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/nosse/pwhash_scryptsalsa208sha256_nosse.c \ 28 | ../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c 29 | endif 30 | 31 | libtoxencryptsave_la_CFLAGS = -I$(top_srcdir) \ 32 | -I$(top_srcdir)/toxcore \ 33 | $(LIBSODIUM_CFLAGS) \ 34 | $(NACL_CFLAGS) \ 35 | $(PTHREAD_CFLAGS) 36 | 37 | libtoxencryptsave_la_LDFLAGS = $(TOXCORE_LT_LDFLAGS) \ 38 | $(EXTRA_LT_LDFLAGS) \ 39 | $(LIBSODIUM_LDFLAGS) \ 40 | $(NACL_LDFLAGS) \ 41 | $(MATH_LDFLAGS) \ 42 | $(RT_LIBS) \ 43 | $(WINSOCK2_LIBS) 44 | 45 | libtoxencryptsave_la_LIBADD = $(LIBSODIUM_LIBS) \ 46 | $(NACL_OBJECTS) \ 47 | $(NAC_LIBS) \ 48 | $(PTHREAD_LIBS) \ 49 | libtoxcore.la 50 | -------------------------------------------------------------------------------- /toxencryptsave/crypto_pwhash_scryptsalsa208sha256/crypto_pwhash_scryptsalsa208sha256.h: -------------------------------------------------------------------------------- 1 | #ifdef HAVE_CONFIG_H 2 | #include "config.h" 3 | #endif 4 | #ifdef VANILLA_NACL /* toxcore only uses this when libsodium is unavailable */ 5 | 6 | #ifndef crypto_pwhash_scryptsalsa208sha256_H 7 | #define crypto_pwhash_scryptsalsa208sha256_H 8 | 9 | #include 10 | #include 11 | 12 | #include "export.h" 13 | 14 | #ifdef __cplusplus 15 | # if __GNUC__ 16 | # pragma GCC diagnostic ignored "-Wlong-long" 17 | # endif 18 | extern "C" { 19 | #endif 20 | 21 | #define crypto_pwhash_scryptsalsa208sha256_SALTBYTES 32U 22 | SODIUM_EXPORT 23 | size_t crypto_pwhash_scryptsalsa208sha256_saltbytes(void); 24 | 25 | #define crypto_pwhash_scryptsalsa208sha256_STRBYTES 102U 26 | SODIUM_EXPORT 27 | size_t crypto_pwhash_scryptsalsa208sha256_strbytes(void); 28 | 29 | #define crypto_pwhash_scryptsalsa208sha256_STRPREFIX "$7$" 30 | SODIUM_EXPORT 31 | const char *crypto_pwhash_scryptsalsa208sha256_strprefix(void); 32 | 33 | #define crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE 524288ULL 34 | SODIUM_EXPORT 35 | size_t crypto_pwhash_scryptsalsa208sha256_opslimit_interactive(void); 36 | 37 | #define crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE 16777216ULL 38 | SODIUM_EXPORT 39 | size_t crypto_pwhash_scryptsalsa208sha256_memlimit_interactive(void); 40 | 41 | #define crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_SENSITIVE 33554432ULL 42 | SODIUM_EXPORT 43 | size_t crypto_pwhash_scryptsalsa208sha256_opslimit_sensitive(void); 44 | 45 | #define crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_SENSITIVE 1073741824ULL 46 | SODIUM_EXPORT 47 | size_t crypto_pwhash_scryptsalsa208sha256_memlimit_sensitive(void); 48 | 49 | SODIUM_EXPORT 50 | int crypto_pwhash_scryptsalsa208sha256(unsigned char * const out, 51 | unsigned long long outlen, 52 | const char * const passwd, 53 | unsigned long long passwdlen, 54 | const unsigned char * const salt, 55 | unsigned long long opslimit, 56 | size_t memlimit); 57 | 58 | SODIUM_EXPORT 59 | int crypto_pwhash_scryptsalsa208sha256_str(char out[crypto_pwhash_scryptsalsa208sha256_STRBYTES], 60 | const char * const passwd, 61 | unsigned long long passwdlen, 62 | unsigned long long opslimit, 63 | size_t memlimit); 64 | 65 | SODIUM_EXPORT 66 | int crypto_pwhash_scryptsalsa208sha256_str_verify(const char str[crypto_pwhash_scryptsalsa208sha256_STRBYTES], 67 | const char * const passwd, 68 | unsigned long long passwdlen); 69 | 70 | SODIUM_EXPORT 71 | int crypto_pwhash_scryptsalsa208sha256_ll(const uint8_t * passwd, size_t passwdlen, 72 | const uint8_t * salt, size_t saltlen, 73 | uint64_t N, uint32_t r, uint32_t p, 74 | uint8_t * buf, size_t buflen); 75 | 76 | #ifdef __cplusplus 77 | } 78 | #endif 79 | 80 | /* Backward compatibility with version 0.5.0 */ 81 | 82 | #define crypto_pwhash_scryptxsalsa208sha256_SALTBYTES crypto_pwhash_scryptsalsa208sha256_SALTBYTES 83 | #define crypto_pwhash_scryptxsalsa208sha256_saltbytes crypto_pwhash_scryptsalsa208sha256_saltbytes 84 | #define crypto_pwhash_scryptxsalsa208sha256_STRBYTES crypto_pwhash_scryptsalsa208sha256_STRBYTES 85 | #define crypto_pwhash_scryptxsalsa208sha256_strbytes crypto_pwhash_scryptsalsa208sha256_strbytes 86 | #define crypto_pwhash_scryptxsalsa208sha256 crypto_pwhash_scryptsalsa208sha256 87 | #define crypto_pwhash_scryptxsalsa208sha256_str crypto_pwhash_scryptsalsa208sha256_str 88 | #define crypto_pwhash_scryptxsalsa208sha256_str_verify crypto_pwhash_scryptsalsa208sha256_str_verify 89 | 90 | #endif 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /toxencryptsave/crypto_pwhash_scryptsalsa208sha256/crypto_scrypt.h: -------------------------------------------------------------------------------- 1 | #ifdef HAVE_CONFIG_H 2 | #include "config.h" 3 | #endif 4 | #ifdef VANILLA_NACL /* toxcore only uses this when libsodium is unavailable */ 5 | 6 | /*- 7 | * Copyright 2009 Colin Percival 8 | * Copyright 2013 Alexander Peslyak 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 1. Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | * 32 | * This file was originally written by Colin Percival as part of the Tarsnap 33 | * online backup system. 34 | */ 35 | #ifndef _CRYPTO_SCRYPT_H_ 36 | #define _CRYPTO_SCRYPT_H_ 37 | 38 | #include 39 | 40 | #define crypto_pwhash_scryptsalsa208sha256_STRPREFIXBYTES 14 41 | #define crypto_pwhash_scryptsalsa208sha256_STRSETTINGBYTES 57 42 | #define crypto_pwhash_scryptsalsa208sha256_STRSALTBYTES 32 43 | #define crypto_pwhash_scryptsalsa208sha256_STRSALTBYTES_ENCODED 43 44 | #define crypto_pwhash_scryptsalsa208sha256_STRHASHBYTES 32 45 | #define crypto_pwhash_scryptsalsa208sha256_STRHASHBYTES_ENCODED 43 46 | 47 | #define BYTES2CHARS(bytes) ((((bytes) * 8) + 5) / 6) 48 | 49 | typedef struct { 50 | void * base, * aligned; 51 | size_t size; 52 | } escrypt_region_t; 53 | 54 | typedef escrypt_region_t escrypt_local_t; 55 | 56 | extern int escrypt_init_local(escrypt_local_t * __local); 57 | 58 | extern int escrypt_free_local(escrypt_local_t * __local); 59 | 60 | extern void *alloc_region(escrypt_region_t * region, size_t size); 61 | extern int free_region(escrypt_region_t * region); 62 | 63 | typedef int (*escrypt_kdf_t)(escrypt_local_t * __local, 64 | const uint8_t * __passwd, size_t __passwdlen, 65 | const uint8_t * __salt, size_t __saltlen, 66 | uint64_t __N, uint32_t __r, uint32_t __p, 67 | uint8_t * __buf, size_t __buflen); 68 | 69 | extern int escrypt_kdf_nosse(escrypt_local_t * __local, 70 | const uint8_t * __passwd, size_t __passwdlen, 71 | const uint8_t * __salt, size_t __saltlen, 72 | uint64_t __N, uint32_t __r, uint32_t __p, 73 | uint8_t * __buf, size_t __buflen); 74 | 75 | extern int escrypt_kdf_sse(escrypt_local_t * __local, 76 | const uint8_t * __passwd, size_t __passwdlen, 77 | const uint8_t * __salt, size_t __saltlen, 78 | uint64_t __N, uint32_t __r, uint32_t __p, 79 | uint8_t * __buf, size_t __buflen); 80 | 81 | extern uint8_t * escrypt_r(escrypt_local_t * __local, 82 | const uint8_t * __passwd, size_t __passwdlen, 83 | const uint8_t * __setting, 84 | uint8_t * __buf, size_t __buflen); 85 | 86 | extern uint8_t * escrypt_gensalt_r( 87 | uint32_t __N_log2, uint32_t __r, uint32_t __p, 88 | const uint8_t * __src, size_t __srclen, 89 | uint8_t * __buf, size_t __buflen); 90 | 91 | #endif /* !_CRYPTO_SCRYPT_H_ */ 92 | 93 | #endif 94 | -------------------------------------------------------------------------------- /toxencryptsave/crypto_pwhash_scryptsalsa208sha256/export.h: -------------------------------------------------------------------------------- 1 | #ifdef HAVE_CONFIG_H 2 | #include "config.h" 3 | #endif 4 | #ifdef VANILLA_NACL /* toxcore only uses this when libsodium is unavailable */ 5 | 6 | #ifndef __SODIUM_EXPORT_H__ 7 | #define __SODIUM_EXPORT_H__ 8 | 9 | #ifndef __GNUC__ 10 | # ifdef __attribute__ 11 | # undef __attribute__ 12 | # endif 13 | # define __attribute__(a) 14 | #endif 15 | 16 | #ifdef SODIUM_STATIC 17 | # define SODIUM_EXPORT 18 | #else 19 | # if defined(_MSC_VER) 20 | # ifdef DLL_EXPORT 21 | # define SODIUM_EXPORT __declspec(dllexport) 22 | # else 23 | # define SODIUM_EXPORT __declspec(dllimport) 24 | # endif 25 | # else 26 | # if defined(__SUNPRO_C) 27 | # define SODIUM_EXPORT __attribute__ __global 28 | # elif defined(_MSG_VER) 29 | # define SODIUM_EXPORT extern __declspec(dllexport) 30 | # else 31 | # define SODIUM_EXPORT __attribute__ ((visibility ("default"))) 32 | # endif 33 | # endif 34 | #endif 35 | 36 | #endif 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /toxencryptsave/crypto_pwhash_scryptsalsa208sha256/note_to_maintainers.txt: -------------------------------------------------------------------------------- 1 | This folder is only meant for use with nacl, i.e. when sodium is unavailable. 2 | 3 | 4 | The files in this folder were mostly copied from 5 | https://github.com/jedisct1/libsodium/tree/0.7.0/src/libsodium/crypto_pwhash/scryptsalsa208sha256, 6 | with #ifdef VANILLA_NACL added around each of them as required for this module. 7 | 8 | export.h, utils.h, and runtime.h were copied from 9 | https://github.com/jedisct1/libsodium/tree/0.7.0/src/libsodium/include/sodium. 10 | utils.h was significantly truncated. 11 | 12 | utils.c and runtime.c were copied from 13 | https://github.com/jedisct1/libsodium/blob/0.7.0/src/libsodium/sodium. 14 | utils.c was also significantly truncated. 15 | -------------------------------------------------------------------------------- /toxencryptsave/crypto_pwhash_scryptsalsa208sha256/pbkdf2-sha256.c: -------------------------------------------------------------------------------- 1 | #ifdef HAVE_CONFIG_H 2 | #include "config.h" 3 | #endif 4 | #ifdef VANILLA_NACL /* toxcore only uses this when libsodium is unavailable */ 5 | 6 | /*- 7 | * Copyright 2005,2007,2009 Colin Percival 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | */ 31 | 32 | #include 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | #include 39 | #include 40 | 41 | #include "pbkdf2-sha256.h" 42 | #include "sysendian.h" 43 | #include "utils.h" 44 | 45 | /** 46 | * PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, c, buf, dkLen): 47 | * Compute PBKDF2(passwd, salt, c, dkLen) using HMAC-SHA256 as the PRF, and 48 | * write the output to buf. The value dkLen must be at most 32 * (2^32 - 1). 49 | */ 50 | void 51 | PBKDF2_SHA256(const uint8_t * passwd, size_t passwdlen, const uint8_t * salt, 52 | size_t saltlen, uint64_t c, uint8_t * buf, size_t dkLen) 53 | { 54 | uint8_t key[32] = {0}; 55 | size_t i; 56 | uint8_t salt_and_ivec[saltlen + 4]; 57 | uint8_t U[32]; 58 | uint8_t T[32]; 59 | uint64_t j; 60 | int k; 61 | size_t clen; 62 | 63 | if (passwdlen > 32) { 64 | /* For some reason libsodium allows 64byte keys meaning keys 65 | * between 32byte and 64bytes are not compatible with libsodium. 66 | toxencryptsave should only give 32byte passwds so this isn't an issue here.*/ 67 | crypto_hash_sha256(key, passwd, passwdlen); 68 | } else { 69 | memcpy(key, passwd, passwdlen); 70 | } 71 | 72 | memcpy(salt_and_ivec, salt, saltlen); 73 | 74 | for (i = 0; i * 32 < dkLen; i++) { 75 | be32enc(salt_and_ivec + saltlen, (uint32_t)(i + 1)); 76 | crypto_auth_hmacsha256(U, salt_and_ivec, sizeof(salt_and_ivec), key); 77 | 78 | memcpy(T, U, 32); 79 | 80 | for (j = 2; j <= c; j++) { 81 | crypto_auth_hmacsha256(U, U, 32, key); 82 | 83 | for (k = 0; k < 32; k++) { 84 | T[k] ^= U[k]; 85 | } 86 | } 87 | 88 | clen = dkLen - i * 32; 89 | if (clen > 32) { 90 | clen = 32; 91 | } 92 | memcpy(&buf[i * 32], T, clen); 93 | } 94 | sodium_memzero((void *) key, sizeof(key)); 95 | } 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /toxencryptsave/crypto_pwhash_scryptsalsa208sha256/pbkdf2-sha256.h: -------------------------------------------------------------------------------- 1 | #ifdef HAVE_CONFIG_H 2 | #include "config.h" 3 | #endif 4 | #ifdef VANILLA_NACL /* toxcore only uses this when libsodium is unavailable */ 5 | 6 | /*- 7 | * Copyright 2005,2007,2009 Colin Percival 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | #ifndef _SHA256_H_ 34 | #define _SHA256_H_ 35 | 36 | #include 37 | 38 | #include 39 | 40 | #include "crypto_auth_hmacsha256.h" 41 | 42 | /** 43 | * PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, c, buf, dkLen): 44 | * Compute PBKDF2(passwd, salt, c, dkLen) using HMAC-SHA256 as the PRF, and 45 | * write the output to buf. The value dkLen must be at most 32 * (2^32 - 1). 46 | */ 47 | void PBKDF2_SHA256(const uint8_t *, size_t, const uint8_t *, size_t, 48 | uint64_t, uint8_t *, size_t); 49 | 50 | #endif /* !_SHA256_H_ */ 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /toxencryptsave/crypto_pwhash_scryptsalsa208sha256/runtime.c: -------------------------------------------------------------------------------- 1 | #ifdef HAVE_CONFIG_H 2 | #include "config.h" 3 | #endif 4 | #ifdef VANILLA_NACL /* toxcore only uses this when libsodium is unavailable */ 5 | 6 | #ifdef HAVE_ANDROID_GETCPUFEATURES 7 | # include 8 | #endif 9 | 10 | #include "runtime.h" 11 | 12 | typedef struct CPUFeatures_ { 13 | int initialized; 14 | int has_neon; 15 | int has_sse2; 16 | int has_sse3; 17 | } CPUFeatures; 18 | 19 | static CPUFeatures _cpu_features; 20 | 21 | #define CPUID_SSE2 0x04000000 22 | #define CPUIDECX_SSE3 0x00000001 23 | 24 | static int 25 | _sodium_runtime_arm_cpu_features(CPUFeatures * const cpu_features) 26 | { 27 | #ifndef __arm__ 28 | cpu_features->has_neon = 0; 29 | return -1; 30 | #else 31 | # ifdef __APPLE__ 32 | # ifdef __ARM_NEON__ 33 | cpu_features->has_neon = 1; 34 | # else 35 | cpu_features->has_neon = 0; 36 | # endif 37 | # elif defined(HAVE_ANDROID_GETCPUFEATURES) && defined(ANDROID_CPU_ARM_FEATURE_NEON) 38 | cpu_features->has_neon = 39 | (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0x0; 40 | # else 41 | cpu_features->has_neon = 0; 42 | # endif 43 | return 0; 44 | #endif 45 | } 46 | 47 | static void 48 | _cpuid(unsigned int cpu_info[4U], const unsigned int cpu_info_type) 49 | { 50 | #ifdef _MSC_VER 51 | __cpuidex((int *) cpu_info, cpu_info_type, 0); 52 | #elif defined(HAVE_CPUID) 53 | cpu_info[0] = cpu_info[1] = cpu_info[2] = cpu_info[3] = 0; 54 | # ifdef __i386__ 55 | __asm__ __volatile__ ("pushfl; pushfl; " 56 | "popl %0; " 57 | "movl %0, %1; xorl %2, %0; " 58 | "pushl %0; " 59 | "popfl; pushfl; popl %0; popfl" : 60 | "=&r" (cpu_info[0]), "=&r" (cpu_info[1]) : 61 | "i" (0x200000)); 62 | if (((cpu_info[0] ^ cpu_info[1]) & 0x200000) == 0x0) { 63 | return; 64 | } 65 | # endif 66 | # ifdef __i386__ 67 | __asm__ __volatile__ ("xchgl %%ebx, %k1; cpuid; xchgl %%ebx, %k1" : 68 | "=a" (cpu_info[0]), "=&r" (cpu_info[1]), 69 | "=c" (cpu_info[2]), "=d" (cpu_info[3]) : 70 | "0" (cpu_info_type), "2" (0U)); 71 | # elif defined(__x86_64__) 72 | __asm__ __volatile__ ("xchgq %%rbx, %q1; cpuid; xchgq %%rbx, %q1" : 73 | "=a" (cpu_info[0]), "=&r" (cpu_info[1]), 74 | "=c" (cpu_info[2]), "=d" (cpu_info[3]) : 75 | "0" (cpu_info_type), "2" (0U)); 76 | # else 77 | __asm__ __volatile__ ("cpuid" : 78 | "=a" (cpu_info[0]), "=b" (cpu_info[1]), 79 | "=c" (cpu_info[2]), "=d" (cpu_info[3]) : 80 | "0" (cpu_info_type), "2" (0U)); 81 | # endif 82 | #else 83 | cpu_info[0] = cpu_info[1] = cpu_info[2] = cpu_info[3] = 0; 84 | #endif 85 | } 86 | 87 | static int 88 | _sodium_runtime_intel_cpu_features(CPUFeatures * const cpu_features) 89 | { 90 | unsigned int cpu_info[4]; 91 | unsigned int id; 92 | 93 | _cpuid(cpu_info, 0x0); 94 | if ((id = cpu_info[0]) == 0U) { 95 | return -1; 96 | } 97 | _cpuid(cpu_info, 0x00000001); 98 | #ifndef HAVE_EMMINTRIN_H 99 | cpu_features->has_sse2 = 0; 100 | #else 101 | cpu_features->has_sse2 = ((cpu_info[3] & CPUID_SSE2) != 0x0); 102 | #endif 103 | 104 | #ifndef HAVE_PMMINTRIN_H 105 | cpu_features->has_sse3 = 0; 106 | #else 107 | cpu_features->has_sse3 = ((cpu_info[2] & CPUIDECX_SSE3) != 0x0); 108 | #endif 109 | 110 | return 0; 111 | } 112 | 113 | int 114 | sodium_runtime_get_cpu_features(void) 115 | { 116 | int ret = -1; 117 | 118 | ret &= _sodium_runtime_arm_cpu_features(&_cpu_features); 119 | ret &= _sodium_runtime_intel_cpu_features(&_cpu_features); 120 | _cpu_features.initialized = 1; 121 | 122 | return ret; 123 | } 124 | 125 | int 126 | sodium_runtime_has_neon(void) { 127 | return _cpu_features.has_neon; 128 | } 129 | 130 | int 131 | sodium_runtime_has_sse2(void) { 132 | return _cpu_features.has_sse2; 133 | } 134 | 135 | int 136 | sodium_runtime_has_sse3(void) { 137 | return _cpu_features.has_sse3; 138 | } 139 | 140 | #endif 141 | -------------------------------------------------------------------------------- /toxencryptsave/crypto_pwhash_scryptsalsa208sha256/runtime.h: -------------------------------------------------------------------------------- 1 | #ifdef HAVE_CONFIG_H 2 | #include "config.h" 3 | #endif 4 | #ifdef VANILLA_NACL /* toxcore only uses this when libsodium is unavailable */ 5 | 6 | #ifndef __SODIUM_RUNTIME_H__ 7 | #define __SODIUM_RUNTIME_H__ 1 8 | 9 | #include "export.h" 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | SODIUM_EXPORT 16 | int sodium_runtime_get_cpu_features(void); 17 | 18 | SODIUM_EXPORT 19 | int sodium_runtime_has_neon(void); 20 | 21 | SODIUM_EXPORT 22 | int sodium_runtime_has_sse2(void); 23 | 24 | SODIUM_EXPORT 25 | int sodium_runtime_has_sse3(void); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /toxencryptsave/crypto_pwhash_scryptsalsa208sha256/scrypt_platform.c: -------------------------------------------------------------------------------- 1 | #ifdef HAVE_CONFIG_H 2 | #include "config.h" 3 | #endif 4 | #ifdef VANILLA_NACL /* toxcore only uses this when libsodium is unavailable */ 5 | 6 | /*- 7 | * Copyright 2013 Alexander Peslyak 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23 | * SUCH DAMAGE. 24 | */ 25 | 26 | #ifdef HAVE_SYS_MMAN_H 27 | # include 28 | #endif 29 | #include 30 | #include 31 | 32 | #include "crypto_scrypt.h" 33 | #include "runtime.h" 34 | 35 | #if !defined(MAP_ANON) && defined(MAP_ANONYMOUS) 36 | # define MAP_ANON MAP_ANONYMOUS 37 | #endif 38 | 39 | void * 40 | alloc_region(escrypt_region_t * region, size_t size) 41 | { 42 | uint8_t * base, * aligned; 43 | #ifdef MAP_ANON 44 | if ((base = (uint8_t *) mmap(NULL, size, PROT_READ | PROT_WRITE, 45 | #ifdef MAP_NOCORE 46 | MAP_ANON | MAP_PRIVATE | MAP_NOCORE, 47 | #else 48 | MAP_ANON | MAP_PRIVATE, 49 | #endif 50 | -1, 0)) == MAP_FAILED) 51 | base = NULL; 52 | aligned = base; 53 | #elif defined(HAVE_POSIX_MEMALIGN) 54 | if ((errno = posix_memalign((void **) &base, 64, size)) != 0) 55 | base = NULL; 56 | aligned = base; 57 | #else 58 | base = aligned = NULL; 59 | if (size + 63 < size) 60 | errno = ENOMEM; 61 | else if ((base = (uint8_t *) malloc(size + 63)) != NULL) { 62 | aligned = base + 63; 63 | aligned -= (uintptr_t)aligned & 63; 64 | } 65 | #endif 66 | region->base = base; 67 | region->aligned = aligned; 68 | region->size = base ? size : 0; 69 | return aligned; 70 | } 71 | 72 | static inline void 73 | init_region(escrypt_region_t * region) 74 | { 75 | region->base = region->aligned = NULL; 76 | region->size = 0; 77 | } 78 | 79 | int 80 | free_region(escrypt_region_t * region) 81 | { 82 | if (region->base) { 83 | #ifdef MAP_ANON 84 | if (munmap(region->base, region->size)) 85 | return -1; 86 | #else 87 | free(region->base); 88 | #endif 89 | } 90 | init_region(region); 91 | return 0; 92 | } 93 | 94 | int 95 | escrypt_init_local(escrypt_local_t * local) 96 | { 97 | init_region(local); 98 | return 0; 99 | } 100 | 101 | int 102 | escrypt_free_local(escrypt_local_t * local) 103 | { 104 | return free_region(local); 105 | } 106 | 107 | #endif 108 | -------------------------------------------------------------------------------- /toxencryptsave/crypto_pwhash_scryptsalsa208sha256/sysendian.h: -------------------------------------------------------------------------------- 1 | #ifdef HAVE_CONFIG_H 2 | #include "config.h" 3 | #endif 4 | #ifdef VANILLA_NACL /* toxcore only uses this when libsodium is unavailable */ 5 | 6 | #ifndef _SYSENDIAN_H_ 7 | #define _SYSENDIAN_H_ 8 | 9 | #include 10 | 11 | /* Avoid namespace collisions with BSD . */ 12 | #define be16dec scrypt_be16dec 13 | #define be16enc scrypt_be16enc 14 | #define be32dec scrypt_be32dec 15 | #define be32enc scrypt_be32enc 16 | #define be64dec scrypt_be64dec 17 | #define be64enc scrypt_be64enc 18 | #define le16dec scrypt_le16dec 19 | #define le16enc scrypt_le16enc 20 | #define le32dec scrypt_le32dec 21 | #define le32enc scrypt_le32enc 22 | #define le64dec scrypt_le64dec 23 | #define le64enc scrypt_le64enc 24 | 25 | static inline uint16_t 26 | be16dec(const void *pp) 27 | { 28 | const uint8_t *p = (uint8_t const *)pp; 29 | 30 | return ((uint16_t)(p[1]) + ((uint16_t)(p[0]) << 8)); 31 | } 32 | 33 | static inline void 34 | be16enc(void *pp, uint16_t x) 35 | { 36 | uint8_t * p = (uint8_t *)pp; 37 | 38 | p[1] = x & 0xff; 39 | p[0] = (x >> 8) & 0xff; 40 | } 41 | 42 | static inline uint32_t 43 | be32dec(const void *pp) 44 | { 45 | const uint8_t *p = (uint8_t const *)pp; 46 | 47 | return ((uint32_t)(p[3]) + ((uint32_t)(p[2]) << 8) + 48 | ((uint32_t)(p[1]) << 16) + ((uint32_t)(p[0]) << 24)); 49 | } 50 | 51 | static inline void 52 | be32enc(void *pp, uint32_t x) 53 | { 54 | uint8_t * p = (uint8_t *)pp; 55 | 56 | p[3] = x & 0xff; 57 | p[2] = (x >> 8) & 0xff; 58 | p[1] = (x >> 16) & 0xff; 59 | p[0] = (x >> 24) & 0xff; 60 | } 61 | 62 | static inline uint64_t 63 | be64dec(const void *pp) 64 | { 65 | const uint8_t *p = (uint8_t const *)pp; 66 | 67 | return ((uint64_t)(p[7]) + ((uint64_t)(p[6]) << 8) + 68 | ((uint64_t)(p[5]) << 16) + ((uint64_t)(p[4]) << 24) + 69 | ((uint64_t)(p[3]) << 32) + ((uint64_t)(p[2]) << 40) + 70 | ((uint64_t)(p[1]) << 48) + ((uint64_t)(p[0]) << 56)); 71 | } 72 | 73 | static inline void 74 | be64enc(void *pp, uint64_t x) 75 | { 76 | uint8_t * p = (uint8_t *)pp; 77 | 78 | p[7] = x & 0xff; 79 | p[6] = (x >> 8) & 0xff; 80 | p[5] = (x >> 16) & 0xff; 81 | p[4] = (x >> 24) & 0xff; 82 | p[3] = (x >> 32) & 0xff; 83 | p[2] = (x >> 40) & 0xff; 84 | p[1] = (x >> 48) & 0xff; 85 | p[0] = (x >> 56) & 0xff; 86 | } 87 | 88 | static inline uint16_t 89 | le16dec(const void *pp) 90 | { 91 | const uint8_t *p = (uint8_t const *)pp; 92 | 93 | return ((uint16_t)(p[0]) + ((uint16_t)(p[1]) << 8)); 94 | } 95 | 96 | static inline void 97 | le16enc(void *pp, uint16_t x) 98 | { 99 | uint8_t * p = (uint8_t *)pp; 100 | 101 | p[0] = x & 0xff; 102 | p[1] = (x >> 8) & 0xff; 103 | } 104 | 105 | static inline uint32_t 106 | le32dec(const void *pp) 107 | { 108 | const uint8_t *p = (uint8_t const *)pp; 109 | 110 | return ((uint32_t)(p[0]) + ((uint32_t)(p[1]) << 8) + 111 | ((uint32_t)(p[2]) << 16) + ((uint32_t)(p[3]) << 24)); 112 | } 113 | 114 | static inline void 115 | le32enc(void *pp, uint32_t x) 116 | { 117 | uint8_t * p = (uint8_t *)pp; 118 | 119 | p[0] = x & 0xff; 120 | p[1] = (x >> 8) & 0xff; 121 | p[2] = (x >> 16) & 0xff; 122 | p[3] = (x >> 24) & 0xff; 123 | } 124 | 125 | static inline uint64_t 126 | le64dec(const void *pp) 127 | { 128 | const uint8_t *p = (uint8_t const *)pp; 129 | 130 | return ((uint64_t)(p[0]) + ((uint64_t)(p[1]) << 8) + 131 | ((uint64_t)(p[2]) << 16) + ((uint64_t)(p[3]) << 24) + 132 | ((uint64_t)(p[4]) << 32) + ((uint64_t)(p[5]) << 40) + 133 | ((uint64_t)(p[6]) << 48) + ((uint64_t)(p[7]) << 56)); 134 | } 135 | 136 | static inline void 137 | le64enc(void *pp, uint64_t x) 138 | { 139 | uint8_t * p = (uint8_t *)pp; 140 | 141 | p[0] = x & 0xff; 142 | p[1] = (x >> 8) & 0xff; 143 | p[2] = (x >> 16) & 0xff; 144 | p[3] = (x >> 24) & 0xff; 145 | p[4] = (x >> 32) & 0xff; 146 | p[5] = (x >> 40) & 0xff; 147 | p[6] = (x >> 48) & 0xff; 148 | p[7] = (x >> 56) & 0xff; 149 | } 150 | 151 | #endif /* !_SYSENDIAN_H_ */ 152 | 153 | #endif 154 | -------------------------------------------------------------------------------- /toxencryptsave/crypto_pwhash_scryptsalsa208sha256/utils.c: -------------------------------------------------------------------------------- 1 | #ifdef HAVE_CONFIG_H 2 | #include "config.h" 3 | #endif 4 | #ifdef VANILLA_NACL /* toxcore only uses this when libsodium is unavailable */ 5 | 6 | #ifndef __STDC_WANT_LIB_EXT1__ 7 | # define __STDC_WANT_LIB_EXT1__ 1 8 | #endif 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #ifdef HAVE_SYS_MMAN_H 19 | # include 20 | #endif 21 | 22 | #include "utils.h" 23 | 24 | #ifdef _WIN32 25 | # include 26 | # include 27 | #else 28 | # include 29 | #endif 30 | 31 | #ifdef HAVE_WEAK_SYMBOLS 32 | __attribute__((weak)) void 33 | __sodium_dummy_symbol_to_prevent_lto(void * const pnt, const size_t len) 34 | { 35 | (void) pnt; 36 | (void) len; 37 | } 38 | #endif 39 | 40 | void 41 | sodium_memzero(void * const pnt, const size_t len) 42 | { 43 | #ifdef _WIN32 44 | SecureZeroMemory(pnt, len); 45 | #elif defined(HAVE_MEMSET_S) 46 | if (memset_s(pnt, (rsize_t) len, 0, (rsize_t) len) != 0) { 47 | abort(); 48 | } 49 | #elif defined(HAVE_EXPLICIT_BZERO) 50 | explicit_bzero(pnt, len); 51 | #elif HAVE_WEAK_SYMBOLS 52 | memset(pnt, 0, len); 53 | __sodium_dummy_symbol_to_prevent_lto(pnt, len); 54 | #else 55 | volatile unsigned char *pnt_ = (volatile unsigned char *) pnt; 56 | size_t i = (size_t) 0U; 57 | 58 | while (i < len) { 59 | pnt_[i++] = 0U; 60 | } 61 | #endif 62 | } 63 | 64 | int 65 | sodium_memcmp(const void * const b1_, const void * const b2_, size_t len) 66 | { 67 | const unsigned char *b1 = (const unsigned char *) b1_; 68 | const unsigned char *b2 = (const unsigned char *) b2_; 69 | size_t i; 70 | unsigned char d = (unsigned char) 0U; 71 | 72 | for (i = 0U; i < len; i++) { 73 | d |= b1[i] ^ b2[i]; 74 | } 75 | return (int) ((1 & ((d - 1) >> 8)) - 1); 76 | } 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /toxencryptsave/crypto_pwhash_scryptsalsa208sha256/utils.h: -------------------------------------------------------------------------------- 1 | #ifdef HAVE_CONFIG_H 2 | #include "config.h" 3 | #endif 4 | #ifdef VANILLA_NACL /* toxcore only uses this when libsodium is unavailable */ 5 | 6 | #ifndef __SODIUM_UTILS_H__ 7 | #define __SODIUM_UTILS_H__ 8 | 9 | #include 10 | 11 | #include "export.h" 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | #if defined(__cplusplus) || !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L 18 | # define _SODIUM_C99(X) 19 | #else 20 | # define _SODIUM_C99(X) X 21 | #endif 22 | 23 | SODIUM_EXPORT 24 | void sodium_memzero(void * const pnt, const size_t len); 25 | 26 | /* WARNING: sodium_memcmp() must be used to verify if two secret keys 27 | * are equal, in constant time. 28 | * It returns 0 if the keys are equal, and -1 if they differ. 29 | * This function is not designed for lexicographical comparisons. 30 | */ 31 | SODIUM_EXPORT 32 | int sodium_memcmp(const void * const b1_, const void * const b2_, size_t len); 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /toxencryptsave/defines.h: -------------------------------------------------------------------------------- 1 | #define TOX_ENC_SAVE_MAGIC_NUMBER "toxEsave" 2 | #define TOX_ENC_SAVE_MAGIC_LENGTH 8 3 | --------------------------------------------------------------------------------