#ifndef __COMMON_H__
#define __COMMON_H__

#include <string.h>
#include <stdlib.h>
#include <assert.h>

#ifdef DEBUG
#include <stdio.h>
#endif

#define PORT                           1443
#define SERVER                         "localhost"
#define CLIENT                         "localhost"
#define CACERT                         "etc/ca/ca.cert.pem"
//#define CERT_HOSTNAME                  "www.cert_testing.com"
#define CERT_HOSTNAME                  "www.dmv.com"
#define KEYFILE_PASS                   "test123"
#define READ_REQUEST                   "ReadRequest"
#define HANDHAKE_REPS                  200
// Keep random data file must at least same size as a buffer size
#define RANDOM_DATA_FILE               "etc/random_data"
#define BUFFER_SIZE                    1024
// Amount bytes of plaintext data exchanged in read-write stets is BUFFER_SIZE*RW_ITERATOIONS
#ifdef DEBUG
#define RW_ITERATIONS                  (1024*10) // 10 MB
#else
#define RW_ITERATIONS                  (1024*200) // 1GB
#endif
// Utils
#define LOG_I(...)                                                              \
    do {                                                                        \
        (void) fprintf(stdout, "[%s() %s:%d] ", __func__, __FILE__, __LINE__);  \
        (void) fprintf(stdout, __VA_ARGS__);                                    \
        (void) fprintf(stdout, "\n");                                           \
    } while (0)
#define ERR(...)            \
    do {                    \
        LOG_I(__VA_ARGS__);   \
        exit(-1);           \
    } while (0)

#define LOG(...) LOG_I(__VA_ARGS__)

#ifdef DEBUG
#define DBG(...) LOG_I(__VA_ARGS__)
#else
#define DBG(...)
#endif

#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))

int connect_once(const char* IP);
void init(void);
void cleanup(void);
void fill_buffer_from_file(unsigned char *b, size_t sz);

// Available tests
void test_Write(const char*, const char*);
void test_Read(const char*, const char*);
void test_Handshake(const char*, const char*, size_t);

#endif // __COMMON_H__