diff options
author | Uros Majstorovic <majstor@majstor.org> | 2017-05-23 22:24:50 +0200 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2017-05-23 22:24:50 +0200 |
commit | b4c8007d3b2082c757ae42008e915872c8ebe671 (patch) | |
tree | cd218340840a0a05779703357742b0c2c92e1b6b /code/test | |
parent | ab0325ae7906230f1ea82f08b27c72b075e9a13d (diff) |
proxy passed test; various bug fixes
Diffstat (limited to 'code/test')
-rw-r--r-- | code/test/Makefile | 23 | ||||
-rw-r--r-- | code/test/basic.c | 2 | ||||
-rw-r--r-- | code/test/client.c | 81 | ||||
-rw-r--r-- | code/test/pr_client.c | 89 | ||||
-rw-r--r-- | code/test/pr_server.c | 80 | ||||
-rw-r--r-- | code/test/proxy.c | 39 | ||||
-rw-r--r-- | code/test/server.c | 61 | ||||
-rw-r--r-- | code/test/stress.c | 2 |
8 files changed, 371 insertions, 6 deletions
diff --git a/code/test/Makefile b/code/test/Makefile index ddfc095..a6ebb90 100644 --- a/code/test/Makefile +++ b/code/test/Makefile @@ -1,12 +1,18 @@ -CFLAGS=-I../core -O3 -Wno-int-to-void-pointer-cast +CFLAGS=-I../core -I../proxy -I../util -O3 -Wno-int-to-void-pointer-cast LDFLAGS=-lm -pthread -dep=../core/libecpcore.a ../core/crypto/libecpcr.a ../core/htable/libecpht.a ../core/posix/libecptr.a ../core/posix/libecptm.a +dep=../core/libecpcore.a ../core/crypto/libecpcr.a ../core/htable/libecpht.a ../core/posix/libecptr.a ../core/posix/libecptm.a ../proxy/libecpproxy.a ../util/libecputil.a %.o: %.c $(CC) $(CFLAGS) -c $< -all: basic stress +all: client server basic stress proxy pr_server pr_client + +client: client.o init.o $(dep) + $(CC) -o $@ $(LDFLAGS) $< init.o $(dep) + +server: server.o init.o $(dep) + $(CC) -o $@ $(LDFLAGS) $< init.o $(dep) basic: basic.o init.o $(dep) $(CC) -o $@ $(LDFLAGS) $< init.o $(dep) @@ -14,6 +20,15 @@ basic: basic.o init.o $(dep) stress: stress.o init.o $(dep) $(CC) -o $@ $(LDFLAGS) $< init.o $(dep) +proxy: proxy.o init_proxy.o $(dep) + $(CC) -o $@ $(LDFLAGS) $< init_proxy.o $(dep) + +pr_server: pr_server.o init_proxy.o $(dep) + $(CC) -o $@ $(LDFLAGS) $< init_proxy.o $(dep) + +pr_client: pr_client.o init_proxy.o $(dep) + $(CC) -o $@ $(LDFLAGS) $< init_proxy.o $(dep) + clean: rm -f *.o - rm -f basic stress + rm -f basic stress client server proxy pr_server pr_client diff --git a/code/test/basic.c b/code/test/basic.c index bcd65bc..36dfc2e 100644 --- a/code/test/basic.c +++ b/code/test/basic.c @@ -2,7 +2,7 @@ #include <string.h> #include <unistd.h> -#include <core.h> +#include "core.h" ECPContext ctx_s; ECPSocket sock_s; diff --git a/code/test/client.c b/code/test/client.c index e69de29..3f33d71 100644 --- a/code/test/client.c +++ b/code/test/client.c @@ -0,0 +1,81 @@ +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <stdlib.h> + +#include "core.h" +#include "util.h" + +ECPContext ctx_c; +ECPSocket sock_c; +ECPConnHandler handler_c; + +ECPNode node; +ECPConnection conn; + +#define CTYPE_TEST 0 +#define MTYPE_MSG 8 + +ssize_t handle_open_c(ECPConnection *conn, unsigned char t, unsigned char *p, ssize_t s) { + uint32_t seq = 0; + + ecp_conn_handle_open(conn, t, p, s); + if (s < 0) { + printf("OPEN ERR:%ld\n", s); + return 0; + } + + unsigned char payload[ECP_SIZE_PLD(1000)]; + unsigned char *buf = ecp_pld_get_buf(payload); + char *msg = "PERA JE CAR!"; + + ecp_pld_set_type(payload, MTYPE_MSG); + strcpy((char *)buf, msg); + ssize_t _rv = ecp_send(conn, payload, sizeof(payload)); + return 0; +} + +ssize_t handle_msg_c(ECPConnection *conn, unsigned char t, unsigned char *p, ssize_t s) { + printf("MSG C:%s size:%ld\n", p, s); + return s; +} + + +static void usage(char *arg) { + fprintf(stderr, "Usage: %s <node.pub>\n", arg); + exit(1); +} + +int main(int argc, char *argv[]) { + int rv; + + if (argc != 2) usage(argv[0]); + + rv = ecp_init(&ctx_c); + printf("ecp_init RV:%d\n", rv); + + rv = ecp_conn_handler_init(&handler_c); + handler_c.msg[ECP_MTYPE_OPEN] = handle_open_c; + handler_c.msg[MTYPE_MSG] = handle_msg_c; + ctx_c.handler[CTYPE_TEST] = &handler_c; + + rv = ecp_sock_create(&sock_c, &ctx_c, NULL); + printf("ecp_sock_create RV:%d\n", rv); + + rv = ecp_sock_open(&sock_c, NULL); + printf("ecp_sock_open RV:%d\n", rv); + + rv = ecp_start_receiver(&sock_c); + printf("ecp_start_receiver RV:%d\n", rv); + + rv = ecp_util_node_load(&ctx_c, &node, argv[1]); + printf("ecp_util_node_load RV:%d\n", rv); + + rv = ecp_conn_create(&conn, &sock_c, CTYPE_TEST); + printf("ecp_conn_create RV:%d\n", rv); + + rv = ecp_conn_open(&conn, &node); + printf("ecp_conn_open RV:%d\n", rv); + + while (1) sleep(1); +}
\ No newline at end of file diff --git a/code/test/pr_client.c b/code/test/pr_client.c new file mode 100644 index 0000000..a40831c --- /dev/null +++ b/code/test/pr_client.c @@ -0,0 +1,89 @@ +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <stdlib.h> + +#include "core.h" +#include "proxy.h" +#include "util.h" + +ECPContext ctx; +ECPSocket sock; +ECPConnHandler handler; + +ECPConnection conn; +ECPNode node; + +ECPConnProxy conn_proxy; +ECPNode node_proxy; + +#define CTYPE_TEST 0 +#define MTYPE_MSG 8 + +ssize_t handle_open(ECPConnection *conn, unsigned char t, unsigned char *p, ssize_t s) { + uint32_t seq = 0; + + ecp_conn_handle_open(conn, t, p, s); + if (s < 0) { + printf("OPEN ERR:%ld\n", s); + return 0; + } + + printf("OPEN!\n"); + + unsigned char payload[ECP_SIZE_PLD(1000)]; + unsigned char *buf = ecp_pld_get_buf(payload); + char *msg = "PERA JE CAR!"; + + ecp_pld_set_type(payload, MTYPE_MSG); + strcpy((char *)buf, msg); + ssize_t _rv = ecp_send(conn, payload, sizeof(payload)); + return 0; +} + +ssize_t handle_msg(ECPConnection *conn, unsigned char t, unsigned char *p, ssize_t s) { + printf("MSG S:%s size:%ld\n", p, s); + return s; +} + +static void usage(char *arg) { + fprintf(stderr, "Usage: %s <server.pub> <proxy.pub>\n", arg); + exit(1); +} + +int main(int argc, char *argv[]) { + int rv; + + if (argc != 3) usage(argv[0]); + + rv = ecp_init(&ctx); + printf("ecp_init RV:%d\n", rv); + + rv = ecp_conn_handler_init(&handler); + handler.msg[ECP_MTYPE_OPEN] = handle_open; + handler.msg[MTYPE_MSG] = handle_msg; + ctx.handler[CTYPE_TEST] = &handler; + + rv = ecp_sock_create(&sock, &ctx, NULL); + printf("ecp_sock_create RV:%d\n", rv); + + rv = ecp_sock_open(&sock, NULL); + printf("ecp_sock_open RV:%d\n", rv); + + rv = ecp_start_receiver(&sock); + printf("ecp_start_receiver RV:%d\n", rv); + + rv = ecp_util_node_load(&ctx, &node, argv[1]); + printf("ecp_util_node_load RV:%d\n", rv); + + rv = ecp_util_node_load(&ctx, &node_proxy, argv[2]); + printf("ecp_util_node_load RV:%d\n", rv); + + rv = ecp_conn_create(&conn, &sock, CTYPE_TEST); + printf("ecp_conn_create RV:%d\n", rv); + + rv = ecp_conn_proxy_open(&conn, &node, &conn_proxy, &node_proxy, 1); + printf("ecp_conn_proxy_open RV:%d\n", rv); + + while (1) sleep(1); +}
\ No newline at end of file diff --git a/code/test/pr_server.c b/code/test/pr_server.c new file mode 100644 index 0000000..0f898ce --- /dev/null +++ b/code/test/pr_server.c @@ -0,0 +1,80 @@ +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <stdlib.h> + +#include "core.h" +#include "proxy.h" +#include "util.h" + +ECPContext ctx; +ECPSocket sock; +ECPDHKey key_perma; +ECPConnHandler handler; + +ECPNode node; +ECPConnection conn; + +#define CTYPE_TEST 0 +#define MTYPE_MSG 8 + +ssize_t handle_open(ECPConnection *conn, unsigned char t, unsigned char *p, ssize_t s) { + printf("OPEN RECEIVED\n"); + return ecp_conn_handle_open(conn, t, p, s); +} + +ssize_t handle_msg(ECPConnection *conn, unsigned char t, unsigned char *p, ssize_t s) { + printf("MSG S:%s size:%ld\n", p, s); + + unsigned char payload[ECP_SIZE_PLD(1000)]; + unsigned char *buf = ecp_pld_get_buf(payload); + char *msg = "VAISTINU JE CAR!"; + + ecp_pld_set_type(payload, MTYPE_MSG); + strcpy((char *)buf, msg); + ssize_t _rv = ecp_send(conn, payload, sizeof(payload)); + + return s; +} + +static void usage(char *arg) { + fprintf(stderr, "Usage: %s <node.priv> <proxy.pub>\n", arg); + exit(1); +} + +int main(int argc, char *argv[]) { + int rv; + + if (argc != 3) usage(argv[0]); + + rv = ecp_init(&ctx); + printf("ecp_init RV:%d\n", rv); + + rv = ecp_conn_handler_init(&handler); + handler.msg[ECP_MTYPE_OPEN] = handle_open; + handler.msg[MTYPE_MSG] = handle_msg; + ctx.handler[CTYPE_TEST] = &handler; + + rv = ecp_util_key_load(&ctx, &key_perma, argv[1]); + printf("ecp_util_key_load RV:%d\n", rv); + + rv = ecp_sock_create(&sock, &ctx, &key_perma); + printf("ecp_sock_create RV:%d\n", rv); + + rv = ecp_sock_open(&sock, NULL); + printf("ecp_sock_open RV:%d\n", rv); + + rv = ecp_start_receiver(&sock); + printf("ecp_start_receiver RV:%d\n", rv); + + rv = ecp_util_node_load(&ctx, &node, argv[2]); + printf("ecp_util_node_load RV:%d\n", rv); + + rv = ecp_conn_create(&conn, &sock, ECP_CTYPE_PROXYB); + printf("ecp_conn_create RV:%d\n", rv); + + rv = ecp_conn_open(&conn, &node); + printf("ecp_conn_open RV:%d\n", rv); + + while (1) sleep(1); +}
\ No newline at end of file diff --git a/code/test/proxy.c b/code/test/proxy.c new file mode 100644 index 0000000..cfea6c1 --- /dev/null +++ b/code/test/proxy.c @@ -0,0 +1,39 @@ +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <stdlib.h> + +#include "core.h" +#include "util.h" + +ECPContext ctx; +ECPSocket sock; +ECPDHKey key_perma; + +static void usage(char *arg) { + fprintf(stderr, "Usage: %s <node.priv> [address]\n", arg); + exit(1); +} + +int main(int argc, char *argv[]) { + int rv; + + if (argc != 2) usage(argv[0]); + + rv = ecp_init(&ctx); + printf("ecp_init RV:%d\n", rv); + + rv = ecp_util_key_load(&ctx, &key_perma, argv[1]); + printf("ecp_util_key_load RV:%d\n", rv); + + rv = ecp_sock_create(&sock, &ctx, &key_perma); + printf("ecp_sock_create RV:%d\n", rv); + + rv = ecp_sock_open(&sock, "0.0.0.0:3000"); + printf("ecp_sock_open RV:%d\n", rv); + + rv = ecp_start_receiver(&sock); + printf("ecp_start_receiver RV:%d\n", rv); + + while (1) sleep(1); +}
\ No newline at end of file diff --git a/code/test/server.c b/code/test/server.c new file mode 100644 index 0000000..71ec2ef --- /dev/null +++ b/code/test/server.c @@ -0,0 +1,61 @@ +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <stdlib.h> + +#include "core.h" +#include "util.h" + +ECPContext ctx_s; +ECPSocket sock_s; +ECPDHKey key_perma_s; +ECPConnHandler handler_s; + +#define CTYPE_TEST 0 +#define MTYPE_MSG 8 + +ssize_t handle_msg_s(ECPConnection *conn, unsigned char t, unsigned char *p, ssize_t s) { + printf("MSG S:%s size:%ld\n", p, s); + + unsigned char payload[ECP_SIZE_PLD(1000)]; + unsigned char *buf = ecp_pld_get_buf(payload); + char *msg = "VAISTINU JE CAR!"; + + ecp_pld_set_type(payload, MTYPE_MSG); + strcpy((char *)buf, msg); + ssize_t _rv = ecp_send(conn, payload, sizeof(payload)); + + return s; +} + +static void usage(char *arg) { + fprintf(stderr, "Usage: %s <node.priv> [address]\n", arg); + exit(1); +} + +int main(int argc, char *argv[]) { + int rv; + + if (argc != 2) usage(argv[0]); + + rv = ecp_init(&ctx_s); + printf("ecp_init RV:%d\n", rv); + + rv = ecp_conn_handler_init(&handler_s); + handler_s.msg[MTYPE_MSG] = handle_msg_s; + ctx_s.handler[CTYPE_TEST] = &handler_s; + + rv = ecp_util_key_load(&ctx_s, &key_perma_s, argv[1]); + printf("ecp_util_key_load RV:%d\n", rv); + + rv = ecp_sock_create(&sock_s, &ctx_s, &key_perma_s); + printf("ecp_sock_create RV:%d\n", rv); + + rv = ecp_sock_open(&sock_s, "0.0.0.0:3000"); + printf("ecp_sock_open RV:%d\n", rv); + + rv = ecp_start_receiver(&sock_s); + printf("ecp_start_receiver RV:%d\n", rv); + + while (1) sleep(1); +}
\ No newline at end of file diff --git a/code/test/stress.c b/code/test/stress.c index 41883c2..c76ebe9 100644 --- a/code/test/stress.c +++ b/code/test/stress.c @@ -6,7 +6,7 @@ #include <sys/time.h> #include <pthread.h> -#include <core.h> +#include "core.h" #ifdef __linux__ #define SIGINFO SIGTSTP |