summaryrefslogtreecommitdiff
path: root/ecp/src/ecp/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ecp/src/ecp/ext')
-rw-r--r--ecp/src/ecp/ext/Makefile4
-rw-r--r--ecp/src/ecp/ext/frag.c143
-rw-r--r--ecp/src/ecp/ext/frag.h12
-rw-r--r--ecp/src/ecp/ext/rbuf_recv.c2
-rw-r--r--ecp/src/ecp/ext/rbuf_send.c2
5 files changed, 2 insertions, 161 deletions
diff --git a/ecp/src/ecp/ext/Makefile b/ecp/src/ecp/ext/Makefile
index b20258f..67c9cbc 100644
--- a/ecp/src/ecp/ext/Makefile
+++ b/ecp/src/ecp/ext/Makefile
@@ -2,10 +2,6 @@ include ../common.mk
obj =
-ifeq ($(with_frag),yes)
-obj += frag.o
-endif
-
ifeq ($(with_rbuf),yes)
obj += rbuf.o rbuf_send.o rbuf_recv.o rbuf_ext.o
endif
diff --git a/ecp/src/ecp/ext/frag.c b/ecp/src/ecp/ext/frag.c
deleted file mode 100644
index f348da6..0000000
--- a/ecp/src/ecp/ext/frag.c
+++ /dev/null
@@ -1,143 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-
-#include <ecp/core.h>
-
-#include "frag.h"
-
-int ecp_frag_iter_init(ECPConnection *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;
-}
-
-void ecp_frag_iter_reset(ECPFragIter *iter) {
- iter->seq = 0;
- iter->frag_cnt = 0;
- iter->pld_size = 0;
-}
-
-ssize_t ecp_pld_defrag(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *payload, size_t pld_size) {
- ECPFragIter *iter = conn->iter;
- 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;
-
- 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;
-}
-
-ssize_t ecp_msg_send_wfrag(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(ECP_SIZE_PLD(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_ext_pld_handle_one(ECPConnection *conn, ecp_seq_t seq, unsigned char *payload, size_t pld_size, ECP2Buffer *bufs) {
- if (conn->iter) {
- 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);
- }
- }
-
- 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(ECP_SIZE_PLD(msg_size, mtype), conn) > ECP_MAX_PKT) {
- return ecp_msg_send_wfrag(conn, mtype, msg, msg_size, packet, payload);
- } else {
- return 0;
- }
-}
diff --git a/ecp/src/ecp/ext/frag.h b/ecp/src/ecp/ext/frag.h
deleted file mode 100644
index 2bf35d1..0000000
--- a/ecp/src/ecp/ext/frag.h
+++ /dev/null
@@ -1,12 +0,0 @@
-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(ECPConnection *conn, ECPFragIter *iter, unsigned char *buffer, size_t buf_size);
-void ecp_frag_iter_reset(ECPFragIter *iter);
-ssize_t ecp_pld_defrag(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *payload, size_t pld_size);
-ssize_t ecp_msg_send_wfrag(ECPConnection *conn, unsigned char mtype, unsigned char *msg, size_t msg_size, ECPBuffer *packet, ECPBuffer *payload);
diff --git a/ecp/src/ecp/ext/rbuf_recv.c b/ecp/src/ecp/ext/rbuf_recv.c
index 1282a78..777af66 100644
--- a/ecp/src/ecp/ext/rbuf_recv.c
+++ b/ecp/src/ecp/ext/rbuf_recv.c
@@ -96,7 +96,7 @@ static void msg_flush(ECPRBConn *conn) {
if (!(rbuf->arr.pld[idx].flags & ECP_RBUF_FLAG_IN_TIMER)) {
ECPTimerItem ti;
- ecp_timer_item_init(&ti, _conn, ECP_MTYPE_RBTIMER, NULL, 0, msg_pts - now);
+ ecp_timer_item_init(&ti, _conn, ECP_MTYPE_RBTIMER, NULL, 0, msg_pts - now, NULL);
rv = ecp_timer_push(&ti);
if (!rv) rbuf->arr.pld[idx].flags |= ECP_RBUF_FLAG_IN_TIMER;
}
diff --git a/ecp/src/ecp/ext/rbuf_send.c b/ecp/src/ecp/ext/rbuf_send.c
index 5716f92..c235ad9 100644
--- a/ecp/src/ecp/ext/rbuf_send.c
+++ b/ecp/src/ecp/ext/rbuf_send.c
@@ -73,7 +73,7 @@ static ssize_t _rbuf_send_flush(ECPConnection *_conn, ECPTimerItem *ti) {
ssize_t ecp_rbuf_send_flush(ECPRBConn *conn) {
ECPConnection *_conn = ecp_rbuf_get_conn(conn);
- return ecp_timer_send(_conn, _rbuf_send_flush, ECP_MTYPE_RBACK, 3, 500);
+ return ecp_timer_send(_conn, _rbuf_send_flush, ECP_MTYPE_RBACK, 3, 500, NULL);
}
ssize_t ecp_rbuf_handle_ack(ECPRBConn *conn, unsigned char *msg, size_t msg_size) {