diff options
author | Uros Majstorovic <majstor@majstor.org> | 2017-08-03 05:40:23 +0200 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2017-08-03 05:40:23 +0200 |
commit | 72520c7339f04849633114d9dca644e32f85e9fb (patch) | |
tree | 2c931544be4d63c3eabf02b4ca68a1eb444c5cc0 | |
parent | 43c30eec5196fa8ace45cc703fffe38c69563220 (diff) |
implemented mtype return mask; fixed nasty ctype bug in conn create
-rw-r--r-- | code/core/core.c | 47 | ||||
-rw-r--r-- | code/core/core.h | 10 | ||||
-rwxr-xr-x | code/core/htable/hashtable.c | 31 | ||||
-rwxr-xr-x | code/core/htable/hashtable.h | 7 | ||||
-rw-r--r-- | code/core/htable/htable.c | 19 | ||||
-rw-r--r-- | code/core/timer.c | 4 | ||||
-rw-r--r-- | code/proxy/proxy.c | 48 |
7 files changed, 97 insertions, 69 deletions
diff --git a/code/core/core.c b/code/core/core.c index ae654c9..544f896 100644 --- a/code/core/core.c +++ b/code/core/core.c @@ -485,7 +485,7 @@ static ssize_t _conn_send_kget(ECPConnection *conn, ECPTimerItem *ti) { unsigned char payload[ECP_SIZE_PLD(0)]; ecp_seq_t seq; - ecp_pld_set_type(payload, ECP_MTYPE_KGET); + ecp_pld_set_type(payload, ECP_MTYPE_KGET_REQ); return ecp_pld_send_wkey(conn, &seq, ECP_ECDH_IDX_PERMA, ECP_ECDH_IDX_INV, payload, sizeof(payload)); } @@ -512,7 +512,7 @@ int ecp_conn_open(ECPConnection *conn, ECPNode *node) { int rv = ecp_conn_init(conn, node); if (rv) return rv; - ssize_t _rv = ecp_timer_send(conn, _conn_send_kget, ECP_MTYPE_KGET, 3, 500); + ssize_t _rv = ecp_timer_send(conn, _conn_send_kget, ECP_MTYPE_KGET_REP, 3, 500); if (_rv < 0) { ecp_conn_unregister(conn); return _rv; @@ -578,14 +578,14 @@ static ssize_t _conn_send_open(ECPConnection *conn, ECPTimerItem *ti) { unsigned char payload[ECP_SIZE_PLD(1)]; unsigned char *buf = ecp_pld_get_buf(payload); - ecp_pld_set_type(payload, ECP_MTYPE_OPEN); + ecp_pld_set_type(payload, ECP_MTYPE_OPEN_REQ); buf[0] = conn->type; return ecp_pld_send(conn, payload, sizeof(payload)); } ssize_t ecp_conn_send_open(ECPConnection *conn) { - return ecp_timer_send(conn, _conn_send_open, ECP_MTYPE_OPEN, 3, 500); + return ecp_timer_send(conn, _conn_send_open, ECP_MTYPE_OPEN_REP, 3, 500); } int ecp_conn_handle_new(ECPSocket *sock, ECPConnection **_conn, ECPConnection *proxy, unsigned char s_idx, unsigned char c_idx, unsigned char *c_public, ecp_aead_key_t *shsec, unsigned char *payload, size_t payload_size) { @@ -597,10 +597,11 @@ int ecp_conn_handle_new(ECPSocket *sock, ECPConnection **_conn, ECPConnection *p if (payload_size < 1) return ECP_ERR; + ctype = payload[0]; + conn = sock->ctx->conn_alloc ? sock->ctx->conn_alloc(ctype) : NULL; if (conn == NULL) return ECP_ERR_ALLOC; - ctype = payload[0]; rv = ecp_conn_create(conn, sock, ctype); if (rv) { if (sock->ctx->conn_free) sock->ctx->conn_free(conn); @@ -664,17 +665,19 @@ ssize_t ecp_conn_handle_open(ECPConnection *conn, ecp_seq_t seq, unsigned char m pthread_mutex_unlock(&conn->mutex); #endif - if (conn->out) { + if (mtype & ECP_MTYPE_FLAG_REP) { + if (!conn->out) return ECP_ERR; return 0; } else { unsigned char payload[ECP_SIZE_PLD(0)]; unsigned char ctype = 0; + if (conn->out) return ECP_ERR; if (size < 1) return ECP_ERR; ctype = msg[0]; - ecp_pld_set_type(payload, ECP_MTYPE_OPEN); + ecp_pld_set_type(payload, ECP_MTYPE_OPEN_REP); ssize_t _rv = ecp_pld_send(conn, payload, sizeof(payload)); return 1; @@ -683,8 +686,11 @@ ssize_t ecp_conn_handle_open(ECPConnection *conn, ecp_seq_t seq, unsigned char m } ssize_t ecp_conn_handle_kget(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, ssize_t size) { - if (conn->out) { + if (mtype & ECP_MTYPE_FLAG_REP) { ECPContext *ctx = conn->sock->ctx; + + if (!conn->out) return ECP_ERR; + #ifdef ECP_WITH_PTHREAD pthread_mutex_lock(&conn->mutex); #endif @@ -713,8 +719,9 @@ ssize_t ecp_conn_handle_kget(ECPConnection *conn, ecp_seq_t seq, unsigned char m } else { unsigned char payload[ECP_SIZE_PLD(ECP_ECDH_SIZE_KEY+1)]; unsigned char *buf = ecp_pld_get_buf(payload); - ecp_pld_set_type(payload, ECP_MTYPE_KGET); + ecp_pld_set_type(payload, ECP_MTYPE_KGET_REP); + if (conn->out) return ECP_ERR; if (size < 0) return size; int rv = ecp_conn_dhkey_get_curr(conn, buf, buf+1); @@ -730,17 +737,19 @@ ssize_t ecp_conn_handle_kget(ECPConnection *conn, ecp_seq_t seq, unsigned char m ssize_t ecp_conn_handle_kput(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, ssize_t size) { if (size < 0) return size; - if (conn->out) { + if (mtype & ECP_MTYPE_FLAG_REP) { + if (!conn->out) return ECP_ERR; return 0; } else { unsigned char payload[ECP_SIZE_PLD(0)]; + if (conn->out) return ECP_ERR; if (size < ECP_ECDH_SIZE_KEY+1) return ECP_ERR; int rv = ecp_conn_dhkey_new_pub(conn, msg[0], msg+1); if (rv) return rv; - ecp_pld_set_type(payload, ECP_MTYPE_KPUT); + ecp_pld_set_type(payload, ECP_MTYPE_KPUT_REP); ssize_t _rv = ecp_pld_send(conn, payload, sizeof(payload)); return ECP_ECDH_SIZE_KEY+1; @@ -758,7 +767,7 @@ static ssize_t _conn_send_kput(ECPConnection *conn, ECPTimerItem *ti) { unsigned char *buf = ecp_pld_get_buf(payload); int rv = ECP_OK; - ecp_pld_set_type(payload, ECP_MTYPE_KPUT); + ecp_pld_set_type(payload, ECP_MTYPE_KPUT_REQ); rv = ecp_conn_dhkey_get_curr(conn, buf, buf+1); if (rv) return rv; @@ -786,7 +795,7 @@ int ecp_conn_dhkey_new(ECPConnection *conn) { if (rv) return rv; - _rv = ecp_timer_send(conn, _conn_send_kput, ECP_MTYPE_KPUT, 3, 500); + _rv = ecp_timer_send(conn, _conn_send_kput, ECP_MTYPE_KPUT_REP, 3, 500); if (_rv < 0) return _rv; return ECP_OK; @@ -1027,16 +1036,16 @@ ssize_t ecp_pkt_handle(ECPSocket *sock, ECPNetAddr *addr, ECPConnection *proxy, memcpy(nonce, packet+ECP_SIZE_PKT_HDR, sizeof(nonce)); if (conn == NULL) { - if (payload[ECP_SIZE_PLD_HDR] == ECP_MTYPE_OPEN) { + if (payload[ECP_SIZE_PLD_HDR] == ECP_MTYPE_OPEN_REQ) { rv = sock->conn_new(sock, &conn, proxy, s_idx, c_idx, packet+ECP_SIZE_PROTO+1, &shsec, payload+ECP_SIZE_MSG_HDR, pld_size-ECP_SIZE_MSG_HDR); if (rv) return rv; seq_bitmap = 0; n_seq = p_seq; - } else if (payload[ECP_SIZE_PLD_HDR] == ECP_MTYPE_KGET) { + } else if (payload[ECP_SIZE_PLD_HDR] == ECP_MTYPE_KGET_REQ) { unsigned char payload_[ECP_SIZE_PLD(ECP_ECDH_SIZE_KEY+1)]; unsigned char *buf = ecp_pld_get_buf(payload_); - ecp_pld_set_type(payload_, ECP_MTYPE_KGET); + ecp_pld_set_type(payload_, ECP_MTYPE_KGET_REP); rv = ecp_sock_dhkey_get_curr(sock, buf, buf+1); if (!rv) { @@ -1165,11 +1174,11 @@ ssize_t ecp_msg_handle(ECPConnection *conn, ecp_seq_t seq, unsigned char *msg, s msg++; rem_size--; - if (mtype >= ECP_MAX_MTYPE) return ECP_ERR_MAX_MTYPE; + if ((mtype & ECP_MTYPE_MASK) >= ECP_MAX_MTYPE) return ECP_ERR_MAX_MTYPE; if (rem_size < ECP_MIN_MSG) return ECP_ERR_MIN_MSG; - if (conn->out) ecp_timer_pop(conn, mtype); - handler = conn->sock->ctx->handler[conn->type] ? conn->sock->ctx->handler[conn->type]->msg[mtype] : NULL; + ecp_timer_pop(conn, mtype); + handler = conn->sock->ctx->handler[conn->type] ? conn->sock->ctx->handler[conn->type]->msg[mtype & ECP_MTYPE_MASK] : NULL; if (handler) { rv = handler(conn, seq, mtype, msg, rem_size); if (rv < 0) return rv; diff --git a/code/core/core.h b/code/core/core.h index 46f0d70..9cf3cf2 100644 --- a/code/core/core.h +++ b/code/core/core.h @@ -53,11 +53,21 @@ #define ECP_ECDH_IDX_INV 0xFF #define ECP_ECDH_IDX_PERMA 0x0F +#define ECP_MTYPE_MASK 0x7f +#define ECP_MTYPE_FLAG_REP 0x80 + #define ECP_MTYPE_OPEN 0x00 #define ECP_MTYPE_KGET 0x01 #define ECP_MTYPE_KPUT 0x02 #define ECP_MTYPE_EXEC 0x03 +#define ECP_MTYPE_OPEN_REQ (ECP_MTYPE_OPEN) +#define ECP_MTYPE_OPEN_REP (ECP_MTYPE_OPEN | ECP_MTYPE_FLAG_REP) +#define ECP_MTYPE_KGET_REQ (ECP_MTYPE_KGET) +#define ECP_MTYPE_KGET_REP (ECP_MTYPE_KGET | ECP_MTYPE_FLAG_REP) +#define ECP_MTYPE_KPUT_REQ (ECP_MTYPE_KPUT) +#define ECP_MTYPE_KPUT_REP (ECP_MTYPE_KPUT | ECP_MTYPE_FLAG_REP) + #define ECP_SIZE_PLD(X) ((X) < ECP_MIN_MSG ? ECP_MIN_MSG + ECP_SIZE_MSG_HDR : (X) + ECP_SIZE_MSG_HDR) #define ECP_SIZE_PKT(X) ((X) < ECP_MIN_MSG ? ECP_MIN_MSG + ECP_SIZE_PKT_HDR+ECP_SIZE_MSG_HDR+ECP_AEAD_SIZE_TAG : (X) + ECP_SIZE_PKT_HDR+ECP_SIZE_MSG_HDR+ECP_AEAD_SIZE_TAG) diff --git a/code/core/htable/hashtable.c b/code/core/htable/hashtable.c index 8174a5d..de15827 100755 --- a/code/core/htable/hashtable.c +++ b/code/core/htable/hashtable.c @@ -24,34 +24,44 @@ const unsigned int prime_table_length = sizeof(primes)/sizeof(primes[0]); const float max_load_factor = 0.65; /*****************************************************************************/ -int -create_hashtable(struct hashtable *h, unsigned int minsize, +struct hashtable * +create_hashtable(unsigned int minsize, unsigned int (*hash_fn) (void*), int (*eq_fn) (void*,void*), void *(*malloc_fn) (size_t), void *(*realloc_fn) (void*,size_t), void (*free_fn) (void*)) { + struct hashtable *h = NULL; unsigned int pindex, size = primes[0]; + /* Check requested hashtable isn't too large */ - if (minsize > (1u << 30)) return 0; + if (minsize > (1u << 30)) return NULL; + + malloc_fn = malloc_fn ? malloc_fn : malloc; + realloc_fn = realloc_fn ? realloc_fn : realloc; + free_fn = free_fn ? free_fn : free; + h = malloc_fn(sizeof(struct hashtable)); + if (NULL == h) return NULL; + memset(h, 0, sizeof(struct hashtable)); + /* Enforce size as prime */ for (pindex=0; pindex < prime_table_length; pindex++) { if (primes[pindex] > minsize) { size = primes[pindex]; break; } } - h->fn_malloc = malloc_fn ? malloc_fn : malloc; - h->fn_realloc = realloc_fn ? realloc_fn : realloc; - h->fn_free = free_fn ? free_fn : free; + h->fn_malloc = malloc_fn; + h->fn_realloc = realloc_fn; + h->fn_free = free_fn; h->tablelength = size; h->primeindex = pindex; h->entrycount = 0; h->fn_hash = hash_fn; h->fn_eq = eq_fn; h->loadlimit = (unsigned int) ceil(size * max_load_factor); - h->table = h->fn_malloc(sizeof(struct entry *) * size); - if (NULL == h->table) return 0; /*oom*/ + h->table = malloc_fn(sizeof(struct entry *) * size); + if (NULL == h->table) { free_fn(h); return NULL; } /*oom*/ memset(h->table, 0, size * sizeof(struct entry *)); - return -1; + return h; } /*****************************************************************************/ @@ -190,7 +200,7 @@ hashtable_remove(struct hashtable *h, void *k) unsigned int hashvalue, index; hashvalue = hashtable_hash(h,k); - index = indexFor(h->tablelength,hashtable_hash(h,k)); + index = indexFor(h->tablelength,hashvalue); pE = &(h->table[index]); e = *pE; while (NULL != e) @@ -227,6 +237,7 @@ hashtable_destroy(struct hashtable *h) { f = e; e = e->next; if (h->fn_free_k) h->fn_free_k(f->k); if (h->fn_free_v) h->fn_free_v(f->v); h->fn_free(f); } } h->fn_free(h->table); + h->fn_free(h); } /* diff --git a/code/core/htable/hashtable.h b/code/core/htable/hashtable.h index d99f1c4..046f740 100755 --- a/code/core/htable/hashtable.h +++ b/code/core/htable/hashtable.h @@ -67,18 +67,17 @@ struct hashtable; * create_hashtable * @name create_hashtable - * @name h hashtable to create * @param minsize minimum initial size of hashtable * @param hash_fn function for hashing keys * @param eq_fn function for determining key equality * @param malloc_fn function malloc * @param realloc_fn function realloc * @param free_fn function free - * @return non-zero on success + * @return hashtable created */ -int -create_hashtable(struct hashtable *h, unsigned int minsize, +struct hashtable * +create_hashtable(unsigned int minsize, unsigned int (*hash_fn) (void*), int (*eq_fn) (void*,void*), void *(*malloc_fn) (size_t), diff --git a/code/core/htable/htable.c b/code/core/htable/htable.c index 4a9ee11..552a03b 100644 --- a/code/core/htable/htable.c +++ b/code/core/htable/htable.c @@ -3,33 +3,17 @@ #include <string.h> #include "hashtable.h" -#include "hashtable_private.h" - -static unsigned int hash_fn(void *k) { - return *((unsigned int *)k); -} - -static int eq_fn(void *k1, void *k2) { - return !memcmp(k1, k2, ECP_ECDH_SIZE_KEY); -} static void *h_create(ECPContext *ctx) { int rv; - struct hashtable *h = malloc(sizeof(struct hashtable)); + struct hashtable *h = create_hashtable(1000, (unsigned int (*)(void *))ctx->cr.dh_pub_hash_fn, (int (*)(void *, void *))ctx->cr.dh_pub_hash_eq, NULL, NULL, NULL); if (h == NULL) return NULL; - rv = create_hashtable(h, 1000, (unsigned int (*)(void *))ctx->cr.dh_pub_hash_fn, (int (*)(void *, void *))ctx->cr.dh_pub_hash_eq, NULL, NULL, NULL); - if (!rv) { - free(h); - return NULL; - } - return h; } static void h_destroy(void *h) { hashtable_destroy(h); - free(h); } static int h_insert(void *h, unsigned char *k, ECPConnection *v) { @@ -39,6 +23,7 @@ static int h_insert(void *h, unsigned char *k, ECPConnection *v) { } static ECPConnection *h_remove(void *h, unsigned char *k) { + printf("REMOVE!!!\n"); return hashtable_remove(h, k); } diff --git a/code/core/timer.c b/code/core/timer.c index 0d06ba4..7767e67 100644 --- a/code/core/timer.c +++ b/code/core/timer.c @@ -22,7 +22,7 @@ void ecp_timer_destroy(ECPTimer *timer) { int ecp_timer_item_init(ECPTimerItem *ti, ECPConnection *conn, unsigned char mtype, unsigned short cnt, unsigned int timeout) { unsigned int abstime = conn->sock->ctx->tm.abstime_ms(timeout); - if (mtype >= ECP_MAX_MTYPE) return ECP_ERR_MAX_MTYPE; + if ((mtype & ECP_MTYPE_MASK) >= ECP_MAX_MTYPE) return ECP_ERR_MAX_MTYPE; ti->conn = conn; ti->mtype = mtype; @@ -181,7 +181,7 @@ unsigned int ecp_timer_exe(ECPSocket *sock) { unsigned char *pld = to_exec[i].pld; unsigned char pld_size = to_exec[i].pld_size; ecp_timer_retry_t *retry = to_exec[i].retry; - ecp_conn_handler_msg_t *handler = conn->sock->ctx->handler[conn->type] ? conn->sock->ctx->handler[conn->type]->msg[mtype] : NULL; + ecp_conn_handler_msg_t *handler = conn->sock->ctx->handler[conn->type] ? conn->sock->ctx->handler[conn->type]->msg[mtype & ECP_MTYPE_MASK] : NULL; if (to_exec[i].cnt) { ssize_t _rv = 0; diff --git a/code/proxy/proxy.c b/code/proxy/proxy.c index 81ce04c..583445f 100644 --- a/code/proxy/proxy.c +++ b/code/proxy/proxy.c @@ -26,6 +26,8 @@ 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; + 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); @@ -68,11 +70,12 @@ static ssize_t _proxyf_send_open(ECPConnection *conn) { ECPConnProxy *conn_p = (ECPConnProxy *)conn; ECPConnection *conn_next = conn_p->next; unsigned char payload[ECP_SIZE_PLD(0)]; + ecp_seq_t seq; if (conn_next == NULL) return ECP_ERR; - ecp_pld_set_type(payload, ECP_MTYPE_KGET); - return ecp_pld_send_wkey(conn_next, ECP_ECDH_IDX_PERMA, ECP_ECDH_IDX_INV, payload, sizeof(payload)); + ecp_pld_set_type(payload, ECP_MTYPE_KGET_REQ); + return ecp_pld_send_wkey(conn_next, &seq, ECP_ECDH_IDX_PERMA, ECP_ECDH_IDX_INV, payload, sizeof(payload)); } static ssize_t _proxyf_retry_kget(ECPConnection *conn, ECPTimerItem *ti) { @@ -87,7 +90,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, 3000); + rv = ecp_timer_item_init(&ti, conn_next, ECP_MTYPE_KGET_REP, 3, 3000); if (rv) return rv; ti.retry = _proxyf_retry_kget; @@ -100,7 +103,8 @@ static ssize_t proxyf_open(ECPConnection *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; - if (conn->out) { + 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) { @@ -110,12 +114,15 @@ static ssize_t proxyf_handle_open(ECPConnection *conn, ecp_seq_t seq, unsigned c 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; } - return 0; + + return ecp_conn_handle_open(conn, seq, mtype, msg, size); } else { ECPContext *ctx = conn->sock->ctx; ECPConnProxyF *conn_p = (ECPConnProxyF *)conn; int rv = ECP_OK; + unsigned char ctype = 0; + if (conn->out) return ECP_ERR; if (size < 0) return size; if (size < 1+2*ECP_ECDH_SIZE_KEY) return ECP_ERR; @@ -124,6 +131,9 @@ static ssize_t proxyf_handle_open(ECPConnection *conn, ecp_seq_t seq, unsigned c pthread_mutex_lock(&conn->mutex); #endif + ctype = msg[0]; + 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; @@ -241,7 +251,7 @@ static ssize_t _proxyb_send_open(ECPConnection *conn, ECPTimerItem *ti) { int rv = ECP_OK; // XXX server should verify perma_key - ecp_pld_set_type(payload, ECP_MTYPE_OPEN); + ecp_pld_set_type(payload, ECP_MTYPE_OPEN_REQ); buf[0] = conn->type; memcpy(buf+1, ctx->cr.dh_pub_get_buf(&sock->key_perma.public), ECP_ECDH_SIZE_KEY); @@ -249,24 +259,27 @@ static ssize_t _proxyb_send_open(ECPConnection *conn, ECPTimerItem *ti) { } static ssize_t proxyb_open(ECPConnection *conn) { - return ecp_timer_send(conn, _proxyb_send_open, ECP_MTYPE_OPEN, 3, 500); + return ecp_timer_send(conn, _proxyb_send_open, ECP_MTYPE_OPEN_REP, 3, 500); } static ssize_t proxyb_handle_open(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, ssize_t size) { ssize_t rv; - if (size < 0) return size; - if (conn->type != ECP_CTYPE_PROXYB) return ECP_ERR; + if (size < 0) return size; + rv = ecp_conn_handle_open(conn, seq, mtype, msg, size); if (rv < 0) return rv; - if (conn->out) { + if (mtype & ECP_MTYPE_FLAG_REP) { + if (!conn->out) return ECP_ERR; return 0; } else { - // XXX should verify perma_key + if (conn->out) return ECP_ERR; if (size < rv+ECP_ECDH_SIZE_KEY) return ECP_ERR; + + // XXX should verify perma_key return rv+ECP_ECDH_SIZE_KEY; } return ECP_ERR; @@ -299,7 +312,7 @@ static ssize_t proxyb_handle_relay(ECPConnection *conn, ecp_seq_t seq, unsigned #ifdef ECP_WITH_PTHREAD pthread_mutex_unlock(&key_next_mutex); #endif - + if (conn == NULL) return ECP_ERR; payload = msg - ECP_SIZE_MSG_HDR; @@ -321,7 +334,7 @@ static ssize_t proxyb_handle_relay(ECPConnection *conn, ecp_seq_t seq, unsigned 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) { unsigned char mtype = ecp_pld_get_type(pld_in); - if ((mtype == ECP_MTYPE_OPEN) || (mtype == ECP_MTYPE_KGET)) { + if ((mtype == ECP_MTYPE_OPEN_REQ) || (mtype == ECP_MTYPE_KGET_REQ)) { ECPConnProxy *conn_p = (ECPConnProxy *)conn; ECPContext *ctx = conn->sock->ctx; ECPConnection *conn_next = conn_p->next; @@ -331,7 +344,7 @@ static ssize_t proxy_set_msg(ECPConnection *conn, unsigned char *pld_out, size_t 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); + ecp_pld_set_type(pld_out, ECP_MTYPE_OPEN_REQ); buf = ecp_pld_get_buf(pld_out); buf[0] = ECP_CTYPE_PROXYF; @@ -449,16 +462,17 @@ int ecp_conn_proxy_init(ECPConnection *conn, ECPNode *conn_node, ECPConnProxy pr static ssize_t _proxy_send_kget(ECPConnection *conn, ECPTimerItem *ti) { unsigned char payload[ECP_SIZE_PLD(0)]; + ecp_seq_t seq; - ecp_pld_set_type(payload, ECP_MTYPE_KGET); - return ecp_pld_send_wkey(conn, ECP_ECDH_IDX_PERMA, ECP_ECDH_IDX_INV, payload, sizeof(payload)); + ecp_pld_set_type(payload, ECP_MTYPE_KGET_REQ); + return ecp_pld_send_wkey(conn, &seq, 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); if (rv) return rv; - ssize_t _rv = ecp_timer_send((ECPConnection *)&proxy[0], _proxy_send_kget, ECP_MTYPE_KGET, 3, 500); + ssize_t _rv = ecp_timer_send((ECPConnection *)&proxy[0], _proxy_send_kget, ECP_MTYPE_KGET_REP, 3, 500); if (_rv < 0) return _rv; return ECP_OK; |