summaryrefslogtreecommitdiff
path: root/code
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2017-05-23 22:24:50 +0200
committerUros Majstorovic <majstor@majstor.org>2017-05-23 22:24:50 +0200
commitb4c8007d3b2082c757ae42008e915872c8ebe671 (patch)
treecd218340840a0a05779703357742b0c2c92e1b6b /code
parentab0325ae7906230f1ea82f08b27c72b075e9a13d (diff)
proxy passed test; various bug fixes
Diffstat (limited to 'code')
-rw-r--r--code/core/Makefile2
-rw-r--r--code/core/config.h1
-rw-r--r--code/core/core.c59
-rw-r--r--code/core/timer.c6
-rw-r--r--code/proxy/proxy.c73
-rw-r--r--code/proxy/proxy.h4
-rw-r--r--code/test/Makefile23
-rw-r--r--code/test/basic.c2
-rw-r--r--code/test/client.c81
-rw-r--r--code/test/pr_client.c89
-rw-r--r--code/test/pr_server.c80
-rw-r--r--code/test/proxy.c39
-rw-r--r--code/test/server.c61
-rw-r--r--code/test/stress.c2
-rw-r--r--code/util/mknode.c2
-rw-r--r--code/util/util.c2
16 files changed, 450 insertions, 76 deletions
diff --git a/code/core/Makefile b/code/core/Makefile
index 2cae048..f0e46a1 100644
--- a/code/core/Makefile
+++ b/code/core/Makefile
@@ -1,5 +1,5 @@
MAKE=make
-CFLAGS = -I. -pthread -O3 $(PIC) -DECP_DEBUG
+CFLAGS = -I. -pthread -O3 $(PIC)
obj = core.o timer.o msgq.o
subdirs = crypto posix htable
diff --git a/code/core/config.h b/code/core/config.h
index 83108a6..94efd29 100644
--- a/code/core/config.h
+++ b/code/core/config.h
@@ -1,2 +1,3 @@
#define ECP_WITH_PTHREAD 1
#define ECP_WITH_HTABLE 1
+#define ECP_DEBUG 1 \ No newline at end of file
diff --git a/code/core/core.c b/code/core/core.c
index 93495d0..02d8ce2 100644
--- a/code/core/core.c
+++ b/code/core/core.c
@@ -170,13 +170,12 @@ int ecp_sock_create(ECPSocket *sock, ECPContext *ctx, ECPDHKey *key) {
if (sock == NULL) return ECP_ERR;
if (ctx == NULL) return ECP_ERR;
- if (key == NULL) return ECP_ERR;
memset(sock, 0, sizeof(ECPSocket));
sock->ctx = ctx;
sock->poll_timeout = ECP_POLL_TIMEOUT;
sock->key_curr = 0;
- sock->key_perma = *key;
+ if (key) sock->key_perma = *key;
sock->conn_new = ecp_conn_handle_new;
rv = ecp_dhkey_generate(sock->ctx, &sock->key[sock->key_curr]);
@@ -217,18 +216,22 @@ void ecp_sock_close(ECPSocket *sock) {
}
int ecp_sock_dhkey_get_curr(ECPSocket *sock, unsigned char *idx, unsigned char *public) {
+ unsigned char _idx;
+
#ifdef ECP_WITH_PTHREAD
pthread_mutex_lock(&sock->mutex);
#endif
- if (idx) *idx = sock->key_curr;
- if (*idx != ECP_ECDH_IDX_INV) sock->ctx->cr.dh_pub_to_buf(public, &sock->key[sock->key_curr].public);
+ _idx = sock->key_curr;
+ if (_idx != ECP_ECDH_IDX_INV) sock->ctx->cr.dh_pub_to_buf(public, &sock->key[_idx].public);
#ifdef ECP_WITH_PTHREAD
pthread_mutex_unlock(&sock->mutex);
#endif
- if (*idx == ECP_ECDH_IDX_INV) return ECP_ERR_ECDH_IDX;
+ if (_idx == ECP_ECDH_IDX_INV) return ECP_ERR_ECDH_IDX;
+
+ if (idx) *idx = _idx;
return ECP_OK;
}
@@ -265,20 +268,17 @@ static int conn_dhkey_new_pair(ECPConnection *conn, ECPDHKey *key) {
ECPContext *ctx = sock->ctx;
conn->key_curr = conn->key_curr == ECP_ECDH_IDX_INV ? 0 : (conn->key_curr+1) % ECP_MAX_CONN_KEY;
- if (ctx->ht.init && conn->out && ecp_conn_is_reg(conn)) {
- int rv;
- unsigned char *pub_s = NULL;
- if ((conn->key_curr != ECP_ECDH_IDX_INV) && conn->key[conn->key_curr].valid) {
- pub_s = ctx->cr.dh_pub_get_buf(&conn->key[conn->key_curr].public);
- ctx->ht.remove(sock->conn.htable, pub_s);
- }
- pub_s = ctx->cr.dh_pub_get_buf(&key->public);
- rv = ctx->ht.insert(sock->conn.htable, pub_s, conn);
- if (rv) return rv;
+ if (ctx->ht.init && conn->out && ecp_conn_is_reg(conn) && conn->key[conn->key_curr].valid) {
+ ctx->ht.remove(sock->conn.htable, ctx->cr.dh_pub_get_buf(&conn->key[conn->key_curr].public));
}
conn->key[conn->key_curr] = *key;
conn->key_idx_map[conn->key_curr] = ECP_ECDH_IDX_INV;
+ if (ctx->ht.init && conn->out && ecp_conn_is_reg(conn)) {
+ int rv = ctx->ht.insert(sock->conn.htable, ctx->cr.dh_pub_get_buf(&conn->key[conn->key_curr].public), conn);
+ if (rv) return rv;
+ }
+
return ECP_OK;
}
@@ -312,13 +312,8 @@ static int conn_dhkey_new_pub_remote(ECPConnection *conn, unsigned char idx, uns
if (idx >= ECP_MAX_SOCK_KEY) return ECP_ERR_ECDH_IDX;
if ((remote->key_idx_map[idx] != ECP_ECDH_IDX_INV) && ctx->cr.dh_pub_eq(public, &remote->key[remote->key_idx_map[idx]].public)) return ECP_ERR_ECDH_KEY_DUP;
- if (ctx->ht.init && !conn->out && ecp_conn_is_reg(conn)) {
- if (remote->key[new].idx != ECP_ECDH_IDX_INV) {
- unsigned char *pub_s = ctx->cr.dh_pub_get_buf(&remote->key[new].public);
- ctx->ht.remove(sock->conn.htable, pub_s);
- }
- int rv = ctx->ht.insert(sock->conn.htable, public, conn);
- if (rv) return rv;
+ if (ctx->ht.init && !conn->out && ecp_conn_is_reg(conn) && (remote->key[new].idx != ECP_ECDH_IDX_INV)) {
+ ctx->ht.remove(sock->conn.htable, ctx->cr.dh_pub_get_buf(&remote->key[new].public));
}
if (remote->key[new].idx != ECP_ECDH_IDX_INV) remote->key_idx_map[remote->key[new].idx] = ECP_ECDH_IDX_INV;
@@ -327,6 +322,11 @@ static int conn_dhkey_new_pub_remote(ECPConnection *conn, unsigned char idx, uns
remote->key[new].idx = idx;
remote->key_curr = new;
+ if (ctx->ht.init && !conn->out && ecp_conn_is_reg(conn)) {
+ int rv = ctx->ht.insert(sock->conn.htable, ctx->cr.dh_pub_get_buf(&remote->key[new].public), conn);
+ if (rv) return rv;
+ }
+
for (i=0; i<ECP_MAX_NODE_KEY; i++) {
conn->shared[i][new].valid = 0;
}
@@ -809,20 +809,23 @@ int ecp_conn_dhkey_new_pub(ECPConnection *conn, unsigned char idx, unsigned char
}
int ecp_conn_dhkey_get_curr(ECPConnection *conn, unsigned char *idx, unsigned char *public) {
+ unsigned char _idx;
ECPSocket *sock = conn->sock;
#ifdef ECP_WITH_PTHREAD
pthread_mutex_lock(&conn->mutex);
#endif
- if (idx) *idx = conn->key_curr;
- if (conn->key_curr != ECP_ECDH_IDX_INV) sock->ctx->cr.dh_pub_to_buf(public, &conn->key[conn->key_curr].public);
+ _idx = conn->key_curr;
+ if (_idx != ECP_ECDH_IDX_INV) sock->ctx->cr.dh_pub_to_buf(public, &conn->key[_idx].public);
#ifdef ECP_WITH_PTHREAD
pthread_mutex_unlock(&conn->mutex);
#endif
- if (*idx == ECP_ECDH_IDX_INV) return ecp_sock_dhkey_get_curr(sock, idx, public);
+ if (_idx == ECP_ECDH_IDX_INV) return ecp_sock_dhkey_get_curr(sock, idx, public);
+
+ if (idx) *idx = _idx;
return ECP_OK;
}
@@ -918,7 +921,6 @@ ssize_t ecp_conn_pack(ECPConnection *conn, ECPNetAddr *addr, unsigned char *pack
ssize_t ecp_proxy_pack(ECPConnection *conn, ECPNetAddr *addr, unsigned char *packet, size_t pkt_size, unsigned char s_idx, unsigned char c_idx, unsigned char *payload, size_t payload_size) {
ECPContext *ctx = conn->sock->ctx;
- ssize_t rv = 0;
if (conn->proxy && ctx->pr.init) {
return ctx->pr.pack(conn, addr, packet, pkt_size, s_idx, c_idx, payload, payload_size);
@@ -1151,7 +1153,7 @@ ssize_t ecp_msg_handle(ECPConnection *conn, unsigned char *msg, size_t msg_size)
if (mtype >= ECP_MAX_MTYPE) return ECP_ERR_MAX_MTYPE;
if (rem_size < ECP_MIN_MSG) return ECP_ERR_MIN_MSG;
- ecp_timer_pop(conn, mtype);
+ if (conn->out) ecp_timer_pop(conn, mtype);
handler = conn->sock->ctx->handler[conn->type] ? conn->sock->ctx->handler[conn->type]->msg[mtype] : NULL;
if (handler) {
rv = handler(conn, mtype, msg, rem_size);
@@ -1161,6 +1163,7 @@ ssize_t ecp_msg_handle(ECPConnection *conn, unsigned char *msg, size_t msg_size)
if (rv > rem_size) return ECP_ERR;
rem_size -= rv;
+ msg += rv;
} else {
return msg_size-rem_size-1;
}
@@ -1193,7 +1196,7 @@ ssize_t ecp_pld_send_wkey(ECPConnection *conn, unsigned char s_idx, unsigned cha
rv = ecp_proxy_pack(conn, &addr, packet, ECP_MAX_PKT, s_idx, c_idx, payload, payload_size);
if (rv < 0) return rv;
-
+
return ecp_pkt_send(sock, &addr, packet, rv);
}
diff --git a/code/core/timer.c b/code/core/timer.c
index cf77d6e..47a3b9d 100644
--- a/code/core/timer.c
+++ b/code/core/timer.c
@@ -184,12 +184,14 @@ unsigned int ecp_timer_exe(ECPSocket *sock) {
ecp_conn_handler_msg_t *handler = conn->sock->ctx->handler[conn->type] ? conn->sock->ctx->handler[conn->type]->msg[mtype] : NULL;
if (to_exec[i].cnt) {
+ ssize_t _rv = 0;
to_exec[i].cnt--;
to_exec[i].abstime = now + to_exec[i].timeout;
if (retry) {
- rv = retry(conn, to_exec+i);
+ _rv = retry(conn, to_exec+i);
+ if (_rv < 0) rv = _rv;
} else {
- ssize_t _rv = ecp_pld_send(conn, pld, pld_size);
+ _rv = ecp_pld_send(conn, pld, pld_size);
if (_rv < 0) rv = _rv;
}
if (!rv) rv = ecp_timer_push(to_exec+i);
diff --git a/code/proxy/proxy.c b/code/proxy/proxy.c
index 3d6ffec..c6bded8 100644
--- a/code/proxy/proxy.c
+++ b/code/proxy/proxy.c
@@ -1,4 +1,4 @@
-#include <core.h>
+#include "core.h"
#include "proxy.h"
#ifdef ECP_WITH_PTHREAD
@@ -24,13 +24,13 @@ static int proxyf_create(ECPConnection *conn, unsigned char *payload, size_t siz
if (size < 2*ECP_ECDH_SIZE_KEY) return ECP_ERR;
conn_p->key_next_curr = 0;
- memcpy(conn_p->key_next[0], payload, ECP_ECDH_SIZE_KEY);
+ memcpy(conn_p->key_next[conn_p->key_next_curr], payload, ECP_ECDH_SIZE_KEY);
memcpy(conn_p->key_out, payload+ECP_ECDH_SIZE_KEY, ECP_ECDH_SIZE_KEY);
#ifdef ECP_WITH_PTHREAD
pthread_mutex_lock(&key_next_mutex);
#endif
- rv = ctx->ht.init ? ctx->ht.insert(key_next_table, payload+1, conn) : ECP_ERR;
+ rv = ctx->ht.init ? ctx->ht.insert(key_next_table, conn_p->key_next[conn_p->key_next_curr], conn) : ECP_ERR;
#ifdef ECP_WITH_PTHREAD
pthread_mutex_unlock(&key_next_mutex);
#endif
@@ -85,7 +85,7 @@ static ssize_t proxyf_open(ECPConnection *conn) {
ECPConnProxy *conn_p = (ECPConnProxy *)conn;
ECPConnection *conn_next = conn_p->next;
- rv = ecp_timer_item_init(&ti, conn_next, ECP_MTYPE_KGET, 3, 500);
+ rv = ecp_timer_item_init(&ti, conn_next, ECP_MTYPE_KGET, 3, 3000);
if (rv) return rv;
ti.retry = _proxyf_retry_kget;
@@ -124,14 +124,12 @@ static ssize_t proxyf_handle_open(ECPConnection *conn, unsigned char mtype, unsi
if (!ecp_conn_is_open(conn)) conn->flags |= ECP_CONN_FLAG_OPEN;
if (memcmp(conn_p->key_next[conn_p->key_next_curr], msg, ECP_ECDH_SIZE_KEY)) {
- rv = ctx->ht.init ? ctx->ht.insert(key_next_table, msg, conn) : ECP_ERR;
- if (!rv) {
- conn_p->key_next_curr = (conn_p->key_next_curr + 1) % ECP_MAX_NODE_KEY;
- if (memcmp(conn_p->key_next[conn_p->key_next_curr], key_null, ECP_ECDH_SIZE_KEY)) {
- if (ctx->ht.init) ctx->ht.remove(key_next_table, conn_p->key_next[conn_p->key_next_curr]);
- }
- memcpy(conn_p->key_next[conn_p->key_next_curr], msg, ECP_ECDH_SIZE_KEY);
+ conn_p->key_next_curr = (conn_p->key_next_curr + 1) % ECP_MAX_NODE_KEY;
+ if (memcmp(conn_p->key_next[conn_p->key_next_curr], key_null, ECP_ECDH_SIZE_KEY)) {
+ if (ctx->ht.init) ctx->ht.remove(key_next_table, conn_p->key_next[conn_p->key_next_curr]);
}
+ memcpy(conn_p->key_next[conn_p->key_next_curr], msg, ECP_ECDH_SIZE_KEY);
+ rv = ctx->ht.init ? ctx->ht.insert(key_next_table, conn_p->key_next[conn_p->key_next_curr], conn) : ECP_ERR;
}
#ifdef ECP_WITH_PTHREAD
@@ -143,6 +141,8 @@ static ssize_t proxyf_handle_open(ECPConnection *conn, unsigned char mtype, unsi
return 1+2*ECP_ECDH_SIZE_KEY;
}
+
+ return ECP_ERR;
}
static ssize_t proxyf_handle_relay(ECPConnection *conn, unsigned char mtype, unsigned char *msg, ssize_t size) {
@@ -179,7 +179,7 @@ static ssize_t proxyf_handle_relay(ECPConnection *conn, unsigned char mtype, uns
payload = msg - ECP_SIZE_MSG_HDR;
ecp_pld_set_type(payload, ECP_MTYPE_EXEC);
- rv = ecp_pld_send(conn_out, payload, ECP_SIZE_PLD(size));
+ rv = ecp_pld_send(conn_out, payload, ECP_SIZE_MSG_HDR+size);
#ifdef ECP_WITH_PTHREAD
pthread_mutex_lock(&conn_out->mutex);
@@ -207,7 +207,7 @@ static int proxyb_create(ECPConnection *conn, unsigned char *payload, size_t siz
#ifdef ECP_WITH_PTHREAD
pthread_mutex_lock(&key_perma_mutex);
#endif
- rv = ctx->ht.init ? ctx->ht.insert(key_perma_table, payload, conn) : ECP_ERR;
+ rv = ctx->ht.init ? ctx->ht.insert(key_perma_table, ctx->cr.dh_pub_get_buf(&conn->node.public), conn) : ECP_ERR;
#ifdef ECP_WITH_PTHREAD
pthread_mutex_unlock(&key_perma_mutex);
#endif
@@ -255,16 +255,19 @@ static ssize_t proxyb_handle_open(ECPConnection *conn, unsigned char mtype, unsi
if (size < 0) return size;
- if (conn->out) return ECP_ERR;
if (conn->type != ECP_CTYPE_PROXYB) return ECP_ERR;
rv = ecp_conn_handle_open(conn, mtype, msg, size);
if (rv < 0) return rv;
-
- // XXX should verify perma_key
- if (size < rv+ECP_ECDH_SIZE_KEY) return ECP_ERR;
- return rv+ECP_ECDH_SIZE_KEY;
+ if (conn->out) {
+ return 0;
+ } else {
+ // XXX should verify perma_key
+ if (size < rv+ECP_ECDH_SIZE_KEY) return ECP_ERR;
+ return rv+ECP_ECDH_SIZE_KEY;
+ }
+ return ECP_ERR;
}
static ssize_t proxyb_handle_relay(ECPConnection *conn, unsigned char mtype, unsigned char *msg, ssize_t size) {
@@ -299,7 +302,7 @@ static ssize_t proxyb_handle_relay(ECPConnection *conn, unsigned char mtype, uns
payload = msg - ECP_SIZE_MSG_HDR;
ecp_pld_set_type(payload, ECP_MTYPE_EXEC);
- rv = ecp_pld_send(conn, payload, ECP_SIZE_PLD(size));
+ rv = ecp_pld_send(conn, payload, ECP_SIZE_MSG_HDR+size);
#ifdef ECP_WITH_PTHREAD
pthread_mutex_lock(&conn->mutex);
@@ -323,7 +326,7 @@ static ssize_t proxy_set_msg(ECPConnection *conn, unsigned char *pld_out, size_t
unsigned char *buf = NULL;
int rv;
- if (pld_out_size < ECP_SIZE_PLD(2+2*ECP_ECDH_SIZE_KEY)) return ECP_ERR;
+ if (pld_out_size < ECP_SIZE_MSG_HDR+2+2*ECP_ECDH_SIZE_KEY) return ECP_ERR;
if (conn_next == NULL) return ECP_ERR;
ecp_pld_set_type(pld_out, ECP_MTYPE_OPEN);
@@ -336,12 +339,12 @@ static ssize_t proxy_set_msg(ECPConnection *conn, unsigned char *pld_out, size_t
memcpy(buf+1+ECP_ECDH_SIZE_KEY, ctx->cr.dh_pub_get_buf(&conn_next->node.public), ECP_ECDH_SIZE_KEY);
buf[1+2*ECP_ECDH_SIZE_KEY] = ECP_MTYPE_RELAY;
- return ECP_SIZE_PLD(2+2*ECP_ECDH_SIZE_KEY);
+ return ECP_SIZE_MSG_HDR+2+2*ECP_ECDH_SIZE_KEY;
}
}
ecp_pld_set_type(pld_out, ECP_MTYPE_RELAY);
- return ECP_SIZE_PLD(0);
+ return ECP_SIZE_MSG_HDR;
}
static ssize_t proxy_pack(ECPConnection *conn, ECPNetAddr *addr, unsigned char *packet, size_t pkt_size, unsigned char s_idx, unsigned char c_idx, unsigned char *payload, size_t payload_size) {
@@ -365,7 +368,7 @@ static ssize_t proxy_pack_raw(ECPConnection *proxy, ECPNetAddr *addr, unsigned c
rv = ecp_pack(ctx, payload_+hdr_size, ECP_MAX_PLD-hdr_size, s_idx, c_idx, public, shsec, nonce, seq, payload, payload_size);
if (rv < 0) return rv;
- return ecp_proxy_pack(proxy, addr, packet, ECP_MAX_PKT, ECP_ECDH_IDX_INV, ECP_ECDH_IDX_INV, payload_, rv+hdr_size);
+ return ecp_proxy_pack(proxy, addr, packet, pkt_size, ECP_ECDH_IDX_INV, ECP_ECDH_IDX_INV, payload_, rv+hdr_size);
}
int ecp_proxy_init(ECPContext *ctx) {
@@ -409,30 +412,30 @@ int ecp_proxy_init(ECPContext *ctx) {
return ECP_OK;
}
-int ecp_conn_proxy_init(ECPConnection *conn, ECPNode *conn_node, ECPConnProxy *proxy[], ECPNode *proxy_node[], int size) {
+int ecp_conn_proxy_init(ECPConnection *conn, ECPNode *conn_node, ECPConnProxy proxy[], ECPNode proxy_node[], int size) {
ECPSocket *sock = conn->sock;
int i, rv;
rv = ecp_conn_init(conn, conn_node);
if (rv) return rv;
- conn->proxy = (ECPConnection *)proxy[size-1];
+ conn->proxy = (ECPConnection *)&proxy[size-1];
for (i=0; i<size; i++) {
- rv = ecp_conn_create((ECPConnection *)proxy[i], sock, ECP_CTYPE_PROXYF);
+ rv = ecp_conn_create((ECPConnection *)&proxy[i], sock, ECP_CTYPE_PROXYF);
if (rv) return rv;
- rv = ecp_conn_init((ECPConnection *)proxy[i], proxy_node[i]);
+ rv = ecp_conn_init((ECPConnection *)&proxy[i], &proxy_node[i]);
if (rv) return rv;
if (i == 0) {
- proxy[i]->b.proxy = NULL;
+ proxy[i].b.proxy = NULL;
} else {
- proxy[i]->b.proxy = (ECPConnection *)proxy[i-1];
+ proxy[i].b.proxy = (ECPConnection *)&proxy[i-1];
}
if (i == size-1) {
- proxy[i]->next = conn;
+ proxy[i].next = conn;
} else {
- proxy[i]->next = (ECPConnection *)proxy[i+1];
+ proxy[i].next = (ECPConnection *)&proxy[i+1];
}
}
@@ -446,12 +449,12 @@ static ssize_t _proxy_send_kget(ECPConnection *conn, ECPTimerItem *ti) {
return ecp_pld_send_wkey(conn, ECP_ECDH_IDX_PERMA, ECP_ECDH_IDX_INV, payload, sizeof(payload));
}
-int ecp_conn_proxy_open(ECPConnection *conn, ECPNode *conn_node, ECPConnProxy *proxy[], ECPNode *proxy_node[], int size) {
+int ecp_conn_proxy_open(ECPConnection *conn, ECPNode *conn_node, ECPConnProxy proxy[], ECPNode proxy_node[], int size) {
int rv = ecp_conn_proxy_init(conn, conn_node, proxy, proxy_node, size);
if (rv) return rv;
-
- ssize_t _rv = ecp_timer_send((ECPConnection *)proxy[0], _proxy_send_kget, ECP_MTYPE_KGET, 3, 500);
- if (_rv < 0) return _rv;
+ ssize_t _rv = ecp_timer_send((ECPConnection *)&proxy[0], _proxy_send_kget, ECP_MTYPE_KGET, 3, 500);
+ if (_rv < 0) return _rv;
+
return ECP_OK;
} \ No newline at end of file
diff --git a/code/proxy/proxy.h b/code/proxy/proxy.h
index f3bc58a..1ae2566 100644
--- a/code/proxy/proxy.h
+++ b/code/proxy/proxy.h
@@ -17,5 +17,5 @@ typedef struct ECPConnProxyF {
int ecp_proxy_init(ECPContext *ctx);
-int ecp_conn_proxy_init(ECPConnection *conn, ECPNode *conn_node, ECPConnProxy *proxy[], ECPNode *proxy_node[], int size);
-int ecp_conn_proxy_open(ECPConnection *conn, ECPNode *conn_node, ECPConnProxy *proxy[], ECPNode *proxy_node[], int size);
+int ecp_conn_proxy_init(ECPConnection *conn, ECPNode *conn_node, ECPConnProxy proxy[], ECPNode proxy_node[], int size);
+int ecp_conn_proxy_open(ECPConnection *conn, ECPNode *conn_node, ECPConnProxy proxy[], ECPNode proxy_node[], int size);
diff --git a/code/test/Makefile b/code/test/Makefile
index ddfc095..a6ebb90 100644
--- a/code/test/Makefile
+++ b/code/test/Makefile
@@ -1,12 +1,18 @@
-CFLAGS=-I../core -O3 -Wno-int-to-void-pointer-cast
+CFLAGS=-I../core -I../proxy -I../util -O3 -Wno-int-to-void-pointer-cast
LDFLAGS=-lm -pthread
-dep=../core/libecpcore.a ../core/crypto/libecpcr.a ../core/htable/libecpht.a ../core/posix/libecptr.a ../core/posix/libecptm.a
+dep=../core/libecpcore.a ../core/crypto/libecpcr.a ../core/htable/libecpht.a ../core/posix/libecptr.a ../core/posix/libecptm.a ../proxy/libecpproxy.a ../util/libecputil.a
%.o: %.c
$(CC) $(CFLAGS) -c $<
-all: basic stress
+all: client server basic stress proxy pr_server pr_client
+
+client: client.o init.o $(dep)
+ $(CC) -o $@ $(LDFLAGS) $< init.o $(dep)
+
+server: server.o init.o $(dep)
+ $(CC) -o $@ $(LDFLAGS) $< init.o $(dep)
basic: basic.o init.o $(dep)
$(CC) -o $@ $(LDFLAGS) $< init.o $(dep)
@@ -14,6 +20,15 @@ basic: basic.o init.o $(dep)
stress: stress.o init.o $(dep)
$(CC) -o $@ $(LDFLAGS) $< init.o $(dep)
+proxy: proxy.o init_proxy.o $(dep)
+ $(CC) -o $@ $(LDFLAGS) $< init_proxy.o $(dep)
+
+pr_server: pr_server.o init_proxy.o $(dep)
+ $(CC) -o $@ $(LDFLAGS) $< init_proxy.o $(dep)
+
+pr_client: pr_client.o init_proxy.o $(dep)
+ $(CC) -o $@ $(LDFLAGS) $< init_proxy.o $(dep)
+
clean:
rm -f *.o
- rm -f basic stress
+ rm -f basic stress client server proxy pr_server pr_client
diff --git a/code/test/basic.c b/code/test/basic.c
index bcd65bc..36dfc2e 100644
--- a/code/test/basic.c
+++ b/code/test/basic.c
@@ -2,7 +2,7 @@
#include <string.h>
#include <unistd.h>
-#include <core.h>
+#include "core.h"
ECPContext ctx_s;
ECPSocket sock_s;
diff --git a/code/test/client.c b/code/test/client.c
index e69de29..3f33d71 100644
--- a/code/test/client.c
+++ b/code/test/client.c
@@ -0,0 +1,81 @@
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#include "core.h"
+#include "util.h"
+
+ECPContext ctx_c;
+ECPSocket sock_c;
+ECPConnHandler handler_c;
+
+ECPNode node;
+ECPConnection conn;
+
+#define CTYPE_TEST 0
+#define MTYPE_MSG 8
+
+ssize_t handle_open_c(ECPConnection *conn, unsigned char t, unsigned char *p, ssize_t s) {
+ uint32_t seq = 0;
+
+ ecp_conn_handle_open(conn, t, p, s);
+ if (s < 0) {
+ printf("OPEN ERR:%ld\n", s);
+ return 0;
+ }
+
+ unsigned char payload[ECP_SIZE_PLD(1000)];
+ unsigned char *buf = ecp_pld_get_buf(payload);
+ char *msg = "PERA JE CAR!";
+
+ ecp_pld_set_type(payload, MTYPE_MSG);
+ strcpy((char *)buf, msg);
+ ssize_t _rv = ecp_send(conn, payload, sizeof(payload));
+ return 0;
+}
+
+ssize_t handle_msg_c(ECPConnection *conn, unsigned char t, unsigned char *p, ssize_t s) {
+ printf("MSG C:%s size:%ld\n", p, s);
+ return s;
+}
+
+
+static void usage(char *arg) {
+ fprintf(stderr, "Usage: %s <node.pub>\n", arg);
+ exit(1);
+}
+
+int main(int argc, char *argv[]) {
+ int rv;
+
+ if (argc != 2) usage(argv[0]);
+
+ rv = ecp_init(&ctx_c);
+ printf("ecp_init RV:%d\n", rv);
+
+ rv = ecp_conn_handler_init(&handler_c);
+ handler_c.msg[ECP_MTYPE_OPEN] = handle_open_c;
+ handler_c.msg[MTYPE_MSG] = handle_msg_c;
+ ctx_c.handler[CTYPE_TEST] = &handler_c;
+
+ rv = ecp_sock_create(&sock_c, &ctx_c, NULL);
+ printf("ecp_sock_create RV:%d\n", rv);
+
+ rv = ecp_sock_open(&sock_c, NULL);
+ printf("ecp_sock_open RV:%d\n", rv);
+
+ rv = ecp_start_receiver(&sock_c);
+ printf("ecp_start_receiver RV:%d\n", rv);
+
+ rv = ecp_util_node_load(&ctx_c, &node, argv[1]);
+ printf("ecp_util_node_load RV:%d\n", rv);
+
+ rv = ecp_conn_create(&conn, &sock_c, CTYPE_TEST);
+ printf("ecp_conn_create RV:%d\n", rv);
+
+ rv = ecp_conn_open(&conn, &node);
+ printf("ecp_conn_open RV:%d\n", rv);
+
+ while (1) sleep(1);
+} \ No newline at end of file
diff --git a/code/test/pr_client.c b/code/test/pr_client.c
new file mode 100644
index 0000000..a40831c
--- /dev/null
+++ b/code/test/pr_client.c
@@ -0,0 +1,89 @@
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#include "core.h"
+#include "proxy.h"
+#include "util.h"
+
+ECPContext ctx;
+ECPSocket sock;
+ECPConnHandler handler;
+
+ECPConnection conn;
+ECPNode node;
+
+ECPConnProxy conn_proxy;
+ECPNode node_proxy;
+
+#define CTYPE_TEST 0
+#define MTYPE_MSG 8
+
+ssize_t handle_open(ECPConnection *conn, unsigned char t, unsigned char *p, ssize_t s) {
+ uint32_t seq = 0;
+
+ ecp_conn_handle_open(conn, t, p, s);
+ if (s < 0) {
+ printf("OPEN ERR:%ld\n", s);
+ return 0;
+ }
+
+ printf("OPEN!\n");
+
+ unsigned char payload[ECP_SIZE_PLD(1000)];
+ unsigned char *buf = ecp_pld_get_buf(payload);
+ char *msg = "PERA JE CAR!";
+
+ ecp_pld_set_type(payload, MTYPE_MSG);
+ strcpy((char *)buf, msg);
+ ssize_t _rv = ecp_send(conn, payload, sizeof(payload));
+ return 0;
+}
+
+ssize_t handle_msg(ECPConnection *conn, unsigned char t, unsigned char *p, ssize_t s) {
+ printf("MSG S:%s size:%ld\n", p, s);
+ return s;
+}
+
+static void usage(char *arg) {
+ fprintf(stderr, "Usage: %s <server.pub> <proxy.pub>\n", arg);
+ exit(1);
+}
+
+int main(int argc, char *argv[]) {
+ int rv;
+
+ if (argc != 3) usage(argv[0]);
+
+ rv = ecp_init(&ctx);
+ printf("ecp_init RV:%d\n", rv);
+
+ rv = ecp_conn_handler_init(&handler);
+ handler.msg[ECP_MTYPE_OPEN] = handle_open;
+ handler.msg[MTYPE_MSG] = handle_msg;
+ ctx.handler[CTYPE_TEST] = &handler;
+
+ rv = ecp_sock_create(&sock, &ctx, NULL);
+ 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_node_load(&ctx, &node, argv[1]);
+ printf("ecp_util_node_load RV:%d\n", rv);
+
+ rv = ecp_util_node_load(&ctx, &node_proxy, argv[2]);
+ printf("ecp_util_node_load RV:%d\n", rv);
+
+ rv = ecp_conn_create(&conn, &sock, CTYPE_TEST);
+ printf("ecp_conn_create RV:%d\n", rv);
+
+ rv = ecp_conn_proxy_open(&conn, &node, &conn_proxy, &node_proxy, 1);
+ printf("ecp_conn_proxy_open RV:%d\n", rv);
+
+ while (1) sleep(1);
+} \ No newline at end of file
diff --git a/code/test/pr_server.c b/code/test/pr_server.c
new file mode 100644
index 0000000..0f898ce
--- /dev/null
+++ b/code/test/pr_server.c
@@ -0,0 +1,80 @@
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#include "core.h"
+#include "proxy.h"
+#include "util.h"
+
+ECPContext ctx;
+ECPSocket sock;
+ECPDHKey key_perma;
+ECPConnHandler handler;
+
+ECPNode node;
+ECPConnection conn;
+
+#define CTYPE_TEST 0
+#define MTYPE_MSG 8
+
+ssize_t handle_open(ECPConnection *conn, unsigned char t, unsigned char *p, ssize_t s) {
+ printf("OPEN RECEIVED\n");
+ return ecp_conn_handle_open(conn, t, p, s);
+}
+
+ssize_t handle_msg(ECPConnection *conn, unsigned char t, unsigned char *p, ssize_t s) {
+ printf("MSG S:%s size:%ld\n", p, s);
+
+ unsigned char payload[ECP_SIZE_PLD(1000)];
+ unsigned char *buf = ecp_pld_get_buf(payload);
+ char *msg = "VAISTINU JE CAR!";
+
+ ecp_pld_set_type(payload, MTYPE_MSG);
+ strcpy((char *)buf, msg);
+ ssize_t _rv = ecp_send(conn, payload, sizeof(payload));
+
+ return s;
+}
+
+static void usage(char *arg) {
+ fprintf(stderr, "Usage: %s <node.priv> <proxy.pub>\n", arg);
+ exit(1);
+}
+
+int main(int argc, char *argv[]) {
+ int rv;
+
+ if (argc != 3) usage(argv[0]);
+
+ rv = ecp_init(&ctx);
+ printf("ecp_init RV:%d\n", rv);
+
+ rv = ecp_conn_handler_init(&handler);
+ handler.msg[ECP_MTYPE_OPEN] = handle_open;
+ handler.msg[MTYPE_MSG] = handle_msg;
+ ctx.handler[CTYPE_TEST] = &handler;
+
+ rv = ecp_util_key_load(&ctx, &key_perma, argv[1]);
+ printf("ecp_util_key_load 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_node_load(&ctx, &node, argv[2]);
+ printf("ecp_util_node_load RV:%d\n", rv);
+
+ rv = ecp_conn_create(&conn, &sock, ECP_CTYPE_PROXYB);
+ printf("ecp_conn_create RV:%d\n", rv);
+
+ rv = ecp_conn_open(&conn, &node);
+ printf("ecp_conn_open RV:%d\n", rv);
+
+ while (1) sleep(1);
+} \ No newline at end of file
diff --git a/code/test/proxy.c b/code/test/proxy.c
new file mode 100644
index 0000000..cfea6c1
--- /dev/null
+++ b/code/test/proxy.c
@@ -0,0 +1,39 @@
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#include "core.h"
+#include "util.h"
+
+ECPContext ctx;
+ECPSocket sock;
+ECPDHKey key_perma;
+
+static void usage(char *arg) {
+ fprintf(stderr, "Usage: %s <node.priv> [address]\n", arg);
+ exit(1);
+}
+
+int main(int argc, char *argv[]) {
+ int rv;
+
+ if (argc != 2) usage(argv[0]);
+
+ rv = ecp_init(&ctx);
+ printf("ecp_init RV:%d\n", rv);
+
+ rv = ecp_util_key_load(&ctx, &key_perma, argv[1]);
+ printf("ecp_util_key_load 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, "0.0.0.0:3000");
+ printf("ecp_sock_open RV:%d\n", rv);
+
+ rv = ecp_start_receiver(&sock);
+ printf("ecp_start_receiver RV:%d\n", rv);
+
+ while (1) sleep(1);
+} \ No newline at end of file
diff --git a/code/test/server.c b/code/test/server.c
new file mode 100644
index 0000000..71ec2ef
--- /dev/null
+++ b/code/test/server.c
@@ -0,0 +1,61 @@
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#include "core.h"
+#include "util.h"
+
+ECPContext ctx_s;
+ECPSocket sock_s;
+ECPDHKey key_perma_s;
+ECPConnHandler handler_s;
+
+#define CTYPE_TEST 0
+#define MTYPE_MSG 8
+
+ssize_t handle_msg_s(ECPConnection *conn, unsigned char t, unsigned char *p, ssize_t s) {
+ printf("MSG S:%s size:%ld\n", p, s);
+
+ unsigned char payload[ECP_SIZE_PLD(1000)];
+ unsigned char *buf = ecp_pld_get_buf(payload);
+ char *msg = "VAISTINU JE CAR!";
+
+ ecp_pld_set_type(payload, MTYPE_MSG);
+ strcpy((char *)buf, msg);
+ ssize_t _rv = ecp_send(conn, payload, sizeof(payload));
+
+ return s;
+}
+
+static void usage(char *arg) {
+ fprintf(stderr, "Usage: %s <node.priv> [address]\n", arg);
+ exit(1);
+}
+
+int main(int argc, char *argv[]) {
+ int rv;
+
+ if (argc != 2) usage(argv[0]);
+
+ rv = ecp_init(&ctx_s);
+ printf("ecp_init RV:%d\n", rv);
+
+ rv = ecp_conn_handler_init(&handler_s);
+ handler_s.msg[MTYPE_MSG] = handle_msg_s;
+ ctx_s.handler[CTYPE_TEST] = &handler_s;
+
+ rv = ecp_util_key_load(&ctx_s, &key_perma_s, argv[1]);
+ printf("ecp_util_key_load RV:%d\n", rv);
+
+ rv = ecp_sock_create(&sock_s, &ctx_s, &key_perma_s);
+ printf("ecp_sock_create RV:%d\n", rv);
+
+ rv = ecp_sock_open(&sock_s, "0.0.0.0:3000");
+ printf("ecp_sock_open RV:%d\n", rv);
+
+ rv = ecp_start_receiver(&sock_s);
+ printf("ecp_start_receiver RV:%d\n", rv);
+
+ while (1) sleep(1);
+} \ No newline at end of file
diff --git a/code/test/stress.c b/code/test/stress.c
index 41883c2..c76ebe9 100644
--- a/code/test/stress.c
+++ b/code/test/stress.c
@@ -6,7 +6,7 @@
#include <sys/time.h>
#include <pthread.h>
-#include <core.h>
+#include "core.h"
#ifdef __linux__
#define SIGINFO SIGTSTP
diff --git a/code/util/mknode.c b/code/util/mknode.c
index 0c389dc..8f40e90 100644
--- a/code/util/mknode.c
+++ b/code/util/mknode.c
@@ -3,7 +3,7 @@
#include <unistd.h>
#include <stdio.h>
-#include <core.h>
+#include "core.h"
#include "util.h"
#define FN_LEN 256
diff --git a/code/util/util.c b/code/util/util.c
index e225ea1..e07748b 100644
--- a/code/util/util.c
+++ b/code/util/util.c
@@ -2,7 +2,7 @@
#include <fcntl.h>
#include <unistd.h>
-#include <core.h>
+#include "core.h"
#include "util.h"
int ecp_util_key_save(ECPContext *ctx, ECPDHKey *key, char *filename) {