security communication with openssl and simplify netio
This commit is contained in:
parent
2a7b7c39bb
commit
8f796b3109
20 changed files with 1176 additions and 922 deletions
119
src/lib/xcectx.c
119
src/lib/xcectx.c
|
|
@ -59,10 +59,11 @@ static int handle_reply(xce_ctx_t* ctx, xce_reply_t* reply)
|
|||
|
||||
static int vtask_entry(vtask_t* task)
|
||||
{
|
||||
endpoint_t* ep = task->ctx.ep;
|
||||
xce_ctx_t* ctx = NULL;
|
||||
int rc = 0;
|
||||
xce_request_t request;
|
||||
io_task_data_t* data = (io_task_data_t*)&(task->data->u.iodata);
|
||||
endpoint_t* ep = data->ep;
|
||||
xce_ctx_t* ctx = NULL;
|
||||
int rc = 0;
|
||||
xce_request_t request;
|
||||
|
||||
if (ep == NULL) {
|
||||
return -EINVAL;
|
||||
|
|
@ -73,7 +74,7 @@ static int vtask_entry(vtask_t* task)
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
rc = ioctx_decode(&(task->ctx), &request);
|
||||
rc = xce_decode(data->pkt, &request);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
|
@ -114,91 +115,28 @@ static int vtask_entry(vtask_t* task)
|
|||
|
||||
return 0;
|
||||
}
|
||||
static int handle_input(endpoint_t* ep)
|
||||
|
||||
static int handle_msg(endpoint_t* ep)
|
||||
{
|
||||
xce_ctx_t* ctx = (xce_ctx_t*)ep->owner;
|
||||
vtask_t* task;
|
||||
int rc = 0;
|
||||
xce_ctx_t* ctx = NULL;
|
||||
|
||||
task = vtask_alloc();
|
||||
if (task == NULL) {
|
||||
return -ENOMEM;
|
||||
if (ep == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
rc = vtask_init(task, (vtask_func_t)&vtask_entry, ep);
|
||||
if (rc < 0) {
|
||||
SET_ERROR(-rc);
|
||||
|
||||
if (rc == -EPIPE) {
|
||||
/* connection broken */
|
||||
TRACE("broken pipe, ep %p", ep);
|
||||
}
|
||||
|
||||
FREEUP(task);
|
||||
return rc;
|
||||
ctx = (xce_ctx_t*)ep->owner;
|
||||
if (ctx == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
rc = vtask_enq(&(ctx->vtaskmgr), task);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int handle_output(endpoint_t* ep)
|
||||
{
|
||||
data_item_t* it;
|
||||
ioctx_t* ctx;
|
||||
int rc;
|
||||
|
||||
it = endpoint_deq(ep);
|
||||
if (it == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ctx = ITPTR_TO_IOCTX(it);
|
||||
|
||||
rc = ioctx_flush(ctx, ep->fd);
|
||||
ioctx_deref(ctx, 1);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int handle_io(struct epoll_event* p)
|
||||
{
|
||||
endpoint_t* ep = (endpoint_t*)p->data.ptr;
|
||||
int rc = 0;
|
||||
|
||||
if ((p->events & EPOLLIN) != 0) {
|
||||
rc = handle_input(ep);
|
||||
}
|
||||
|
||||
if (rc >= 0) {
|
||||
if ((p->events & EPOLLOUT) != 0) {
|
||||
rc = handle_output(ep);
|
||||
}
|
||||
}
|
||||
|
||||
if (rc < 0) {
|
||||
xce_ctx_t* ctx = (xce_ctx_t*)ep->owner;
|
||||
iomgr_t* iomgr = &(ctx->iomgr);
|
||||
iomgr_unmonitor(iomgr, ep);
|
||||
endpoint_deref(ep);
|
||||
|
||||
xce_try_wakeup(ctx, -EIO);
|
||||
|
||||
ctx->state = XCE_CTX_DOWN;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return vtask_handle_msg(&(ctx->vtaskmgr), (vtask_func_t)vtask_entry,
|
||||
(void*)ep);
|
||||
}
|
||||
|
||||
int xce_ctx_init(xce_ctx_t* ctx, char* name, char* key)
|
||||
{
|
||||
int rc;
|
||||
int rc;
|
||||
SSL_CTX* ssl_ctx = NULL;
|
||||
|
||||
if ((ctx == NULL) || (name == NULL) || (key == NULL)) {
|
||||
return -EINVAL;
|
||||
|
|
@ -215,14 +153,24 @@ int xce_ctx_init(xce_ctx_t* ctx, char* name, char* key)
|
|||
return -ENOMEM;
|
||||
}
|
||||
|
||||
initialize_openssl();
|
||||
ssl_ctx = create_ssl_context(NULL, NULL);
|
||||
if (ssl_ctx == NULL) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
rc = cbuf_init(&(ctx->wbuf), 1, sizeof(int));
|
||||
if (rc < 0) {
|
||||
FREEUP(ctx->myinfo.name);
|
||||
FREEUP(ctx->myinfo.key);
|
||||
cleanup_openssl();
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
iomgr_init(&(ctx->iomgr));
|
||||
iomgr_set_ssl_ctx(&(ctx->iomgr), ssl_ctx);
|
||||
|
||||
vtaskmgr_init(&(ctx->vtaskmgr), 4);
|
||||
|
||||
ctx->ep = NULL;
|
||||
|
|
@ -245,6 +193,8 @@ void xce_ctx_fini(xce_ctx_t* ctx)
|
|||
FREEUP(ctx->myinfo.name);
|
||||
FREEUP(ctx->myinfo.key);
|
||||
|
||||
cleanup_openssl();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -264,7 +214,9 @@ int xce_ctx_set_endpoint(xce_ctx_t* ctx, endpoint_t* ep)
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
ctx->ep = ep;
|
||||
ctx->ep = ep;
|
||||
ctx->ep->iomgr = &(ctx->iomgr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -280,8 +232,9 @@ int xce_ctx_start(xce_ctx_t* ctx)
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
endpoint_set_handler(ctx->ep, handle_io, ctx);
|
||||
rc = iomgr_monitor(&(ctx->iomgr), ctx->ep);
|
||||
endpoint_set_owner(ctx->ep, ctx);
|
||||
endpoint_set_msg_handler(ctx->ep, (msg_handler_t)handle_msg);
|
||||
rc = iomgr_monitor(ctx->ep);
|
||||
if (rc < 0) {
|
||||
ctx->state = XCE_CTX_ERR;
|
||||
return rc;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue