summaryrefslogtreecommitdiff
path: root/ecp
diff options
context:
space:
mode:
Diffstat (limited to 'ecp')
-rw-r--r--ecp/src/ecp/core.c109
-rw-r--r--ecp/src/ecp/core.h38
-rw-r--r--ecp/src/ecp/timer.c24
-rw-r--r--ecp/src/ecp/timer.h2
-rw-r--r--ecp/src/ecp/vconn/vconn.c52
-rw-r--r--ecp/src/ecp/vconn/vconn.h2
-rw-r--r--ecp/src/platform/fe310/transport.c5
7 files changed, 152 insertions, 80 deletions
diff --git a/ecp/src/ecp/core.c b/ecp/src/ecp/core.c
index 6c17def..b962278 100644
--- a/ecp/src/ecp/core.c
+++ b/ecp/src/ecp/core.c
@@ -665,7 +665,7 @@ ECPConnection *ecp_sock_gct_search(ECPSocket *sock, ecp_ecdh_public_t *public) {
#endif
if (_ecp_conn_in_gct(_conn) && (memcmp(&_conn->remote.key_perma.public, public, sizeof(_conn->remote.key_perma.public)) == 0)) {
- /* conn has to be registered to be in conn_table */
+ /* conn has to be registered and ready to be in conn table with gct flag set */
_conn->refcount++;
conn = _conn;
}
@@ -1043,6 +1043,7 @@ int _ecp_conn_clr_uflags(ECPConnection *conn, unsigned char flags) {
}
int _ecp_conn_test_uflags(ECPConnection *conn, unsigned char flags) {
+ if (flags & ~ECP_CONN_FLAG_UMASK) return 0;
return !!(conn->flags & flags);
}
@@ -1143,6 +1144,18 @@ int ecp_conn_set_closed(ECPConnection *conn) {
return is_cls ? ECP_ERR_CLOSED : ECP_OK;
}
+void ecp_conn_set_rdy(ECPConnection *conn) {
+#ifdef ECP_WITH_PTHREAD
+ pthread_mutex_lock(&conn->mutex);
+#endif
+
+ _ecp_conn_set_rdy(conn);
+
+#ifdef ECP_WITH_PTHREAD
+ pthread_mutex_unlock(&conn->mutex);
+#endif
+}
+
void *ecp_conn_set_param(ECPConnection *conn, void *param) {
void *r;
@@ -1277,10 +1290,11 @@ void ecp_conn_destroy(ECPConnection *conn) {
void ecp_conn_free(ECPConnection *conn) {
ECPContext *ctx = conn->sock->ctx;
+ if (ecp_conn_nofree(conn)) return;
if (ctx->conn_free) ctx->conn_free(conn);
}
-int ecp_conn_insert(ECPConnection *conn) {
+int ecp_conn_insert(ECPConnection *conn, int rdy) {
ECPSocket *sock = conn->sock;
int rv;
@@ -1289,9 +1303,11 @@ int ecp_conn_insert(ECPConnection *conn) {
pthread_mutex_lock(&conn->mutex);
#endif
- _ecp_conn_set_reg(conn);
rv = conn_table_insert(conn);
- if (rv) _ecp_conn_clr_reg(conn);
+ if (!rv) {
+ _ecp_conn_set_reg(conn);
+ if (rdy) _ecp_conn_set_rdy(conn);
+ }
#ifdef ECP_WITH_PTHREAD
pthread_mutex_unlock(&conn->mutex);
@@ -1445,28 +1461,35 @@ int _ecp_conn_open(ECPConnection *conn, ECPConnection *parent, ECPNode *node, in
ssize_t _rv;
rv = ecp_conn_create_outb(conn, parent, node);
- if (rv) {
- ecp_conn_free(conn);
- return rv;
- }
+ if (rv) return rv;
- rv = ecp_conn_insert(conn);
+ rv = ecp_conn_insert(conn, 0);
if (rv) {
+ ecp_conn_set_flags(conn, ECP_CONN_FLAG_NOFREE);
ecp_conn_destroy(conn);
return rv;
}
- _rv = ecp_send_init_req(conn, retry);
- if (_rv < 0) {
- ecp_timer_remove(conn);
- ecp_conn_remove(conn);
- if (!ecp_conn_is_gc(conn)) ecp_conn_refcount_dec(conn);
- rv = _rv;
+ if (retry) {
+ ECPTimerItem ti;
+
+ ecp_timer_item_init(&ti, conn, ECP_MTYPE_OPEN_REP, ecp_retry_init_req, ECP_SEND_TRIES-1, ECP_SEND_TIMEOUT, NULL);
+ rv = _ecp_timer_push(&ti, 0);
+ if (rv) {
+ ecp_conn_remove(conn);
+ ecp_conn_set_flags(conn, ECP_CONN_FLAG_NOFREE);
+ if (!ecp_conn_is_gc(conn)) ecp_conn_refcount_dec(conn);
+ ecp_conn_refcount_dec(conn);
+ return rv;
+ }
}
- ecp_conn_refcount_dec(conn);
+ ecp_conn_set_rdy(conn);
+ _rv = ecp_send_init_req(conn, NULL);
+ if (_rv < 0) ECP_LOG_ERR(conn->sock, "ecp_receiver: err:%d\n", (int)_rv);
+ if (!retry) ecp_conn_refcount_dec(conn);
- return rv;
+ return ECP_OK;
}
int ecp_conn_open(ECPConnection *conn, ECPNode *node) {
@@ -1487,6 +1510,7 @@ void _ecp_conn_close(ECPConnection *conn) {
if (_ecp_conn_is_open(conn)) {
ecp_close_handler_t handler;
+ _ecp_conn_clr_rdy(conn);
_ecp_conn_clr_open(conn);
_ecp_conn_clr_open_p(conn);
handler = ecp_get_close_handler(conn);
@@ -1544,20 +1568,22 @@ void ecp_conn_unlock(ECPConnection *conn) {
}
int ecp_conn_refcount_inc(ECPConnection *conn) {
- int is_reg;
+ int is_reg, is_rdy;
#ifdef ECP_WITH_PTHREAD
pthread_mutex_lock(&conn->mutex);
#endif
is_reg = _ecp_conn_is_reg(conn);
- if (is_reg) conn->refcount++;
+ is_rdy = _ecp_conn_is_rdy(conn);
+ if (is_reg && is_rdy) conn->refcount++;
#ifdef ECP_WITH_PTHREAD
pthread_mutex_unlock(&conn->mutex);
#endif
if (!is_reg) return ECP_ERR_CLOSED;
+ if (!is_rdy) return ECP_ERR_READY;
return ECP_OK;
}
@@ -1789,7 +1815,7 @@ void ecp_err_handle(ECPConnection *conn, unsigned char mtype, int err) {
if (err_handler) err_handler(conn, mtype, err);
}
-static ssize_t _send_ireq(ECPConnection *conn, ECPTimerItem *ti) {
+ssize_t ecp_send_init_req(ECPConnection *conn, ECPTimerItem *ti) {
ECPBuffer packet;
ECPBuffer payload;
unsigned char pkt_buf[ECP_SIZE_PKT_BUF_IREQ(ECP_SIZE_PLD(ECP_SIZE_ZPAD_PLD, ECP_MTYPE_INIT_REQ), conn)];
@@ -1810,7 +1836,7 @@ static ssize_t _send_ireq(ECPConnection *conn, ECPTimerItem *ti) {
return rv;
}
-static ssize_t _retry_ireq(ECPConnection *conn, ECPTimerItem *ti) {
+ssize_t ecp_retry_init_req(ECPConnection *conn, ECPTimerItem *ti) {
ECPSocket *sock = conn->sock;
ECPDHKey key;
int is_open, refcount_ok;
@@ -1852,7 +1878,10 @@ static ssize_t _retry_ireq(ECPConnection *conn, ECPTimerItem *ti) {
}
if (refcount_ok) {
- return _send_ireq(conn, ti);
+ ssize_t _rv;
+
+ _rv = ecp_send_init_req(conn, ti);
+ return _rv;
} else {
/* check later */
rv = ecp_timer_push(ti);
@@ -1860,22 +1889,6 @@ static ssize_t _retry_ireq(ECPConnection *conn, ECPTimerItem *ti) {
}
}
-ssize_t ecp_send_init_req(ECPConnection *conn, int retry) {
- ssize_t rv;
-
- if (retry) {
- ECPTimerItem ti;
-
- ecp_timer_item_init(&ti, conn, ECP_MTYPE_OPEN_REP, _retry_ireq, ECP_SEND_TRIES-1, ECP_SEND_TIMEOUT, NULL);
-
- rv = _send_ireq(conn, &ti);
- } else {
- rv = _send_ireq(conn, NULL);
- }
-
- return rv;
-}
-
ssize_t ecp_handle_init_req(ECPSocket *sock, ECPConnection *parent, ecp_tr_addr_t *addr, unsigned char c_idx, unsigned char *public_buf, unsigned char *msg, size_t msg_size, ecp_aead_key_t *shkey, ECP2Buffer *bufs) {
unsigned char _public_buf[ECP_SIZE_ECDH_PUB];
ssize_t rv;
@@ -2103,7 +2116,7 @@ ssize_t ecp_handle_open_req(ECPSocket *sock, ECPConnection *parent, unsigned cha
return _rv;
}
- _rv = ecp_conn_insert(conn);
+ _rv = ecp_conn_insert(conn, 1);
if (_rv) {
ecp_conn_destroy(conn);
return _rv;
@@ -2186,7 +2199,7 @@ int ecp_handle_open(ECPConnection *conn, ECP2Buffer *bufs) {
ecp_tr_release(bufs->packet, 1);
_rv = ecp_send_open_rep(conn);
- if (_rv < 0) return _rv;
+ if (_rv < 0) ECP_LOG_ERR(conn->sock, "ecp_handle_open: send reply err:%d\n", (int)_rv);
} else if (ecp_conn_is_root(conn)) {
ecp_conn_remove_addr(conn);
}
@@ -2401,6 +2414,10 @@ ssize_t ecp_unpack(ECPSocket *sock, ECPConnection *parent, ecp_tr_addr_t *addr,
#endif
if (conn) {
+ if (!_ecp_conn_is_rdy(conn)) {
+ _rv = ECP_ERR_READY;
+ goto unpack_conn_fin;
+ }
is_inb = ecp_conn_is_inb(conn);
is_open = _ecp_conn_is_open(conn);
@@ -2420,10 +2437,14 @@ ssize_t ecp_unpack(ECPSocket *sock, ECPConnection *parent, ecp_tr_addr_t *addr,
pkt_size -= ECP_SIZE_PKT_HDR_IREP;
} else {
_rv = ECP_ERR_PKT;
+ goto unpack_conn_fin;
}
- 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++;
+unpack_conn_fin:
+
#ifdef ECP_WITH_PTHREAD
pthread_mutex_unlock(&conn->mutex);
#endif
@@ -3251,11 +3272,7 @@ void ecp_receiver(ECPSocket *sock) {
size_t pkt_size = rv;
rv = recv_p(sock, &addr, &packet, pkt_size);
- if ((rv < 0) && ctx->logger) {
- int _rv = rv;
-
- ctx->logger("ecp_receiver: err:%d\n", rv);
- }
+ if (rv < 0) ECP_LOG_ERR(sock, "ecp_receiver: err:%d\n", (int)rv);
}
next = ecp_timer_exe(sock);
}
diff --git a/ecp/src/ecp/core.h b/ecp/src/ecp/core.h
index 2cd8750..e79eefc 100644
--- a/ecp/src/ecp/core.h
+++ b/ecp/src/ecp/core.h
@@ -20,7 +20,8 @@
#define ECP_ERR_MTYPE -10
#define ECP_ERR_CTYPE -11
#define ECP_ERR_HANDLER -12
-#define ECP_ERR_CLOSED -13
+#define ECP_ERR_READY -13
+#define ECP_ERR_CLOSED -14
#define ECP_ERR_PKT -20
#define ECP_ERR_ZPAD -21
@@ -195,6 +196,7 @@
#define ECP_MTYPE_FLAG_SYS 0x80
#define ECP_MTYPE_FLAG_FRAG 0x40
#define ECP_MTYPE_FLAG_PTS 0x20
+
#define ECP_MTYPE_MASK 0x1F
#define ECP_MTYPE_ZPAD (0x1F | ECP_MTYPE_FLAG_SYS)
@@ -209,32 +211,32 @@
#define ECP_CTYPE_MASK 0x7F
/* immutable flags */
-#define ECP_CONN_FLAG_INB 0x80
-#define ECP_CONN_FLAG_VBOX 0x01
-#define ECP_CONN_FLAG_RBUF 0x02
-#define ECP_CONN_FLAG_GC 0x04
-
-#define ECP_CONN_FLAG_MASK 0x7F
+#define ECP_CONN_FLAG_INB 0x01
+#define ECP_CONN_FLAG_NOFREE 0x02
+#define ECP_CONN_FLAG_VBOX 0x04
+#define ECP_CONN_FLAG_GC 0x08
/* mutable flags */
#define ECP_CONN_FLAG_REG 0x01
-#define ECP_CONN_FLAG_OPEN 0x02
-#define ECP_CONN_FLAG_OPEN_P 0x04
-#define ECP_CONN_FLAG_CLOSED 0x08
-#define ECP_CONN_FLAG_GCT 0x10
+#define ECP_CONN_FLAG_RDY 0x02
+#define ECP_CONN_FLAG_OPEN 0x04
+#define ECP_CONN_FLAG_OPEN_P 0x08
+#define ECP_CONN_FLAG_CLOSED 0x10
+#define ECP_CONN_FLAG_GCT 0x20
-#define ECP_CONN_FLAG_UMASK 0xE0
+#define ECP_CONN_FLAG_UMASK 0xC0
#define ECP_SEND_FLAG_REPLY 0x01
#define ECP_SEND_FLAG_MORE 0x02
+#define ecp_conn_nofree(conn) ((conn)->flags_im & ECP_CONN_FLAG_NOFREE)
#define ecp_conn_has_vbox(conn) ((conn)->flags_im & ECP_CONN_FLAG_VBOX)
-#define ecp_conn_has_rbuf(conn) ((conn)->flags_im & ECP_CONN_FLAG_RBUF)
#define ecp_conn_is_gc(conn) ((conn)->flags_im & ECP_CONN_FLAG_GC)
#define ecp_conn_is_inb(conn) ((conn)->flags_im & ECP_CONN_FLAG_INB)
#define ecp_conn_is_outb(conn) (!((conn)->flags_im & ECP_CONN_FLAG_INB))
#define ecp_conn_is_sys(conn) ((conn)->type & ECP_CTYPE_FLAG_SYS)
#define _ecp_conn_is_reg(conn) ((conn)->flags & ECP_CONN_FLAG_REG)
+#define _ecp_conn_is_rdy(conn) ((conn)->flags & ECP_CONN_FLAG_RDY)
#define _ecp_conn_is_open(conn) ((conn)->flags & ECP_CONN_FLAG_OPEN)
#define _ecp_conn_is_open_p(conn) ((conn)->flags & ECP_CONN_FLAG_OPEN_P)
#define _ecp_conn_is_closed(conn) ((conn)->flags & ECP_CONN_FLAG_CLOSED)
@@ -243,12 +245,14 @@
#define ecp_conn_set_inb(conn) ((conn)->flags_im |= ECP_CONN_FLAG_INB)
#define ecp_conn_set_outb(conn) ((conn)->flags_im &= ~ECP_CONN_FLAG_INB)
#define _ecp_conn_set_reg(conn) ((conn)->flags |= ECP_CONN_FLAG_REG)
+#define _ecp_conn_set_rdy(conn) ((conn)->flags |= ECP_CONN_FLAG_RDY)
#define _ecp_conn_set_open(conn) ((conn)->flags |= ECP_CONN_FLAG_OPEN)
#define _ecp_conn_set_open_p(conn) ((conn)->flags |= ECP_CONN_FLAG_OPEN_P)
#define _ecp_conn_set_closed(conn) ((conn)->flags |= ECP_CONN_FLAG_CLOSED)
#define _ecp_conn_push_gct(conn) ((conn)->flags |= ECP_CONN_FLAG_GCT)
#define _ecp_conn_clr_reg(conn) ((conn)->flags &= ~ECP_CONN_FLAG_REG)
+#define _ecp_conn_clr_rdy(conn) ((conn)->flags &= ~ECP_CONN_FLAG_RDY)
#define _ecp_conn_clr_open(conn) ((conn)->flags &= ~ECP_CONN_FLAG_OPEN)
#define _ecp_conn_clr_open_p(conn) ((conn)->flags &= ~ECP_CONN_FLAG_OPEN_P)
#define _ecp_conn_clr_closed(conn) ((conn)->flags &= ~ECP_CONN_FLAG_CLOSED)
@@ -302,6 +306,8 @@ typedef void (*ecp_close_handler_t) (struct ECPConnection *conn);
typedef ssize_t (*ecp_msg_handler_t) (struct ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, size_t msg_size, struct ECP2Buffer *b);
typedef ssize_t (*ecp_oreq_send_t) (struct ECPConnection *conn, unsigned char *cookie);
+#define ECP_LOG_ERR(sock, ...) { if (sock->ctx->logger) sock->ctx->logger(__VA_ARGS__); }
+
typedef struct ECPBuffer {
unsigned char *buffer;
size_t size;
@@ -486,6 +492,7 @@ int ecp_conn_test_uflags(ECPConnection *conn, unsigned char flags);
int ecp_conn_is_reg(ECPConnection *conn);
int ecp_conn_is_open(ECPConnection *conn);
int ecp_conn_set_closed(ECPConnection *conn);
+void ecp_conn_set_rdy(ECPConnection *conn);
void *ecp_conn_set_param(ECPConnection *conn, void *param);
void *ecp_conn_get_param(ECPConnection *conn);
void ecp_conn_set_remote_key(ECPConnection *conn, ECPDHPub *key);
@@ -496,7 +503,7 @@ int ecp_conn_create_outb(ECPConnection *conn, ECPConnection *parent, ECPNode *no
void ecp_conn_destroy(ECPConnection *conn);
void ecp_conn_free(ECPConnection *conn);
-int ecp_conn_insert(ECPConnection *conn);
+int ecp_conn_insert(ECPConnection *conn, int rdy);
int ecp_conn_insert_gc(ECPConnection *conn);
int _ecp_conn_remove(ECPConnection *conn);
void ecp_conn_remove(ECPConnection *conn);
@@ -533,7 +540,8 @@ ecp_err_handler_t ecp_get_err_handler(ECPConnection *conn);
ecp_oreq_send_t ecp_get_oreq_send_f(ECPConnection *conn);
void ecp_err_handle(ECPConnection *conn, unsigned char mtype, int err);
-ssize_t ecp_send_init_req(ECPConnection *conn, int retry);
+ssize_t ecp_send_init_req(ECPConnection *conn, ECPTimerItem *ti);
+ssize_t ecp_retry_init_req(ECPConnection *conn, ECPTimerItem *ti);
ssize_t ecp_handle_init_req(ECPSocket *sock, ECPConnection *parent, ecp_tr_addr_t *addr, unsigned char c_idx, unsigned char *public_buf, unsigned char *msg, size_t msg_size, ecp_aead_key_t *shkey, ECP2Buffer *bufs);
ssize_t ecp_send_init_rep(ECPSocket *sock, ECPConnection *parent, ecp_tr_addr_t *addr, unsigned char c_idx, unsigned char *public_buf, ecp_aead_key_t *shkey);
ssize_t ecp_handle_init_rep(ECPConnection *conn, unsigned char *msg, size_t msg_size, unsigned char *nonce_buf, ECP2Buffer *bufs);
diff --git a/ecp/src/ecp/timer.c b/ecp/src/ecp/timer.c
index 1c4cae6..81d900f 100644
--- a/ecp/src/ecp/timer.c
+++ b/ecp/src/ecp/timer.c
@@ -38,7 +38,7 @@ void *ecp_timer_get_param(ECPTimerItem *ti) {
return ti->param;
}
-int ecp_timer_push(ECPTimerItem *ti) {
+int _ecp_timer_push(ECPTimerItem *ti, int refcount_inc) {
ECPConnection *conn = ti->conn;
ECPTimer *timer = &conn->sock->timer;
int i, rv = ECP_OK;
@@ -48,15 +48,14 @@ int ecp_timer_push(ECPTimerItem *ti) {
#ifdef ECP_WITH_PTHREAD
pthread_mutex_lock(&timer->mutex);
#endif
- rv = ecp_conn_refcount_inc(conn);
- if (rv) {
- conn = NULL;
- goto timer_push_fin;
- }
if (timer->head == ECP_MAX_TIMER-1) {
rv = ECP_ERR_MAX_TIMER;
goto timer_push_fin;
}
+ if (refcount_inc) {
+ rv = ecp_conn_refcount_inc(conn);
+ if (rv) goto timer_push_fin;
+ }
for (i=timer->head; i>=0; i--) {
if (ECP_STS_LTE(ti->abstime, timer->item[i].abstime)) {
@@ -79,12 +78,13 @@ timer_push_fin:
pthread_mutex_unlock(&timer->mutex);
#endif
- if (rv && conn) {
- ecp_conn_refcount_dec(conn);
- }
return rv;
}
+int ecp_timer_push(ECPTimerItem *ti) {
+ return _ecp_timer_push(ti, 1);
+}
+
void ecp_timer_pop(ECPConnection *conn, unsigned char mtype, ecp_seq_t seq, unsigned char frag_cnt, unsigned char frag_tot) {
ECPTimer *timer = &conn->sock->timer;
int i;
@@ -220,11 +220,7 @@ ecp_sts_t ecp_timer_exe(ECPSocket *sock) {
ssize_t rv;
rv = retry(conn, to_exec+i);
- if ((rv < 0) && ctx->logger) {
- int _rv = rv;
-
- ctx->logger("ecp_timer_exe: retry err:%d\n", _rv);
- }
+ if (rv < 0) ECP_LOG_ERR(sock, "ecp_timer_exe: retry err:%d\n", (int)rv);
}
} else {
int rv;
diff --git a/ecp/src/ecp/timer.h b/ecp/src/ecp/timer.h
index 2b44060..eca90b1 100644
--- a/ecp/src/ecp/timer.h
+++ b/ecp/src/ecp/timer.h
@@ -29,6 +29,8 @@ int ecp_timer_create(ECPTimer *timer);
void ecp_timer_destroy(ECPTimer *timer);
void ecp_timer_item_init(ECPTimerItem *ti, struct ECPConnection *conn, unsigned char mtype, ecp_timer_retry_t retry_f, unsigned short cnt, ecp_sts_t timeout, void *param);
void *ecp_timer_get_param(ECPTimerItem *ti);
+
+int _ecp_timer_push(ECPTimerItem *ti, int refcount_inc);
int ecp_timer_push(ECPTimerItem *ti);
void ecp_timer_pop(struct ECPConnection *conn, unsigned char mtype, ecp_seq_t seq, unsigned char frag_cnt, unsigned char frag_tot);
void ecp_timer_remove(struct ECPConnection *conn);
diff --git a/ecp/src/ecp/vconn/vconn.c b/ecp/src/ecp/vconn/vconn.c
index 780faab..e8d9b35 100644
--- a/ecp/src/ecp/vconn/vconn.c
+++ b/ecp/src/ecp/vconn/vconn.c
@@ -257,6 +257,7 @@ void ecp_vconn_init(ECPVConnOutb vconn[], ecp_ecdh_public_t keys[], size_t vconn
for (i=0; i<vconn_size; i++) {
memcpy(&key.public, &keys[i], sizeof(keys[i]));
ecp_conn_init(&vconn[i].b, sock, ECP_CTYPE_VCONN);
+ if (i != 0) ecp_conn_set_flags(&vconn[i].b, ECP_CONN_FLAG_NOFREE);
ecp_conn_set_remote_key(&vconn[i].b, &key);
if (i < vconn_size - 1) {
vconn[i].next = &vconn[i + 1].b;
@@ -298,6 +299,30 @@ int ecp_vconn_open(ECPVConnOutb *vconn, ECPConnection *conn, ECPNode *node) {
return rv;
}
+static void vconn_close(ECPVConnOutb *vconn) {
+ ECPConnection *conn, *parent, *next;
+
+ conn = vconn->next;
+ while (conn->type == ECP_CTYPE_VCONN) {
+ next = ((ECPVConnOutb *)conn)->next;
+ ecp_conn_free(conn);
+ conn = next;
+ }
+ conn = &vconn->b;
+ while (conn) {
+ parent = conn->parent;
+ ecp_conn_close(conn);
+ conn = parent;
+ }
+}
+
+void ecp_vconn_close(ECPConnection *conn) {
+ ECPVConnOutb *vconn;
+
+ vconn = (ECPVConnOutb *)conn->parent;
+ if (vconn) vconn_close(vconn);
+}
+
int ecp_vconn_handle_open(ECPConnection *conn, ECP2Buffer *bufs) {
ECPVConnOutb *vconn = (ECPVConnOutb *)conn;
int rv;
@@ -308,6 +333,7 @@ int ecp_vconn_handle_open(ECPConnection *conn, ECP2Buffer *bufs) {
/* we should release incoming packet before sending next open packet */
ecp_tr_release(bufs->packet, 1);
rv = _ecp_conn_open(vconn->next, conn, NULL, 1);
+ /* err will be handled by ecp_vconn_handle_err */
return rv;
}
@@ -341,6 +367,30 @@ void ecp_vconn_handle_close(ECPConnection *conn) {
#endif /* ECP_WITH_HTABLE */
+void ecp_vconn_handle_err(ECPConnection *conn, unsigned char mtype, int err) {
+ if (ecp_conn_is_outb(conn) && (mtype == ECP_MTYPE_OPEN_REP)) {
+ ECPVConnOutb *vconn = (ECPVConnOutb *)conn;
+
+ while (vconn) {
+ ECPConnection *_conn = &vconn->b;
+
+ if (_conn->type != ECP_CTYPE_VCONN) {
+ ecp_err_handle(_conn, mtype, err);
+ break;
+ }
+ vconn = (ECPVConnOutb *)vconn->next;
+ }
+ vconn = (ECPVConnOutb *)conn;
+ vconn_close(vconn);
+ } else {
+ ECPContext *ctx = conn->sock->ctx;
+
+ if (ctx->handle_err) {
+ ctx->handle_err(conn, mtype, err);
+ }
+ }
+}
+
ssize_t ecp_vconn_handle_msg(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, size_t msg_size, ECP2Buffer *bufs) {
ssize_t rv;
@@ -539,7 +589,7 @@ void ecp_vconn_sock_destroy(ECPSocket *sock) {
int ecp_vconn_handler_init(ECPContext *ctx, ECPConnHandler *vconn_handler) {
int rv;
- ecp_conn_handler_init(vconn_handler, ecp_vconn_handle_open, ecp_vconn_handle_close, ecp_vconn_handle_msg, NULL);
+ ecp_conn_handler_init(vconn_handler, ecp_vconn_handle_open, ecp_vconn_handle_close, ecp_vconn_handle_msg, ecp_vconn_handle_err);
ecp_conn_handler_set_oreq_f(vconn_handler, ecp_vconn_send_open_req);
rv = ecp_ctx_set_handler(ctx, ECP_CTYPE_VCONN, vconn_handler);
return rv;
diff --git a/ecp/src/ecp/vconn/vconn.h b/ecp/src/ecp/vconn/vconn.h
index d024f8e..a0e076f 100644
--- a/ecp/src/ecp/vconn/vconn.h
+++ b/ecp/src/ecp/vconn/vconn.h
@@ -30,10 +30,12 @@ void ecp_vconn_init(ECPVConnOutb vconn[], ecp_ecdh_public_t keys[], size_t vconn
void ecp_vconn_init_inb(ECPVConnInb *vconn, ECPSocket *sock);
#endif
int ecp_vconn_open(ECPVConnOutb *vconn, ECPConnection *conn, ECPNode *node);
+void ecp_vconn_close(ECPConnection *conn);
int ecp_vconn_handle_open(ECPConnection *conn, ECP2Buffer *bufs);
#ifdef ECP_WITH_HTABLE
void ecp_vconn_handle_close(ECPConnection *conn);
#endif
+void ecp_vconn_handle_err(ECPConnection *conn, unsigned char mtype, int err);
ssize_t ecp_vconn_handle_msg(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, size_t msg_size, ECP2Buffer *bufs);
ssize_t ecp_vconn_send_open_req(ECPConnection *conn, unsigned char *cookie);
diff --git a/ecp/src/platform/fe310/transport.c b/ecp/src/platform/fe310/transport.c
index b53534d..1ae0f56 100644
--- a/ecp/src/platform/fe310/transport.c
+++ b/ecp/src/platform/fe310/transport.c
@@ -35,11 +35,8 @@ static void packet_handler(unsigned char type, unsigned char *buffer, uint16_t l
ctx = _ecp_tr_sock->ctx;
rv = ecp_pkt_handle(_ecp_tr_sock, NULL, &addr, &bufs, len-EOS_SOCK_SIZE_UDP_HDR);
- if ((rv < 0) && ctx->logger) {
- int _rv = rv;
+ if (rv < 0) ECP_LOG_ERR(_ecp_tr_sock, "packet_handler: err:%d\n", (int)rv);
- ctx->logger("packet_handler: err:%d\n", _rv);
- }
if (bufs.packet->buffer) {
eos_net_free(buffer, 0);
} else {