summaryrefslogtreecommitdiff
path: root/ecp/test
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2024-06-03 04:06:21 +0200
committerUros Majstorovic <majstor@majstor.org>2024-06-03 04:06:21 +0200
commit109f39e09630409a30a9f4e8183f539c499f07ba (patch)
tree4492b38e1840be67e9ffedadb30df8f8baf9a0a7 /ecp/test
parent4c2c25f80b3cc173f09f6113e0ee623866948b87 (diff)
improved (v)conn init / open / init vlink / open vlink API; implemented randezvous hashing
Diffstat (limited to 'ecp/test')
-rw-r--r--ecp/test/Makefile12
-rw-r--r--ecp/test/basic.c8
-rw-r--r--ecp/test/client.c15
-rw-r--r--ecp/test/dir.c34
-rw-r--r--ecp/test/init.c2
-rw-r--r--ecp/test/init.h2
-rw-r--r--ecp/test/init_vconn.c2
-rw-r--r--ecp/test/init_vconn.h2
-rw-r--r--ecp/test/vc_client.c27
-rw-r--r--ecp/test/vc_common.c128
-rw-r--r--ecp/test/vc_common.h2
-rw-r--r--ecp/test/vc_inb.c124
-rw-r--r--ecp/test/vc_outb.c128
-rw-r--r--ecp/test/vc_server.c38
-rw-r--r--ecp/test/vconn_inb.c110
-rw-r--r--ecp/test/vconn_outb.c117
-rw-r--r--ecp/test/vcs.c21
17 files changed, 308 insertions, 464 deletions
diff --git a/ecp/test/Makefile b/ecp/test/Makefile
index 3fc85d1..44ac16a 100644
--- a/ecp/test/Makefile
+++ b/ecp/test/Makefile
@@ -4,8 +4,10 @@ CFLAGS += -I../util
dep = ../build-posix/*.a ../util/libecputil.a
target = basic client server dir
+ifeq ($(with_vconn),yes)
ifeq ($(with_htable),yes)
-target += vcs vc_server vc_client vc_inb vc_outb
+target += vcs vc_server vc_client vconn_inb vconn_outb
+endif
endif
@@ -26,11 +28,11 @@ server: server.o init.o $(dep)
dir: dir.o $(dep)
$(CC) -o $@ $< init.o $(dep) $(LDFLAGS)
-vc_inb: vc_inb.o vc_common.o init_vconn.o $(dep)
- $(CC) -o $@ $< vc_common.o init_vconn.o $(dep) $(LDFLAGS)
+vconn_inb: vconn_inb.o init_vconn.o $(dep)
+ $(CC) -o $@ $< init_vconn.o $(dep) $(LDFLAGS)
-vc_outb: vc_outb.o vc_common.o init_vconn.o $(dep)
- $(CC) -o $@ $< vc_common.o init_vconn.o $(dep) $(LDFLAGS)
+vconn_outb: vconn_outb.o init_vconn.o $(dep)
+ $(CC) -o $@ $< init_vconn.o $(dep) $(LDFLAGS)
vcs: vcs.o init_vconn.o $(dep)
$(CC) -o $@ $< init_vconn.o $(dep) $(LDFLAGS)
diff --git a/ecp/test/basic.c b/ecp/test/basic.c
index 68cc604..06d9fb3 100644
--- a/ecp/test/basic.c
+++ b/ecp/test/basic.c
@@ -49,7 +49,6 @@ int main(int argc, char *argv[]) {
ecp_tr_addr_t addr;
ECPDHKey key_perma_c;
ECPDHKey key_perma_s;
- ECPNode node;
int rv;
/* server */
@@ -93,12 +92,11 @@ int main(int argc, char *argv[]) {
rv = ecp_start_receiver(&sock_c);
LOG("ecp_start_receiver", rv);
- ecp_node_init(&node, &key_perma_s.public, NULL);
- rv = ecp_node_set_addr(&node, "127.0.0.1:3000");
- LOG("ecp_node_set_addr", rv);
+ rv = ecp_addr_init(&addr, "127.0.0.1:3000");
+ LOG("ecp_addr_init", rv);
ecp_conn_init(&conn, &sock_c, CTYPE_TEST);
- rv = ecp_conn_open(&conn, &node);
+ rv = ecp_conn_open(&conn, &key_perma_s.public, &addr);
LOG("ecp_conn_open", rv);
while (1) sleep(1);
diff --git a/ecp/test/client.c b/ecp/test/client.c
index eb39c92..de4fe9c 100644
--- a/ecp/test/client.c
+++ b/ecp/test/client.c
@@ -39,8 +39,8 @@ static void usage(char *arg) {
int main(int argc, char *argv[]) {
ECPDHKey key_perma;
- ECPNode node;
- ecp_ecdh_public_t node_pub;
+ ecp_tr_addr_t addr;
+ ecp_ecdh_public_t public;
int rv;
/* client */
@@ -64,15 +64,14 @@ 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);
ecp_conn_init(&conn, &sock, CTYPE_TEST);
- rv = ecp_conn_open(&conn, &node);
+ rv = ecp_conn_open(&conn, &public, &addr);
LOG("ecp_conn_open", rv);
while (1) sleep(1);
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; i<dir_list->count; 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 <address> <node.priv>\n", arg);
+ fprintf(stderr, "Usage: %s <address> <dir.pub>\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();
diff --git a/ecp/test/init.c b/ecp/test/init.c
index 7004794..c56c28d 100644
--- a/ecp/test/init.c
+++ b/ecp/test/init.c
@@ -4,7 +4,7 @@
#include <ecp/core.h>
static void handle_err(ECPConnection *conn, unsigned char mtype, int err) {
- printf("ERR: CTYPE:0x%x MTYPE:0x%x ERR:%d\n", conn->type, mtype, err);
+ printf("ERROR: CTYPE:0x%x MTYPE:0x%x ERR:%d\n", conn->type, mtype, err);
}
static ECPConnection *conn_new(ECPSocket *sock, ECPConnection *parent, unsigned char type) {
diff --git a/ecp/test/init.h b/ecp/test/init.h
index 7edba6e..efa8bcb 100644
--- a/ecp/test/init.h
+++ b/ecp/test/init.h
@@ -1,3 +1,3 @@
-#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); }
int ecp_init(ECPContext *ctx); \ No newline at end of file
diff --git a/ecp/test/init_vconn.c b/ecp/test/init_vconn.c
index 273ae5d..8421365 100644
--- a/ecp/test/init_vconn.c
+++ b/ecp/test/init_vconn.c
@@ -6,7 +6,7 @@
#include <ecp/vconn/vconn.h>
static void handle_err(ECPConnection *conn, unsigned char mtype, int err) {
- printf("ERR: CTYPE:0x%x MTYPE:0x%x ERR:%d\n", conn->type, mtype, err);
+ printf("ERROR: CTYPE:0x%x MTYPE:0x%x ERR:%d\n", conn->type, mtype, err);
}
static ECPConnection *conn_new(ECPSocket *sock, ECPConnection *parent, unsigned char type) {
diff --git a/ecp/test/init_vconn.h b/ecp/test/init_vconn.h
index 06f10e2..a2228dd 100644
--- a/ecp/test/init_vconn.h
+++ b/ecp/test/init_vconn.h
@@ -1,3 +1,3 @@
-#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); }
int ecp_init(ECPContext *ctx, ECPConnHandler *vconn_handler, ECPConnHandler *vlink_handler); \ No newline at end of file
diff --git a/ecp/test/vc_client.c b/ecp/test/vc_client.c
index f46824b..a32b22a 100644
--- a/ecp/test/vc_client.c
+++ b/ecp/test/vc_client.c
@@ -16,7 +16,7 @@ ECPConnHandler handler;
ECPConnHandler vconn_handler;
ECPConnHandler vlink_handler;
ECPConnection conn;
-ECPVConnOutb vconn[3];
+ECPVConnOutb vconn[ECP_MAX_PARENT];
#define CTYPE_TEST 0
#define MTYPE_MSG 0
@@ -25,7 +25,9 @@ static int handle_open(ECPConnection *conn, ECP2Buffer *b) {
char *_msg = "PERA JE CAR!";
ssize_t rv;
- printf("OPEN\n");
+ printf("Press ENTER key to start\n");
+ while(getchar()!='\n');
+
rv = ecp_msg_send(conn, MTYPE_MSG, (unsigned char *)_msg, strlen(_msg)+1);
return ECP_OK;
@@ -44,12 +46,12 @@ static void usage(char *arg) {
int main(int argc, char *argv[]) {
ECPDHKey key_perma;
- ECPNode node;
- ecp_ecdh_public_t node_pub;
- ecp_ecdh_public_t vconn_pub[3];
+ ecp_tr_addr_t addr;
+ ecp_ecdh_public_t public;
+ ecp_ecdh_public_t vconn_pub[ECP_MAX_PARENT];
int rv, i;
- if ((argc < 4) || (argc > 6)) usage(argv[0]);
+ if ((argc < 4) || (argc > 3 + ECP_MAX_PARENT)) usage(argv[0]);
rv = ecp_init(&ctx, &vconn_handler, &vlink_handler);
LOG("ecp_init", rv);
@@ -64,7 +66,7 @@ int main(int argc, char *argv[]) {
LOG("ecp_sock_create", rv);
rv = ecp_vconn_sock_create(&sock);
- LOG("ecp_vconn_htable_init", rv);
+ LOG("ecp_vconn_sock_create", rv);
rv = ecp_sock_open(&sock, NULL);
LOG("ecp_sock_open", rv);
@@ -72,12 +74,11 @@ int main(int argc, char *argv[]) {
rv = ecp_start_receiver(&sock);
LOG("ecp_start_receiver", rv);
- rv = ecp_util_load_key(argv[1], &node_pub, NULL);
+ rv = ecp_util_load_key(argv[1], &public, NULL);
LOG("ecp_util_load_key", rv);
- ecp_node_init(&node, &node_pub, NULL);
- rv = ecp_node_set_addr(&node, argv[2]);
- LOG("ecp_node_set_addr", rv);
+ rv = ecp_addr_init(&addr, argv[2]);
+ LOG("ecp_addr_init", rv);
for (i=3; i<argc; i++) {
rv = ecp_util_load_key(argv[i], &vconn_pub[i-3], NULL);
@@ -85,8 +86,8 @@ int main(int argc, char *argv[]) {
}
ecp_conn_init(&conn, &sock, CTYPE_TEST);
- ecp_vconn_init(vconn, vconn_pub, argc-3, &sock);
- rv = ecp_vconn_open(vconn, &conn, &node);
+ ecp_vconn_init(vconn, argc-3, &conn, &sock);
+ rv = ecp_vconn_open(vconn, vconn_pub, &addr, &public);
LOG("ecp_vconn_open", rv);
while (1) sleep(1);
diff --git a/ecp/test/vc_common.c b/ecp/test/vc_common.c
deleted file mode 100644
index 4f544ae..0000000
--- a/ecp/test/vc_common.c
+++ /dev/null
@@ -1,128 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <arpa/inet.h>
-
-#include <ecp/core.h>
-#include <ecp/dir/dir.h>
-#include <ecp/vconn/vconn.h>
-
-#include <openssl/crypto.h>
-#include <openssl/sha.h>
-
-#include "vc_common.h"
-
-#define VCONN_NODES 3
-
-#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
-#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))
-
-static void msg_remove_item(unsigned char *msg, uint16_t i, uint16_t c) {
- if (c - i - 1) memmove(msg + i * ECP_SIZE_DIR_ITEM, msg + (i + 1) * ECP_SIZE_DIR_ITEM, (c - i - 1) * ECP_SIZE_DIR_ITEM);
-}
-
-static void hrw_select(unsigned char *msg, uint16_t count, ecp_ecdh_public_t *pub, ecp_ecdh_public_t *hrw_pub, ecp_ecdh_public_t vconn_pub[], size_t *_vconn_size, ecp_tr_addr_t *addr) {
- unsigned char *_msg = msg;
- unsigned char hash[SHA_DIGEST_LENGTH];
- unsigned char hrw_hash[SHA_DIGEST_LENGTH];
- ecp_ecdh_public_t hash_pub[2];
- size_t vconn_size = *_vconn_size;
- ECPDirItem dir_item;
- SHA_CTX ctx;
- int i, hrw_i;
-
- if (count == 0) return;
-
- memset(hrw_hash, 0, sizeof(hrw_hash));
- memcpy(&hash_pub[0], pub, sizeof(ecp_ecdh_public_t));
-
- for (i=0; i<count; i++) {
- unsigned char *host;
- uint16_t port;
- size_t rv;
-
- rv = ecp_dir_parse_item(&dir_item, _msg);
- _msg += rv;
-
- host = dir_item.node.addr.host;
- port = dir_item.node.addr.port;
- printf("ITEM: %d.%d.%d.%d:%d\n", host[0], host[1], host[2], host[3], ntohs(port));
-
- memcpy(&hash_pub[1], &dir_item.node.key_perma.public, sizeof(ecp_ecdh_public_t));
- SHA1_Init(&ctx);
- SHA1_Update(&ctx, hash_pub, sizeof(hash_pub));
- SHA1_Final(hash, &ctx);
- if (memcmp(hrw_hash, hash, sizeof(hash)) < 0) {
- hrw_i = i;
- memcpy(hrw_hash, hash, sizeof(hash));
- memcpy(hrw_pub, &dir_item.node.key_perma, sizeof(ecp_ecdh_public_t));
- }
- }
-
- printf("SELECTED: %d\n", hrw_i);
- msg_remove_item(msg, hrw_i, count);
- count--;
-
- vconn_size = MIN(count, vconn_size);
- for (i=0; i<vconn_size; i++) {
- uint16_t s;
-
- s = arc4random() % count;
- _msg = msg + s * ECP_SIZE_DIR_ITEM;
- ecp_dir_parse_item(&dir_item, _msg);
- memcpy(&vconn_pub[i], &dir_item.node.key_perma, sizeof(ecp_ecdh_public_t));
- if (i==0) *addr = dir_item.node.addr;
- msg_remove_item(msg, s, count);
- count--;
- }
- *_vconn_size = vconn_size;
-}
-
-int vc_open_inb(ECPConnection *vlink, unsigned char *msg, uint16_t count, ecp_ecdh_public_t *local_pub) {
- ecp_ecdh_public_t vconn_pub[VCONN_NODES - 1];
- ecp_ecdh_public_t hrw_pub;
- ecp_tr_addr_t addr;
- ECPNode node;
- ECPVConnOutb *vconn;
- size_t vconn_size;
- int rv;
-
- vconn_size = VCONN_NODES - 1;
- hrw_select(msg, count, local_pub, &hrw_pub, vconn_pub, &vconn_size, &addr);
-
- vconn = malloc(sizeof(ECPVConnOutb) * vconn_size);
- if (vconn == NULL) return ECP_ERR_ALLOC;
-
- ecp_vconn_init(vconn, vconn_pub, vconn_size, vlink->sock);
- ecp_node_init(&node, &hrw_pub, &addr);
- rv = ecp_vconn_open(vconn, vlink, &node);
- printf("ecp_vconn_open RV:%d\n", rv);
-
- return ECP_OK;
-}
-
-int vc_open_outb(ECPConnection *conn, unsigned char *msg, uint16_t count, ecp_ecdh_public_t *remote_pub) {
- ecp_ecdh_public_t vconn_pub[VCONN_NODES];
- ecp_ecdh_public_t hrw_pub;
- ecp_tr_addr_t addr;
- ECPNode node;
- ECPVConnOutb *vconn;
- size_t vconn_size;
- int rv;
-
- vconn_size = VCONN_NODES - 1;
- hrw_select(msg, count, remote_pub, &hrw_pub, vconn_pub, &vconn_size, &addr);
- memcpy(&vconn_pub[vconn_size], &hrw_pub, sizeof(ecp_ecdh_public_t));
- vconn_size++;
-
- vconn = malloc(sizeof(ECPVConnOutb) * vconn_size);
- if (vconn == NULL) return ECP_ERR_ALLOC;
-
- ecp_vconn_init(vconn, vconn_pub, vconn_size, conn->sock);
- ecp_node_init(&node, remote_pub, &addr);
- rv = ecp_vconn_open(vconn, conn, &node);
- printf("ecp_vconn_open RV:%d\n", rv);
-
- return ECP_OK;
-}
diff --git a/ecp/test/vc_common.h b/ecp/test/vc_common.h
deleted file mode 100644
index a684566..0000000
--- a/ecp/test/vc_common.h
+++ /dev/null
@@ -1,2 +0,0 @@
-int vc_open_inb(ECPConnection *vlink, unsigned char *msg, uint16_t count, ecp_ecdh_public_t *local_pub);
-int vc_open_outb(ECPConnection *conn, unsigned char *msg, uint16_t count, ecp_ecdh_public_t *remote_pub);
diff --git a/ecp/test/vc_inb.c b/ecp/test/vc_inb.c
deleted file mode 100644
index 0c75c5d..0000000
--- a/ecp/test/vc_inb.c
+++ /dev/null
@@ -1,124 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdio.h>
-
-#include <ecp/core.h>
-#include <ecp/dir/dir.h>
-#include <ecp/vconn/vconn.h>
-
-#include <util.h>
-
-#include "init_vconn.h"
-#include "vc_common.h"
-
-ECPContext ctx;
-ECPSocket sock;
-ECPConnHandler handler;
-ECPConnHandler dir_handler;
-ECPConnHandler vconn_handler;
-ECPConnHandler vlink_handler;
-
-#define CTYPE_TEST 0
-#define MTYPE_MSG 0
-
-static int handle_open(ECPConnection *conn, ECP2Buffer *b) {
- printf("OPEN\n");
-
- return ECP_OK;
-}
-
-static ssize_t handle_msg(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, size_t msg_size, ECP2Buffer *b) {
- char *_msg = "VAISTINU JE CAR!";
- ssize_t rv;
-
- printf("MSG:%s size:%ld\n", msg, msg_size);
- rv = ecp_msg_send(conn, MTYPE_MSG, (unsigned char *)_msg, strlen(_msg)+1);
-
- return msg_size;
-}
-
-static ssize_t handle_dir_msg(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, size_t msg_size, ECP2Buffer *b) {
- size_t rsize;
- uint16_t count;
- ECPConnection *vlink;
- int rv;
-
- if (msg_size < sizeof(uint16_t)) return ECP_ERR_SIZE;
-
- count = \
- ((uint16_t)msg[0] << 8) | \
- ((uint16_t)msg[1]);
-
- printf("DIR MSG:%d\n", count);
-
- rsize = sizeof(uint16_t) + count * ECP_SIZE_DIR_ITEM;
- if (msg_size < rsize) return ECP_ERR_SIZE;
-
- msg += sizeof(uint16_t);
-
- vlink = malloc(sizeof(ECPConnection));
- if (vlink == NULL) return ECP_ERR_ALLOC;
-
- ecp_vlink_init(vlink, conn->sock);
- rv = vc_open_inb(vlink, msg, count, &conn->sock->key_perma.public);
- if (rv) {
- free(vlink);
- return rv;
- }
-
- return rsize;
-}
-
-static void usage(char *arg) {
- fprintf(stderr, "Usage: %s <my.priv> <dir pub> <dir addr>\n", arg);
- exit(1);
-}
-
-int main(int argc, char *argv[]) {
- ECPConnection *conn_dir;
- ECPNode node_dir;
- ecp_ecdh_public_t dir_pub;
- ECPDHKey key_perma;
- int rv;
-
- if (argc != 4) usage(argv[0]);
-
- rv = ecp_init(&ctx, &vconn_handler, &vlink_handler);
- printf("ecp_init RV:%d\n", rv);
-
- ecp_conn_handler_init(&dir_handler, ecp_dir_handle_open, NULL, handle_dir_msg, NULL);
- ecp_ctx_set_handler(&ctx, ECP_CTYPE_DIR, &dir_handler);
-
- ecp_conn_handler_init(&handler, handle_open, NULL, handle_msg, NULL);
- ecp_ctx_set_handler(&ctx, CTYPE_TEST, &handler);
-
- rv = ecp_util_load_key(argv[1], &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_sock_open(&sock, NULL);
- printf("ecp_sock_open RV:%d\n", rv);
-
- rv = ecp_start_receiver(&sock);
- printf("ecp_start_receiver RV:%d\n", rv);
-
- rv = ecp_util_load_key(argv[2], &dir_pub, NULL);
- printf("ecp_util_load_key RV:%d\n", rv);
-
- ecp_node_init(&node_dir, &dir_pub, NULL);
- rv = ecp_node_set_addr(&node_dir, argv[3]);
- printf("ecp_node_set_addr RV:%d\n", rv);
-
- conn_dir = malloc(sizeof(ECPConnection));
- if (conn_dir == NULL) printf("out of memory\n");
-
- ecp_dir_conn_init(conn_dir, &sock);
- rv = ecp_conn_open(conn_dir, &node_dir);
- printf("ecp_conn_open RV:%d\n", rv);
-
- while (1) sleep(1);
-}
diff --git a/ecp/test/vc_outb.c b/ecp/test/vc_outb.c
deleted file mode 100644
index 4b14244..0000000
--- a/ecp/test/vc_outb.c
+++ /dev/null
@@ -1,128 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdio.h>
-
-#include <ecp/core.h>
-#include <ecp/dir/dir.h>
-#include <ecp/vconn/vconn.h>
-
-#include <util.h>
-
-#include "init_vconn.h"
-#include "vc_common.h"
-
-ECPContext ctx;
-ECPSocket sock;
-ECPConnHandler handler;
-ECPConnHandler dir_handler;
-ECPConnHandler vconn_handler;
-ECPConnHandler vlink_handler;
-ecp_ecdh_public_t remote_pub;
-
-#define CTYPE_TEST 0
-#define MTYPE_MSG 0
-
-static int handle_open(ECPConnection *conn, ECP2Buffer *b) {
- char *_msg = "PERA JE CAR!";
- ssize_t rv;
-
- printf("OPEN\n");
- rv = ecp_msg_send(conn, MTYPE_MSG, (unsigned char *)_msg, strlen(_msg)+1);
-
- return ECP_OK;
-}
-
-static ssize_t handle_msg(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, size_t msg_size, ECP2Buffer *b) {
- printf("MSG:%s size:%ld\n", msg, msg_size);
-
- return msg_size;
-}
-
-static ssize_t handle_dir_msg(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, size_t msg_size, ECP2Buffer *b) {
- size_t rsize;
- uint16_t count;
- ECPConnection *_conn;
- int rv;
-
- if (msg_size < sizeof(uint16_t)) return ECP_ERR_SIZE;
-
- count = \
- ((uint16_t)msg[0] << 8) | \
- ((uint16_t)msg[1]);
-
- printf("DIR MSG:%d\n", count);
-
- rsize = sizeof(uint16_t) + count * ECP_SIZE_DIR_ITEM;
- if (msg_size < rsize) return ECP_ERR_SIZE;
-
- msg += sizeof(uint16_t);
-
- _conn = malloc(sizeof(ECPConnection));
- if (_conn == NULL) return ECP_ERR_ALLOC;
-
- ecp_conn_init(_conn, conn->sock, CTYPE_TEST);
- rv = vc_open_outb(_conn, msg, count, &remote_pub);
- if (rv) {
- printf("vc_open_outb RV:%d\n", rv);
- free(_conn);
- return rv;
- }
-
- return rsize;
-}
-
-static void usage(char *arg) {
- fprintf(stderr, "Usage: %s <remote.pub> <dir pub> <dir addr>\n", arg);
- exit(1);
-}
-
-int main(int argc, char *argv[]) {
- ECPConnection *conn_dir;
- ECPNode node_dir;
- ecp_ecdh_public_t dir_pub;
- ECPDHKey key_perma;
- int rv;
-
- if (argc != 4) usage(argv[0]);
-
- rv = ecp_init(&ctx, &vconn_handler, &vlink_handler);
- printf("ecp_init RV:%d\n", rv);
-
- ecp_conn_handler_init(&dir_handler, ecp_dir_handle_open, NULL, handle_dir_msg, NULL);
- ecp_ctx_set_handler(&ctx, ECP_CTYPE_DIR, &dir_handler);
-
- ecp_conn_handler_init(&handler, handle_open, NULL, handle_msg, NULL);
- ecp_ctx_set_handler(&ctx, CTYPE_TEST, &handler);
-
- rv = ecp_dhkey_gen(&key_perma);
- printf("ecp_dhkey_gen RV:%d\n", rv);
-
- rv = ecp_sock_create(&sock, &ctx, &key_perma);
- printf("ecp_sock_create RV:%d\n", rv);
-
- rv = ecp_sock_open(&sock, NULL);
- printf("ecp_sock_open RV:%d\n", rv);
-
- rv = ecp_start_receiver(&sock);
- printf("ecp_start_receiver RV:%d\n", rv);
-
- rv = ecp_util_load_key(argv[1], &remote_pub, NULL);
- printf("ecp_util_load_key RV:%d\n", rv);
-
- rv = ecp_util_load_key(argv[2], &dir_pub, NULL);
- printf("ecp_util_load_key RV:%d\n", rv);
-
- ecp_node_init(&node_dir, &dir_pub, NULL);
- rv = ecp_node_set_addr(&node_dir, argv[3]);
- printf("ecp_node_set_addr RV:%d\n", rv);
-
- conn_dir = malloc(sizeof(ECPConnection));
- if (conn_dir == NULL) printf("out of memory\n");
-
- ecp_dir_conn_init(conn_dir, &sock);
- rv = ecp_conn_open(conn_dir, &node_dir);
- printf("ecp_conn_open RV:%d\n", rv);
-
- while (1) sleep(1);
-}
diff --git a/ecp/test/vc_server.c b/ecp/test/vc_server.c
index a1a1c51..5157c84 100644
--- a/ecp/test/vc_server.c
+++ b/ecp/test/vc_server.c
@@ -16,7 +16,7 @@ ECPConnHandler handler;
ECPConnHandler vconn_handler;
ECPConnHandler vlink_handler;
ECPConnection conn;
-ECPVConnOutb vconn[3];
+ECPVConnOutb vconn[ECP_MAX_PARENT];
#define CTYPE_TEST 0
#define MTYPE_MSG 0
@@ -44,11 +44,11 @@ static void usage(char *arg) {
int main(int argc, char *argv[]) {
ECPDHKey key_perma;
- ECPNode node;
- ecp_ecdh_public_t node_pub;
+ ecp_tr_addr_t addr;
+ ecp_ecdh_public_t vconn_pub[ECP_MAX_PARENT];
int rv, i;
- if ((argc < 4) || (argc > 7)) usage(argv[0]);
+ if ((argc < 4) || (argc > 3 + ECP_MAX_PARENT)) usage(argv[0]);
rv = ecp_init(&ctx, &vconn_handler, &vlink_handler);
LOG("ecp_init", rv);
@@ -64,7 +64,7 @@ int main(int argc, char *argv[]) {
LOG("ecp_sock_create", rv);
rv = ecp_vconn_sock_create(&sock);
- LOG("ecp_vconn_htable_init", rv);
+ LOG("ecp_vconn_sock_create", rv);
rv = ecp_sock_open(&sock, NULL);
LOG("ecp_sock_open", rv);
@@ -72,27 +72,21 @@ int main(int argc, char *argv[]) {
rv = ecp_start_receiver(&sock);
LOG("ecp_start_receiver", rv);
- rv = ecp_util_load_key(argv[argc-1], &node_pub, NULL);
- LOG("ecp_util_load_key", rv);
+ rv = ecp_addr_init(&addr, argv[2]);
+ LOG("ecp_addr_init", rv);
- ecp_node_init(&node, &node_pub, NULL);
- rv = ecp_node_set_addr(&node, argv[2]);
- LOG("ecp_node_set_addr", rv);
+ for (i=3; i<argc; i++) {
+ rv = ecp_util_load_key(argv[i], &vconn_pub[i-3], NULL);
+ LOG("ecp_util_load_key", rv);
+ }
- ecp_vlink_init(&conn, &sock);
if (argc > 4) {
- ecp_ecdh_public_t vconn_pub[3];
-
- for (i=3; i<argc-1; i++) {
- rv = ecp_util_load_key(argv[i], &vconn_pub[i-3], NULL);
- LOG("ecp_util_load_key", rv);
- }
- ecp_vconn_init(vconn, vconn_pub, argc-4, &sock);
-
- rv = ecp_vconn_open(vconn, &conn, &node);
- LOG("ecp_vconn_open", rv);
+ ecp_vconn_init_vlink(vconn, argc-3, &sock);
+ rv = ecp_vconn_open_vlink(vconn, vconn_pub, &addr);
+ LOG("ecp_vconn_open_vlink", rv);
} else {
- rv = ecp_conn_open(&conn, &node);
+ ecp_vlink_init(&conn, &sock);
+ rv = ecp_conn_open(&conn, &vconn_pub[0], &addr);
LOG("ecp_conn_open", rv);
}
diff --git a/ecp/test/vconn_inb.c b/ecp/test/vconn_inb.c
new file mode 100644
index 0000000..7701a2d
--- /dev/null
+++ b/ecp/test/vconn_inb.c
@@ -0,0 +1,110 @@
+#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 <ecp/vconn/vconn.h>
+
+#include <util.h>
+
+#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];
+
+#define CTYPE_TEST 0
+#define MTYPE_MSG 0
+
+static int handle_open(ECPConnection *conn, ECP2Buffer *b) {
+ printf("OPEN\n");
+
+ return ECP_OK;
+}
+
+static ssize_t handle_msg(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, size_t msg_size, ECP2Buffer *b) {
+ char *_msg = "VAISTINU JE CAR!";
+ ssize_t rv;
+
+ printf("MSG:%s size:%ld\n", msg, msg_size);
+ rv = ecp_msg_send(conn, MTYPE_MSG, (unsigned char *)_msg, strlen(_msg)+1);
+
+ 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;
+
+ LOG("handle_dir_list", err);
+
+ _rv = ecp_dir_hrw_select(dir_list, &sock->key_perma.public, vconn_pub, ECP_MAX_PARENT, &addr);
+ LOG("ecp_dir_hrw_select", (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_list_destroy(dir_list);
+}
+
+static void usage(char *arg) {
+ fprintf(stderr, "Usage: %s <server.priv> <address> <dir.pub>\n", arg);
+ exit(1);
+}
+
+int main(int argc, char *argv[]) {
+ ECPDHKey key_perma;
+ ecp_tr_addr_t addr;
+ ecp_ecdh_public_t public;
+ int rv;
+
+ if (argc != 4) usage(argv[0]);
+
+ rv = ecp_init(&ctx, &vconn_handler, &vlink_handler);
+ LOG("ecp_init", rv);
+
+ rv = ecp_dir_set_handler(&ctx, &dir_handler, handle_dir_list);
+ LOG("ecp_dir_set_handler", rv);
+
+ ecp_conn_handler_init(&handler, handle_open, NULL, handle_msg, NULL);
+ ecp_ctx_set_handler(&ctx, CTYPE_TEST, &handler);
+
+ rv = ecp_util_load_key(argv[1], &key_perma.public, &key_perma.private);
+ LOG("ecp_util_load_key", rv);
+ key_perma.valid = 1;
+
+ rv = ecp_sock_create(&sock, &ctx, &key_perma);
+ LOG("ecp_sock_create", rv);
+
+ rv = ecp_vconn_sock_create(&sock);
+ LOG("ecp_vconn_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_addr_init(&addr, argv[2]);
+ LOG("ecp_addr_init", rv);
+
+ 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);
+ LOG("ecp_dir_get", rv);
+
+ while(1) pause();
+}
diff --git a/ecp/test/vconn_outb.c b/ecp/test/vconn_outb.c
new file mode 100644
index 0000000..8b7782b
--- /dev/null
+++ b/ecp/test/vconn_outb.c
@@ -0,0 +1,117 @@
+#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 <ecp/vconn/vconn.h>
+
+#include <util.h>
+
+#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];
+ecp_ecdh_public_t srv_public;
+
+#define CTYPE_TEST 0
+#define MTYPE_MSG 0
+
+static int handle_open(ECPConnection *conn, ECP2Buffer *b) {
+ char *_msg = "PERA JE CAR!";
+ ssize_t rv;
+
+ printf("Press ENTER key to start\n");
+ while(getchar()!='\n');
+
+ rv = ecp_msg_send(conn, MTYPE_MSG, (unsigned char *)_msg, strlen(_msg)+1);
+
+ return ECP_OK;
+}
+
+static ssize_t handle_msg(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, size_t msg_size, ECP2Buffer *b) {
+ printf("MSG:%s size:%ld\n", msg, msg_size);
+
+ 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;
+
+ LOG("handle_dir_list", err);
+
+ _rv = ecp_dir_hrw_select(dir_list, &srv_public, vconn_pub, ECP_MAX_PARENT, &addr);
+ LOG("ecp_dir_hrw_select", (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_list_destroy(dir_list);
+}
+
+static void usage(char *arg) {
+ fprintf(stderr, "Usage: %s <server.pub> <address> <dir.pub>\n", arg);
+ exit(1);
+}
+
+int main(int argc, char *argv[]) {
+ ECPDHKey key_perma;
+ ecp_tr_addr_t addr;
+ ecp_ecdh_public_t public;
+ int rv;
+
+ if (argc != 4) usage(argv[0]);
+
+ rv = ecp_init(&ctx, &vconn_handler, &vlink_handler);
+ LOG("ecp_init", rv);
+
+ rv = ecp_dir_set_handler(&ctx, &dir_handler, handle_dir_list);
+ LOG("ecp_dir_set_handler", rv);
+
+ ecp_conn_handler_init(&handler, handle_open, NULL, handle_msg, NULL);
+ ecp_ctx_set_handler(&ctx, CTYPE_TEST, &handler);
+
+ rv = ecp_dhkey_gen(&key_perma);
+ LOG("ecp_dhkey_gen", rv);
+
+ rv = ecp_sock_create(&sock, &ctx, &key_perma);
+ LOG("ecp_sock_create", rv);
+
+ rv = ecp_vconn_sock_create(&sock);
+ LOG("ecp_vconn_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[1], &srv_public, NULL);
+ LOG("ecp_util_load_key", rv);
+
+ rv = ecp_addr_init(&addr, argv[2]);
+ LOG("ecp_addr_init", rv);
+
+ 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);
+ LOG("ecp_dir_get", rv);
+
+ while (1) sleep(1);
+}
diff --git a/ecp/test/vcs.c b/ecp/test/vcs.c
index 1260f2b..48bab41 100644
--- a/ecp/test/vcs.c
+++ b/ecp/test/vcs.c
@@ -26,16 +26,13 @@ static int vlink_handle_open(ECPConnection *_conn, ECP2Buffer *bufs) {
/* 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);
+ rv = ecp_conn_open(conn_r, &_conn->remote.key_perma.public, &_conn->remote.addr);
printf("open return connection: ecp_conn_open RV:%d\n", rv);
if (rv) return rv;
}
@@ -63,7 +60,7 @@ int main(int argc, char *argv[]) {
LOG("ecp_sock_create", rv);
rv = ecp_vconn_sock_create(&sock);
- LOG("ecp_vconn_htable_init", rv);
+ LOG("ecp_vconn_sock_create", rv);
rv = ecp_addr_init(&addr, argv[1]);
LOG("ecp_addr_init", rv);
@@ -75,18 +72,16 @@ int main(int argc, char *argv[]) {
LOG("ecp_start_receiver", rv);
if (argc == 5) {
- ECPNode node;
- ecp_ecdh_public_t node_pub;
+ ecp_ecdh_public_t public;
- rv = ecp_util_load_key(argv[4], &node_pub, NULL);
- LOG("ecp_util_load_key", rv);
+ rv = ecp_addr_init(&addr, argv[3]);
+ LOG("ecp_addr_init", rv);
- ecp_node_init(&node, &node_pub, NULL);
- rv = ecp_node_set_addr(&node, argv[3]);
- LOG("ecp_node_set_addr", rv);
+ rv = ecp_util_load_key(argv[4], &public, NULL);
+ LOG("ecp_util_load_key", rv);
ecp_vlink_init(&conn, &sock);
- rv = ecp_conn_open(&conn, &node);
+ rv = ecp_conn_open(&conn, &public, &addr);
LOG("ecp_conn_open", rv);
} else {
memset(&conn, 0, sizeof(conn));