From 109f39e09630409a30a9f4e8183f539c499f07ba Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Mon, 3 Jun 2024 04:06:21 +0200 Subject: improved (v)conn init / open / init vlink / open vlink API; implemented randezvous hashing --- ecp/test/dir.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'ecp/test/dir.c') diff --git a/ecp/test/dir.c b/ecp/test/dir.c index 9c04432..f9a4543 100644 --- a/ecp/test/dir.c +++ b/ecp/test/dir.c @@ -14,24 +14,35 @@ ECPSocket sock; ECPConnection conn; ECPConnHandler dir_handler; -#define LOG(fmt, rv) { printf(fmt " RV:%d\n", rv); if (rv) exit(1); } +#define LOG(fmt, rv) { printf(fmt " RV:%d\n", rv); if (rv<0) 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) { +static void print_list(ECPSocket *sock, ECPDirList *dir_list, int err) { + int i; + unsigned char *host; + uint16_t port; + + printf("DIR LIST COUNT:%d\n", dir_list->count); + for (i=0; icount; i++) { + host = dir_list->items[i].node.addr.host; + port = dir_list->items[i].node.addr.port; + + printf("ADDR: %d.%d.%d.%d:%d\n", host[0], host[1], host[2], host[3], ntohs(port)); + } ecp_dir_list_destroy(dir_list); } static void usage(char *arg) { - fprintf(stderr, "Usage: %s
\n", arg); + fprintf(stderr, "Usage: %s
\n", arg); exit(1); } int main(int argc, char *argv[]) { - ECPNode node; - ecp_ecdh_public_t node_pub; + ecp_tr_addr_t addr; + ecp_ecdh_public_t public; int rv; if (argc != 3) usage(argv[0]); @@ -40,7 +51,7 @@ int main(int argc, char *argv[]) { LOG("ecp_ctx_init", rv); rv = ecp_dir_set_handler(&ctx, &dir_handler, print_list); - LOG("ecp_dir_ctx_init", rv); + LOG("ecp_dir_set_handler", rv); rv = ecp_sock_create(&sock, &ctx, NULL); LOG("ecp_sock_create", rv); @@ -51,14 +62,13 @@ int main(int argc, char *argv[]) { 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); + rv = ecp_addr_init(&addr, argv[1]); + LOG("ecp_addr_init", rv); - ecp_node_init(&node, &node_pub, NULL); - rv = ecp_node_set_addr(&node, argv[1]); - LOG("ecp_node_set_addr", rv); + rv = ecp_util_load_key(argv[2], &public, NULL); + LOG("ecp_util_load_key", rv); - rv = ecp_dir_get(&conn, &sock, &node, 0); + rv = ecp_dir_get(&conn, &sock, &public, &addr, 0); LOG("ecp_dir_get", rv); while(1) pause(); -- cgit v1.2.3