summaryrefslogtreecommitdiff
path: root/client.c
diff options
context:
space:
mode:
authorGDR! <gdr@gdr.name>2015-06-19 21:54:59 +0200
committerGDR! <gdr@gdr.name>2015-06-19 21:54:59 +0200
commit8d4dd7660af8cd3856d0d54d92386ce3ef1bc333 (patch)
treedaad5c239d82553a876359087d9e62be60952eab /client.c
parent8f9376b7ab3f9fca1514eb63c7ae7d545042b168 (diff)
PSK authentication
Diffstat (limited to 'client.c')
-rw-r--r--client.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/client.c b/client.c
index d2ef837..929e2f5 100644
--- a/client.c
+++ b/client.c
@@ -1,3 +1,4 @@
1#include <time.h>
1#include "log.h" 2#include "log.h"
2#include "main.h" 3#include "main.h"
3#include "client.h" 4#include "client.h"
@@ -220,6 +221,7 @@ int do_client_loop(char *tox_id_str)
220 uint32_t friendnumber; 221 uint32_t friendnumber;
221 struct timeval tv; 222 struct timeval tv;
222 fd_set fds; 223 fd_set fds;
224 static time_t invitation_sent_time = 0;
223 TOX_ERR_FRIEND_QUERY friend_query_error; 225 TOX_ERR_FRIEND_QUERY friend_query_error;
224 TOX_ERR_FRIEND_CUSTOM_PACKET custom_packet_error; 226 TOX_ERR_FRIEND_CUSTOM_PACKET custom_packet_error;
225 227
@@ -260,10 +262,18 @@ int do_client_loop(char *tox_id_str)
260 break; 262 break;
261 case CLIENT_STATE_CONNECTED: 263 case CLIENT_STATE_CONNECTED:
262 { 264 {
263 uint8_t data[] = "Hi, fellow tuntox instance!"; 265 uint8_t* data = "Hi, fellow tuntox instance!";
264 uint16_t length = sizeof(data); 266 uint16_t length = sizeof(data);
265 TOX_ERR_FRIEND_ADD add_error; 267 TOX_ERR_FRIEND_ADD add_error;
266 268
269 if(use_shared_secret)
270 {
271 data = shared_secret;
272 data[TOX_MAX_FRIEND_REQUEST_LENGTH-1] = '\0';
273 length = strlen(data)+1;
274 log_printf(L_DEBUG, "Sent shared secret of length %u\n", length);
275 }
276
267 log_printf(L_INFO, "Connected. Sending friend request.\n"); 277 log_printf(L_INFO, "Connected. Sending friend request.\n");
268 278
269 friendnumber = tox_friend_add( 279 friendnumber = tox_friend_add(
@@ -274,12 +284,15 @@ int do_client_loop(char *tox_id_str)
274 &add_error 284 &add_error
275 ); 285 );
276 286
277 if(friendnumber == UINT32_MAX) 287 if(add_error != TOX_ERR_FRIEND_ADD_OK)
278 { 288 {
279 log_printf(L_ERROR, "Error %u adding friend %s\n", add_error, tox_id); 289 unsigned char tox_printable_id[TOX_ADDRESS_SIZE * 2 + 1];
290 id_to_string(tox_printable_id, tox_id);
291 log_printf(L_ERROR, "Error %u adding friend %s\n", add_error, tox_printable_id);
280 exit(-1); 292 exit(-1);
281 } 293 }
282 294
295 invitation_sent_time = time(NULL);
283 state = CLIENT_STATE_SENTREQUEST; 296 state = CLIENT_STATE_SENTREQUEST;
284 log_printf(L_INFO, "Waiting for friend to accept us...\n"); 297 log_printf(L_INFO, "Waiting for friend to accept us...\n");
285 } 298 }
@@ -302,6 +315,11 @@ int do_client_loop(char *tox_id_str)
302 } 315 }
303 else 316 else
304 { 317 {
318 if(0 && (time(NULL) - invitation_sent_time > 60))
319 {
320 log_printf(L_INFO, "Sending another friend request...");
321 state = CLIENT_STATE_CONNECTED;
322 }
305 } 323 }
306 } 324 }
307 break; 325 break;