summaryrefslogtreecommitdiff
path: root/ecp/test
diff options
context:
space:
mode:
Diffstat (limited to 'ecp/test')
-rw-r--r--ecp/test/dir.c8
-rw-r--r--ecp/test/vconn_inb.c86
-rw-r--r--ecp/test/vconn_outb.c92
3 files changed, 138 insertions, 48 deletions
diff --git a/ecp/test/dir.c b/ecp/test/dir.c
index f9a4543..9beea27 100644
--- a/ecp/test/dir.c
+++ b/ecp/test/dir.c
@@ -2,6 +2,7 @@
#include <string.h>
#include <unistd.h>
#include <stdio.h>
+#include <arpa/inet.h>
#include <ecp/core.h>
#include <ecp/dir/dir.h>
@@ -20,10 +21,13 @@ 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(ECPSocket *sock, ECPDirList *dir_list, int err) {
- int i;
+static void print_list(ECPConnection *conn, void *list, int err) {
+ ECPDirList *dir_list = list;
unsigned char *host;
uint16_t port;
+ int i;
+
+ LOG("print_list", err);
printf("DIR LIST COUNT:%d\n", dir_list->count);
for (i=0; i<dir_list->count; i++) {
diff --git a/ecp/test/vconn_inb.c b/ecp/test/vconn_inb.c
index 7701a2d..53e8807 100644
--- a/ecp/test/vconn_inb.c
+++ b/ecp/test/vconn_inb.c
@@ -12,18 +12,30 @@
#include "init_vconn.h"
-ECPContext ctx;
-ECPSocket sock;
-ECPConnHandler handler;
-ECPConnHandler vconn_handler;
-ECPConnHandler vlink_handler;
-ECPConnHandler dir_handler;
-ECPConnection dir_conn;
-ECPVConnOutb vconn[ECP_MAX_PARENT];
+ECPDirList *_dir_list = NULL;
#define CTYPE_TEST 0
#define MTYPE_MSG 0
+static void vlink_open(ECPSocket *sock) {
+ ECPVConnOutb *vconn;
+ ecp_tr_addr_t addr;
+ ecp_ecdh_public_t vconn_pub[ECP_MAX_PARENT];
+ ssize_t vconn_size, _rv;
+ int rv;
+
+ _rv = ecp_dir_sel_vconn(_dir_list, &sock->key_perma.public, vconn_pub, ECP_MAX_PARENT, &addr);
+ LOG("ecp_dir_sel_vconn", (int)_rv);
+
+ vconn_size = _rv;
+ vconn = malloc(vconn_size * sizeof(ECPVConnOutb));
+ if (vconn == NULL) LOG("vconn malloc", ECP_ERR_ALLOC);
+
+ ecp_vconn_init_vlink(vconn, vconn_size, sock);
+ rv = ecp_vconn_open_vlink(vconn, vconn_pub, &addr);
+ LOG("ecp_vconn_open_vlink", rv);
+}
+
static int handle_open(ECPConnection *conn, ECP2Buffer *b) {
printf("OPEN\n");
@@ -40,23 +52,41 @@ static ssize_t handle_msg(ECPConnection *conn, ecp_seq_t seq, unsigned char mtyp
return msg_size;
}
-static void handle_dir_list(ECPSocket *sock, ECPDirList *dir_list, int err) {
- ecp_tr_addr_t addr;
- ecp_ecdh_public_t vconn_pub[ECP_MAX_PARENT];
- ssize_t _rv, vconn_size;
- int rv;
+static void handle_err(ECPConnection *conn, unsigned char mtype, int err) {
+ if (mtype == ECP_MTYPE_OPEN_REP) {
+ ecp_dir_set_unavailable(_dir_list, &conn->remote.key_perma.public);
+ vlink_open(conn->sock);
+ }
+ ecp_vconn_close(conn);
+}
- LOG("handle_dir_list", err);
+static void handle_dir_list(ECPConnection *conn, void *list, int err) {
+ ECPDirList *dir_list = list;
- _rv = ecp_dir_hrw_select(dir_list, &sock->key_perma.public, vconn_pub, ECP_MAX_PARENT, &addr);
- LOG("ecp_dir_hrw_select", (int)_rv);
+ if (err && _dir_list) {
+ ECPConnection *dir_conn;
+ ecp_tr_addr_t addr;
+ ecp_ecdh_public_t public;
+ int rv;
- vconn_size = _rv;
- ecp_vconn_init_vlink(vconn, vconn_size, sock);
- rv = ecp_vconn_open_vlink(vconn, vconn_pub, &addr);
- LOG("ecp_vconn_open_vlink", rv);
+ ecp_dir_set_unavailable(_dir_list, &conn->remote.key_perma.public);
+ rv = ecp_dir_sel_dir(_dir_list, &public, &addr);
+ LOG("ecp_dir_sel_dir", rv);
- ecp_dir_list_destroy(dir_list);
+ dir_conn = malloc(sizeof(ECPConnection));
+ if (dir_conn == NULL) LOG("dir_conn malloc", ECP_ERR_ALLOC);
+
+ rv = ecp_dir_get(dir_conn, conn->sock, &public, &addr, 0);
+ LOG("ecp_dir_get", rv);
+
+ return;
+ }
+ LOG("handle_dir_list", err);
+
+ if (_dir_list) ecp_dir_list_destroy(_dir_list);
+ _dir_list = dir_list;
+
+ vlink_open(conn->sock);
}
static void usage(char *arg) {
@@ -65,7 +95,14 @@ static void usage(char *arg) {
}
int main(int argc, char *argv[]) {
+ ECPContext ctx;
+ ECPSocket sock;
ECPDHKey key_perma;
+ ECPConnHandler handler;
+ ECPConnHandler vconn_handler;
+ ECPConnHandler vlink_handler;
+ ECPConnHandler dir_handler;
+ ECPConnection *dir_conn;
ecp_tr_addr_t addr;
ecp_ecdh_public_t public;
int rv;
@@ -74,6 +111,8 @@ int main(int argc, char *argv[]) {
rv = ecp_init(&ctx, &vconn_handler, &vlink_handler);
LOG("ecp_init", rv);
+ vconn_handler.handle_err = handle_err;
+ vlink_handler.handle_err = handle_err;
rv = ecp_dir_set_handler(&ctx, &dir_handler, handle_dir_list);
LOG("ecp_dir_set_handler", rv);
@@ -103,7 +142,10 @@ int main(int argc, char *argv[]) {
rv = ecp_util_load_key(argv[3], &public, NULL);
LOG("ecp_util_load_key", rv);
- rv = ecp_dir_get(&dir_conn, &sock, &public, &addr, 0);
+ dir_conn = malloc(sizeof(ECPConnection));
+ if (dir_conn == NULL) LOG("dir_conn malloc", ECP_ERR_ALLOC);
+
+ rv = ecp_dir_get(dir_conn, &sock, &public, &addr, 0);
LOG("ecp_dir_get", rv);
while(1) pause();
diff --git a/ecp/test/vconn_outb.c b/ecp/test/vconn_outb.c
index 8b7782b..69c0929 100644
--- a/ecp/test/vconn_outb.c
+++ b/ecp/test/vconn_outb.c
@@ -12,20 +12,36 @@
#include "init_vconn.h"
-ECPContext ctx;
-ECPSocket sock;
-ECPConnHandler handler;
-ECPConnHandler vconn_handler;
-ECPConnHandler vlink_handler;
-ECPConnHandler dir_handler;
-ECPConnection dir_conn;
-ECPConnection conn;
-ECPVConnOutb vconn[ECP_MAX_PARENT];
+ECPDirList *_dir_list = NULL;
ecp_ecdh_public_t srv_public;
#define CTYPE_TEST 0
#define MTYPE_MSG 0
+static void vconn_open(ECPSocket *sock) {
+ ECPConnection *conn;
+ ECPVConnOutb *vconn;
+ ecp_tr_addr_t addr;
+ ecp_ecdh_public_t vconn_pub[ECP_MAX_PARENT];
+ ssize_t vconn_size, _rv;
+ int rv;
+
+ _rv = ecp_dir_sel_vconn(_dir_list, &srv_public, vconn_pub, ECP_MAX_PARENT, &addr);
+ LOG("ecp_dir_sel_vconn", (int)_rv);
+
+ vconn_size = _rv;
+ conn = malloc(sizeof(ECPConnection));
+ if (conn == NULL) LOG("conn malloc", ECP_ERR_ALLOC);
+
+ vconn = malloc(vconn_size * sizeof(ECPVConnOutb));
+ if (vconn == NULL) LOG("vconn malloc", ECP_ERR_ALLOC);
+
+ ecp_conn_init(conn, sock, CTYPE_TEST);
+ ecp_vconn_init(vconn, vconn_size, conn, sock);
+ rv = ecp_vconn_open(vconn, vconn_pub, &addr, &srv_public);
+ LOG("ecp_vconn_open", rv);
+}
+
static int handle_open(ECPConnection *conn, ECP2Buffer *b) {
char *_msg = "PERA JE CAR!";
ssize_t rv;
@@ -44,24 +60,41 @@ static ssize_t handle_msg(ECPConnection *conn, ecp_seq_t seq, unsigned char mtyp
return msg_size;
}
-static void handle_dir_list(ECPSocket *sock, ECPDirList *dir_list, int err) {
- ecp_tr_addr_t addr;
- ecp_ecdh_public_t vconn_pub[ECP_MAX_PARENT];
- ssize_t _rv, vconn_size;
- int rv;
+static void handle_err(ECPConnection *conn, unsigned char mtype, int err) {
+ if (mtype == ECP_MTYPE_OPEN_REP) {
+ ecp_dir_set_unavailable(_dir_list, &conn->remote.key_perma.public);
+ vconn_open(conn->sock);
+ }
+ ecp_vconn_close(conn);
+}
- LOG("handle_dir_list", err);
+static void handle_dir_list(ECPConnection *conn, void *list, int err) {
+ ECPDirList *dir_list = list;
- _rv = ecp_dir_hrw_select(dir_list, &srv_public, vconn_pub, ECP_MAX_PARENT, &addr);
- LOG("ecp_dir_hrw_select", (int)_rv);
+ if (err && _dir_list) {
+ ECPConnection *dir_conn;
+ ecp_tr_addr_t addr;
+ ecp_ecdh_public_t public;
+ int rv;
- vconn_size = _rv;
- ecp_conn_init(&conn, sock, CTYPE_TEST);
- ecp_vconn_init(vconn, vconn_size, &conn, sock);
- rv = ecp_vconn_open(vconn, vconn_pub, &addr, &srv_public);
- LOG("ecp_vconn_open", rv);
+ ecp_dir_set_unavailable(_dir_list, &conn->remote.key_perma.public);
+ rv = ecp_dir_sel_dir(_dir_list, &public, &addr);
+ LOG("ecp_dir_sel_dir", rv);
- ecp_dir_list_destroy(dir_list);
+ dir_conn = malloc(sizeof(ECPConnection));
+ if (dir_conn == NULL) LOG("dir_conn malloc", ECP_ERR_ALLOC);
+
+ rv = ecp_dir_get(dir_conn, conn->sock, &public, &addr, 0);
+ LOG("ecp_dir_get", rv);
+
+ return;
+ }
+ LOG("handle_dir_list", err);
+
+ if (_dir_list) ecp_dir_list_destroy(_dir_list);
+ _dir_list = dir_list;
+
+ vconn_open(conn->sock);
}
static void usage(char *arg) {
@@ -70,7 +103,14 @@ static void usage(char *arg) {
}
int main(int argc, char *argv[]) {
+ ECPContext ctx;
+ ECPSocket sock;
ECPDHKey key_perma;
+ ECPConnHandler handler;
+ ECPConnHandler vconn_handler;
+ ECPConnHandler vlink_handler;
+ ECPConnHandler dir_handler;
+ ECPConnection *dir_conn;
ecp_tr_addr_t addr;
ecp_ecdh_public_t public;
int rv;
@@ -79,6 +119,7 @@ int main(int argc, char *argv[]) {
rv = ecp_init(&ctx, &vconn_handler, &vlink_handler);
LOG("ecp_init", rv);
+ vconn_handler.handle_err = handle_err;
rv = ecp_dir_set_handler(&ctx, &dir_handler, handle_dir_list);
LOG("ecp_dir_set_handler", rv);
@@ -110,7 +151,10 @@ int main(int argc, char *argv[]) {
rv = ecp_util_load_key(argv[3], &public, NULL);
LOG("ecp_util_load_key", rv);
- rv = ecp_dir_get(&dir_conn, &sock, &public, &addr, 0);
+ dir_conn = malloc(sizeof(ECPConnection));
+ if (dir_conn == NULL) LOG("dir_conn malloc", ECP_ERR_ALLOC);
+
+ rv = ecp_dir_get(dir_conn, &sock, &public, &addr, 0);
LOG("ecp_dir_get", rv);
while (1) sleep(1);