diff options
author | Uros Majstorovic <majstor@majstor.org> | 2017-08-12 23:09:10 +0200 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2017-08-12 23:09:10 +0200 |
commit | 770fc69429e6b61ca648b15816fd003819abe3e2 (patch) | |
tree | 389d80d2de0afd5851801cf3246f949edda0d49e | |
parent | 83aa3fed513e26e0457c6744cb110aa420d2831a (diff) |
conn_close handler added
-rw-r--r-- | code/core/core.c | 5 | ||||
-rw-r--r-- | code/core/core.h | 2 | ||||
-rw-r--r-- | code/core/rbuf.c | 2 | ||||
-rw-r--r-- | code/proxy/proxy.c | 10 |
4 files changed, 13 insertions, 6 deletions
diff --git a/code/core/core.c b/code/core/core.c index 069c910..a7ef3de 100644 --- a/code/core/core.c +++ b/code/core/core.c @@ -580,7 +580,10 @@ int ecp_conn_close(ECPConnection *conn, unsigned int timeout) { if (refcount) return ECP_ERR_TIMEOUT; #endif - if (!conn->out) { + if (conn->out) { + ecp_conn_close_t *handler = conn->sock->ctx->handler[conn->type] ? conn->sock->ctx->handler[conn->type]->conn_close : NULL; + if (handler) handler(conn); + } else { ecp_conn_destroy_t *handler = conn->sock->ctx->handler[conn->type] ? conn->sock->ctx->handler[conn->type]->conn_destroy : NULL; if (handler) handler(conn); if (conn->proxy) { diff --git a/code/core/core.h b/code/core/core.h index 382b2c1..b0694b2 100644 --- a/code/core/core.h +++ b/code/core/core.h @@ -117,6 +117,7 @@ typedef void ecp_conn_free_t (struct ECPConnection *c); typedef int ecp_conn_create_t (struct ECPConnection *c, unsigned char *msg, size_t sz); typedef void ecp_conn_destroy_t (struct ECPConnection *c); typedef ssize_t ecp_conn_open_t (struct ECPConnection *c); +typedef void ecp_conn_close_t (struct ECPConnection *c); typedef struct ECPCryptoIface { int init; @@ -196,6 +197,7 @@ typedef struct ECPConnHandler { ecp_conn_create_t *conn_create; ecp_conn_destroy_t *conn_destroy; ecp_conn_open_t *conn_open; + ecp_conn_close_t *conn_close; } ECPConnHandler; typedef struct ECPSockCTable { diff --git a/code/core/rbuf.c b/code/core/rbuf.c index bb110b9..d92c3f1 100644 --- a/code/core/rbuf.c +++ b/code/core/rbuf.c @@ -51,7 +51,7 @@ int ecp_conn_rbuf_start(ECPConnection *conn, ecp_seq_t seq) { return ECP_OK; } -ssize_t ecp_conn_rbuf_pkt_send(struct ECPConnection *conn, ECPNetAddr *addr, unsigned char *packet, size_t pkt_size, ecp_seq_t seq, int idx) { +ssize_t ecp_conn_rbuf_pkt_send(ECPConnection *conn, ECPNetAddr *addr, unsigned char *packet, size_t pkt_size, ecp_seq_t seq, int idx) { int do_send; ECPRBSend *buf = conn->rbuf.send; diff --git a/code/proxy/proxy.c b/code/proxy/proxy.c index 6dfa672..4da0acb 100644 --- a/code/proxy/proxy.c +++ b/code/proxy/proxy.c @@ -272,6 +272,10 @@ static ssize_t proxyb_open(ECPConnection *conn) { return ecp_timer_send(conn, _proxyb_send_open, ECP_MTYPE_OPEN_REP, 3, 500); } +static void proxyb_close(ECPConnection *conn) { + proxyb_remove(conn); +} + static ssize_t proxyb_handle_open(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, ssize_t size) { ssize_t rv; int is_open; @@ -299,13 +303,10 @@ static ssize_t proxyb_handle_open(ECPConnection *conn, ecp_seq_t seq, unsigned c } return rv; } else { - unsigned char ctype = 0; - if (conn->out) return ECP_ERR; if (size < rv+ECP_ECDH_SIZE_KEY) return ECP_ERR; - ctype = msg[0]; - msg++; + msg += rv; // XXX should verify perma_key return rv+ECP_ECDH_SIZE_KEY; @@ -445,6 +446,7 @@ int ecp_proxy_init(ECPContext *ctx) { handler_b.conn_create = proxyb_create; handler_b.conn_destroy = proxyb_destroy; handler_b.conn_open = proxyb_open; + handler_b.conn_close = proxyb_close; handler_b.msg[ECP_MTYPE_OPEN] = proxyb_handle_open; handler_b.msg[ECP_MTYPE_EXEC] = ecp_conn_handle_exec; handler_b.msg[ECP_MTYPE_RELAY] = proxyb_handle_relay; |