diff options
-rwxr-xr-x | code/build.sh | 2 | ||||
-rw-r--r-- | code/proxy/proxy.h | 22 | ||||
-rw-r--r-- | code/test/Makefile | 20 | ||||
-rw-r--r-- | code/test/init_vconn.c (renamed from code/test/init_proxy.c) | 8 | ||||
-rw-r--r-- | code/test/vc_client.c (renamed from code/test/pr_client.c) | 14 | ||||
-rw-r--r-- | code/test/vc_server.c (renamed from code/test/pr_server.c) | 6 | ||||
-rw-r--r-- | code/test/vcs.c (renamed from code/test/proxy.c) | 4 | ||||
-rw-r--r-- | code/vconn/Makefile (renamed from code/proxy/Makefile) | 4 | ||||
-rw-r--r-- | code/vconn/vconn.c (renamed from code/proxy/proxy.c) | 192 | ||||
-rw-r--r-- | code/vconn/vconn.h | 22 |
10 files changed, 147 insertions, 147 deletions
diff --git a/code/build.sh b/code/build.sh index 96f26e3..ce29ff5 100755 --- a/code/build.sh +++ b/code/build.sh @@ -1,6 +1,6 @@ #!/bin/sh -subdirs="core proxy util test" +subdirs="core vconn util test" for i in $subdirs; do (cd $i && make $1 && cd ..) || exit; diff --git a/code/proxy/proxy.h b/code/proxy/proxy.h deleted file mode 100644 index 6f82cd2..0000000 --- a/code/proxy/proxy.h +++ /dev/null @@ -1,22 +0,0 @@ -#define ECP_CTYPE_PROXYF 1 -#define ECP_CTYPE_PROXYB 2 - -#define ECP_MTYPE_RELAY 0x08 -#define ECP_MTYPE_EXEC 0x09 - -typedef struct ECPConnProxy { - ECPConnection b; - ECPConnection *next; -} ECPConnProxy; - -typedef struct ECPConnProxyF { - ECPConnection b; - unsigned char key_next[ECP_MAX_NODE_KEY][ECP_ECDH_SIZE_KEY]; - unsigned char key_next_curr; - unsigned char key_out[ECP_ECDH_SIZE_KEY]; -} 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); diff --git a/code/test/Makefile b/code/test/Makefile index 8f42021..997f77e 100644 --- a/code/test/Makefile +++ b/code/test/Makefile @@ -1,12 +1,12 @@ -CFLAGS=-I../core -I../proxy -I../util -O3 -Wno-int-to-void-pointer-cast +CFLAGS=-I../core -I../vconn -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 ../proxy/libecpproxy.a ../util/libecputil.a +dep=../core/libecpcore.a ../core/crypto/libecpcr.a ../core/htable/libecpht.a ../core/posix/libecptr.a ../core/posix/libecptm.a ../vconn/libecpvconn.a ../util/libecputil.a %.o: %.c $(CC) $(CFLAGS) -c $< -all: basic client server echo stress proxy pr_server pr_client +all: basic client server echo stress vcs vc_server vc_client basic: basic.o init.o $(dep) $(CC) -o $@ $< init.o $(dep) $(LDFLAGS) @@ -23,14 +23,14 @@ echo: echo.o init.o $(dep) stress: stress.o init.o $(dep) $(CC) -o $@ $< init.o $(dep) $(LDFLAGS) -proxy: proxy.o init_proxy.o $(dep) - $(CC) -o $@ $< init_proxy.o $(dep) $(LDFLAGS) +vcs: vcs.o init_vconn.o $(dep) + $(CC) -o $@ $< init_vconn.o $(dep) $(LDFLAGS) -pr_server: pr_server.o init_proxy.o $(dep) - $(CC) -o $@ $< init_proxy.o $(dep) $(LDFLAGS) +vc_server: vc_server.o init_vconn.o $(dep) + $(CC) -o $@ $< init_vconn.o $(dep) $(LDFLAGS) -pr_client: pr_client.o init_proxy.o $(dep) - $(CC) -o $@ $< init_proxy.o $(dep) $(LDFLAGS) +vc_client: vc_client.o init_vconn.o $(dep) + $(CC) -o $@ $< init_vconn.o $(dep) $(LDFLAGS) opus_root=../../../opus-1.1.5 @@ -42,4 +42,4 @@ voip: voip.o init.o $(dep) clean: rm -f *.o - rm -f basic client server echo stress proxy pr_server pr_client voip + rm -f basic client server echo stress vcs vc_server vc_client voip diff --git a/code/test/init_proxy.c b/code/test/init_vconn.c index c7f560d..2e82598 100644 --- a/code/test/init_proxy.c +++ b/code/test/init_vconn.c @@ -3,7 +3,7 @@ #include <unistd.h> #include "core.h" -#include "proxy.h" +#include "vconn.h" static int v_rng(void *buf, size_t bufsize) { int fd; @@ -17,8 +17,8 @@ static int v_rng(void *buf, size_t bufsize) { static ECPConnection *conn_alloc(unsigned char type) { switch (type) { - case ECP_CTYPE_PROXYF: - return malloc(sizeof(ECPConnProxyF)); + case ECP_CTYPE_VCONN: + return malloc(sizeof(ECPVConnIn)); default: return malloc(sizeof(ECPConnection)); } @@ -38,5 +38,5 @@ int ecp_init(ECPContext *ctx) { ctx->conn_alloc = conn_alloc; ctx->conn_free = conn_free; - return ecp_proxy_init(ctx); + return ecp_ctx_vconn_init(ctx); }
\ No newline at end of file diff --git a/code/test/pr_client.c b/code/test/vc_client.c index d643dd3..586fec5 100644 --- a/code/test/pr_client.c +++ b/code/test/vc_client.c @@ -4,7 +4,7 @@ #include <stdlib.h> #include "core.h" -#include "proxy.h" +#include "vconn.h" #include "util.h" ECPContext ctx; @@ -14,8 +14,8 @@ ECPConnHandler handler; ECPConnection conn; ECPNode node; -ECPConnProxy conn_proxy[20]; -ECPNode node_proxy[20]; +ECPVConnection vconn[20]; +ECPNode vconn_node[20]; #define CTYPE_TEST 0 #define MTYPE_MSG 8 @@ -47,7 +47,7 @@ ssize_t handle_msg(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned } static void usage(char *arg) { - fprintf(stderr, "Usage: %s <server.pub> <p1.pub> ... <pn.pub>\n", arg); + fprintf(stderr, "Usage: %s <server.pub> <v1.pub> ... <vn.pub>\n", arg); exit(1); } @@ -77,15 +77,15 @@ int main(int argc, char *argv[]) { printf("ecp_util_node_load RV:%d\n", rv); for (i=0; i<argc-2; i++) { - rv = ecp_util_node_load(&ctx, &node_proxy[i], argv[i+2]); + rv = ecp_util_node_load(&ctx, &vconn_node[i], argv[i+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, argc-2); - printf("ecp_conn_proxy_open RV:%d\n", rv); + rv = ecp_vconn_open(&conn, &node, vconn, vconn_node, argc-2); + printf("ecp_vconn_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/vc_server.c index 2fd81a6..fb6b923 100644 --- a/code/test/pr_server.c +++ b/code/test/vc_server.c @@ -4,7 +4,7 @@ #include <stdlib.h> #include "core.h" -#include "proxy.h" +#include "vconn.h" #include "util.h" ECPContext ctx; @@ -38,7 +38,7 @@ ssize_t handle_msg(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned } static void usage(char *arg) { - fprintf(stderr, "Usage: %s <node.priv> <proxy.pub>\n", arg); + fprintf(stderr, "Usage: %s <node.priv> <vcs.pub>\n", arg); exit(1); } @@ -70,7 +70,7 @@ int main(int argc, char *argv[]) { 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); + rv = ecp_conn_create(&conn, &sock, ECP_CTYPE_VLINK); printf("ecp_conn_create RV:%d\n", rv); rv = ecp_conn_open(&conn, &node); diff --git a/code/test/proxy.c b/code/test/vcs.c index ae7cce5..1dbf67d 100644 --- a/code/test/proxy.c +++ b/code/test/vcs.c @@ -5,7 +5,7 @@ #include "core.h" #include "util.h" -#include "proxy.h" +#include "vconn.h" ECPContext ctx; ECPSocket sock; @@ -43,7 +43,7 @@ int main(int argc, char *argv[]) { rv = ecp_util_node_load(&ctx, &node, argv[3]); printf("ecp_util_node_load RV:%d\n", rv); - rv = ecp_conn_create(&conn, &sock, ECP_CTYPE_PROXYB); + rv = ecp_conn_create(&conn, &sock, ECP_CTYPE_VLINK); printf("ecp_conn_create RV:%d\n", rv); rv = ecp_conn_open(&conn, &node); diff --git a/code/proxy/Makefile b/code/vconn/Makefile index 9a8490c..0292b0d 100644 --- a/code/proxy/Makefile +++ b/code/vconn/Makefile @@ -1,13 +1,13 @@ CFLAGS = -I../core -pthread -O3 $(PIC) -obj = proxy.o +obj = vconn.o %.o: %.c %.h $(CC) $(CFLAGS) -c $< all: $(obj) - $(AR) rcs libecpproxy.a $(obj) + $(AR) rcs libecpvconn.a $(obj) clean: rm -f *.o *.a
\ No newline at end of file diff --git a/code/proxy/proxy.c b/code/vconn/vconn.c index a981a2f..97ced70 100644 --- a/code/proxy/proxy.c +++ b/code/vconn/vconn.c @@ -1,5 +1,5 @@ #include "core.h" -#include "proxy.h" +#include "vconn.h" #include <string.h> @@ -16,26 +16,26 @@ static unsigned char key_null[ECP_ECDH_SIZE_KEY] = { 0 }; static ECPConnHandler handler_f; static ECPConnHandler handler_b; -static int proxyf_create(ECPConnection *conn, unsigned char *payload, size_t size) { +static int vconn_create(ECPConnection *conn, unsigned char *payload, size_t size) { ECPContext *ctx = conn->sock->ctx; - ECPConnProxyF *conn_p = (ECPConnProxyF *)conn; + ECPVConnIn *conn_v = (ECPVConnIn *)conn; int rv = ECP_OK; if (conn->out) return ECP_ERR; - if (conn->type != ECP_CTYPE_PROXYF) return ECP_ERR; + if (conn->type != ECP_CTYPE_VCONN) return ECP_ERR; if (size < 2*ECP_ECDH_SIZE_KEY) return ECP_ERR; - conn_p->key_next_curr = 0; - memset(conn_p->key_next, 0, sizeof(conn_p->key_next)); - memset(conn_p->key_out, 0, sizeof(conn_p->key_out)); - 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); + conn_v->key_next_curr = 0; + memset(conn_v->key_next, 0, sizeof(conn_v->key_next)); + memset(conn_v->key_out, 0, sizeof(conn_v->key_out)); + memcpy(conn_v->key_next[conn_v->key_next_curr], payload, ECP_ECDH_SIZE_KEY); + memcpy(conn_v->key_out, payload+ECP_ECDH_SIZE_KEY, ECP_ECDH_SIZE_KEY); #ifdef ECP_WITH_PTHREAD pthread_mutex_lock(&key_next_mutex); #endif #ifdef ECP_WITH_HTABLE - rv = ctx->ht.init ? ctx->ht.insert(key_next_table, conn_p->key_next[conn_p->key_next_curr], conn) : ECP_ERR; + rv = ctx->ht.init ? ctx->ht.insert(key_next_table, conn_v->key_next[conn_v->key_next_curr], conn) : ECP_ERR; #endif #ifdef ECP_WITH_PTHREAD pthread_mutex_unlock(&key_next_mutex); @@ -44,12 +44,12 @@ static int proxyf_create(ECPConnection *conn, unsigned char *payload, size_t siz return rv; } -static void proxyf_destroy(ECPConnection *conn) { +static void vconn_destroy(ECPConnection *conn) { ECPContext *ctx = conn->sock->ctx; - ECPConnProxyF *conn_p = (ECPConnProxyF *)conn; + ECPVConnIn *conn_v = (ECPVConnIn *)conn; if (conn->out) return; - if (conn->type != ECP_CTYPE_PROXYF) return; + if (conn->type != ECP_CTYPE_VCONN) return; #ifdef ECP_WITH_PTHREAD pthread_mutex_lock(&key_next_mutex); @@ -59,7 +59,7 @@ static void proxyf_destroy(ECPConnection *conn) { if (ctx->ht.init) { int i; for (i=0; i<ECP_MAX_NODE_KEY; i++) { - if (memcmp(conn_p->key_next[i], key_null, ECP_ECDH_SIZE_KEY)) ctx->ht.remove(key_next_table, conn_p->key_next[i]); + if (memcmp(conn_v->key_next[i], key_null, ECP_ECDH_SIZE_KEY)) ctx->ht.remove(key_next_table, conn_v->key_next[i]); } } #endif @@ -69,9 +69,9 @@ static void proxyf_destroy(ECPConnection *conn) { #endif } -static ssize_t _proxyf_send_open(ECPConnection *conn) { - ECPConnProxy *conn_p = (ECPConnProxy *)conn; - ECPConnection *conn_next = conn_p->next; +static ssize_t _vconn_send_open(ECPConnection *conn) { + ECPVConnection *conn_v = (ECPVConnection *)conn; + ECPConnection *conn_next = conn_v->next; unsigned char payload[ECP_SIZE_PLD(0)]; if (conn_next == NULL) return ECP_ERR; @@ -80,38 +80,38 @@ static ssize_t _proxyf_send_open(ECPConnection *conn) { return ecp_pld_send_wkey(conn_next, ECP_ECDH_IDX_PERMA, ECP_ECDH_IDX_INV, payload, sizeof(payload)); } -static ssize_t _proxyf_retry_kget(ECPConnection *conn, ECPTimerItem *ti) { +static ssize_t _vconn_retry_kget(ECPConnection *conn, ECPTimerItem *ti) { if (conn->parent == NULL) return ECP_ERR; - return _proxyf_send_open(conn->parent); + return _vconn_send_open(conn->parent); } -static ssize_t proxyf_open(ECPConnection *conn) { +static ssize_t vconn_open(ECPConnection *conn) { int rv = ECP_OK; ECPTimerItem ti; - ECPConnProxy *conn_p = (ECPConnProxy *)conn; - ECPConnection *conn_next = conn_p->next; + ECPVConnection *conn_v = (ECPVConnection *)conn; + ECPConnection *conn_next = conn_v->next; rv = ecp_timer_item_init(&ti, conn_next, ECP_MTYPE_KGET_REP, 3, 3000); if (rv) return rv; - ti.retry = _proxyf_retry_kget; + ti.retry = _vconn_retry_kget; rv = ecp_timer_push(&ti); if (rv) return rv; - return _proxyf_send_open(conn); + return _vconn_send_open(conn); } -static ssize_t proxyf_handle_open(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, ssize_t size) { - if (conn->type != ECP_CTYPE_PROXYF) return ECP_ERR; +static ssize_t vconn_handle_open(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, ssize_t size) { + if (conn->type != ECP_CTYPE_VCONN) return ECP_ERR; if (mtype & ECP_MTYPE_FLAG_REP) { if (!conn->out) return ECP_ERR; if (size < 0) { ecp_conn_handler_msg_t *handler = NULL; - while (conn->type == ECP_CTYPE_PROXYF) { - ECPConnProxy *conn_p = (ECPConnProxy *)conn; - conn = conn_p->next; + while (conn->type == ECP_CTYPE_VCONN) { + ECPVConnection *conn_v = (ECPVConnection *)conn; + conn = conn_v->next; } handler = conn->sock->ctx->handler[conn->type] ? conn->sock->ctx->handler[conn->type]->msg[ECP_MTYPE_OPEN] : NULL; return handler ? handler(conn, seq, mtype, msg, size) : size; @@ -120,7 +120,7 @@ static ssize_t proxyf_handle_open(ECPConnection *conn, ecp_seq_t seq, unsigned c return ecp_conn_handle_open(conn, seq, mtype, msg, size); } else { ECPContext *ctx = conn->sock->ctx; - ECPConnProxyF *conn_p = (ECPConnProxyF *)conn; + ECPVConnIn *conn_v = (ECPVConnIn *)conn; int rv = ECP_OK; unsigned char ctype = 0; @@ -137,17 +137,17 @@ static ssize_t proxyf_handle_open(ECPConnection *conn, ecp_seq_t seq, unsigned c msg++; 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)) { - conn_p->key_next_curr = (conn_p->key_next_curr + 1) % ECP_MAX_NODE_KEY; + if (memcmp(conn_v->key_next[conn_v->key_next_curr], msg, ECP_ECDH_SIZE_KEY)) { + conn_v->key_next_curr = (conn_v->key_next_curr + 1) % ECP_MAX_NODE_KEY; #ifdef ECP_WITH_HTABLE if (ctx->ht.init) { - if (memcmp(conn_p->key_next[conn_p->key_next_curr], key_null, ECP_ECDH_SIZE_KEY)) ctx->ht.remove(key_next_table, conn_p->key_next[conn_p->key_next_curr]); - rv = ctx->ht.insert(key_next_table, conn_p->key_next[conn_p->key_next_curr], conn); + if (memcmp(conn_v->key_next[conn_v->key_next_curr], key_null, ECP_ECDH_SIZE_KEY)) ctx->ht.remove(key_next_table, conn_v->key_next[conn_v->key_next_curr]); + rv = ctx->ht.insert(key_next_table, conn_v->key_next[conn_v->key_next_curr], conn); } else { rv = ECP_ERR; } #endif - if (!rv) memcpy(conn_p->key_next[conn_p->key_next_curr], msg, ECP_ECDH_SIZE_KEY); + if (!rv) memcpy(conn_v->key_next[conn_v->key_next_curr], msg, ECP_ECDH_SIZE_KEY); } #ifdef ECP_WITH_PTHREAD @@ -163,15 +163,15 @@ static ssize_t proxyf_handle_open(ECPConnection *conn, ecp_seq_t seq, unsigned c return ECP_ERR; } -static ssize_t proxyf_handle_relay(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, ssize_t size) { +static ssize_t vconn_handle_relay(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, ssize_t size) { ECPContext *ctx = conn->sock->ctx; ECPConnection *conn_out = NULL; - ECPConnProxyF *conn_p = (ECPConnProxyF *)conn; + ECPVConnIn *conn_v = (ECPVConnIn *)conn; unsigned char *payload = NULL; ssize_t rv; if (conn->out) return ECP_ERR; - if (conn->type != ECP_CTYPE_PROXYF) return ECP_ERR; + if (conn->type != ECP_CTYPE_VCONN) return ECP_ERR; if (size < 0) return size; if (size < ECP_MIN_PKT) return ECP_ERR_MIN_PKT; @@ -180,7 +180,7 @@ static ssize_t proxyf_handle_relay(ECPConnection *conn, ecp_seq_t seq, unsigned pthread_mutex_lock(&key_perma_mutex); #endif #ifdef ECP_WITH_HTABLE - conn_out = ctx->ht.init ? ctx->ht.search(key_perma_table, conn_p->key_out) : NULL; + conn_out = ctx->ht.init ? ctx->ht.search(key_perma_table, conn_v->key_out) : NULL; #endif if (conn_out) { #ifdef ECP_WITH_PTHREAD @@ -213,7 +213,7 @@ static ssize_t proxyf_handle_relay(ECPConnection *conn, ecp_seq_t seq, unsigned return size; } -static int proxyb_insert(ECPConnection *conn) { +static int vlink_insert(ECPConnection *conn) { int rv = ECP_OK; ECPContext *ctx = conn->sock->ctx; @@ -230,7 +230,7 @@ static int proxyb_insert(ECPConnection *conn) { return rv; } -static void proxyb_remove(ECPConnection *conn) { +static void vlink_remove(ECPConnection *conn) { ECPContext *ctx = conn->sock->ctx; #ifdef ECP_WITH_PTHREAD @@ -244,29 +244,29 @@ static void proxyb_remove(ECPConnection *conn) { #endif } -static int proxyb_create(ECPConnection *conn, unsigned char *payload, size_t size) { +static int vlink_create(ECPConnection *conn, unsigned char *payload, size_t size) { ECPContext *ctx = conn->sock->ctx; if (conn->out) return ECP_ERR; - if (conn->type != ECP_CTYPE_PROXYB) return ECP_ERR; + if (conn->type != ECP_CTYPE_VLINK) return ECP_ERR; // XXX should verify perma_key if (size < ECP_ECDH_SIZE_KEY) return ECP_ERR; ctx->cr.dh_pub_from_buf(&conn->node.public, payload); - return proxyb_insert(conn); + return vlink_insert(conn); } -static void proxyb_destroy(ECPConnection *conn) { +static void vlink_destroy(ECPConnection *conn) { ECPContext *ctx = conn->sock->ctx; if (conn->out) return; - if (conn->type != ECP_CTYPE_PROXYB) return; + if (conn->type != ECP_CTYPE_VLINK) return; - proxyb_remove(conn); + vlink_remove(conn); } -static ssize_t _proxyb_send_open(ECPConnection *conn, ECPTimerItem *ti) { +static ssize_t _vlink_send_open(ECPConnection *conn, ECPTimerItem *ti) { ECPSocket *sock = conn->sock; ECPContext *ctx = sock->ctx; unsigned char payload[ECP_SIZE_PLD(ECP_ECDH_SIZE_KEY+1)]; @@ -281,19 +281,19 @@ static ssize_t _proxyb_send_open(ECPConnection *conn, ECPTimerItem *ti) { return ecp_pld_send(conn, payload, sizeof(payload)); } -static ssize_t proxyb_open(ECPConnection *conn) { - return ecp_timer_send(conn, _proxyb_send_open, ECP_MTYPE_OPEN_REP, 3, 500); +static ssize_t vlink_open(ECPConnection *conn) { + return ecp_timer_send(conn, _vlink_send_open, ECP_MTYPE_OPEN_REP, 3, 500); } -static void proxyb_close(ECPConnection *conn) { - proxyb_remove(conn); +static void vlink_close(ECPConnection *conn) { + vlink_remove(conn); } -static ssize_t proxyb_handle_open(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, ssize_t size) { +static ssize_t vlink_handle_open(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, ssize_t size) { ssize_t rv; int is_open; - if (conn->type != ECP_CTYPE_PROXYB) return ECP_ERR; + if (conn->type != ECP_CTYPE_VLINK) return ECP_ERR; if (size < 0) return size; @@ -311,7 +311,7 @@ static ssize_t proxyb_handle_open(ECPConnection *conn, ecp_seq_t seq, unsigned c if (mtype & ECP_MTYPE_FLAG_REP) { if (!conn->out) return ECP_ERR; if (!is_open) { - int rv = proxyb_insert(conn); + int rv = vlink_insert(conn); if (rv) return rv; } return rv; @@ -328,12 +328,12 @@ static ssize_t proxyb_handle_open(ECPConnection *conn, ecp_seq_t seq, unsigned c return ECP_ERR; } -static ssize_t proxyb_handle_relay(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, ssize_t size) { +static ssize_t vlink_handle_relay(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, ssize_t size) { ECPContext *ctx = conn->sock->ctx; unsigned char *payload = NULL; ssize_t rv; - if (conn->type != ECP_CTYPE_PROXYB) return ECP_ERR; + if (conn->type != ECP_CTYPE_VLINK) return ECP_ERR; if (size < 0) return size; if (size < ECP_MIN_PKT) return ECP_ERR_MIN_PKT; @@ -375,13 +375,13 @@ static ssize_t proxyb_handle_relay(ECPConnection *conn, ecp_seq_t seq, unsigned return size; } -static ssize_t proxy_set_msg(ECPConnection *conn, unsigned char *pld_out, size_t pld_out_size, unsigned char *pld_in, size_t pld_in_size) { - if ((conn->type == ECP_CTYPE_PROXYF) && conn->out) { +static ssize_t vconn_set_msg(ECPConnection *conn, unsigned char *pld_out, size_t pld_out_size, unsigned char *pld_in, size_t pld_in_size) { + if ((conn->type == ECP_CTYPE_VCONN) && conn->out) { unsigned char mtype = ecp_pld_get_type(pld_in); if ((mtype == ECP_MTYPE_OPEN_REQ) || (mtype == ECP_MTYPE_KGET_REQ)) { - ECPConnProxy *conn_p = (ECPConnProxy *)conn; + ECPVConnection *conn_v = (ECPVConnection *)conn; ECPContext *ctx = conn->sock->ctx; - ECPConnection *conn_next = conn_p->next; + ECPConnection *conn_next = conn_v->next; unsigned char *buf = NULL; int rv; @@ -391,7 +391,7 @@ static ssize_t proxy_set_msg(ECPConnection *conn, unsigned char *pld_out, size_t ecp_pld_set_type(pld_out, ECP_MTYPE_OPEN_REQ); buf = ecp_pld_get_buf(pld_out); - buf[0] = ECP_CTYPE_PROXYF; + buf[0] = ECP_CTYPE_VCONN; rv = ecp_conn_dhkey_get_curr(conn_next, NULL, buf+1); if (rv) return rv; @@ -407,68 +407,68 @@ static ssize_t proxy_set_msg(ECPConnection *conn, unsigned char *pld_out, size_t } -static ssize_t proxy_pack(ECPConnection *conn, unsigned char *packet, size_t pkt_size, unsigned char s_idx, unsigned char c_idx, unsigned char *payload, size_t payload_size, ECPNetAddr *addr, ecp_seq_t *seq, int *rbuf_idx) { +static ssize_t vconn_pack(ECPConnection *conn, unsigned char *packet, size_t pkt_size, unsigned char s_idx, unsigned char c_idx, unsigned char *payload, size_t payload_size, ECPNetAddr *addr, ecp_seq_t *seq, int *rbuf_idx) { ECPContext *ctx = conn->sock->ctx; if (conn->parent) { unsigned char payload_[ECP_MAX_PLD]; - ssize_t rv, hdr_size = proxy_set_msg(conn->parent, payload_, sizeof(payload_), payload, payload_size); + ssize_t rv, hdr_size = vconn_set_msg(conn->parent, payload_, sizeof(payload_), payload, payload_size); if (hdr_size < 0) return hdr_size; rv = ecp_conn_pack(conn, payload_+hdr_size, ECP_MAX_PLD-hdr_size, s_idx, c_idx, payload, payload_size, NULL, seq, rbuf_idx); if (rv < 0) return rv; - return proxy_pack(conn->parent, packet, pkt_size, ECP_ECDH_IDX_INV, ECP_ECDH_IDX_INV, payload_, rv+hdr_size, addr, NULL, NULL); + return vconn_pack(conn->parent, packet, pkt_size, ECP_ECDH_IDX_INV, ECP_ECDH_IDX_INV, payload_, rv+hdr_size, addr, NULL, NULL); } else { return ecp_conn_pack(conn, packet, pkt_size, s_idx, c_idx, payload, payload_size, addr, seq, rbuf_idx); } } -static ssize_t proxy_pack_raw(ECPSocket *sock, ECPConnection *parent, unsigned char *packet, size_t pkt_size, unsigned char s_idx, unsigned char c_idx, ecp_dh_public_t *public, ecp_aead_key_t *shsec, unsigned char *nonce, ecp_seq_t seq, unsigned char *payload, size_t payload_size, ECPNetAddr *addr) { +static ssize_t vconn_pack_raw(ECPSocket *sock, ECPConnection *parent, unsigned char *packet, size_t pkt_size, unsigned char s_idx, unsigned char c_idx, ecp_dh_public_t *public, ecp_aead_key_t *shsec, unsigned char *nonce, ecp_seq_t seq, unsigned char *payload, size_t payload_size, ECPNetAddr *addr) { ECPContext *ctx = sock->ctx; if (parent) { unsigned char payload_[ECP_MAX_PLD]; - ssize_t rv, hdr_size = proxy_set_msg(parent, payload_, sizeof(payload_), payload, payload_size); + ssize_t rv, hdr_size = vconn_set_msg(parent, payload_, sizeof(payload_), payload, payload_size); if (hdr_size < 0) return hdr_size; 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 proxy_pack(parent, packet, pkt_size, ECP_ECDH_IDX_INV, ECP_ECDH_IDX_INV, payload_, rv+hdr_size, addr, NULL, NULL); + return vconn_pack(parent, packet, pkt_size, ECP_ECDH_IDX_INV, ECP_ECDH_IDX_INV, payload_, rv+hdr_size, addr, NULL, NULL); } else { return ecp_pack(ctx, packet, pkt_size, s_idx, c_idx, public, shsec, nonce, seq, payload, payload_size); } } -int ecp_proxy_init(ECPContext *ctx) { +int ecp_ctx_vconn_init(ECPContext *ctx) { int rv; rv = ecp_conn_handler_init(&handler_f); if (rv) return rv; - handler_f.conn_create = proxyf_create; - handler_f.conn_destroy = proxyf_destroy; - handler_f.conn_open = proxyf_open; - handler_f.msg[ECP_MTYPE_OPEN] = proxyf_handle_open; + handler_f.conn_create = vconn_create; + handler_f.conn_destroy = vconn_destroy; + handler_f.conn_open = vconn_open; + handler_f.msg[ECP_MTYPE_OPEN] = vconn_handle_open; handler_f.msg[ECP_MTYPE_EXEC] = ecp_conn_handle_exec; - handler_f.msg[ECP_MTYPE_RELAY] = proxyf_handle_relay; - ctx->handler[ECP_CTYPE_PROXYF] = &handler_f; + handler_f.msg[ECP_MTYPE_RELAY] = vconn_handle_relay; + ctx->handler[ECP_CTYPE_VCONN] = &handler_f; rv = ecp_conn_handler_init(&handler_b); if (rv) return rv; - handler_b.conn_create = proxyb_create; - handler_b.conn_destroy = proxyb_destroy; - handler_b.conn_open = proxyb_open; - handler_b.conn_close = proxyb_close; - handler_b.msg[ECP_MTYPE_OPEN] = proxyb_handle_open; + handler_b.conn_create = vlink_create; + handler_b.conn_destroy = vlink_destroy; + handler_b.conn_open = vlink_open; + handler_b.conn_close = vlink_close; + handler_b.msg[ECP_MTYPE_OPEN] = vlink_handle_open; handler_b.msg[ECP_MTYPE_EXEC] = ecp_conn_handle_exec; - handler_b.msg[ECP_MTYPE_RELAY] = proxyb_handle_relay; - ctx->handler[ECP_CTYPE_PROXYB] = &handler_b; + handler_b.msg[ECP_MTYPE_RELAY] = vlink_handle_relay; + ctx->handler[ECP_CTYPE_VLINK] = &handler_b; - ctx->pack = proxy_pack; - ctx->pack_raw = proxy_pack_raw; + ctx->pack = vconn_pack; + ctx->pack_raw = vconn_pack_raw; #ifdef ECP_WITH_PTHREAD pthread_mutex_init(&key_perma_mutex, NULL); @@ -485,48 +485,48 @@ 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_vconn_init(ECPConnection *conn, ECPNode *conn_node, ECPVConnection vconn[], ECPNode vconn_node[], int size) { ECPSocket *sock = conn->sock; int i, rv; rv = ecp_conn_init(conn, conn_node); if (rv) return rv; - conn->parent = (ECPConnection *)&proxy[size-1]; + conn->parent = (ECPConnection *)&vconn[size-1]; for (i=0; i<size; i++) { - rv = ecp_conn_create((ECPConnection *)&proxy[i], sock, ECP_CTYPE_PROXYF); + rv = ecp_conn_create((ECPConnection *)&vconn[i], sock, ECP_CTYPE_VCONN); if (rv) return rv; - rv = ecp_conn_init((ECPConnection *)&proxy[i], &proxy_node[i]); + rv = ecp_conn_init((ECPConnection *)&vconn[i], &vconn_node[i]); if (rv) return rv; if (i == 0) { - proxy[i].b.parent = NULL; + vconn[i].b.parent = NULL; } else { - proxy[i].b.parent = (ECPConnection *)&proxy[i-1]; + vconn[i].b.parent = (ECPConnection *)&vconn[i-1]; } if (i == size-1) { - proxy[i].next = conn; + vconn[i].next = conn; } else { - proxy[i].next = (ECPConnection *)&proxy[i+1]; + vconn[i].next = (ECPConnection *)&vconn[i+1]; } } return ECP_OK; } -static ssize_t _proxy_send_kget(ECPConnection *conn, ECPTimerItem *ti) { +static ssize_t _vconn_send_kget(ECPConnection *conn, ECPTimerItem *ti) { unsigned char payload[ECP_SIZE_PLD(0)]; ecp_pld_set_type(payload, ECP_MTYPE_KGET_REQ); 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 rv = ecp_conn_proxy_init(conn, conn_node, proxy, proxy_node, size); +int ecp_vconn_open(ECPConnection *conn, ECPNode *conn_node, ECPVConnection vconn[], ECPNode vconn_node[], int size) { + int rv = ecp_vconn_init(conn, conn_node, vconn, vconn_node, size); if (rv) return rv; - ssize_t _rv = ecp_timer_send((ECPConnection *)&proxy[0], _proxy_send_kget, ECP_MTYPE_KGET_REP, 3, 500); + ssize_t _rv = ecp_timer_send((ECPConnection *)&vconn[0], _vconn_send_kget, ECP_MTYPE_KGET_REP, 3, 500); if (_rv < 0) return _rv; return ECP_OK; diff --git a/code/vconn/vconn.h b/code/vconn/vconn.h new file mode 100644 index 0000000..07832c7 --- /dev/null +++ b/code/vconn/vconn.h @@ -0,0 +1,22 @@ +#define ECP_CTYPE_VCONN 1 +#define ECP_CTYPE_VLINK 2 + +#define ECP_MTYPE_RELAY 0x08 +#define ECP_MTYPE_EXEC 0x09 + +typedef struct ECPVConnection { + ECPConnection b; + ECPConnection *next; +} ECPVConnection; + +typedef struct ECPVConnIn { + ECPConnection b; + unsigned char key_next[ECP_MAX_NODE_KEY][ECP_ECDH_SIZE_KEY]; + unsigned char key_next_curr; + unsigned char key_out[ECP_ECDH_SIZE_KEY]; +} ECPVConnIn; + +int ecp_ctx_vconn_init(ECPContext *ctx); + +int ecp_vconn_init(ECPConnection *conn, ECPNode *conn_node, ECPVConnection vconn[], ECPNode vconn_node[], int size); +int ecp_vconn_open(ECPConnection *conn, ECPNode *conn_node, ECPVConnection vconn[], ECPNode vconn_node[], int size); |