From 38fdc24c2cc0c942337481e825c69004c93fc358 Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Sat, 27 Apr 2024 01:23:43 +0200 Subject: updated tests --- ecp/README | 22 +++++++++++----------- ecp/test/client.c | 4 ++-- ecp/test/server.c | 2 +- ecp/test/vc_client.c | 11 +++++++---- ecp/test/vc_inb.c | 6 +++--- ecp/test/vc_outb.c | 8 ++++---- ecp/test/vc_server.c | 13 ++++++++----- ecp/test/vcs.c | 35 ++++++++++++++++++++++++++++++++--- 8 files changed, 68 insertions(+), 33 deletions(-) diff --git a/ecp/README b/ecp/README index ec6ae47..557fc9d 100644 --- a/ecp/README +++ b/ecp/README @@ -9,16 +9,16 @@ To (re)build library, utilities and tests simply do: ./build.sh (MAKE=gmake ./build.sh on *BSD systems) In tests subdirectory you will find simple test examples. To test vc_server and vc_client (vconn feature) do: - util/mknode n1 - util/mknode n2 - util/mknode n3 - util/mknode server - cd tests + mkdir test/keys + util/keygen test/keys/n1.pub test/keys/n1.priv + util/keygen test/keys/n2.pub test/keys/n2.priv + util/keygen test/keys/n3.pub test/keys/n3.priv + util/keygen test/keys/server.pub test/keys/server.priv + cd test Then launch servers (each in its own terminal): - ./vcs 0.0.0.0:3001 ../n1.priv - ./vcs 0.0.0.0:3002 ../n2.priv 127.0.0.1:3001 ../n1.pub - ./vcs 0.0.0.0:3003 ../n3.priv 127.0.0.1:3002 ../n2.pub - ./vc_server ../server.priv 127.0.0.1:3001 ../n1.pub ../n2.pub ../n3.pub - ./vc_client ../server.pub 127.0.0.1:3001 ../n1.pub ../n2.pub ../n3.pub - \ No newline at end of file + ./vcs 0.0.0.0:3001 keys/n1.priv + ./vcs 0.0.0.0:3002 keys/n2.priv 127.0.0.1:3001 keys/n1.pub + ./vcs 0.0.0.0:3003 keys/n3.priv 127.0.0.1:3002 keys/n2.pub + ./vc_server keys/server.priv 127.0.0.1:3001 keys/n1.pub keys/n2.pub keys/n3.pub + ./vc_client keys/server.pub 127.0.0.1:3001 keys/n1.pub keys/n2.pub keys/n3.pub diff --git a/ecp/test/client.c b/ecp/test/client.c index 52a8587..af905d5 100644 --- a/ecp/test/client.c +++ b/ecp/test/client.c @@ -64,8 +64,8 @@ int main(int argc, char *argv[]) { rv = ecp_start_receiver(&sock); printf("ecp_start_receiver RV:%d\n", rv); - rv = ecp_util_load_pub(&node_pub, argv[2]); - printf("ecp_util_load_pub RV:%d\n", rv); + rv = ecp_util_load_key(argv[2], &node_pub, NULL); + printf("ecp_util_load_key RV:%d\n", rv); ecp_node_init(&node, &node_pub, NULL); rv = ecp_node_set_addr(&node, argv[1]); diff --git a/ecp/test/server.c b/ecp/test/server.c index 19b2f4f..003e3b3 100644 --- a/ecp/test/server.c +++ b/ecp/test/server.c @@ -46,7 +46,7 @@ int main(int argc, char *argv[]) { ecp_conn_handler_init(&handler, handle_msg, NULL, NULL, NULL); ecp_ctx_set_handler(&ctx, CTYPE_TEST, &handler); - rv = ecp_util_load_key(&key_perma.public, &key_perma.private, argv[2]); + rv = ecp_util_load_key(argv[2], &key_perma.public, &key_perma.private); printf("ecp_util_load_key RV:%d\n", rv); key_perma.valid = 1; diff --git a/ecp/test/vc_client.c b/ecp/test/vc_client.c index 41c364d..af4a3cd 100644 --- a/ecp/test/vc_client.c +++ b/ecp/test/vc_client.c @@ -63,22 +63,25 @@ int main(int argc, char *argv[]) { rv = ecp_sock_create(&sock, &ctx, &key_perma); printf("ecp_sock_create RV:%d\n", rv); + rv = ecp_vconn_sock_create(&sock); + printf("ecp_vconn_htable_init 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_load_pub(&node_pub, argv[1]); - printf("ecp_util_load_pub RV:%d\n", rv); + rv = ecp_util_load_key(argv[1], &node_pub, NULL); + printf("ecp_util_load_key RV:%d\n", 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); for (i=3; iparent == NULL) && ecp_conn_is_inb(_conn) && (memcmp(&_conn->remote.key_perma.public, &conn.remote.key_perma.public, sizeof(conn.remote.key_perma.public)) != 0)) { + ECPNode node; + ECPConnection *conn_r; + + ecp_node_init(&node, &_conn->remote.key_perma.public, &_conn->remote.addr); + + conn_r = malloc(sizeof(ECPConnection)); + if (conn_r == NULL) return ECP_ERR_ALLOC; + + ecp_vlink_init(conn_r, _conn->sock); + rv = ecp_conn_open(conn_r, &node); + printf("open return connection: ecp_conn_open RV:%d\n", rv); + if (rv) return rv; + } + + rv = ecp_vlink_handle_open(_conn, bufs); + return rv; +} + int main(int argc, char *argv[]) { ecp_tr_addr_t addr; ECPDHKey key_perma; @@ -30,14 +53,18 @@ int main(int argc, char *argv[]) { rv = ecp_init(&ctx, &vconn_handler, &vlink_handler); printf("ecp_init RV:%d\n", rv); + vlink_handler.handle_open = vlink_handle_open; - rv = ecp_util_load_key(&key_perma.public, &key_perma.private, argv[2]); + rv = ecp_util_load_key(argv[2], &key_perma.public, &key_perma.private); printf("ecp_util_load_key RV:%d\n", rv); key_perma.valid = 1; rv = ecp_sock_create(&sock, &ctx, &key_perma); printf("ecp_sock_create RV:%d\n", rv); + rv = ecp_vconn_sock_create(&sock); + printf("ecp_vconn_htable_init RV:%d\n", rv); + rv = ecp_addr_init(&addr, argv[1]); printf("ecp_addr_init RV:%d\n", rv); @@ -51,8 +78,8 @@ int main(int argc, char *argv[]) { ECPNode node; ecp_ecdh_public_t node_pub; - rv = ecp_util_load_pub(&node_pub, argv[4]); - printf("ecp_util_load_pub RV:%d\n", rv); + rv = ecp_util_load_key(argv[4], &node_pub, NULL); + printf("ecp_util_load_key RV:%d\n", rv); ecp_node_init(&node, &node_pub, NULL); rv = ecp_node_set_addr(&node, argv[3]); @@ -61,6 +88,8 @@ int main(int argc, char *argv[]) { ecp_vlink_init(&conn, &sock); rv = ecp_conn_open(&conn, &node); printf("ecp_conn_open RV:%d\n", rv); + } else { + memset(&conn, 0, sizeof(conn)); } while (1) sleep(1); -- cgit v1.2.3