From 53081df814e070a64482f163e6808b1fa5092f00 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Sun, 24 Nov 2024 04:15:48 +0400 Subject: [PATCH] Commented addrbook code in main. Uncommented audio code in main. --- src/main.c | 52 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/src/main.c b/src/main.c index 265f102..3458d9b 100644 --- a/src/main.c +++ b/src/main.c @@ -91,8 +91,7 @@ void cleanup(void) { crypt_key_destroy(&ok); crypt_key_destroy(&rk); - // if (audio_terminate_soundsystem() == -1) - // return 1; + audio_terminate_soundsystem(); } void signal_handler(int signo) { @@ -122,9 +121,9 @@ int main(int argc, const char **argv) { return 1; } - // if (audio_init_soundsystem() == -1) - // return 1; - + if (audio_init_soundsystem() == -1) + return 1; +/* FILE *addrbook_file = fopen(opts.addressbook_path, "r"); if (addrbook_file != NULL) { addrbook_load(&ab, addrbook_file); @@ -143,6 +142,8 @@ int main(int argc, const char **argv) { } } + addrbook_destroy(&ab); +*/ FILE *pkey_file = fopen(opts.key_pub_path, "r"); FILE *skey_file = fopen(opts.key_sec_path, "r"); if (pkey_file == NULL || skey_file == NULL) { @@ -198,6 +199,7 @@ int main(int argc, const char **argv) { if (signal(SIGSEGV, signal_handler) == SIG_ERR) fprintf(stderr, "Cannot catch SIGSEGV.\n"); + (opts.mode == 'c') ? (result = net_client_init(&n, opts.addr, opts.port)) : (result = net_server_init(&n, opts.addr , opts.port)); @@ -216,26 +218,32 @@ int main(int argc, const char **argv) { fprintf(stdout, "A connection with %s established!\n", rkph); - unsigned char aud_buf[AUDIO_BUF_SIZE]; - memset(aud_buf, 0, AUDIO_BUF_SIZE); + unsigned char aud_buf[AUDIO_BUF_SIZE] = {0}; + unsigned long long aud_buf_len = AUDIO_BUF_SIZE; + unsigned char aud_c_buf[CLEN(AUDIO_BUF_SIZE)] = {0}; + unsigned long long aud_c_buf_len = CLEN(AUDIO_BUF_SIZE); - // audio_init_default(&aud, CHANNELS, SAMPLE_RATE, FRAMES_PER_BUFFFER); + audio_init_default(&aud, CHANNELS, SAMPLE_RATE, FRAMES_PER_BUFFFER); - // (opts.mode == 'c') ? - // (audio_stream_input_toggle(&aud)) - // : (audio_stream_output_toggle(&aud)); - - // for (size_t i = 0; i < (20 * SAMPLE_RATE)/FRAMES_PER_BUFFFER; ++i) { - // if (opts.mode == 'c') { - // audio_read(&aud, aud_buf, AUDIO_BUF_SIZE); - // } else { - // // - // } - // } + (opts.mode == 'c') ? + (audio_stream_input_toggle(&aud)) + : (audio_stream_output_toggle(&aud)); - // (opts.mode == 'c') ? - // (audio_stream_input_toggle(&aud)) - // : (audio_stream_output_toggle(&aud)); + for (size_t i = 0; i < (10 * SAMPLE_RATE)/FRAMES_PER_BUFFFER; ++i) { + if (opts.mode == 'c') { + audio_read(&aud, aud_buf, AUDIO_BUF_SIZE); + crypt_session_encrypt(&s, aud_buf, AUDIO_BUF_SIZE, aud_c_buf, &aud_c_buf_len); + net_send(&n, aud_c_buf, aud_c_buf_len); + } else { + net_recv(&n, &aud_c_buf, aud_c_buf_len); + crypt_session_decrypt(&s, aud_c_buf, aud_c_buf_len, aud_buf, &aud_buf_len); + audio_write(&aud, aud_buf, aud_buf_len); + } + } + + (opts.mode == 'c') ? + (audio_stream_input_toggle(&aud)) + : (audio_stream_output_toggle(&aud)); cleanup: