From 234c44453ba42c4487abecfa74a16b262f6ed9c2 Mon Sep 17 00:00:00 2001 From: Joshua Miller Date: Mon, 14 Oct 2013 00:51:47 -0500 Subject: [PATCH] added delay for auth sign to prevent prematurely reading buffer that was just sent --- src/udtcat.h | 1 + src/udtcat_threads.cpp | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/udtcat.h b/src/udtcat.h index 72914ec..9a379f5 100644 --- a/src/udtcat.h +++ b/src/udtcat.h @@ -38,6 +38,7 @@ typedef struct rs_args{ int use_crypto; int verbose; int n_crypto_threads; + } rs_args; typedef struct thread_args{ diff --git a/src/udtcat_threads.cpp b/src/udtcat_threads.cpp index 06a05c3..c9987ee 100644 --- a/src/udtcat_threads.cpp +++ b/src/udtcat_threads.cpp @@ -69,7 +69,8 @@ void send_full(UDTSOCKET sock, char* buffer, int len){ } -void recv_full(UDTSOCKET sock, char* buffer, int len){ +void recv_full(UDTSOCKET sock, char* buffer, int len) +{ int recvd = 0; int rs = 0; @@ -88,8 +89,11 @@ void recv_full(UDTSOCKET sock, char* buffer, int len){ } const int KEY_LEN = 1026; +int signed_auth; + -void auth_peer(rs_args* args){ +void auth_peer(rs_args* args) +{ char key[KEY_LEN]; @@ -97,8 +101,12 @@ void auth_peer(rs_args* args){ memset(key, 1, KEY_LEN); + signed_auth = 0; + send_full(*args->usocket, key, KEY_LEN); - sleep(.5); + + while (!signed_auth); + recv_full(*args->usocket, signed_key, KEY_LEN); fprintf(stderr, "key: "); print_bytes(key, 16); @@ -118,7 +126,8 @@ void auth_peer(rs_args* args){ } -void sign_auth(rs_args* args){ +void sign_auth(rs_args* args) +{ char key[KEY_LEN]; @@ -136,6 +145,8 @@ void sign_auth(rs_args* args){ send_full(*args->usocket, key, KEY_LEN); + signed_auth = 1; + }