From d830d95720e41b3374dd1edda04ef1ea4272967d Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Sun, 13 Aug 2017 00:22:37 +0200 Subject: proxy renamed to vconn --- code/test/Makefile | 20 +++++------ code/test/init_proxy.c | 42 ----------------------- code/test/init_vconn.c | 42 +++++++++++++++++++++++ code/test/pr_client.c | 91 -------------------------------------------------- code/test/pr_server.c | 80 -------------------------------------------- code/test/proxy.c | 54 ------------------------------ code/test/vc_client.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++ code/test/vc_server.c | 80 ++++++++++++++++++++++++++++++++++++++++++++ code/test/vcs.c | 54 ++++++++++++++++++++++++++++++ 9 files changed, 277 insertions(+), 277 deletions(-) delete mode 100644 code/test/init_proxy.c create mode 100644 code/test/init_vconn.c delete mode 100644 code/test/pr_client.c delete mode 100644 code/test/pr_server.c delete mode 100644 code/test/proxy.c create mode 100644 code/test/vc_client.c create mode 100644 code/test/vc_server.c create mode 100644 code/test/vcs.c (limited to 'code/test') diff --git a/code/test/Makefile b/code/test/Makefile index 8f42021..997f77e 100644 --- a/code/test/Makefile +++ b/code/test/Makefile @@ -1,12 +1,12 @@ -CFLAGS=-I../core -I../proxy -I../util -O3 -Wno-int-to-void-pointer-cast +CFLAGS=-I../core -I../vconn -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 ../proxy/libecpproxy.a ../util/libecputil.a +dep=../core/libecpcore.a ../core/crypto/libecpcr.a ../core/htable/libecpht.a ../core/posix/libecptr.a ../core/posix/libecptm.a ../vconn/libecpvconn.a ../util/libecputil.a %.o: %.c $(CC) $(CFLAGS) -c $< -all: basic client server echo stress proxy pr_server pr_client +all: basic client server echo stress vcs vc_server vc_client basic: basic.o init.o $(dep) $(CC) -o $@ $< init.o $(dep) $(LDFLAGS) @@ -23,14 +23,14 @@ echo: echo.o init.o $(dep) stress: stress.o init.o $(dep) $(CC) -o $@ $< init.o $(dep) $(LDFLAGS) -proxy: proxy.o init_proxy.o $(dep) - $(CC) -o $@ $< init_proxy.o $(dep) $(LDFLAGS) +vcs: vcs.o init_vconn.o $(dep) + $(CC) -o $@ $< init_vconn.o $(dep) $(LDFLAGS) -pr_server: pr_server.o init_proxy.o $(dep) - $(CC) -o $@ $< init_proxy.o $(dep) $(LDFLAGS) +vc_server: vc_server.o init_vconn.o $(dep) + $(CC) -o $@ $< init_vconn.o $(dep) $(LDFLAGS) -pr_client: pr_client.o init_proxy.o $(dep) - $(CC) -o $@ $< init_proxy.o $(dep) $(LDFLAGS) +vc_client: vc_client.o init_vconn.o $(dep) + $(CC) -o $@ $< init_vconn.o $(dep) $(LDFLAGS) opus_root=../../../opus-1.1.5 @@ -42,4 +42,4 @@ voip: voip.o init.o $(dep) clean: rm -f *.o - rm -f basic client server echo stress proxy pr_server pr_client voip + rm -f basic client server echo stress vcs vc_server vc_client voip diff --git a/code/test/init_proxy.c b/code/test/init_proxy.c deleted file mode 100644 index c7f560d..0000000 --- a/code/test/init_proxy.c +++ /dev/null @@ -1,42 +0,0 @@ -#include -#include -#include - -#include "core.h" -#include "proxy.h" - -static int v_rng(void *buf, size_t bufsize) { - int fd; - - if((fd = open("/dev/urandom", O_RDONLY)) < 0) return -1; - size_t nb = read(fd, buf, bufsize); - close(fd); - if (nb != bufsize) return -1; - return 0; -} - -static ECPConnection *conn_alloc(unsigned char type) { - switch (type) { - case ECP_CTYPE_PROXYF: - return malloc(sizeof(ECPConnProxyF)); - default: - return malloc(sizeof(ECPConnection)); - } -} - -static void conn_free(ECPConnection *conn) { - free(conn); -} - -int ecp_init(ECPContext *ctx) { - int rv; - - rv = ecp_ctx_create(ctx); - if (rv) return rv; - - ctx->rng = v_rng; - ctx->conn_alloc = conn_alloc; - ctx->conn_free = conn_free; - - return ecp_proxy_init(ctx); -} \ No newline at end of file diff --git a/code/test/init_vconn.c b/code/test/init_vconn.c new file mode 100644 index 0000000..2e82598 --- /dev/null +++ b/code/test/init_vconn.c @@ -0,0 +1,42 @@ +#include +#include +#include + +#include "core.h" +#include "vconn.h" + +static int v_rng(void *buf, size_t bufsize) { + int fd; + + if((fd = open("/dev/urandom", O_RDONLY)) < 0) return -1; + size_t nb = read(fd, buf, bufsize); + close(fd); + if (nb != bufsize) return -1; + return 0; +} + +static ECPConnection *conn_alloc(unsigned char type) { + switch (type) { + case ECP_CTYPE_VCONN: + return malloc(sizeof(ECPVConnIn)); + default: + return malloc(sizeof(ECPConnection)); + } +} + +static void conn_free(ECPConnection *conn) { + free(conn); +} + +int ecp_init(ECPContext *ctx) { + int rv; + + rv = ecp_ctx_create(ctx); + if (rv) return rv; + + ctx->rng = v_rng; + ctx->conn_alloc = conn_alloc; + ctx->conn_free = conn_free; + + return ecp_ctx_vconn_init(ctx); +} \ No newline at end of file diff --git a/code/test/pr_client.c b/code/test/pr_client.c deleted file mode 100644 index d643dd3..0000000 --- a/code/test/pr_client.c +++ /dev/null @@ -1,91 +0,0 @@ -#include -#include -#include -#include - -#include "core.h" -#include "proxy.h" -#include "util.h" - -ECPContext ctx; -ECPSocket sock; -ECPConnHandler handler; - -ECPConnection conn; -ECPNode node; - -ECPConnProxy conn_proxy[20]; -ECPNode node_proxy[20]; - -#define CTYPE_TEST 0 -#define MTYPE_MSG 8 - -ssize_t handle_open(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s) { - uint32_t seq = 0; - - ecp_conn_handle_open(conn, sq, t, p, s); - if (s < 0) { - printf("OPEN ERR:%ld\n", s); - return s; - } - - 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 s; -} - -ssize_t handle_msg(ECPConnection *conn, ecp_seq_t sq, 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 ... \n", arg); - exit(1); -} - -int main(int argc, char *argv[]) { - int rv, i; - - if ((argc < 3) || (argc > 22)) 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); - - for (i=0; i -#include -#include -#include - -#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, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s) { - printf("OPEN RECEIVED\n"); - return ecp_conn_handle_open(conn, sq, t, p, s); -} - -ssize_t handle_msg(ECPConnection *conn, ecp_seq_t sq, 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 \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 deleted file mode 100644 index ae7cce5..0000000 --- a/code/test/proxy.c +++ /dev/null @@ -1,54 +0,0 @@ -#include -#include -#include -#include - -#include "core.h" -#include "util.h" -#include "proxy.h" - -ECPContext ctx; -ECPSocket sock; -ECPDHKey key_perma; - -ECPNode node; -ECPConnection conn; - -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 < 3) || (argc > 4)) usage(argv[0]); - - rv = ecp_init(&ctx); - printf("ecp_init RV:%d\n", rv); - - rv = ecp_util_key_load(&ctx, &key_perma, argv[2]); - 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, argv[1]); - printf("ecp_sock_open RV:%d\n", rv); - - rv = ecp_start_receiver(&sock); - printf("ecp_start_receiver RV:%d\n", rv); - - if (argc == 4) { - rv = ecp_util_node_load(&ctx, &node, argv[3]); - 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/vc_client.c b/code/test/vc_client.c new file mode 100644 index 0000000..586fec5 --- /dev/null +++ b/code/test/vc_client.c @@ -0,0 +1,91 @@ +#include +#include +#include +#include + +#include "core.h" +#include "vconn.h" +#include "util.h" + +ECPContext ctx; +ECPSocket sock; +ECPConnHandler handler; + +ECPConnection conn; +ECPNode node; + +ECPVConnection vconn[20]; +ECPNode vconn_node[20]; + +#define CTYPE_TEST 0 +#define MTYPE_MSG 8 + +ssize_t handle_open(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s) { + uint32_t seq = 0; + + ecp_conn_handle_open(conn, sq, t, p, s); + if (s < 0) { + printf("OPEN ERR:%ld\n", s); + return s; + } + + 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 s; +} + +ssize_t handle_msg(ECPConnection *conn, ecp_seq_t sq, 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 ... \n", arg); + exit(1); +} + +int main(int argc, char *argv[]) { + int rv, i; + + if ((argc < 3) || (argc > 22)) 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); + + for (i=0; i +#include +#include +#include + +#include "core.h" +#include "vconn.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, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s) { + printf("OPEN RECEIVED\n"); + return ecp_conn_handle_open(conn, sq, t, p, s); +} + +ssize_t handle_msg(ECPConnection *conn, ecp_seq_t sq, 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 \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_VLINK); + 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/vcs.c b/code/test/vcs.c new file mode 100644 index 0000000..1dbf67d --- /dev/null +++ b/code/test/vcs.c @@ -0,0 +1,54 @@ +#include +#include +#include +#include + +#include "core.h" +#include "util.h" +#include "vconn.h" + +ECPContext ctx; +ECPSocket sock; +ECPDHKey key_perma; + +ECPNode node; +ECPConnection conn; + +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 < 3) || (argc > 4)) usage(argv[0]); + + rv = ecp_init(&ctx); + printf("ecp_init RV:%d\n", rv); + + rv = ecp_util_key_load(&ctx, &key_perma, argv[2]); + 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, argv[1]); + printf("ecp_sock_open RV:%d\n", rv); + + rv = ecp_start_receiver(&sock); + printf("ecp_start_receiver RV:%d\n", rv); + + if (argc == 4) { + rv = ecp_util_node_load(&ctx, &node, argv[3]); + printf("ecp_util_node_load RV:%d\n", rv); + + rv = ecp_conn_create(&conn, &sock, ECP_CTYPE_VLINK); + 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 -- cgit v1.2.3