summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--INSTALL.md24
-rw-r--r--core/Messenger.c62
-rw-r--r--core/Messenger.h15
-rw-r--r--testing/nTox_win32.c15
4 files changed, 66 insertions, 50 deletions
diff --git a/INSTALL.md b/INSTALL.md
index 87451948..d6a5b3f9 100644
--- a/INSTALL.md
+++ b/INSTALL.md
@@ -57,21 +57,30 @@ make
57<a name="osx" /> 57<a name="osx" />
58###OS X: 58###OS X:
59 59
60You need the latest XCode with the Developer Tools (Preferences -> Downloads -> Command Line Tools).
61The following libraries are required along with libsodium and cmake for Mountain Lion and XCode 4.6.3 install libtool, automake and autoconf. You can download them with Homebrew, or install them manually.
62
63There are no binaries/executables going to /bin/ or /usr/bin/ now. Everything is compiled and ran from the inside your local branch. See [Usage](#usage) below.
64
60<a name="homebrew" /> 65<a name="homebrew" />
61####Homebrew: 66####Homebrew:
62``` 67```
63brew install libtool automake autoconf libconfig libsodium cmake 68brew install libtool automake autoconf libconfig libsodium cmake
64cmake . 69cmake .
65make 70make
66sudo make install
67``` 71```
68 72
69<a name="non-homebrew" /> 73<a name="non-homebrew" />
70####Non-homebrew: 74####Non-homebrew:
71 75
72Much the same as Linux, remember to install the latest XCode and the developer tools (Preferences -> Downloads -> Command Line Tools). 76Grab the following packages:
73Users running Mountain Lion and the latest version of XCode (4.6.3) will also need to install libtool, automake and autoconf. 77 * http://www.gnu.org/software/libtool/
74They 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: 78 * http://www.gnu.org/software/autoconf/
79 * http://www.gnu.org/software/automake/
80 * http://www.cmake.org/
81 * https://github.com/jedisct1/libsodium
82
83Uncompress and install them all. Make sure to follow the README as the instructions change, but they all follow the same pattern below:
75 84
76```bash 85```bash
77./configure 86./configure
@@ -79,6 +88,13 @@ make
79sudo make install 88sudo make install
80``` 89```
81 90
91In your local TOX repository:
92
93```bash
94cmake .
95make
96```
97
82Do not install them from macports (or any dependencies for that matter) as they get shoved in the wrong directory 98Do not install them from macports (or any dependencies for that matter) as they get shoved in the wrong directory
83and make your life more annoying. 99and make your life more annoying.
84 100
diff --git a/core/Messenger.c b/core/Messenger.c
index e60357c8..c768633e 100644
--- a/core/Messenger.c
+++ b/core/Messenger.c
@@ -94,30 +94,30 @@ int getclient_id(int friend_id, uint8_t *client_id)
94 * client_id is the client id of the friend 94 * client_id is the client id of the friend
95 * data is the data and length is the length 95 * data is the data and length is the length
96 * returns the friend number if success 96 * returns the friend number if success
97 * return -1 if message length is too long 97 * return FA_TOOLONG if message length is too long
98 * return -2 if no message (message length must be >= 1 byte) 98 * return FAERR_NOMESSAGE if no message (message length must be >= 1 byte)
99 * return -3 if user's own key 99 * return FAERR_OWNKEY if user's own key
100 * return -4 if friend request already sent or already a friend 100 * return FAERR_ALREADYSENT if friend request already sent or already a friend
101 * return -5 for unknown error 101 * return FAERR_UNKNOWN for unknown error
102 */ 102 */
103int m_addfriend(uint8_t *client_id, uint8_t *data, uint16_t length) 103int m_addfriend(uint8_t *client_id, uint8_t *data, uint16_t length)
104{ 104{
105 if (length >= (MAX_DATA_SIZE - crypto_box_PUBLICKEYBYTES 105 if (length >= (MAX_DATA_SIZE - crypto_box_PUBLICKEYBYTES
106 - crypto_box_NONCEBYTES - crypto_box_BOXZEROBYTES 106 - crypto_box_NONCEBYTES - crypto_box_BOXZEROBYTES
107 + crypto_box_ZEROBYTES)) 107 + crypto_box_ZEROBYTES))
108 return -1; 108 return FAERR_TOOLONG;
109 if (length < 1) 109 if (length < 1)
110 return -2; 110 return FAERR_NOMESSAGE;
111 if (memcmp(client_id, self_public_key, crypto_box_PUBLICKEYBYTES) == 0) 111 if (memcmp(client_id, self_public_key, crypto_box_PUBLICKEYBYTES) == 0)
112 return -3; 112 return FAERR_OWNKEY;
113 if (getfriend_id(client_id) != -1) 113 if (getfriend_id(client_id) != -1)
114 return -4; 114 return FAERR_ALREADYSENT;
115 115
116 uint32_t i; 116 uint32_t i;
117 for (i = 0; i <= numfriends; ++i) { /*TODO: dynamic memory allocation, this will segfault if there are more than MAX_NUM_FRIENDS*/ 117 for (i = 0; i <= numfriends; ++i) { /*TODO: dynamic memory allocation, this will segfault if there are more than MAX_NUM_FRIENDS*/
118 if(friendlist[i].status == 0) { 118 if(friendlist[i].status == NOFRIEND) {
119 DHT_addfriend(client_id); 119 DHT_addfriend(client_id);
120 friendlist[i].status = 1; 120 friendlist[i].status = FRIEND_ADDED;
121 friendlist[i].crypt_connection_id = -1; 121 friendlist[i].crypt_connection_id = -1;
122 friendlist[i].friend_request_id = -1; 122 friendlist[i].friend_request_id = -1;
123 memcpy(friendlist[i].client_id, client_id, CLIENT_ID_SIZE); 123 memcpy(friendlist[i].client_id, client_id, CLIENT_ID_SIZE);
@@ -130,7 +130,7 @@ int m_addfriend(uint8_t *client_id, uint8_t *data, uint16_t length)
130 return i; 130 return i;
131 } 131 }
132 } 132 }
133 return -5; 133 return FAERR_UNKNOWN;
134} 134}
135 135
136int m_addfriend_norequest(uint8_t * client_id) 136int m_addfriend_norequest(uint8_t * client_id)
@@ -139,9 +139,9 @@ int m_addfriend_norequest(uint8_t * client_id)
139 return -1; 139 return -1;
140 uint32_t i; 140 uint32_t i;
141 for (i = 0; i <= numfriends; ++i) {/*TODO: dynamic memory allocation, this will segfault if there are more than MAX_NUM_FRIENDS*/ 141 for (i = 0; i <= numfriends; ++i) {/*TODO: dynamic memory allocation, this will segfault if there are more than MAX_NUM_FRIENDS*/
142 if(friendlist[i].status == 0) { 142 if(friendlist[i].status == NOFRIEND) {
143 DHT_addfriend(client_id); 143 DHT_addfriend(client_id);
144 friendlist[i].status = 2; 144 friendlist[i].status = FRIEND_REQUESTED;
145 friendlist[i].crypt_connection_id = -1; 145 friendlist[i].crypt_connection_id = -1;
146 friendlist[i].friend_request_id = -1; 146 friendlist[i].friend_request_id = -1;
147 memcpy(friendlist[i].client_id, client_id, CLIENT_ID_SIZE); 147 memcpy(friendlist[i].client_id, client_id, CLIENT_ID_SIZE);
@@ -169,7 +169,7 @@ int m_delfriend(int friendnumber)
169 uint32_t i; 169 uint32_t i;
170 170
171 for (i = numfriends; i != 0; --i) { 171 for (i = numfriends; i != 0; --i) {
172 if (friendlist[i-1].status != 0) 172 if (friendlist[i-1].status != NOFRIEND)
173 break; 173 break;
174 } 174 }
175 numfriends = i; 175 numfriends = i;
@@ -177,15 +177,15 @@ int m_delfriend(int friendnumber)
177 return 0; 177 return 0;
178} 178}
179 179
180/* return 4 if friend is online 180/* return FRIEND_ONLINE if friend is online
181 return 3 if friend is confirmed 181 return FRIEND_CONFIRMED if friend is confirmed
182 return 2 if the friend request was sent 182 return FRIEND_REQUESTED if the friend request was sent
183 return 1 if the friend was added 183 return FRIEND_ADDED if the friend was added
184 return 0 if there is no friend with that number */ 184 return NOFRIEND if there is no friend with that number */
185int m_friendstatus(int friendnumber) 185int m_friendstatus(int friendnumber)
186{ 186{
187 if (friendnumber < 0 || friendnumber >= numfriends) 187 if (friendnumber < 0 || friendnumber >= numfriends)
188 return 0; 188 return NOFRIEND;
189 return friendlist[friendnumber].status; 189 return friendlist[friendnumber].status;
190} 190}
191 191
@@ -196,7 +196,7 @@ int m_sendmessage(int friendnumber, uint8_t *message, uint32_t length)
196{ 196{
197 if (friendnumber < 0 || friendnumber >= numfriends) 197 if (friendnumber < 0 || friendnumber >= numfriends)
198 return 0; 198 return 0;
199 if (length >= MAX_DATA_SIZE || friendlist[friendnumber].status != 4) 199 if (length >= MAX_DATA_SIZE || friendlist[friendnumber].status != FRIEND_ONLINE)
200 /* this does not mean the maximum message length is MAX_DATA_SIZE - 1, it is actually 17 bytes less. */ 200 /* this does not mean the maximum message length is MAX_DATA_SIZE - 1, it is actually 17 bytes less. */
201 return 0; 201 return 0;
202 uint8_t temp[MAX_DATA_SIZE]; 202 uint8_t temp[MAX_DATA_SIZE];
@@ -385,15 +385,15 @@ static void doFriends()
385 int len; 385 int len;
386 uint8_t temp[MAX_DATA_SIZE]; 386 uint8_t temp[MAX_DATA_SIZE];
387 for (i = 0; i < numfriends; ++i) { 387 for (i = 0; i < numfriends; ++i) {
388 if (friendlist[i].status == 1) { 388 if (friendlist[i].status == FRIEND_ADDED) {
389 int fr = send_friendrequest(friendlist[i].client_id, friendlist[i].info, friendlist[i].info_size); 389 int fr = send_friendrequest(friendlist[i].client_id, friendlist[i].info, friendlist[i].info_size);
390 if (fr == 0) /* TODO: This needs to be fixed so that it sends the friend requests a couple of times in case of packet loss */ 390 if (fr == 0) /* TODO: This needs to be fixed so that it sends the friend requests a couple of times in case of packet loss */
391 friendlist[i].status = 2; 391 friendlist[i].status = FRIEND_REQUESTED;
392 else if (fr > 0) 392 else if (fr > 0)
393 friendlist[i].status = 2; 393 friendlist[i].status = FRIEND_REQUESTED;
394 } 394 }
395 if (friendlist[i].status == 2 || friendlist[i].status == 3) { /* friend is not online */ 395 if (friendlist[i].status == FRIEND_REQUESTED || friendlist[i].status == FRIEND_CONFIRMED) { /* friend is not online */
396 if (friendlist[i].status == 2) { 396 if (friendlist[i].status == FRIEND_REQUESTED) {
397 if (friendlist[i].friend_request_id + 10 < unix_time()) { /*I know this is hackish but it should work.*/ 397 if (friendlist[i].friend_request_id + 10 < unix_time()) { /*I know this is hackish but it should work.*/
398 send_friendrequest(friendlist[i].client_id, friendlist[i].info, friendlist[i].info_size); 398 send_friendrequest(friendlist[i].client_id, friendlist[i].info, friendlist[i].info_size);
399 friendlist[i].friend_request_id = unix_time(); 399 friendlist[i].friend_request_id = unix_time();
@@ -406,7 +406,7 @@ static void doFriends()
406 friendlist[i].crypt_connection_id = crypto_connect(friendlist[i].client_id, friendip); 406 friendlist[i].crypt_connection_id = crypto_connect(friendlist[i].client_id, friendip);
407 break; 407 break;
408 case 3: /* Connection is established */ 408 case 3: /* Connection is established */
409 friendlist[i].status = 4; 409 friendlist[i].status = FRIEND_ONLINE;
410 break; 410 break;
411 case 4: 411 case 4:
412 crypto_kill(friendlist[i].crypt_connection_id); 412 crypto_kill(friendlist[i].crypt_connection_id);
@@ -416,7 +416,7 @@ static void doFriends()
416 break; 416 break;
417 } 417 }
418 } 418 }
419 while (friendlist[i].status == 4) { /* friend is online */ 419 while (friendlist[i].status == FRIEND_ONLINE) { /* friend is online */
420 if (friendlist[i].name_sent == 0) { 420 if (friendlist[i].name_sent == 0) {
421 if (m_sendname(i, self_name, self_name_length)) 421 if (m_sendname(i, self_name, self_name_length))
422 friendlist[i].name_sent = 1; 422 friendlist[i].name_sent = 1;
@@ -456,7 +456,7 @@ static void doFriends()
456 if (is_cryptoconnected(friendlist[i].crypt_connection_id) == 4) { /* if the connection timed out, kill it */ 456 if (is_cryptoconnected(friendlist[i].crypt_connection_id) == 4) { /* if the connection timed out, kill it */
457 crypto_kill(friendlist[i].crypt_connection_id); 457 crypto_kill(friendlist[i].crypt_connection_id);
458 friendlist[i].crypt_connection_id = -1; 458 friendlist[i].crypt_connection_id = -1;
459 friendlist[i].status = 3; 459 friendlist[i].status = FRIEND_CONFIRMED;
460 } 460 }
461 break; 461 break;
462 } 462 }
@@ -477,7 +477,7 @@ static void doInbound()
477 friendlist[friend_id].crypt_connection_id = 477 friendlist[friend_id].crypt_connection_id =
478 accept_crypto_inbound(inconnection, public_key, secret_nonce, session_key); 478 accept_crypto_inbound(inconnection, public_key, secret_nonce, session_key);
479 479
480 friendlist[friend_id].status = 3; 480 friendlist[friend_id].status = FRIEND_CONFIRMED;
481 } 481 }
482 } 482 }
483} 483}
diff --git a/core/Messenger.h b/core/Messenger.h
index 3f144ff4..acf62a32 100644
--- a/core/Messenger.h
+++ b/core/Messenger.h
@@ -42,6 +42,21 @@ extern "C" {
42#define PACKET_ID_USERSTATUS 49 42#define PACKET_ID_USERSTATUS 49
43#define PACKET_ID_MESSAGE 64 43#define PACKET_ID_MESSAGE 64
44 44
45/* status definitions */
46#define FRIEND_ONLINE 4
47#define FRIEND_CONFIRMED 3
48#define FRIEND_REQUESTED 2
49#define FRIEND_ADDED 1
50#define NOFRIEND 0
51
52/* errors for m_addfriend
53 * FAERR - Friend Add Error */
54#define FAERR_TOOLONG -1
55#define FAERR_NOMESSAGE -2
56#define FAERR_OWNKEY -3
57#define FAERR_ALREADYSENT -4
58#define FAERR_UNKNOWN -5
59
45/* don't assume MAX_USERSTATUS_LENGTH will stay at 128, it may be increased 60/* don't assume MAX_USERSTATUS_LENGTH will stay at 128, it may be increased
46 to an absurdly large number later */ 61 to an absurdly large number later */
47 62
diff --git a/testing/nTox_win32.c b/testing/nTox_win32.c
index 42780923..27fc6ff3 100644
--- a/testing/nTox_win32.c
+++ b/testing/nTox_win32.c
@@ -151,21 +151,6 @@ void line_eval(char* line)
151 else if (inpt_command == 'l') { 151 else if (inpt_command == 'l') {
152 int activefriends = 0; 152 int activefriends = 0;
153 int i; 153 int i;
154
155 for (i = 0; i <= getnumfriends(); i++)
156 {
157 if (m_friendstatus(i) == 4)
158 activefriends++;
159 }
160
161 printf("\n[i] Friend List | Total: %d\n\n", activefriends);
162
163 for (i = 0; i <= getnumfriends(); i++) {
164 char name[MAX_NAME_LENGTH];
165 getname(i, (uint8_t*)name);
166 if (m_friendstatus(i) == 4)
167 printf("[%d] %s\n\n", i, (uint8_t*)name);
168 }
169 } 154 }
170 155
171 else if (inpt_command == 'd') { 156 else if (inpt_command == 'd') {