diff options
-rw-r--r-- | ecp/src/ecp/Makefile | 6 | ||||
-rw-r--r-- | ecp/src/ecp/core.c | 60 | ||||
-rw-r--r-- | ecp/src/ecp/ext.h | 8 | ||||
-rw-r--r-- | ecp/src/ecp/ext/Makefile | 13 | ||||
-rw-r--r-- | ecp/src/ecp/ext/ext.c | 69 | ||||
-rw-r--r-- | ecp/src/ecp/ext/frag.c | 129 | ||||
-rw-r--r-- | ecp/src/ecp/ext/frag.h | 13 | ||||
-rw-r--r-- | ecp/test/Makefile | 2 | ||||
-rw-r--r-- | ecp/test/basic.c | 73 | ||||
-rw-r--r-- | ecp/test/init.c | 29 |
10 files changed, 314 insertions, 88 deletions
diff --git a/ecp/src/ecp/Makefile b/ecp/src/ecp/Makefile index 2bdd563..c403829 100644 --- a/ecp/src/ecp/Makefile +++ b/ecp/src/ecp/Makefile @@ -31,11 +31,11 @@ install: all if [ -f vconn/libecpvconn.a ]; then \ install vconn/libecpvconn.a $(build_dir); \ fi - if [ -f dir/libecpext.a ]; then \ - install vconn/libecpext.a $(build_dir); \ + if [ -f ext/libecpext.a ]; then \ + install ext/libecpext.a $(build_dir); \ fi if [ -f dir/libecpdir.a ]; then \ - install vconn/libecpdir.a $(build_dir); \ + install dir/libecpdir.a $(build_dir); \ fi clean: diff --git a/ecp/src/ecp/core.c b/ecp/src/ecp/core.c index badb09e..3cb236f 100644 --- a/ecp/src/ecp/core.c +++ b/ecp/src/ecp/core.c @@ -389,6 +389,16 @@ void ecp_sock_get_nonce(ECPSocket *sock, ecp_nonce_t *nonce) { #endif } +int ecp_cookie_gen(ECPSocket *sock, unsigned char *cookie, unsigned char *public_buf) { + memcpy(cookie, public_buf, ECP_SIZE_COOKIE); + return ECP_OK; +} + +int ecp_cookie_verify(ECPSocket *sock, unsigned char *cookie, unsigned char *public_buf) { + if (memcmp(cookie, public_buf, ECP_SIZE_COOKIE) == 0) return ECP_OK; + return ECP_ERR_COOKIE; +} + ECPConnection *ecp_sock_keys_search(ECPSocket *sock, ecp_ecdh_public_t *public) { ECPConnection *conn; @@ -828,8 +838,8 @@ void ecp_conn_remove_addr(ECPConnection *conn) { conn_table_remove_addr(conn); #ifdef ECP_WITH_PTHREAD + pthread_mutex_unlock(&conn->mutex); pthread_mutex_unlock(&sock->conn_table.mutex); - pthread_mutex_lock(&conn->mutex); #endif } @@ -1037,11 +1047,14 @@ int ecp_conn_dhkey_set_pub(ECPConnection *conn, unsigned char idx, ecp_ecdh_publ if (ecp_conn_is_inb(conn)) pthread_mutex_lock(&sock->conn_table.mutex); pthread_mutex_lock(&conn->mutex); #endif + rv = conn_dhkey_set_pub(conn, idx, public); + #ifdef ECP_WITH_PTHREAD pthread_mutex_unlock(&conn->mutex); if (ecp_conn_is_inb(conn)) pthread_mutex_unlock(&sock->conn_table.mutex); #endif + if (rv == ECP_ERR_ECDH_KEY_DUP) rv = ECP_OK; return rv; @@ -1694,14 +1707,7 @@ ssize_t ecp_unpack(ECPSocket *sock, ECPConnection *parent, ecp_tr_addr_t *addr, is_inb = ecp_conn_is_inb(conn); is_open = ecp_conn_is_open(conn); - if (is_open) { - nonce_buf = packet+ECP_SIZE_PROTO+1+ECP_SIZE_ECDH_PUB; - packet += ECP_SIZE_PKT_HDR; - pkt_size -= ECP_SIZE_PKT_HDR; - - nonce_conn = conn->nonce_in; - nonce_map = conn->nonce_map; - } else if (!is_inb && (idx == ECP_ECDH_IDX_INV)) { + if (!is_open && !is_inb && (idx == ECP_ECDH_IDX_INV)) { nonce_buf = packet+ECP_SIZE_PROTO+1; packet += ECP_SIZE_PROTO+1+ECP_SIZE_NONCE; pkt_size -= ECP_SIZE_PROTO+1+ECP_SIZE_NONCE; @@ -1709,9 +1715,17 @@ ssize_t ecp_unpack(ECPSocket *sock, ECPConnection *parent, ecp_tr_addr_t *addr, s_idx = ECP_ECDH_IDX_PERMA; c_idx = conn->key_curr; } else { - _rv = ECP_ERR; + public_buf = packet+ECP_SIZE_PROTO+1; + nonce_buf = public_buf+ECP_SIZE_ECDH_PUB; + packet += ECP_SIZE_PKT_HDR; + pkt_size -= ECP_SIZE_PKT_HDR; + + if (is_open) { + nonce_conn = conn->nonce_in; + nonce_map = conn->nonce_map; + } } - if (!_rv) _rv = conn_shkey_get(conn, s_idx, c_idx, &shkey); + _rv = conn_shkey_get(conn, s_idx, c_idx, &shkey); if (!_rv) conn->refcount++; #ifdef ECP_WITH_PTHREAD @@ -1884,22 +1898,26 @@ ssize_t ecp_unpack(ECPSocket *sock, ECPConnection *parent, ecp_tr_addr_t *addr, pld_size -= rv; } - if (conn && is_open) { + if (conn) { + if (is_open) { #ifdef ECP_WITH_PTHREAD - pthread_mutex_lock(&conn->mutex); + pthread_mutex_lock(&conn->mutex); #endif - conn->nonce_in = nonce_in; - conn->nonce_map = nonce_map; - if (is_inb && addr) conn->remote.addr = *addr; + conn->nonce_in = nonce_in; + conn->nonce_map = nonce_map; + if (is_inb && addr) conn->remote.addr = *addr; #ifdef ECP_WITH_PTHREAD - pthread_mutex_unlock(&conn->mutex); + pthread_mutex_unlock(&conn->mutex); #endif - *_conn = conn; - *_payload = payload; - *_seq = (ecp_seq_t)nonce_pkt; + *_conn = conn; + *_payload = payload; + *_seq = (ecp_seq_t)nonce_pkt; + } else { + ecp_conn_refcount_dec(conn); + } } return _pkt_size - pld_size; @@ -2023,7 +2041,7 @@ static ssize_t _pack(ECPBuffer *packet, ECPPktMeta *pkt_meta, ECPBuffer *payload pkt_buf += 3; if (pkt_meta->public) { - memcpy(pkt_buf, &pkt_meta->public, ECP_SIZE_ECDH_PUB); + memcpy(pkt_buf, pkt_meta->public, ECP_SIZE_ECDH_PUB); pkt_buf += ECP_SIZE_ECDH_PUB; } if (pkt_meta->cookie) { diff --git a/ecp/src/ecp/ext.h b/ecp/src/ecp/ext.h new file mode 100644 index 0000000..811b6d1 --- /dev/null +++ b/ecp/src/ecp/ext.h @@ -0,0 +1,8 @@ +int ecp_ext_err_handle(ECPConnection *conn, unsigned char mtype, int err); +int ecp_ext_conn_open(ECPConnection *conn); +void ecp_ext_conn_destroy(ECPConnection *conn); +ssize_t ecp_ext_msg_handle(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, size_t msg_size, ECP2Buffer *bufs); +ssize_t ecp_ext_pld_store(ECPConnection *conn, ecp_seq_t seq, unsigned char *payload, size_t pld_size, ECP2Buffer *bufs); +ssize_t ecp_ext_pld_handle(ECPConnection *conn, ecp_seq_t seq, unsigned char *payload, size_t pld_size, ECP2Buffer *bufs); +ssize_t ecp_ext_pld_send(ECPConnection *conn, ECPBuffer *payload, size_t pld_size, ECPBuffer *packet, size_t pkt_size, unsigned char flags, ECPTimerItem *ti, ecp_tr_addr_t *addr); +ssize_t ecp_ext_msg_send(ECPConnection *conn, unsigned char mtype, unsigned char *msg, size_t msg_size, ECPBuffer *packet, ECPBuffer *payload); diff --git a/ecp/src/ecp/ext/Makefile b/ecp/src/ecp/ext/Makefile new file mode 100644 index 0000000..0e61e83 --- /dev/null +++ b/ecp/src/ecp/ext/Makefile @@ -0,0 +1,13 @@ +include ../common.mk + +obj = ext.o frag.o rbuf.o rbuf_send.o rbuf_recv.o msgq.o + + +%.o: %.c + $(CC) $(CFLAGS) -c $< + +all: $(obj) + $(AR) rcs libecpext.a $(obj) + +clean: + rm -f *.o *.a diff --git a/ecp/src/ecp/ext/ext.c b/ecp/src/ecp/ext/ext.c new file mode 100644 index 0000000..d407e80 --- /dev/null +++ b/ecp/src/ecp/ext/ext.c @@ -0,0 +1,69 @@ +#include <stdlib.h> + +#include <core.h> +#include <ext.h> + +#include "rbuf.h" +#include "frag.h" + +int ecp_ext_err_handle(ECPConnection *conn, unsigned char mtype, int err) { + ECPRBConn *_conn = ecp_rbuf_get_rbconn(conn); + + if (_conn) return ecp_rbuf_err_handle(_conn, mtype, err); + return ECP_PASS; +} + +int ecp_ext_conn_open(ECPConnection *conn) { + ECPRBConn *_conn = ecp_rbuf_get_rbconn(conn); + + if (_conn) ecp_rbuf_start(_conn); + return ECP_OK; +} + +void ecp_ext_conn_destroy(ECPConnection *conn) { + ECPRBConn *_conn = ecp_rbuf_get_rbconn(conn); + if (_conn) ecp_rbuf_destroy(_conn); +} + +ssize_t ecp_ext_msg_handle(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, size_t msg_size, ECP2Buffer *bufs) { + ECPRBConn *_conn = ecp_rbuf_get_rbconn(conn); + + if (_conn) return ecp_rbuf_msg_handle(_conn, seq, mtype, msg, msg_size, bufs); + return 0; +} + +ssize_t ecp_ext_pld_store(ECPConnection *conn, ecp_seq_t seq, unsigned char *payload, size_t pld_size, ECP2Buffer *bufs) { + ECPRBConn *_conn = ecp_rbuf_get_rbconn(conn); + + if (_conn && _conn->recv) return ecp_rbuf_store(_conn, seq, payload, pld_size); + return 0; +} + +ssize_t ecp_ext_pld_handle(ECPConnection *conn, ecp_seq_t seq, unsigned char *payload, size_t pld_size, ECP2Buffer *bufs) { + unsigned char mtype; + int rv; + + rv = ecp_pld_get_type(payload, pld_size, &mtype); + if (rv) return rv; + + if (mtype & ECP_MTYPE_FLAG_FRAG) { + return ecp_pld_defrag(conn, seq, mtype, payload, pld_size); + } else { + return 0; + } +} + +ssize_t ecp_ext_pld_send(ECPConnection *conn, ECPBuffer *payload, size_t pld_size, ECPBuffer *packet, size_t pkt_size, unsigned char flags, ECPTimerItem *ti, ecp_tr_addr_t *addr) { + ECPRBConn *_conn = ecp_rbuf_get_rbconn(conn); + + if (_conn && _conn->send) return ecp_rbuf_pld_send(_conn, payload, pld_size, packet, pkt_size, ti); + return 0; +} + +ssize_t ecp_ext_msg_send(ECPConnection *conn, unsigned char mtype, unsigned char *msg, size_t msg_size, ECPBuffer *packet, ECPBuffer *payload) { + if (ECP_SIZE_PKT_BUF(msg_size, mtype, conn) > ECP_MAX_PKT) { + return ecp_msg_frag(conn, mtype, msg, msg_size, packet, payload); + } else { + return 0; + } +} diff --git a/ecp/src/ecp/ext/frag.c b/ecp/src/ecp/ext/frag.c new file mode 100644 index 0000000..ce87d81 --- /dev/null +++ b/ecp/src/ecp/ext/frag.c @@ -0,0 +1,129 @@ +#include <stdlib.h> +#include <string.h> + +#include <core.h> + +#include "rbuf.h" +#include "frag.h" + +int ecp_frag_iter_init(ECPRBConn *conn, ECPFragIter *iter, unsigned char *buffer, size_t buf_size) { + memset(iter, 0, sizeof(ECPFragIter)); + iter->buffer = buffer; + iter->buf_size = buf_size; + + conn->iter = iter; + return ECP_OK; +} + +ECPFragIter *ecp_frag_iter_get(ECPRBConn *conn) { + return conn->iter; +} + +void ecp_frag_iter_reset(ECPFragIter *iter) { + iter->seq = 0; + iter->frag_cnt = 0; + iter->pld_size = 0; +} + +ssize_t ecp_msg_frag(ECPConnection *conn, unsigned char mtype, unsigned char *msg, size_t msg_size, ECPBuffer *packet, ECPBuffer *payload) { + unsigned char *msg_buf; + unsigned char *pld_buf; + size_t pld_size; + size_t frag_size, frag_size_final; + ecp_nonce_t nonce, nonce_start; + int pkt_cnt = 0; + int i; + + mtype |= ECP_MTYPE_FLAG_FRAG; + frag_size = ECP_MAX_PKT - ECP_SIZE_PKT_BUF(0, mtype, conn); + pkt_cnt = msg_size / frag_size; + frag_size_final = msg_size - frag_size * pkt_cnt; + if (frag_size_final) pkt_cnt++; + +#ifdef ECP_WITH_PTHREAD + pthread_mutex_lock(&conn->mutex); +#endif + + nonce_start = conn->nonce_out; + conn->nonce_out += pkt_cnt; + +#ifdef ECP_WITH_PTHREAD + pthread_mutex_unlock(&conn->mutex); +#endif + + pld_buf = payload->buffer; + pld_size = payload->size; + for (i=0; i<pkt_cnt; i++) { + ssize_t rv; + + ecp_pld_set_type(pld_buf, pld_size, mtype); + ecp_pld_set_frag(pld_buf, pld_size, i, pkt_cnt, frag_size); + msg_buf = ecp_pld_get_msg(pld_buf, pld_size); + + if ((i == pkt_cnt - 1) && frag_size_final) frag_size = frag_size_final; + memcpy(msg_buf, msg, frag_size); + msg += frag_size; + nonce = nonce_start + i; + + rv = ecp_pld_send_wnonce(conn, packet, payload, ECP_SIZE_PLD(frag_size, mtype), 0, &nonce); + if (rv < 0) return rv; + } + + return msg_size; +} + +ssize_t ecp_pld_defrag(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *payload, size_t pld_size) { + ECPRBConn *_conn = NULL; + ECPFragIter *iter = NULL; + unsigned char *msg; + unsigned char frag_cnt, frag_tot; + uint16_t frag_size; + size_t hdr_size, msg_size; + size_t buf_offset; + int rv; + + _conn = ecp_rbuf_get_rbconn(conn); + if (conn) iter = ecp_frag_iter_get(_conn); + if (iter == NULL) ECP_ERR_ITER; + + rv = ecp_pld_get_frag(payload, pld_size, &frag_cnt, &frag_tot, &frag_size); + if (rv) return ECP_ERR; + + msg = ecp_pld_get_msg(payload, pld_size); + if (msg == NULL) return ECP_ERR; + hdr_size = msg - payload; + + msg_size = pld_size - hdr_size; + if (msg_size == 0) return ECP_ERR; + + if (iter->pld_size && (iter->seq + frag_cnt != seq)) ecp_frag_iter_reset(iter); + + if (iter->pld_size == 0) { + iter->seq = seq - frag_cnt; + iter->frag_cnt = 0; + } + + mtype &= ~ECP_MTYPE_FLAG_FRAG; + buf_offset = ECP_SIZE_MTYPE + ECP_SIZE_MT_FLAG(mtype) + frag_size * frag_cnt; + if (buf_offset + msg_size > iter->buf_size) return ECP_ERR_SIZE; + memcpy(iter->buffer + buf_offset, msg, msg_size); + + if (frag_cnt == 0) { + if (ECP_SIZE_MTYPE + ECP_SIZE_MT_FLAG(mtype) > iter->buf_size) return ECP_ERR_SIZE; + + iter->buffer[0] = mtype; + if (ECP_SIZE_MT_FLAG(mtype)) { + memcpy(iter->buffer + ECP_SIZE_MTYPE, payload + ECP_SIZE_MTYPE, ECP_SIZE_MT_FLAG(mtype)); + } + msg_size += ECP_SIZE_MTYPE + ECP_SIZE_MT_FLAG(mtype); + } + + iter->frag_cnt++; + iter->pld_size += msg_size; + if (iter->frag_cnt == frag_tot) { + ecp_pld_handle_one(conn, iter->seq, iter->buffer, iter->pld_size, NULL); + ecp_frag_iter_reset(iter); + } + + return pld_size; +} diff --git a/ecp/src/ecp/ext/frag.h b/ecp/src/ecp/ext/frag.h new file mode 100644 index 0000000..1400c1d --- /dev/null +++ b/ecp/src/ecp/ext/frag.h @@ -0,0 +1,13 @@ +typedef struct ECPFragIter { + ecp_seq_t seq; + unsigned char frag_cnt; + unsigned char *buffer; + size_t buf_size; + size_t pld_size; +} ECPFragIter; + +int ecp_frag_iter_init(ECPRBConn *conn, ECPFragIter *iter, unsigned char *buffer, size_t buf_size); +ECPFragIter *ecp_frag_iter_get(ECPRBConn *conn); +void ecp_frag_iter_reset(ECPFragIter *iter); +ssize_t ecp_msg_frag(ECPConnection *conn, unsigned char mtype, unsigned char *msg, size_t msg_size, ECPBuffer *packet, ECPBuffer *payload); +ssize_t ecp_pld_defrag(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *payload, size_t pld_size);
\ No newline at end of file diff --git a/ecp/test/Makefile b/ecp/test/Makefile index 20b50e5..ce12a87 100644 --- a/ecp/test/Makefile +++ b/ecp/test/Makefile @@ -7,7 +7,7 @@ dep=../build-posix/*.a ../util/libecputil.a %.o: %.c $(CC) $(CFLAGS) -c $< -all: basic dir server echo frag stress vcs vc_server vc_client vc_client_t +all: basic # dir server echo frag stress vcs vc_server vc_client vc_client_t basic: basic.o init.o $(dep) $(CC) -o $@ $< init.o $(dep) $(LDFLAGS) diff --git a/ecp/test/basic.c b/ecp/test/basic.c index 0f4e322..2edb174 100644 --- a/ecp/test/basic.c +++ b/ecp/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; @@ -18,58 +18,48 @@ ECPNode node; ECPConnection conn; #define CTYPE_TEST 0 -#define MTYPE_MSG 8 +#define MTYPE_MSG 0 -ssize_t handle_open_c(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s, ECP2Buffer *b) { - uint32_t seq = 0; +int handle_open_c(ECPConnection *conn, ECP2Buffer *b) { + char *_msg = "PERA JE CAR!"; + ssize_t rv; - ecp_conn_handle_open(conn, sq, t, p, s, b); - if (s < 0) { - printf("OPEN ERR:%ld\n", s); - return s; - } + printf("OPEN\n"); + rv = ecp_msg_send(conn, MTYPE_MSG, (unsigned char *)_msg, strlen(_msg)+1); - char *msg = "PERA JE CAR!"; - unsigned char buf[1000]; - - strcpy((char *)buf, msg); - ssize_t _rv = ecp_send(conn, MTYPE_MSG, buf, 1000); - - return s; + return ECP_OK; } -ssize_t handle_msg_c(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s, ECP2Buffer *b) { - printf("MSG C:%s size:%ld\n", p, s); - return s; +ssize_t handle_msg_c(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, size_t msg_size, ECP2Buffer *b) { + printf("MSG C:%s size:%ld\n", msg, msg_size); + return msg_size; } -ssize_t handle_msg_s(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s, ECP2Buffer *b) { - printf("MSG S:%s size:%ld\n", p, s); - - char *msg = "VAISTINU JE CAR!"; - unsigned char buf[1000]; +ssize_t handle_msg_s(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; - strcpy((char *)buf, msg); - ssize_t _rv = ecp_send(conn, MTYPE_MSG, buf, 1000); + printf("MSG S:%s size:%ld\n", msg, msg_size); + rv = ecp_msg_send(conn, MTYPE_MSG, (unsigned char *)_msg, strlen(_msg)+1); - return s; + return msg_size; } int main(int argc, char *argv[]) { int rv; + /* server */ 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; + ecp_conn_handler_init(&handler_s, handle_msg_s, NULL, NULL, NULL); + ecp_ctx_set_handler(&ctx_s, &handler_s, CTYPE_TEST); - rv = ecp_dhkey_gen(&ctx_s, &key_perma_s); + rv = ecp_dhkey_gen(&key_perma_s); printf("ecp_dhkey_gen RV:%d\n", rv); - rv = ecp_sock_init(&sock_s, &ctx_s, &key_perma_s); - printf("ecp_sock_init 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); @@ -77,19 +67,18 @@ int main(int argc, char *argv[]) { rv = ecp_start_receiver(&sock_s); printf("ecp_start_receiver RV:%d\n", rv); + /* client */ 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; + ecp_conn_handler_init(&handler_c, handle_msg_c, handle_open_c, NULL, NULL); + ecp_ctx_set_handler(&ctx_c, &handler_c, CTYPE_TEST); - rv = ecp_dhkey_gen(&ctx_c, &key_perma_c); + rv = ecp_dhkey_gen(&key_perma_c); printf("ecp_dhkey_gen RV:%d\n", rv); - rv = ecp_sock_init(&sock_c, &ctx_c, &key_perma_c); - printf("ecp_sock_init RV:%d\n", rv); + rv = ecp_sock_create(&sock_c, &ctx_c, &key_perma_c); + printf("ecp_sock_create RV:%d\n", rv); rv = ecp_sock_open(&sock_c, NULL); printf("ecp_sock_open RV:%d\n", rv); @@ -100,8 +89,8 @@ int main(int argc, char *argv[]) { rv = ecp_node_init(&node, &key_perma_s.public, "127.0.0.1:3000"); printf("ecp_node_init RV:%d\n", rv); - rv = ecp_conn_init(&conn, &sock_c, CTYPE_TEST); - printf("ecp_conn_init 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); diff --git a/ecp/test/init.c b/ecp/test/init.c index 7b59578..f4b033a 100644 --- a/ecp/test/init.c +++ b/ecp/test/init.c @@ -1,17 +1,10 @@ #include <stdlib.h> -#include <fcntl.h> -#include <unistd.h> +#include <stdio.h> -#include "core.h" +#include <core.h> -static int v_rng(void *buf, size_t bufsize) { - int fd; - - if((fd = open("/dev/urandom", O_RDONLY)) < 0) return -1; - size_t nb = read(fd, buf, bufsize); - close(fd); - if (nb != bufsize) return -1; - return 0; +void handle_err(ECPConnection *conn, unsigned char mtype, int err) { + printf("ERR: CTYPE:%d MTYPE:%x ERR:%d\n", conn->type, mtype, err); } static ECPConnection *conn_alloc(ECPSocket *sock, unsigned char type) { @@ -21,7 +14,7 @@ static ECPConnection *conn_alloc(ECPSocket *sock, unsigned char type) { conn = malloc(sizeof(ECPConnection)); if (conn == NULL) return NULL; - rv = ecp_conn_init(conn, sock, type); + rv = ecp_conn_create_inb(conn, sock, type); if (rv) { free(conn); return NULL; @@ -36,12 +29,6 @@ static void conn_free(ECPConnection *conn) { int ecp_init(ECPContext *ctx) { int rv; - rv = ecp_ctx_init(ctx); - if (rv) return rv; - - ctx->rng = v_rng; - ctx->conn_alloc = conn_alloc; - ctx->conn_free = conn_free; - - return ECP_OK; -}
\ No newline at end of file + rv = ecp_ctx_init(ctx, handle_err, NULL, conn_alloc, conn_free); + return rv; +} |