diff options
Diffstat (limited to 'ecp/test/dir.c')
| -rw-r--r-- | ecp/test/dir.c | 65 | 
1 files changed, 65 insertions, 0 deletions
| 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(); +} | 
