From 3caa77e7dae8ece7564085968c06e5cb4e1a8181 Mon Sep 17 00:00:00 2001 From: Treeki Date: Mon, 20 Jan 2014 09:26:38 +0100 Subject: move global TLS init into a separate function --- core.cpp | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/core.cpp b/core.cpp index 71857d3..b67f0a2 100644 --- a/core.cpp +++ b/core.cpp @@ -700,20 +700,12 @@ void Server::close() { } -int main(int argc, char **argv) { - clientCount = 0; - for (int i = 0; i < CLIENT_LIMIT; i++) - clients[i] = NULL; - serverCount = 0; - for (int i = 0; i < SERVER_LIMIT; i++) - servers[i] = NULL; - - +bool initTLS() { int ret; ret = gnutls_global_init(); if (ret != GNUTLS_E_SUCCESS) { printf("gnutls_global_init failure: %s\n", gnutls_strerror(ret)); - return 1; + return false; } unsigned int bits = gnutls_sec_param_to_pk_bits(GNUTLS_PK_DH, GNUTLS_SEC_PARAM_LEGACY); @@ -721,25 +713,41 @@ int main(int argc, char **argv) { ret = gnutls_dh_params_init(&dh_params); if (ret != GNUTLS_E_SUCCESS) { printf("dh_params_init failure: %s\n", gnutls_strerror(ret)); - return 1; + return false; } ret = gnutls_dh_params_generate2(dh_params, bits); if (ret != GNUTLS_E_SUCCESS) { printf("dh_params_generate2 failure: %s\n", gnutls_strerror(ret)); - return 1; + return false; } gnutls_certificate_allocate_credentials(&clientCreds); ret = gnutls_certificate_set_x509_key_file(clientCreds, "ssl_test.crt", "ssl_test.key", GNUTLS_X509_FMT_PEM); if (ret != GNUTLS_E_SUCCESS) { printf("set_x509_key_file failure: %s\n", gnutls_strerror(ret)); - return 1; + return false; } gnutls_certificate_set_dh_params(clientCreds, dh_params); gnutls_certificate_allocate_credentials(&serverCreds); + return true; +} + + +int main(int argc, char **argv) { + clientCount = 0; + for (int i = 0; i < CLIENT_LIMIT; i++) + clients[i] = NULL; + serverCount = 0; + for (int i = 0; i < SERVER_LIMIT; i++) + servers[i] = NULL; + + + if (!initTLS()) + return 0; + DNS::start(); -- cgit v1.2.3