1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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, printf);
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();
}
|