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/test/vcs.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'ecp/test/vcs.c') diff --git a/ecp/test/vcs.c b/ecp/test/vcs.c index 92d1eb2..4f4564b 100644 --- a/ecp/test/vcs.c +++ b/ecp/test/vcs.c @@ -21,6 +21,29 @@ static void usage(char *arg) { exit(1); } +static int vlink_handle_open(ECPConnection *_conn, ECP2Buffer *bufs) { + int rv; + + /* open return connection */ + if ((_conn->parent == 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