ffi-tox 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1ea0d69f0ac06a753a7fb1299542b5f5ebfe935d
4
+ data.tar.gz: ecbc2f0a1fec17416aa57890fe6be315225d7d18
5
+ SHA512:
6
+ metadata.gz: 68ae7ba6278cb10d41dbe042f59d10304444b25ef7802c0c19919e3ca63a93c86efb6cb5af63cb979906da9f6cacab43ddf85a434092bd550ed41151dbe7ff01
7
+ data.tar.gz: 678b27211d2dd376c8ee8d631c2f44b8da2b9039c68fa535e36bfeeb06dab5554cbc286b356183053fc5d6e61031e1a2f67e429c839bce17f14086bca6a28a41
@@ -1,11 +1,31 @@
1
1
  cmake_minimum_required(VERSION 2.6.0)
2
2
 
3
+ set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
4
+
5
+ if(NOT WIN32)
6
+ option(USE_NACL "Use NaCl library instead of libsodium")
7
+ endif()
8
+
9
+ if(USE_NACL)
10
+ find_package(NaCl REQUIRED)
11
+
12
+ include_directories(${NACL_INCLUDE_DIR})
13
+ add_definitions(-DVANILLA_NACL)
14
+
15
+ set(LINK_CRYPTO_LIBRARY ${NACL_LIBRARIES})
16
+ endif()
17
+
3
18
  #MinGW prints more warnings for -Wall than gcc does, thus causing build to fail
4
19
  if(NOT WIN32)
5
20
  if(("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") OR ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang"))
6
21
  message(STATUS "==== ${CMAKE_C_COMPILER_ID} detected - Adding compiler flags ====")
7
22
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror")
8
23
  endif()
24
+ find_package(SODIUM REQUIRED)
25
+ endif()
26
+
27
+ if(NOT USE_NACL)
28
+ set(LINK_CRYPTO_LIBRARY ${SODIUM_LIBRARY})
9
29
  endif()
10
30
 
11
31
  macro(linkCoreLibraries exe_name)
@@ -16,8 +36,10 @@ macro(linkCoreLibraries exe_name)
16
36
  ${CMAKE_SOURCE_DIR}/sodium/lib/libsodium.a
17
37
  ws2_32)
18
38
  else()
39
+ include_directories(${SODIUM_INCLUDE_DIR})
19
40
  target_link_libraries(${exe_name} core
20
- sodium)
41
+ ${LINK_CRYPTO_LIBRARY})
42
+
21
43
  endif()
22
44
  endmacro()
23
45
 
@@ -25,4 +47,4 @@ cmake_policy(SET CMP0011 NEW)
25
47
 
26
48
  add_subdirectory(core)
27
49
  add_subdirectory(testing)
