summaryrefslogtreecommitdiff
path: root/ecp/test
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2024-05-14 23:09:36 +0200
committerUros Majstorovic <majstor@majstor.org>2024-05-14 23:09:36 +0200
commit6d50a8bff1938a8d7f398275a886aca37d6f6a7c (patch)
tree9a292e5c35b509bd0f4eda52d995ab37edf90590 /ecp/test
parent5769607dabd338973110d0ecd51b3d61f5f305ff (diff)
tests improved logging; add dir client test
Diffstat (limited to 'ecp/test')
-rw-r--r--ecp/test/Makefile7
-rw-r--r--ecp/test/basic.c27
-rw-r--r--ecp/test/client.c16
-rw-r--r--ecp/test/dir.c65
-rw-r--r--ecp/test/init.h2
-rw-r--r--ecp/test/init_vconn.h2
-rw-r--r--ecp/test/server.c12
-rw-r--r--ecp/test/vc_client.c20
-rw-r--r--ecp/test/vc_common.c4
-rw-r--r--ecp/test/vc_server.c22
-rw-r--r--ecp/test/vcs.c20
11 files changed, 135 insertions, 62 deletions
diff --git a/ecp/test/Makefile b/ecp/test/Makefile
index 3e5effe..3fc85d1 100644
--- a/ecp/test/Makefile
+++ b/ecp/test/Makefile
@@ -3,9 +3,9 @@ include $(src_dir)/ecp/common.mk
CFLAGS += -I../util
dep = ../build-posix/*.a ../util/libecputil.a
-target = basic client server
+target = basic client server dir
ifeq ($(with_htable),yes)
-target += vc_inb vc_outb vcs vc_server vc_client
+target += vcs vc_server vc_client vc_inb vc_outb
endif
@@ -23,6 +23,9 @@ client: client.o init.o $(dep)
server: server.o init.o $(dep)
$(CC) -o $@ $< init.o $(dep) $(LDFLAGS)
+dir: dir.o $(dep)
+ $(CC) -o $@ $< init.o $(dep) $(LDFLAGS)
+
vc_inb: vc_inb.o vc_common.o init_vconn.o $(dep)
$(CC) -o $@ $< vc_common.o init_vconn.o $(dep) $(LDFLAGS)
diff --git a/ecp/test/basic.c b/ecp/test/basic.c
index 2e6bfd0..68cc604 100644
--- a/ecp/test/basic.c
+++ b/ecp/test/basic.c
@@ -1,3 +1,4 @@
+#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
@@ -53,52 +54,52 @@ int main(int argc, char *argv[]) {
/* server */
rv = ecp_init(&ctx_s);
- printf("ecp_init RV:%d\n", rv);
+ LOG("ecp_init", rv);
ecp_conn_handler_init(&handler_s, NULL, NULL, handle_msg_s, NULL);
ecp_ctx_set_handler(&ctx_s, CTYPE_TEST, &handler_s);
rv = ecp_dhkey_gen(&key_perma_s);
- printf("ecp_dhkey_gen RV:%d\n", rv);
+ LOG("ecp_dhkey_gen", rv);
rv = ecp_sock_create(&sock_s, &ctx_s, &key_perma_s);
- printf("ecp_sock_create RV:%d\n", rv);
+ LOG("ecp_sock_create", rv);
rv = ecp_addr_init(&addr, "0.0.0.0:3000");
- printf("ecp_addr_init RV:%d\n", rv);
+ LOG("ecp_addr_init", rv);
rv = ecp_sock_open(&sock_s, &addr);
- printf("ecp_sock_open RV:%d\n", rv);
+ LOG("ecp_sock_open", rv);
rv = ecp_start_receiver(&sock_s);
- printf("ecp_start_receiver RV:%d\n", rv);
+ LOG("ecp_start_receiver", rv);
/* client */
rv = ecp_init(&ctx_c);
- printf("ecp_init RV:%d\n", rv);
+ LOG("ecp_init", rv);
ecp_conn_handler_init(&handler_c, handle_open_c, NULL, handle_msg_c, NULL);
ecp_ctx_set_handler(&ctx_c, CTYPE_TEST, &handler_c);
rv = ecp_dhkey_gen(&key_perma_c);
- printf("ecp_dhkey_gen RV:%d\n", rv);
+ LOG("ecp_dhkey_gen", rv);
rv = ecp_sock_create(&sock_c, &ctx_c, &key_perma_c);
- printf("ecp_sock_create RV:%d\n", rv);
+ LOG("ecp_sock_create", rv);
rv = ecp_sock_open(&sock_c, NULL);
- printf("ecp_sock_open RV:%d\n", rv);
+ LOG("ecp_sock_open", rv);
rv = ecp_start_receiver(&sock_c);
- printf("ecp_start_receiver RV:%d\n", rv);
+ LOG("ecp_start_receiver", rv);
ecp_node_init(&node, &key_perma_s.public, NULL);
rv = ecp_node_set_addr(&node, "127.0.0.1:3000");
- printf("ecp_node_set_addr RV:%d\n", rv);
+ LOG("ecp_node_set_addr", rv);
ecp_conn_init(&conn, &sock_c, CTYPE_TEST);
rv = ecp_conn_open(&conn, &node);
- printf("ecp_conn_open RV:%d\n", rv);
+ LOG("ecp_conn_open", rv);
while (1) sleep(1);
}
diff --git a/ecp/test/client.c b/ecp/test/client.c
index 0236f97..eb39c92 100644
--- a/ecp/test/client.c
+++ b/ecp/test/client.c
@@ -47,33 +47,33 @@ int main(int argc, char *argv[]) {
if (argc != 3) usage(argv[0]);
rv = ecp_init(&ctx);
- printf("ecp_init RV:%d\n", rv);
+ LOG("ecp_init", rv);
ecp_conn_handler_init(&handler, handle_open, NULL, handle_msg, NULL);
ecp_ctx_set_handler(&ctx, CTYPE_TEST, &handler);
rv = ecp_dhkey_gen(&key_perma);
- printf("ecp_dhkey_gen RV:%d\n", rv);
+ LOG("ecp_dhkey_gen", rv);
rv = ecp_sock_create(&sock, &ctx, &key_perma);
- printf("ecp_sock_create RV:%d\n", rv);
+ LOG("ecp_sock_create", rv);
rv = ecp_sock_open(&sock, NULL);
- printf("ecp_sock_open RV:%d\n", rv);
+ LOG("ecp_sock_open", rv);
rv = ecp_start_receiver(&sock);
- printf("ecp_start_receiver RV:%d\n", rv);
+ LOG("ecp_start_receiver", rv);
rv = ecp_util_load_key(argv[2], &node_pub, NULL);
- printf("ecp_util_load_key RV:%d\n", rv);
+ LOG("ecp_util_load_key", rv);
ecp_node_init(&node, &node_pub, NULL);
rv = ecp_node_set_addr(&node, argv[1]);
- printf("ecp_node_set_addr RV:%d\n", rv);
+ LOG("ecp_node_set_addr", rv);
ecp_conn_init(&conn, &sock, CTYPE_TEST);
rv = ecp_conn_open(&conn, &node);
- printf("ecp_conn_open RV:%d\n", rv);
+ LOG("ecp_conn_open", rv);
while (1) sleep(1);
}
diff --git a/ecp/test/dir.c b/ecp/test/dir.c
new file mode 100644
index 0000000..099ecbb
--- /dev/null
+++ b/ecp/test/dir.c
@@ -0,0 +1,65 @@
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdio.h>
+
+#include <ecp/core.h>
+#include <ecp/dir/dir.h>
+#include <ecp/dir/dir_client.h>
+
+#include <util.h>
+
+ECPContext ctx;
+ECPSocket sock;
+ECPConnection conn;
+ECPConnHandler dir_handler;
+
+#define LOG(fmt, rv) { printf(fmt " RV:%d\n", rv); if (rv) exit(1); }
+
+static void handle_err(ECPConnection *conn, unsigned char mtype, int err) {
+ printf("ERROR: CTYPE:0x%x MTYPE:0x%x ERR:%d\n", conn->type, mtype, err);
+}
+
+static void print_list(ECPDirList *dir_list, int err) {
+ ecp_dir_list_destroy(dir_list);
+}
+
+static void usage(char *arg) {
+ fprintf(stderr, "Usage: %s <address> <node.priv>\n", arg);
+ exit(1);
+}
+
+int main(int argc, char *argv[]) {
+ ECPNode node;
+ ecp_ecdh_public_t node_pub;
+ int rv;
+
+ if (argc != 3) usage(argv[0]);
+
+ rv = ecp_ctx_init(&ctx, NULL, NULL, NULL, handle_err);
+ LOG("ecp_ctx_init", rv);
+
+ rv = ecp_dir_set_handler(&ctx, &dir_handler, print_list);
+ LOG("ecp_dir_ctx_init", rv);
+
+ rv = ecp_sock_create(&sock, &ctx, NULL);
+ LOG("ecp_sock_create", rv);
+
+ rv = ecp_sock_open(&sock, NULL);
+ LOG("ecp_sock_open", rv);
+
+ rv = ecp_start_receiver(&sock);
+ LOG("ecp_start_receiver", rv);
+
+ rv = ecp_util_load_key(argv[2], &node_pub, NULL);
+ LOG("ecp_util_load_key", rv);
+
+ ecp_node_init(&node, &node_pub, NULL);
+ rv = ecp_node_set_addr(&node, argv[1]);
+ LOG("ecp_node_set_addr", rv);
+
+ rv = ecp_dir_get(&conn, &sock, &node, 0);
+ LOG("ecp_dir_get", rv);
+
+ while(1) pause();
+}
diff --git a/ecp/test/init.h b/ecp/test/init.h
index a1a21d1..7edba6e 100644
--- a/ecp/test/init.h
+++ b/ecp/test/init.h
@@ -1 +1,3 @@
+#define LOG(fmt, rv) { printf(fmt " RV:%d\n", rv); if (rv) exit(1); }
+
int ecp_init(ECPContext *ctx); \ No newline at end of file
diff --git a/ecp/test/init_vconn.h b/ecp/test/init_vconn.h
index 64e3269..06f10e2 100644
--- a/ecp/test/init_vconn.h
+++ b/ecp/test/init_vconn.h
@@ -1 +1,3 @@
+#define LOG(fmt, rv) { printf(fmt " RV:%d\n", rv); if (rv) exit(1); }
+
int ecp_init(ECPContext *ctx, ECPConnHandler *vconn_handler, ECPConnHandler *vlink_handler); \ No newline at end of file
diff --git a/ecp/test/server.c b/ecp/test/server.c
index 0af41c6..9943adb 100644
--- a/ecp/test/server.c
+++ b/ecp/test/server.c
@@ -41,26 +41,26 @@ int main(int argc, char *argv[]) {
if (argc != 3) usage(argv[0]);
rv = ecp_init(&ctx);
- printf("ecp_init RV:%d\n", rv);
+ LOG("ecp_init", rv);
ecp_conn_handler_init(&handler, NULL, NULL, handle_msg, NULL);
ecp_ctx_set_handler(&ctx, CTYPE_TEST, &handler);
rv = ecp_util_load_key(argv[2], &key_perma.public, &key_perma.private);
- printf("ecp_util_load_key RV:%d\n", rv);
+ LOG("ecp_util_load_key", rv);
key_perma.valid = 1;
rv = ecp_sock_create(&sock, &ctx, &key_perma);
- printf("ecp_sock_create RV:%d\n", rv);
+ LOG("ecp_sock_create", rv);
rv = ecp_addr_init(&addr, argv[1]);
- printf("ecp_addr_init RV:%d\n", rv);
+ LOG("ecp_addr_init", rv);
rv = ecp_sock_open(&sock, &addr);
- printf("ecp_sock_open RV:%d\n", rv);
+ LOG("ecp_sock_open", rv);
rv = ecp_start_receiver(&sock);
- printf("ecp_start_receiver RV:%d\n", rv);
+ LOG("ecp_start_receiver", rv);
while (1) sleep(1);
}
diff --git a/ecp/test/vc_client.c b/ecp/test/vc_client.c
index d157081..f46824b 100644
--- a/ecp/test/vc_client.c
+++ b/ecp/test/vc_client.c
@@ -52,42 +52,42 @@ int main(int argc, char *argv[]) {
if ((argc < 4) || (argc > 6)) usage(argv[0]);
rv = ecp_init(&ctx, &vconn_handler, &vlink_handler);
- printf("ecp_init RV:%d\n", rv);
+ LOG("ecp_init", rv);
ecp_conn_handler_init(&handler, handle_open, NULL, handle_msg, NULL);
ecp_ctx_set_handler(&ctx, CTYPE_TEST, &handler);
rv = ecp_dhkey_gen(&key_perma);
- printf("ecp_dhkey_gen RV:%d\n", rv);
+ LOG("ecp_dhkey_gen", rv);
rv = ecp_sock_create(&sock, &ctx, &key_perma);
- printf("ecp_sock_create RV:%d\n", rv);
+ LOG("ecp_sock_create", rv);
rv = ecp_vconn_sock_create(&sock);
- printf("ecp_vconn_htable_init RV:%d\n", rv);
+ LOG("ecp_vconn_htable_init", rv);
rv = ecp_sock_open(&sock, NULL);
- printf("ecp_sock_open RV:%d\n", rv);
+ LOG("ecp_sock_open", rv);
rv = ecp_start_receiver(&sock);
- printf("ecp_start_receiver RV:%d\n", rv);
+ LOG("ecp_start_receiver", rv);
rv = ecp_util_load_key(argv[1], &node_pub, NULL);
- printf("ecp_util_load_key RV:%d\n", rv);
+ LOG("ecp_util_load_key", rv);
ecp_node_init(&node, &node_pub, NULL);
rv = ecp_node_set_addr(&node, argv[2]);
- printf("ecp_node_set_addr RV:%d\n", rv);
+ LOG("ecp_node_set_addr", rv);
for (i=3; i<argc; i++) {
rv = ecp_util_load_key(argv[i], &vconn_pub[i-3], NULL);
- printf("ecp_util_load_key RV:%d\n", rv);
+ LOG("ecp_util_load_key", rv);
}
ecp_conn_init(&conn, &sock, CTYPE_TEST);
ecp_vconn_init(vconn, vconn_pub, argc-3, &sock);
rv = ecp_vconn_open(vconn, &conn, &node);
- printf("ecp_vconn_open RV:%d\n", rv);
+ LOG("ecp_vconn_open", rv);
while (1) sleep(1);
}
diff --git a/ecp/test/vc_common.c b/ecp/test/vc_common.c
index efc7140..4f544ae 100644
--- a/ecp/test/vc_common.c
+++ b/ecp/test/vc_common.c
@@ -42,7 +42,7 @@ static void hrw_select(unsigned char *msg, uint16_t count, ecp_ecdh_public_t *pu
uint16_t port;
size_t rv;
- rv = ecp_dir_item_parse(&dir_item, _msg);
+ rv = ecp_dir_parse_item(&dir_item, _msg);
_msg += rv;
host = dir_item.node.addr.host;
@@ -70,7 +70,7 @@ static void hrw_select(unsigned char *msg, uint16_t count, ecp_ecdh_public_t *pu
s = arc4random() % count;
_msg = msg + s * ECP_SIZE_DIR_ITEM;
- ecp_dir_item_parse(&dir_item, _msg);
+ ecp_dir_parse_item(&dir_item, _msg);
memcpy(&vconn_pub[i], &dir_item.node.key_perma, sizeof(ecp_ecdh_public_t));
if (i==0) *addr = dir_item.node.addr;
msg_remove_item(msg, s, count);
diff --git a/ecp/test/vc_server.c b/ecp/test/vc_server.c
index b664a1c..a1a1c51 100644
--- a/ecp/test/vc_server.c
+++ b/ecp/test/vc_server.c
@@ -51,33 +51,33 @@ int main(int argc, char *argv[]) {
if ((argc < 4) || (argc > 7)) usage(argv[0]);
rv = ecp_init(&ctx, &vconn_handler, &vlink_handler);
- printf("ecp_init RV:%d\n", rv);
+ LOG("ecp_init", rv);
ecp_conn_handler_init(&handler, handle_open, NULL, handle_msg, NULL);
ecp_ctx_set_handler(&ctx, CTYPE_TEST, &handler);
rv = ecp_util_load_key(argv[1], &key_perma.public, &key_perma.private);
- printf("ecp_util_load_key RV:%d\n", rv);
+ LOG("ecp_util_load_key", rv);
key_perma.valid = 1;
rv = ecp_sock_create(&sock, &ctx, &key_perma);
- printf("ecp_sock_create RV:%d\n", rv);
+ LOG("ecp_sock_create", rv);
rv = ecp_vconn_sock_create(&sock);
- printf("ecp_vconn_htable_init RV:%d\n", rv);
+ LOG("ecp_vconn_htable_init", rv);
rv = ecp_sock_open(&sock, NULL);
- printf("ecp_sock_open RV:%d\n", rv);
+ LOG("ecp_sock_open", rv);
rv = ecp_start_receiver(&sock);
- printf("ecp_start_receiver RV:%d\n", rv);
+ LOG("ecp_start_receiver", rv);
rv = ecp_util_load_key(argv[argc-1], &node_pub, NULL);
- printf("ecp_util_load_key RV:%d\n", rv);
+ LOG("ecp_util_load_key", rv);
ecp_node_init(&node, &node_pub, NULL);
rv = ecp_node_set_addr(&node, argv[2]);
- printf("ecp_node_set_addr RV:%d\n", rv);
+ LOG("ecp_node_set_addr", rv);
ecp_vlink_init(&conn, &sock);
if (argc > 4) {
@@ -85,15 +85,15 @@ int main(int argc, char *argv[]) {
for (i=3; i<argc-1; i++) {
rv = ecp_util_load_key(argv[i], &vconn_pub[i-3], NULL);
- printf("ecp_util_load_key RV:%d\n", rv);
+ LOG("ecp_util_load_key", rv);
}
ecp_vconn_init(vconn, vconn_pub, argc-4, &sock);
rv = ecp_vconn_open(vconn, &conn, &node);
- printf("ecp_vconn_open RV:%d\n", rv);
+ LOG("ecp_vconn_open", rv);
} else {
rv = ecp_conn_open(&conn, &node);
- printf("ecp_conn_open RV:%d\n", rv);
+ LOG("ecp_conn_open", rv);
}
while (1) sleep(1);
diff --git a/ecp/test/vcs.c b/ecp/test/vcs.c
index 4f4564b..1260f2b 100644
--- a/ecp/test/vcs.c
+++ b/ecp/test/vcs.c
@@ -52,42 +52,42 @@ int main(int argc, char *argv[]) {
if ((argc < 3) || (argc > 5)) usage(argv[0]);
rv = ecp_init(&ctx, &vconn_handler, &vlink_handler);
- printf("ecp_init RV:%d\n", rv);
+ LOG("ecp_init", rv);
vlink_handler.handle_open = vlink_handle_open;
rv = ecp_util_load_key(argv[2], &key_perma.public, &key_perma.private);
- printf("ecp_util_load_key RV:%d\n", rv);
+ LOG("ecp_util_load_key", rv);
key_perma.valid = 1;
rv = ecp_sock_create(&sock, &ctx, &key_perma);
- printf("ecp_sock_create RV:%d\n", rv);
+ LOG("ecp_sock_create", rv);
rv = ecp_vconn_sock_create(&sock);
- printf("ecp_vconn_htable_init RV:%d\n", rv);
+ LOG("ecp_vconn_htable_init", rv);
rv = ecp_addr_init(&addr, argv[1]);
- printf("ecp_addr_init RV:%d\n", rv);
+ LOG("ecp_addr_init", rv);
rv = ecp_sock_open(&sock, &addr);
- printf("ecp_sock_open RV:%d\n", rv);
+ LOG("ecp_sock_open", rv);
rv = ecp_start_receiver(&sock);
- printf("ecp_start_receiver RV:%d\n", rv);
+ LOG("ecp_start_receiver", rv);
if (argc == 5) {
ECPNode node;
ecp_ecdh_public_t node_pub;
rv = ecp_util_load_key(argv[4], &node_pub, NULL);
- printf("ecp_util_load_key RV:%d\n", rv);
+ LOG("ecp_util_load_key", rv);
ecp_node_init(&node, &node_pub, NULL);
rv = ecp_node_set_addr(&node, argv[3]);
- printf("ecp_node_set_addr RV:%d\n", rv);
+ LOG("ecp_node_set_addr", rv);
ecp_vlink_init(&conn, &sock);
rv = ecp_conn_open(&conn, &node);
- printf("ecp_conn_open RV:%d\n", rv);
+ LOG("ecp_conn_open", rv);
} else {
memset(&conn, 0, sizeof(conn));
}