summaryrefslogtreecommitdiff
path: root/code
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2017-08-22 05:44:21 +0200
committerUros Majstorovic <majstor@majstor.org>2017-08-22 05:44:21 +0200
commit680922c97ca94e832e75b20f5aa22a00a6a80420 (patch)
tree52c2427cc96782d2cee5541a29296d62ef26f2fd /code
parent050bf97c2dc6c22e7b3134e281ee892e5351439f (diff)
seq implemented; conn reset implemented
Diffstat (limited to 'code')
-rw-r--r--code/core/TODO2
-rw-r--r--code/core/core.c166
-rw-r--r--code/core/core.h12
-rw-r--r--code/core/msgq.c2
-rw-r--r--code/core/rbuf.c2
-rw-r--r--code/core/rbuf.h9
-rw-r--r--code/core/rbuf_recv.c20
-rw-r--r--code/core/rbuf_send.c20
8 files changed, 159 insertions, 74 deletions
diff --git a/code/core/TODO b/code/core/TODO
index bd4cc70..f48cd69 100644
--- a/code/core/TODO
+++ b/code/core/TODO
@@ -1,6 +1,6 @@
+ check for nonce
++ check for seq
-- check for seq (without rbuf)
- memzero keys after usage
- implement socket message queue
diff --git a/code/core/core.c b/code/core/core.c
index b319afb..cee72c4 100644
--- a/code/core/core.c
+++ b/code/core/core.c
@@ -321,6 +321,20 @@ static int conn_dhkey_new_pair(ECPConnection *conn, ECPDHKey *key) {
return ECP_OK;
}
+static void conn_dhkey_del_pair(ECPConnection *conn, unsigned char idx) {
+ ECPSocket *sock = conn->sock;
+ ECPContext *ctx = sock->ctx;
+
+#ifdef ECP_WITH_HTABLE
+ if (ctx->ht.init && conn->out && ecp_conn_is_reg(conn) && conn->key[idx].valid) {
+ ctx->ht.remove(sock->conn.htable, ctx->cr.dh_pub_get_buf(&conn->key[idx].public));
+ }
+#endif
+
+ memset(&conn->key[idx], 0, sizeof(conn->key[idx]));
+ conn->key_idx_map[idx] = ECP_ECDH_IDX_INV;
+}
+
static int conn_dhkey_new_pub_local(ECPConnection *conn, unsigned char idx) {
// Remote obtained our key
unsigned char new = conn->key_idx_curr == ECP_ECDH_IDX_INV ? 0 : (conn->key_idx_curr+1) % ECP_MAX_NODE_KEY;
@@ -525,14 +539,13 @@ int ecp_conn_init(ECPConnection *conn, ECPNode *node) {
ECPContext *ctx = conn->sock->ctx;
int rv = ECP_OK;
- if (conn == NULL) return ECP_ERR;
if (node == NULL) return ECP_ERR;
- if (ctx->rng == NULL) return ECP_ERR_RNG;
conn->out = 1;
conn->node = *node;
- rv = ctx->rng(conn->nonce, ECP_AEAD_SIZE_NONCE);
- if (!rv) rv = ecp_dhkey_generate(ctx, &key);
+ rv = ecp_dhkey_generate(ctx, &key);
+ if (!rv) rv = ctx->rng(conn->nonce, ECP_AEAD_SIZE_NONCE);
+
if (!rv) rv = conn_dhkey_new_pair(conn, &key);
if (!rv) rv = conn_dhkey_new_pub_local(conn, conn->key_curr);
if (!rv) rv = ecp_conn_register(conn);
@@ -596,6 +609,42 @@ int ecp_conn_close(ECPConnection *conn, unsigned int timeout) {
return ECP_OK;
}
+int ecp_conn_reset(ECPConnection *conn) {
+ ECPDHKey key;
+ ECPSocket *sock = conn->sock;
+ ECPContext *ctx = sock->ctx;
+ int rv = ECP_OK;
+ int i;
+
+ rv = ecp_dhkey_generate(ctx, &key);
+ if (rv) return rv;
+
+#ifdef ECP_WITH_PTHREAD
+ pthread_mutex_lock(&sock->conn.mutex);
+ pthread_mutex_lock(&conn->mutex);
+#endif
+
+ for (i=0; i<ECP_MAX_CONN_KEY; i++) {
+ conn_dhkey_del_pair(conn, i);
+ }
+ conn->key_curr = 0;
+ rv = conn_dhkey_new_pair(conn, &key);
+
+#ifdef ECP_WITH_PTHREAD
+ pthread_mutex_unlock(&sock->conn.mutex);
+#endif
+
+ if (!rv) rv = conn_dhkey_new_pub_local(conn, conn->key_curr);
+ if (!rv) rv = ctx->rng(conn->nonce, ECP_AEAD_SIZE_NONCE);
+ conn->flags &= ~ECP_CONN_FLAG_OPEN;
+
+#ifdef ECP_WITH_PTHREAD
+ pthread_mutex_unlock(&conn->mutex);
+#endif
+
+ return rv;
+}
+
int ecp_conn_handler_init(ECPConnHandler *handler) {
memset(handler, 0, sizeof(ECPConnHandler));
handler->msg[ECP_MTYPE_OPEN] = ecp_conn_handle_open;
@@ -687,29 +736,44 @@ int ecp_conn_handle_new(ECPSocket *sock, ECPConnection **_conn, ECPConnection *p
ssize_t ecp_conn_handle_open(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, ssize_t size) {
int is_open;
- if (size < 0) return size;
#ifdef ECP_WITH_PTHREAD
pthread_mutex_lock(&conn->mutex);
#endif
is_open = ecp_conn_is_open(conn);
+ if (!is_open) conn->flags |= ECP_CONN_FLAG_OPEN;
#ifdef ECP_WITH_PTHREAD
pthread_mutex_unlock(&conn->mutex);
#endif
- if (!is_open) conn->flags |= ECP_CONN_FLAG_OPEN;
-
if (mtype & ECP_MTYPE_FLAG_REP) {
- int rv;
-
if (!conn->out) return ECP_ERR;
-#ifdef ECP_WITH_RBUF
- if (!is_open && conn->rbuf.recv) {
- rv = ecp_rbuf_recv_start(conn, seq);
+ if (is_open && size == ECP_ERR_TIMEOUT) {
+ int rv = ecp_conn_reset(conn);
if (rv) return rv;
+
+ return 0;
}
+
+ if (size < 0) return size;
+
+ if (!is_open) {
+#ifdef ECP_WITH_PTHREAD
+ pthread_mutex_lock(&conn->mutex);
+#endif
+ conn->seq_in = seq;
+ conn->seq_in_map = 1;
+#ifdef ECP_WITH_PTHREAD
+ pthread_mutex_unlock(&conn->mutex);
#endif
+#ifdef ECP_WITH_RBUF
+ if (conn->rbuf.recv) {
+ int rv = ecp_rbuf_recv_start(conn, seq);
+ if (rv) return rv;
+ }
+#endif
+ }
return 0;
} else {
@@ -717,6 +781,7 @@ ssize_t ecp_conn_handle_open(ECPConnection *conn, ecp_seq_t seq, unsigned char m
unsigned char ctype = 0;
if (conn->out) return ECP_ERR;
+ if (size < 0) return size;
if (size < 1) return ECP_ERR;
ctype = msg[0];
@@ -1013,8 +1078,9 @@ ssize_t ecp_pkt_handle(ECPSocket *sock, ECPNetAddr *addr, ECPConnection *parent,
ECPConnection *conn = NULL;
ECPDHKey *key = NULL;
int rv = ECP_OK;
- ecp_seq_t c_seq, p_seq, n_seq;
- uint32_t seq_bitmap;
+ int seq_check = 1;
+ ecp_seq_t seq_c, seq_p, seq_n;
+ ecp_ack_t seq_map;
ssize_t pld_size, cnt_size, proc_size;
s_idx = (packet[ECP_SIZE_PROTO] & 0xF0) >> 4;
@@ -1053,8 +1119,9 @@ ssize_t ecp_pkt_handle(ECPSocket *sock, ECPNetAddr *addr, ECPConnection *parent,
if (!rv && key) memcpy(&private, &key->private, sizeof(private));
if (!rv && conn) {
- c_seq = conn->seq_in;
- seq_bitmap = conn->seq_in_bitmap;
+ seq_check = ecp_conn_is_open(conn) ? 1 : 0;
+ seq_c = conn->seq_in;
+ seq_map = conn->seq_in_map;
conn->refcount++;
}
@@ -1074,7 +1141,7 @@ ssize_t ecp_pkt_handle(ECPSocket *sock, ECPNetAddr *addr, ECPConnection *parent,
if (pld_size < ECP_SIZE_MSG_HDR) rv = ECP_ERR_DECRYPT;
if (rv) goto pkt_handle_err;
- p_seq = \
+ seq_p = \
(payload[0] << 24) | \
(payload[1] << 16) | \
(payload[2] << 8) | \
@@ -1087,8 +1154,8 @@ ssize_t ecp_pkt_handle(ECPSocket *sock, ECPNetAddr *addr, ECPConnection *parent,
rv = sock->conn_new(sock, &conn, parent, 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;
+ seq_map = 1;
+ seq_n = seq_p;
} 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_);
@@ -1096,7 +1163,7 @@ ssize_t ecp_pkt_handle(ECPSocket *sock, ECPNetAddr *addr, ECPConnection *parent,
rv = ecp_sock_dhkey_get_curr(sock, buf, buf+1);
if (!rv) {
- ssize_t _rv = ecp_pld_send_raw(sock, parent, addr, s_idx, c_idx, &public, &shsec, nonce, p_seq, payload_, sizeof(payload_));
+ ssize_t _rv = ecp_pld_send_raw(sock, parent, addr, s_idx, c_idx, &public, &shsec, nonce, seq_p, payload_, sizeof(payload_));
if (_rv < 0) rv = _rv;
}
return ECP_MIN_PKT;
@@ -1104,25 +1171,38 @@ ssize_t ecp_pkt_handle(ECPSocket *sock, ECPNetAddr *addr, ECPConnection *parent,
return ECP_ERR_CONN_NOT_FOUND;
}
} else {
- /*
- if ((c_seq > p_seq) && (c_seq - p_seq >= 32)) rv = ECP_ERR_SEQ;
- if ((p_seq > c_seq) && (p_seq - c_seq > 32)) rv = ECP_ERR_SEQ;
+#ifdef ECP_WITH_RBUF
+ if (conn->rbuf.recv || (payload[ECP_SIZE_PLD_HDR] == ECP_MTYPE_RBACK) || (payload[ECP_SIZE_PLD_HDR] == ECP_MTYPE_RBFLUSH)) seq_check = 0;
+#endif
+
+ if (seq_check) {
+ if (ECP_SEQ_LTE(seq_p, seq_c)) {
+ ecp_seq_t seq_offset = seq_c - seq_p;
+ if (seq_offset < ECP_SIZE_ACKB) {
+ ecp_ack_t ack_mask = ((ecp_ack_t)1 << seq_offset);
+ if (ack_mask & seq_map) rv = ECP_ERR_SEQ;
+ if (!rv) seq_n = seq_c;
+ } else {
+ rv = ECP_ERR_SEQ;
+ }
+ } else {
+ ecp_seq_t seq_offset = seq_p - seq_c;
+ if (seq_offset < ECP_MAX_SEQ_FORWARD) {
+ if (seq_offset < ECP_SIZE_ACKB) {
+ seq_map = seq_map << seq_offset;
+ } else {
+ seq_map = 0;
+ }
+ seq_map |= 1;
+ seq_n = seq_p;
+ } else {
+ rv = ECP_ERR_SEQ;
+ }
+ }
- if (rv) goto pkt_handle_err;
-
- if (p_seq <= c_seq) {
- uint32_t p_bit = (uint32_t)1 << (c_seq - p_seq);
- if (seq_bitmap & p_bit) rv = ECP_ERR_SEQ;
if (rv) goto pkt_handle_err;
- seq_bitmap = seq_bitmap | p_bit;
- n_seq = c_seq;
- } else {
- seq_bitmap = seq_bitmap << (p_seq - c_seq);
- seq_bitmap = seq_bitmap | 1;
- n_seq = p_seq;
}
- */
-
+
if (key) {
#ifdef ECP_WITH_PTHREAD
pthread_mutex_lock(&conn->mutex);
@@ -1151,9 +1231,9 @@ ssize_t ecp_pkt_handle(ECPSocket *sock, ECPNetAddr *addr, ECPConnection *parent,
#endif
#ifdef ECP_WITH_RBUF
- if (conn->rbuf.recv) proc_size = ecp_rbuf_recv_store(conn, p_seq, payload+pld_size-cnt_size, cnt_size);
+ if (conn->rbuf.recv) proc_size = ecp_rbuf_recv_store(conn, seq_p, payload+pld_size-cnt_size, cnt_size);
#endif
- if (proc_size == 0) proc_size = ecp_msg_handle(conn, p_seq, payload+pld_size-cnt_size, cnt_size);
+ if (proc_size == 0) proc_size = ecp_msg_handle(conn, seq_p, payload+pld_size-cnt_size, cnt_size);
if (proc_size < 0) rv = ECP_ERR_HANDLE;
if (!rv) cnt_size -= proc_size;
@@ -1161,9 +1241,9 @@ ssize_t ecp_pkt_handle(ECPSocket *sock, ECPNetAddr *addr, ECPConnection *parent,
#ifdef ECP_WITH_PTHREAD
pthread_mutex_lock(&conn->mutex);
#endif
- if (!rv) {
- conn->seq_in = n_seq;
- conn->seq_in_bitmap = seq_bitmap;
+ if (!rv && seq_check) {
+ conn->seq_in = seq_n;
+ conn->seq_in_map = seq_map;
}
conn->refcount--;
#ifdef ECP_WITH_PTHREAD
@@ -1304,6 +1384,7 @@ ssize_t ecp_send(ECPConnection *conn, unsigned char *payload, size_t payload_siz
}
ssize_t ecp_receive(ECPConnection *conn, unsigned char mtype, unsigned char *msg, size_t msg_size, unsigned int timeout) {
+#ifdef ECP_WITH_RBUF
#ifdef ECP_WITH_MSGQ
pthread_mutex_lock(&conn->rbuf.recv->msgq.mutex);
ssize_t rv = ecp_conn_msgq_pop(conn, mtype, msg, msg_size, timeout);
@@ -1312,6 +1393,9 @@ ssize_t ecp_receive(ECPConnection *conn, unsigned char mtype, unsigned char *msg
#else
return ECP_ERR_NOT_IMPLEMENTED;
#endif
+#else
+ return ECP_ERR_NOT_IMPLEMENTED;
+#endif
}
static int recv_p(ECPSocket *sock) {
diff --git a/code/core/core.h b/code/core/core.h
index 04fb5ee..989927a 100644
--- a/code/core/core.h
+++ b/code/core/core.h
@@ -74,6 +74,8 @@
#define ECP_CONN_FLAG_REG 0x01
#define ECP_CONN_FLAG_OPEN 0x02
+#define ECP_MAX_SEQ_FORWARD 1024
+
#define ecp_conn_is_reg(conn) ((conn->flags) & ECP_CONN_FLAG_REG)
#define ecp_conn_is_open(conn) ((conn->flags) & ECP_CONN_FLAG_OPEN)
@@ -83,7 +85,15 @@
#include <stdint.h>
typedef long ssize_t;
+
+typedef uint32_t ecp_ack_t;
+#define ECP_SIZE_ACKB (sizeof(ecp_ack_t)*8)
+#define ECP_ACK_FULL (~(ecp_ack_t)0)
+
typedef uint32_t ecp_seq_t;
+#define ECP_SEQ_HALF ((ecp_seq_t)1 << (sizeof(ecp_seq_t) * 8 - 1))
+#define ECP_SEQ_LT(a,b) ((ecp_seq_t)((ecp_seq_t)(a) - (ecp_seq_t)(b)) > ECP_SEQ_HALF)
+#define ECP_SEQ_LTE(a,b) ((ecp_seq_t)((ecp_seq_t)(b) - (ecp_seq_t)(a)) < ECP_SEQ_HALF)
#ifdef ECP_WITH_PTHREAD
#include <pthread.h>
@@ -251,7 +261,7 @@ typedef struct ECPConnection {
unsigned short refcount;
ecp_seq_t seq_out;
ecp_seq_t seq_in;
- uint32_t seq_in_bitmap;
+ ecp_ack_t seq_in_map;
ECPSocket *sock;
ECPNode node;
ECPDHRKeyBucket remote;
diff --git a/code/core/msgq.c b/code/core/msgq.c
index 4c1252b..7356eb8 100644
--- a/code/core/msgq.c
+++ b/code/core/msgq.c
@@ -89,7 +89,7 @@ int ecp_conn_msgq_push(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype)
msgq->seq_msg[mtype][MSG_IDX_MASK(msgq->idx_w[mtype])] = seq;
msgq->idx_w[mtype]++;
- if (ECP_RBUF_SEQ_LT(msgq->seq_max, seq)) msgq->seq_max = seq;
+ if (ECP_SEQ_LT(msgq->seq_max, seq)) msgq->seq_max = seq;
return ECP_OK;
}
diff --git a/code/core/rbuf.c b/code/core/rbuf.c
index f4ec3a4..5cbc18e 100644
--- a/code/core/rbuf.c
+++ b/code/core/rbuf.c
@@ -9,7 +9,7 @@ int ecp_rbuf_init(ECPRBuffer *rbuf, ECPRBMessage *msg, unsigned int msg_size) {
rbuf->msg_size = msg_size;
memset(rbuf->msg, 0, sizeof(ECPRBMessage) * msg_size);
} else {
- rbuf->msg_size = ECP_RBUF_SEQ_HALF;
+ rbuf->msg_size = ECP_SEQ_HALF;
}
return ECP_OK;
diff --git a/code/core/rbuf.h b/code/core/rbuf.h
index 77663ad..a965755 100644
--- a/code/core/rbuf.h
+++ b/code/core/rbuf.h
@@ -13,17 +13,8 @@
#define ECP_ERR_RBUF_DUP -100
#define ECP_ERR_RBUF_FULL -101
-typedef uint32_t ecp_ack_t;
typedef uint32_t ecp_win_t;
-#define ECP_RBUF_SEQ_HALF ((ecp_seq_t)1 << (sizeof(ecp_seq_t)*8-1))
-
-#define ECP_RBUF_ACK_FULL (~(ecp_ack_t)0)
-#define ECP_RBUF_ACK_SIZE (sizeof(ecp_ack_t)*8)
-
-#define ECP_RBUF_SEQ_LT(a,b) ((ecp_seq_t)((ecp_seq_t)(a) - (ecp_seq_t)(b)) > ECP_RBUF_SEQ_HALF)
-#define ECP_RBUF_SEQ_LTE(a,b) ((ecp_seq_t)((ecp_seq_t)(b) - (ecp_seq_t)(a)) < ECP_RBUF_SEQ_HALF)
-
/* size must be power of 2 */
#define ECP_RBUF_IDX_MASK(idx, size) ((idx) & ((size) - 1))
diff --git a/code/core/rbuf_recv.c b/code/core/rbuf_recv.c
index e73c602..fba8219 100644
--- a/code/core/rbuf_recv.c
+++ b/code/core/rbuf_recv.c
@@ -3,7 +3,7 @@
#include <string.h>
#define ACK_RATE 8
-#define ACK_MASK_FIRST ((ecp_ack_t)1 << (ECP_RBUF_ACK_SIZE - 1))
+#define ACK_MASK_FIRST ((ecp_ack_t)1 << (ECP_SIZE_ACKB - 1))
static ssize_t msg_store(ECPConnection *conn, ecp_seq_t seq, unsigned char *msg, size_t msg_size) {
ECPRBRecv *buf = conn->rbuf.recv;
@@ -28,7 +28,7 @@ static ssize_t msg_store(ECPConnection *conn, ecp_seq_t seq, unsigned char *msg,
ssize_t rv = ecp_rbuf_msg_store(&buf->rbuf, seq, -1, msg, msg_size, ECP_RBUF_FLAG_IN_RBUF | ECP_RBUF_FLAG_IN_MSGQ, flags);
if (rv < 0) return rv;
- if (ECP_RBUF_SEQ_LT(buf->rbuf.seq_max, seq)) buf->rbuf.seq_max = seq;
+ if (ECP_SEQ_LT(buf->rbuf.seq_max, seq)) buf->rbuf.seq_max = seq;
if (flags & ECP_RBUF_FLAG_SYS) ecp_msg_handle(conn, seq, msg, msg_size);
return rv;
@@ -109,16 +109,16 @@ static int ack_shift(ECPRBRecv *buf) {
idx = ecp_rbuf_msg_idx(&buf->rbuf, buf->seq_ack);
if (idx < 0) return idx;
- while (ECP_RBUF_SEQ_LT(buf->seq_ack, buf->rbuf.seq_max)) {
+ while (ECP_SEQ_LT(buf->seq_ack, buf->rbuf.seq_max)) {
idx = ECP_RBUF_IDX_MASK(idx + 1, buf->rbuf.msg_size);
buf->seq_ack++;
- if ((buf->rbuf.msg[idx].flags & ECP_RBUF_FLAG_IN_RBUF) && (buf->ack_map == ECP_RBUF_ACK_FULL)) continue;
+ if ((buf->rbuf.msg[idx].flags & ECP_RBUF_FLAG_IN_RBUF) && (buf->ack_map == ECP_ACK_FULL)) continue;
buf->ack_map = buf->ack_map << 1;
if (buf->rbuf.msg[idx].flags & ECP_RBUF_FLAG_IN_RBUF) {
buf->ack_map |= 1;
- } else if (!do_ack && ECP_RBUF_SEQ_LTE(buf->seq_ack, buf->rbuf.seq_max - 2 * buf->hole_max)) {
+ } else if (!do_ack && ECP_SEQ_LTE(buf->seq_ack, buf->rbuf.seq_max - 2 * buf->hole_max)) {
do_ack = 1;
}
@@ -157,7 +157,7 @@ int ecp_rbuf_recv_create(ECPConnection *conn, ECPRBRecv *buf, ECPRBMessage *msg,
rv = ecp_rbuf_init(&buf->rbuf, msg, msg_size);
if (rv) return rv;
- buf->ack_map = ECP_RBUF_ACK_FULL;
+ buf->ack_map = ECP_ACK_FULL;
buf->ack_rate = ACK_RATE;
#ifdef ECP_WITH_MSGQ
@@ -229,10 +229,10 @@ ssize_t ecp_rbuf_recv_store(ECPConnection *conn, ecp_seq_t seq, unsigned char *m
mtype = msg[0] & ECP_MTYPE_MASK;
if ((mtype == ECP_MTYPE_RBACK) || (mtype == ECP_MTYPE_RBFLUSH)) return ecp_msg_handle(conn, seq, msg, msg_size);
- if (ECP_RBUF_SEQ_LT(buf->rbuf.seq_max, seq)) ack_pkt = seq - buf->rbuf.seq_max;
- if (ECP_RBUF_SEQ_LTE(seq, buf->seq_ack)) {
+ if (ECP_SEQ_LT(buf->rbuf.seq_max, seq)) ack_pkt = seq - buf->rbuf.seq_max;
+ if (ECP_SEQ_LTE(seq, buf->seq_ack)) {
ecp_seq_t seq_offset = buf->seq_ack - seq;
- if (seq_offset < ECP_RBUF_ACK_SIZE) {
+ if (seq_offset < ECP_SIZE_ACKB) {
ecp_ack_t ack_mask = ((ecp_ack_t)1 << seq_offset);
if (ack_mask & buf->ack_map) return ECP_ERR_RBUF_DUP;
@@ -246,7 +246,7 @@ ssize_t ecp_rbuf_recv_store(ECPConnection *conn, ecp_seq_t seq, unsigned char *m
return ECP_ERR_RBUF_DUP;
}
} else {
- if ((buf->ack_map == ECP_RBUF_ACK_FULL) && (seq == (ecp_seq_t)(buf->seq_ack + 1))) {
+ if ((buf->ack_map == ECP_ACK_FULL) && (seq == (ecp_seq_t)(buf->seq_ack + 1))) {
if ((buf->flags & ECP_RBUF_FLAG_MSGQ) || buf->deliver_delay) {
rv = msg_store(conn, seq, msg, msg_size);
if (rv < 0) return rv;
diff --git a/code/core/rbuf_send.c b/code/core/rbuf_send.c
index b6cdbac..f70f162 100644
--- a/code/core/rbuf_send.c
+++ b/code/core/rbuf_send.c
@@ -109,23 +109,23 @@ ssize_t ecp_rbuf_handle_ack(ECPConnection *conn, ecp_seq_t seq, unsigned char mt
seq_ack++;
if (buf->flags & ECP_RBUF_FLAG_CCONTROL) buf->in_transit = buf->cnt_cc ? buf->seq_cc - seq_ack : rbuf->seq_max - seq_ack + 1;
- if (ack_map != ECP_RBUF_ACK_FULL) {
+ if (ack_map != ECP_ACK_FULL) {
int nack_first = 0;
unsigned int msg_start;
ecp_seq_t seq_start;
ecp_win_t nack_cnt = 0;
- seq_ack -= ECP_RBUF_ACK_SIZE;
+ seq_ack -= ECP_SIZE_ACKB;
#ifdef ECP_WITH_PTHREAD
pthread_mutex_unlock(&buf->mutex);
#endif
- for (i=0; i<ECP_RBUF_ACK_SIZE; i++) {
- if ((ack_map & ((ecp_ack_t)1 << (ECP_RBUF_ACK_SIZE - i - 1))) == 0) {
+ for (i=0; i<ECP_SIZE_ACKB; i++) {
+ if ((ack_map & ((ecp_ack_t)1 << (ECP_SIZE_ACKB - i - 1))) == 0) {
nack_cnt++;
if (buf->flags & ECP_RBUF_FLAG_RELIABLE) {
- unsigned int _idx = ECP_RBUF_IDX_MASK(idx + 1 - ECP_RBUF_ACK_SIZE + i, rbuf->msg_size);
+ unsigned int _idx = ECP_RBUF_IDX_MASK(idx + 1 - ECP_SIZE_ACKB + i, rbuf->msg_size);
if ((rbuf->msg[_idx].size == 0) || (rbuf->msg[_idx].flags & ECP_RBUF_FLAG_SYS)) {
unsigned char payload[ECP_SIZE_PLD(0)];
ecp_pld_set_type(payload, ECP_MTYPE_NOP);
@@ -147,12 +147,12 @@ ssize_t ecp_rbuf_handle_ack(ECPConnection *conn, ecp_seq_t seq, unsigned char mt
#endif
if (buf->flags & ECP_RBUF_FLAG_CCONTROL) buf->in_transit += nack_cnt;
- buf->nack_rate = (buf->nack_rate * 7 + ((ECP_RBUF_ACK_SIZE - nack_cnt) * NACK_RATE_UNIT) / ECP_RBUF_ACK_SIZE) / 8;
+ buf->nack_rate = (buf->nack_rate * 7 + ((ECP_SIZE_ACKB - nack_cnt) * NACK_RATE_UNIT) / ECP_SIZE_ACKB) / 8;
if (buf->flags & ECP_RBUF_FLAG_RELIABLE) {
rbuf->seq_start = seq_start;
rbuf->msg_start = msg_start;
} else {
- rbuf->seq_start = seq_ack + ECP_RBUF_ACK_SIZE;
+ rbuf->seq_start = seq_ack + ECP_SIZE_ACKB;
rbuf->msg_start = ECP_RBUF_IDX_MASK(idx + 1, rbuf->msg_size);
}
} else {
@@ -161,7 +161,7 @@ ssize_t ecp_rbuf_handle_ack(ECPConnection *conn, ecp_seq_t seq, unsigned char mt
rbuf->msg_start = ECP_RBUF_IDX_MASK(idx + 1, rbuf->msg_size);
}
if (buf->flush) {
- if (ECP_RBUF_SEQ_LT(buf->seq_flush, rbuf->seq_start)) buf->flush = 0;
+ if (ECP_SEQ_LT(buf->seq_flush, rbuf->seq_start)) buf->flush = 0;
if (buf->flush) do_flush = 1;
}
if (buf->cnt_cc) cc_flush(conn);
@@ -253,7 +253,7 @@ int ecp_rbuf_flush(ECPConnection *conn) {
#endif
if (buf->flush) {
- if (ECP_RBUF_SEQ_LT(buf->seq_flush, seq)) buf->seq_flush = seq;
+ if (ECP_SEQ_LT(buf->seq_flush, seq)) buf->seq_flush = seq;
} else {
buf->flush = 1;
buf->seq_flush = seq;
@@ -309,7 +309,7 @@ ssize_t ecp_rbuf_pkt_send(ECPRBSend *buf, ECPSocket *sock, ECPNetAddr *addr, ECP
pthread_mutex_lock(&buf->mutex);
#endif
- if (ECP_RBUF_SEQ_LT(buf->rbuf.seq_max, seq)) buf->rbuf.seq_max = seq;
+ if (ECP_SEQ_LT(buf->rbuf.seq_max, seq)) buf->rbuf.seq_max = seq;
if (buf->cnt_cc || (buf->in_transit >= buf->win_size)) {
if (!buf->cnt_cc) buf->seq_cc = seq;