28
- add_subdirectory(other)
50
+ add_subdirectory(other)
@@ -1,12 +1,25 @@
1
+ #Install Instructions
2
+
3
+ - [Installation](#installation)
4
+ - [Linux](#linux)
5
+ - [OS X](#osx)
6
+ - [Homebrew](#homebrew)
7
+ - [Non-Homebrew](#non-homebrew)
8
+ - [Windows](#windows)
9
+ - [Usage](#usage)
10
+
11
+ <a name="installation" />
1
12
  ##Installation
2
13
 
14
+ <a name="linux" />
3
15
  ###Linux:
4
16
 
5
17
  Build dependencies:
6
18
 
7
19
  ```bash
8
- apt-get install build-essential libtool autotools-dev automake libconfig-dev ncurses-dev cmake
20
+ apt-get install build-essential libtool autotools-dev automake libconfig-dev ncurses-dev cmake checkinstall
9
21
  ```
22
+ Note that `libconfig-dev` should be >= 1.4.
10
23
 
11
24
  You should get and install [libsodium](https://github.com/jedisct1/libsodium):
12
25
  ```bash
@@ -15,15 +28,18 @@ cd libsodium
15
28
  git checkout tags/0.4.2
16
29
  ./autogen.sh
17
30
  ./configure && make check
18
- sudo make install
31
+ sudo checkinstall --install --pkgname libsodium --pkgversion 0.4.2 --nodoc
19
32
  sudo ldconfig
20
33
  ```
21
34
 
22
- Then clone this repo and run:
35
+ Then clone this repo and generate makefile:
23
36
  ```bash
37
+ git clone git://github.com/irungentoo/ProjectTox-Core.git
38
+ cd ProjectTox-Core
24
39
  mkdir build && cd build
25
40
  cmake ..
26
41
  ```
42
+ Note that you should call cmake on the root [`CMakeLists.txt`](/CMakeLists.txt) file only.
27
43
 
28
44
  Then you can build any of the [`/testing`](/testing) and [`/other`](/other) that are currently supported on your platform by running:
29
45
  ```bash
@@ -39,9 +55,22 @@ Or you could just build everything that is supported on your platform by running
39
55
  make
40
56
  ```
41
57
 
42
- ###OSX:
58
+ <a name="osx" />
59
+ ###OS X:
43
60
 
44
- Much the same as above, remember to install the latest XCode and the developer tools (Preferences -> Downloads -> Command Line Tools).
61
+ <a name="homebrew" />
62
+ ####Homebrew:
63
+ ```
64
+ brew install libtool automake autoconf libconfig libsodium cmake
65
+ cmake .
66
+ make
67
+ sudo make install
68
+ ```
69
+
70
+ <a name="non-homebrew" />
71
+ ####Non-homebrew:
72
+
73
+ Much the same as Linux, remember to install the latest XCode and the developer tools (Preferences -> Downloads -> Command Line Tools).
45
74
  Users running Mountain Lion and the latest version of XCode (4.6.3) will also need to install libtool, automake and autoconf.
46
75
  They are easy enough to install, grab them from http://www.gnu.org/software/libtool/, http://www.gnu.org/software/autoconf/ and http://www.gnu.org/software/automake/, then follow these steps for each:
47
76
 
@@ -58,6 +87,7 @@ Another thing you may want to install is the latest gcc, this caused me a few pr
58
87
  no longer includes gcc and instead uses LLVM-GCC, a nice install guide can be found at
59
88
  http://caiustheory.com/install-gcc-421-apple-build-56663-with-xcode-42
60
89
 
90
+ <a name="windows" />
61
91
  ###Windows:
62
92
 
63
93
  You should install:
@@ -75,6 +105,7 @@ Navigate in `cmd` to this repo and run:
75
105
  mkdir build && cd build
76
106
  cmake -G "MinGW Makefiles" ..
77
107
  ```
108
+ Note that you should call cmake on the root [`CMakeLists.txt`](/CMakeLists.txt) file only.
78
109
 
79
110
  Then you can build any of the [`/testing`](/testing) and [`/other`](/other) that are currently supported on your platform by running:
80
111
  ```cmd
@@ -89,3 +120,8 @@ Or you could just build everything that is supported on your platform by running
89
120
  ```bash
90
121
  mingw32-make
91
122
  ```
123
+
124
+ <a name="usage" />
125
+ ## Usage
126
+
127
+ - [Start Guide](start_guide.md)
@@ -1,54 +1,53 @@
1
1
  ![Project Tox](https://rbt.asia/boards/g/img/0352/79/1373823047559.png "Project Tox")
2
- Project Tox, _also known as Tox_, is a FOSS instant messaging application aimed to replace Skype.<br />
2
+ Project Tox, _also known as Tox_, is a FOSS (Free and Open Source Software) instant messaging application aimed to replace Skype.<br />
3
3
 
4
- With the rise of governmental monitoring programs, Tox aims to be an easy to use application that allows people to connect with friends and loved ones without the worry of privacy.<br /> <br />
4
+ With the rise of governmental monitoring programs, Tox aims to be an easy to use, all-in-one communication platform (including audio, and videochats in the future) that ensures their users full privacy and secure message delivery.<br /> <br />
5
5
 
6
6
 
7
7
 
8
-
9
- **IRC**: #tox on Freenode, alternatively, you can use the [webchat](http://webchat.freenode.net/?channels=#tox).<br />
8
+ **IRC**: #tox on freenode, alternatively, you can use the [webchat](http://webchat.freenode.net/?channels=#tox).<br />
10
9
  **Website**: [http://tox.im](http://tox.im)
11
10
 
12
11
  **Website translations**: [see stal888's repository](https://github.com/stal888/ProjectTox-Website)<br/>
13
12
  **Qt GUI**: [see nurupo's repository](https://github.com/nurupo/ProjectTox-Qt-GUI)
14
13
 
14
+ **How to build Tox on Linux**: [YouTube video](http://www.youtube.com/watch?v=M4WXE4VKmyg)<br />
15
+ **How to use Tox on Windows**: [YouTube video](http://www.youtube.com/watch?v=qg_j_sDb6WQ)<br />
16
+ **For Mac OSX read INSTALL.md**
17
+
18
+ ### Objectives:
15
19
 
20
+ Keep everything really simple.
16
21
 
17
22
  ## The Complex Stuff:
18
- + Tox must use UDP simply because you can't hole punch with TCP. It's possible, but it doesn't work all the time.
19
- + Every peer is represented as a byte string (the public key of the peer [client id])
23
+ + Tox must use UDP simply because [hole punching](http://en.wikipedia.org/wiki/UDP_hole_punching) with TCP is not as reliable.
24
+ + Every peer is represented as a [byte string](https://en.wikipedia.org/wiki/String_(computer_science)) (the public key of the peer [client ID]).
20
25
  + We're using torrent-style DHT so that peers can find the IP of the other peers when they have their ID.
21
26
  + Once the client has the IP of that peer, they start initiating a secure connection with each other. (See [Crypto](https://github.com/irungentoo/ProjectTox-Core/wiki/Crypto))
22
- + When both peers are securely connect with the encryption, they can securely exchange messages, initiate a video chat, send files, etc.<br />
23
- + Current build status: [![Build Status](https://travis-ci.org/irungentoo/ProjectTox-Core.png?branch=master)](https://travis-ci.org/irungentoo/ProjectTox-Core)
27
+ + When both peers are securely connected, they can exchange messages, initiate a video chat, send files, etc, all using encrypted communications.
28
+ + Current build status: [![Build Status](https://travis-ci.org/irungentoo/ProjectTox-Core.png?branch=master)](https://travis-ci.org/irungentoo/ProjectTox-Core)
24
29
 
25
30
  ## Roadmap:
26
- - [x] Get our DHT working perfectly.(Done, needs large scale testing though.)
27
- - [x] Reliable connection (See Lossless_UDP protocol) to other peers according to client id. (Done, see DHT_sendfiletest.c for an example)
31
+ - [x] Get our DHT working perfectly. (Done, needs large scale testing though)
32
+ - [x] Reliable connection (See Lossless UDP protocol) to other peers according to client ID. (Done, see `DHT_sendfiletest.c` for an example)
28
33
  - [x] Encryption. (Done)
29
- - [ ] Get a simple text only im client working perfectly. (This is where we are)
30
- - [ ] Streaming media
31
- - [ ] ???
34
+ - [ ] Get a simple text only IM client working perfectly. (This is where we are)
35
+ - [ ] Streaming media
36
+ - [ ] ???
32
37
 
33
38
  For further information, check our [To-do list](https://github.com/irungentoo/ProjectTox-Core/wiki/TODO)
34
39
 
35
-
36
- ### Important-stuff:
37
-
38
- Use the same UDP socket for everything
39
-
40
- Keep everything really simple.
41
-
42
- ### Details and Documents:
43
-
44
- [DHT Protocol](https://github.com/irungentoo/ProjectTox-Core/wiki/DHT)<br />
45
- [Lossless UDP Protocol](https://github.com/irungentoo/ProjectTox-Core/wiki/Lossless-UDP)<br />
46
- [Crypto](https://github.com/irungentoo/ProjectTox-Core/wiki/Crypto)<br />
47
- [Ideas](https://github.com/irungentoo/ProjectTox-Core/wiki/Ideas)
48
-
49
40
  ### Why are you doing this? There are already a bunch of free skype alternatives.
50
- The goal of this project is to create a configuration-free p2p skype
41
+ The goal of this project is to create a configuration-free P2P skype
51
42
  replacement. Configuration-free means that the user will simply have to open the program and
52
43
  without any account configuration will be capable of adding people to his
53
- friends list and start conversing with them. There are many so called skype replacements and all of them are either hard to
54
- configure for the normal user or suffer from being much too centralized.
44
+ friends list and start conversing with them. There are many so-called skype replacements and all of them are either hard to
45
+ configure for the normal user or suffer from being way too centralized.
46
+
47
+ ### Documentation:
48
+
49
+ - [Installation](/INSTALL.md)
50
+ - [DHT Protocol](https://github.com/irungentoo/ProjectTox-Core/wiki/DHT)<br />
51
+ - [Lossless UDP Protocol](https://github.com/irungentoo/ProjectTox-Core/wiki/Lossless-UDP)<br />
52
+ - [Crypto](https://github.com/irungentoo/ProjectTox-Core/wiki/Crypto)<br />
53
+ - [Ideas](https://github.com/irungentoo/ProjectTox-Core/wiki/Ideas)
@@ -0,0 +1,15 @@
1
+ # Find LIBCONFIG
2
+ #
3
+ # LIBCONFIG_INCLUDE_DIR
4
+ # LIBCONFIG_LIBRARY
5
+ # LIBCONFIG_FOUND
6
+ #
7
+
8
+ FIND_PATH(LIBCONFIG_INCLUDE_DIR NAMES libconfig.h)
9
+
10
+ FIND_LIBRARY(LIBCONFIG_LIBRARY NAMES config)
11
+
12
+ INCLUDE(FindPackageHandleStandardArgs)
13
+ FIND_PACKAGE_HANDLE_STANDARD_ARGS(LIBCONFIG DEFAULT_MSG LIBCONFIG_LIBRARY LIBCONFIG_INCLUDE_DIR)
14
+
15
+ MARK_AS_ADVANCED(LIBCONFIG_INCLUDE_DIR LIBCONFIG_LIBRARY)
@@ -0,0 +1,17 @@
1
+ find_path(NACL_INCLUDE_DIR crypto_box.h
2
+ $ENV{NACL_INCLUDE_DIR} /usr/include/nacl/
3
+ DOC "Directory which contain NaCl headers")
4
+
5
+ find_path(NACL_LIBRARY_DIR libnacl.a
6
+ $ENV{NACL_LIBRARY_DIR} /usr/lib/nacl
7
+ DOC "Directory which contain libnacl.a, cpucycles.o, and randombytes.o")
8
+
9
+ if(NACL_LIBRARY_DIR)
10
+ set(NACL_LIBRARIES
11
+ "${NACL_LIBRARY_DIR}/cpucycles.o"
12
+ "${NACL_LIBRARY_DIR}/libnacl.a"
13
+ "${NACL_LIBRARY_DIR}/randombytes.o")
14
+ endif()
15
+
16
+ include(FindPackageHandleStandardArgs)
17
+ find_package_handle_standard_args(NaCl DEFAULT_MSG NACL_INCLUDE_DIR NACL_LIBRARY_DIR NACL_LIBRARIES)
@@ -0,0 +1,15 @@
1
+ # Find SODIUM
2
+ #
3
+ # SODIUM_INCLUDE_DIR
4
+ # SODIUM_LIBRARY
5
+ # SODIUM_FOUND
6
+ #
7
+
8
+ FIND_PATH(SODIUM_INCLUDE_DIR NAMES sodium.h)
9
+
10
+ FIND_LIBRARY(SODIUM_LIBRARY NAMES sodium)
11
+
12
+ INCLUDE(FindPackageHandleStandardArgs)
13
+ FIND_PACKAGE_HANDLE_STANDARD_ARGS(SODIUM DEFAULT_MSG SODIUM_LIBRARY SODIUM_INCLUDE_DIR)
14
+
15
+ MARK_AS_ADVANCED(SODIUM_INCLUDE_DIR SODIUM_LIBRARY)
@@ -3,6 +3,8 @@ project(core C)
3
3
 
4
4
  if(WIN32)
5
5
  include_directories(${CMAKE_HOME_DIRECTORY}/sodium/include/)
6
+ else(WIN32)
7
+ include_directories(${SODIUM_INCLUDE_DIR})
6
8
  endif()
7
9
 
8
10
  set(core_sources
@@ -308,12 +308,16 @@ IP_Port connection_ip(int connection_id)
308
308
  /* returns the number of packets in the queue waiting to be successfully sent. */
309
309
  uint32_t sendqueue(int connection_id)
310
310
  {
311
+ if (connection_id < 0 || connection_id >= MAX_CONNECTIONS)
312
+ return 0;
311
313
  return connections[connection_id].sendbuff_packetnum - connections[connection_id].successful_sent;
312
314
  }
313
315
 
314
316
  /* returns the number of packets in the queue waiting to be successfully read with read_packet(...) */
315
317
  uint32_t recvqueue(int connection_id)
316
318
  {
319
+ if (connection_id < 0 || connection_id >= MAX_CONNECTIONS)
320
+ return 0;
317
321
  return connections[connection_id].recv_packetnum - connections[connection_id].successful_read;
318
322
  }
319
323
 
@@ -321,6 +325,8 @@ uint32_t recvqueue(int connection_id)
321
325
  return -1 if no packet in queue */
322
326
  char id_packet(int connection_id)
323
327
  {
328
+ if (connection_id < 0 || connection_id >= MAX_CONNECTIONS)
329
+ return -1;
324
330
  if (recvqueue(connection_id) != 0 && connections[connection_id].status != 0)
325
331
  return connections[connection_id].recvbuffer[connections[connection_id].successful_read % MAX_QUEUE_NUM].data[0];
326
332
  return -1;
@@ -99,18 +99,21 @@ int getclient_id(int friend_id, uint8_t *client_id)
99
99
  client_id is the client id of the friend
100
100
  data is the data and length is the length
101
101
  returns the friend number if success
102
- return -1 if failure. */
102
+ return -1 if key length is wrong.
103
+ return -2 if user's own key
104
+ return -3 if already a friend
105
+ return -4 for other*/
103
106
  int m_addfriend(uint8_t *client_id, uint8_t *data, uint16_t length)
104
107
  {
105
108
  if (length == 0 || length >=
106
109
  (MAX_DATA_SIZE - crypto_box_PUBLICKEYBYTES - crypto_box_NONCEBYTES - crypto_box_BOXZEROBYTES + crypto_box_ZEROBYTES))
107
110
  return -1;
108
111
  if (memcmp(client_id, self_public_key, crypto_box_PUBLICKEYBYTES) == 0)
109
- return -1;
112
+ return -2;
110
113
  if (getfriend_id(client_id) != -1)
111
- return -1;
114
+ return -3;
112
115
  uint32_t i;
113
- for (i = 0; i <= numfriends; ++i) {
116
+ for (i = 0; i <= numfriends; ++i) { /*TODO: dynamic memory allocation, this will segfault if there are more than MAX_NUM_FRIENDS*/
114
117
  if(friendlist[i].status == 0) {
115
118
  DHT_addfriend(client_id);
116
119
  friendlist[i].status = 1;
@@ -126,7 +129,7 @@ int m_addfriend(uint8_t *client_id, uint8_t *data, uint16_t length)
126
129
  return i;
127
130
  }
128
131
  }
129
- return -1;
132
+ return -4;
130
133
  }
131
134
 
132
135
  int m_addfriend_norequest(uint8_t * client_id)
@@ -134,7 +137,7 @@ int m_addfriend_norequest(uint8_t * client_id)
134
137
  if (getfriend_id(client_id) != -1)
135
138
  return -1;
136
139
  uint32_t i;
137
- for (i = 0; i <= numfriends; ++i) {
140
+ for (i = 0; i <= numfriends; ++i) {/*TODO: dynamic memory allocation, this will segfault if there are more than MAX_NUM_FRIENDS*/
138
141
  if(friendlist[i].status == 0) {
139
142
  DHT_addfriend(client_id);
140
143
  friendlist[i].status = 2;
@@ -163,11 +166,13 @@ int m_delfriend(int friendnumber)
163
166
  free(friendlist[friendnumber].userstatus);
164
167
  memset(&friendlist[friendnumber], 0, sizeof(Friend));
165
168
  uint32_t i;
169
+
166
170
  for (i = numfriends; i != 0; --i) {
167
- if (friendlist[i].status != 0)
171
+ if (friendlist[i-1].status != 0)
168
172
  break;
169
173
  }
170
174
  numfriends = i;
175
+
171
176
  return 0;
172
177
  }
173
178
 
@@ -178,7 +183,7 @@ int m_delfriend(int friendnumber)
178
183
  return 0 if there is no friend with that number */
179
184
  int m_friendstatus(int friendnumber)
180
185
  {
181
- if (friendnumber < 0 || friendnumber >= MAX_NUM_FRIENDS)
186
+ if (friendnumber < 0 || friendnumber >= numfriends)
182
187
  return 0;
183
188
  return friendlist[friendnumber].status;
184
189
  }
@@ -188,7 +193,7 @@ int m_friendstatus(int friendnumber)
188
193
  return 0 if it was not */
189
194
  int m_sendmessage(int friendnumber, uint8_t *message, uint32_t length)
190
195
  {
191
- if (friendnumber < 0 || friendnumber >= MAX_NUM_FRIENDS)
196
+ if (friendnumber < 0 || friendnumber >= numfriends)
192
197
  return 0;
193
198
  if (length >= MAX_DATA_SIZE || friendlist[friendnumber].status != 4)
194
199
  /* this does not mean the maximum message length is MAX_DATA_SIZE - 1, it is actually 17 bytes less. */
@@ -240,6 +245,16 @@ int setname(uint8_t * name, uint16_t length)
240
245
  return 0;
241
246
  }
242
247
 
248
+ /* get our nickname
249
+ put it in name
250
+ name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH bytes.
251
+ return the length of the name */
252
+ uint16_t getself_name(uint8_t *name)
253
+ {
254
+ memcpy(name, self_name, self_name_length);
255
+ return self_name_length;
256
+ }
257
+
243
258
  /* get name of friendnumber
244
259
  put it in name
245
260
  name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH bytes.
@@ -46,11 +46,14 @@ extern "C" {
46
46
  to an absurdly large number later */
47
47
 
48
48
  /* add a friend
49
- set the data that will be sent along with friend request
50
- client_id is the client id of the friend
51
- data is the data and length is the length
52
- returns the friend number if success
53
- return -1 if failure. */
49
+ set the data that will be sent along with friend request
50
+ client_id is the client id of the friend
51
+ data is the data and length is the length
52
+ returns the friend number if success
53
+ return -1 if key length is wrong.
54
+ return -2 if user's own key
55
+ return -3 if already a friend
56
+ return -4 for other*/
54
57
  int m_addfriend(uint8_t *client_id, uint8_t *data, uint16_t length);
55
58
 
56
59
 
@@ -92,6 +95,11 @@ int m_sendmessage(int friendnumber, uint8_t *message, uint32_t length);
92
95
  return -1 if failure */
93
96
  int setname(uint8_t *name, uint16_t length);
94
97
 
98
+ /* get our nickname
99
+ put it in name
100
+ return the length of the name*/
101
+ uint16_t getself_name(uint8_t *name);
102
+
95
103
  /* get name of friendnumber
96
104
  put it in name
97
105
  name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes.