1
0

Reorganised the main() func.

This commit is contained in:
Alexander Andreev 2024-03-26 17:44:35 +04:00
parent de1d4085b9
commit 9e9b0ba047
Signed by: Arav
GPG Key ID: 25969B23DCB5CA34

View File

@ -17,8 +17,6 @@ void usage(void) {
}
int main(int argc, char **argv) {
int ret = 0;
if (argc < 4) {
usage();
return -1;
@ -35,42 +33,30 @@ int main(int argc, char **argv) {
char *addr = argv[2];
char *port = argv[3];
if (direction != 'c' && direction != 's') {
usage();
return -1;
}
int result = 0;
net_t n;
crypt_session_t s;
crypt_key_t ok, rk;
if (crypt_key_gen(&ok) == -1) {
ret = -1;
if ((result = crypt_key_gen(&ok)) == -1)
goto cleanup;
}
if (direction == 'c') {
if (net_client_init(&n, addr, port) == -1) {
ret = -1;
(direction == 'c') ?
(result = net_client_init(&n, addr, port))
: (result = net_server_init(&n, addr, port));
if (result != 0)
goto cleanup;
}
int res = client_handshake(&n, &s, &ok, &rk);
if (res != 0) {
ret = res;
(direction == 'c') ?
(result = client_handshake(&n, &s, &ok, &rk))
: (result = server_handshake(&n, &s, &ok, &rk));
if (result != 0)
goto cleanup;
}
} else if (direction == 's') {
if (net_server_init(&n, addr, port) == -1) {
ret = -1;
goto cleanup;
}
int res = server_handshake(&n, &s, &ok, &rk);
if (res != 0) {
ret = -1;
goto cleanup;
}
} else {
usage();
}
fprintf(stderr, "A connection established!\n");
@ -84,7 +70,7 @@ cleanup:
// if (audio_terminate_soundsystem() == -1)
// return -1;
return ret;
return result;
}
int handshake(const unsigned char * hello, const char * remote_hello, crypt_session_t *const s, crypt_key_t *const ok, crypt_key_t *const rk) {