From 7c70a430f9c708be2fcce8c9a0d8cecde7f75fc0 Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Tue, 23 May 2017 03:49:54 +0200 Subject: changes for proxy --- code/test/stress.c | 53 +++++++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 24 deletions(-) (limited to 'code/test/stress.c') diff --git a/code/test/stress.c b/code/test/stress.c index c278af1..808611e 100644 --- a/code/test/stress.c +++ b/code/test/stress.c @@ -16,7 +16,8 @@ #define NUM_C 256 #define MSG_RATE 65 -#define PTYPE_MSG 16 +#define CTYPE_TEST 0 +#define MTYPE_MSG 8 ECPContext ctx_s; ECPDHKey key_perma_s; @@ -84,7 +85,8 @@ void *sender(ECPConnection *c) { c->sock->ctx->rng(&rnd, sizeof(uint32_t)); usleep(rnd % (2000000/msg_rate)); - ssize_t _rv = ecp_send(c, PTYPE_MSG, payload, 1000); + ecp_pld_set_type(payload, MTYPE_MSG); + ssize_t _rv = ecp_send(c, payload, sizeof(payload)); if (c_start && (_rv > 0)) { pthread_mutex_lock(&t_mtx[idx]); t_sent[idx]++; @@ -93,9 +95,12 @@ void *sender(ECPConnection *c) { } } -ssize_t handle_open_c(ECPConnection *c, unsigned char t, unsigned char *p, ssize_t s) { - int idx = (int)(c->conn_data); - int rv = pthread_create(&s_thd[idx], NULL, (void *(*)(void *))sender, (void *)c); +ssize_t handle_open_c(ECPConnection *conn, unsigned char t, unsigned char *p, ssize_t s) { + int idx = (int)(conn->conn_data); + int rv = 0; + + ecp_conn_handle_open(conn, t, p, s); + rv = pthread_create(&s_thd[idx], NULL, (void *(*)(void *))sender, (void *)conn); if (rv) { char msg[256]; sprintf(msg, "THD %d CREATE\n", idx); @@ -105,8 +110,8 @@ ssize_t handle_open_c(ECPConnection *c, unsigned char t, unsigned char *p, ssize return 0; } -ssize_t handle_msg_c(ECPConnection *c, unsigned char t, unsigned char *p, ssize_t s) { - int idx = (int)(c->conn_data); +ssize_t handle_msg_c(ECPConnection *conn, unsigned char t, unsigned char *p, ssize_t s) { + int idx = (int)(conn->conn_data); unsigned char payload[ECP_SIZE_PLD(1000)]; if (c_start) { @@ -115,21 +120,18 @@ ssize_t handle_msg_c(ECPConnection *c, unsigned char t, unsigned char *p, ssize_ pthread_mutex_unlock(&t_mtx[idx]); } - // ssize_t _rv = ecp_send(c, PTYPE_MSG, payload, 1000); + // ecp_pld_set_type(payload, MTYPE_MSG); + // ssize_t _rv = ecp_send(c, payload, sizeof(payload)); return s; } -ssize_t handle_msg_s(ECPConnection *c, unsigned char t, unsigned char *p, ssize_t s) { +ssize_t handle_msg_s(ECPConnection *conn, unsigned char t, unsigned char *p, ssize_t s) { unsigned char payload[ECP_SIZE_PLD(1000)]; - ssize_t _rv = ecp_send(c, PTYPE_MSG, payload, 1000); + ecp_pld_set_type(payload, MTYPE_MSG); + ssize_t _rv = ecp_send(conn, payload, sizeof(payload)); return s; } -int conn_create(ECPConnection *c, unsigned char *p, size_t s) { - c->handler = &handler_s; - return ECP_OK; -} - int main(int argc, char *argv[]) { char addr[256]; int rv; @@ -165,14 +167,15 @@ int main(int argc, char *argv[]) { sigaction(SIGINFO, &actINFO, NULL); rv = ecp_init(&ctx_s); + if (!rv) rv = ecp_conn_handler_init(&handler_s); + handler_s.msg[MTYPE_MSG] = handle_msg_s; + ctx_s.handler[CTYPE_TEST] = &handler_s; + if (!rv) rv = ecp_dhkey_generate(&ctx_s, &key_perma_s); - if (!rv) rv = ecp_conn_hander_init(&handler_s); - handler_s.f[PTYPE_MSG] = handle_msg_s; for (i=0; i