mirror of https://github.com/yandex/odyssey.git
Move contexts under mm_self
This commit is contained in:
parent
c4b7a3cc18
commit
553f176e99
|
@ -74,6 +74,8 @@ machine_create(char *name, machine_coroutine_t function, void *arg)
|
||||||
machine->id = 0;
|
machine->id = 0;
|
||||||
machine->main = function;
|
machine->main = function;
|
||||||
machine->main_arg = arg;
|
machine->main_arg = arg;
|
||||||
|
machine->server_tls_ctx = NULL;
|
||||||
|
machine->client_tls_ctx = NULL;
|
||||||
machine->name = NULL;
|
machine->name = NULL;
|
||||||
if (name) {
|
if (name) {
|
||||||
machine->name = strdup(name);
|
machine->name = strdup(name);
|
||||||
|
|
|
@ -24,6 +24,8 @@ struct mm_machine
|
||||||
mm_coroutine_cache_t coroutine_cache;
|
mm_coroutine_cache_t coroutine_cache;
|
||||||
mm_loop_t loop;
|
mm_loop_t loop;
|
||||||
mm_list_t link;
|
mm_list_t link;
|
||||||
|
struct mm_tls_ctx *server_tls_ctx;
|
||||||
|
struct mm_tls_ctx *client_tls_ctx;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern __thread mm_machine_t *mm_self;
|
extern __thread mm_machine_t *mm_self;
|
||||||
|
|
|
@ -173,20 +173,17 @@ mm_tls_error(mm_io_t *io, int ssl_rc, char *fmt, ...)
|
||||||
errno = EIO;
|
errno = EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
__thread mm_tls_ctx_t *server_tls_ctx = NULL;
|
|
||||||
__thread mm_tls_ctx_t *client_tls_ctx = NULL;
|
|
||||||
|
|
||||||
SSL_CTX*
|
SSL_CTX*
|
||||||
mm_tls_get_context(mm_io_t *io, int is_client) {
|
mm_tls_get_context(mm_io_t *io, int is_client) {
|
||||||
mm_tls_ctx_t *ctx_container;
|
mm_tls_ctx_t *ctx_container;
|
||||||
if (is_client)
|
if (is_client)
|
||||||
ctx_container = client_tls_ctx;
|
ctx_container = mm_self->client_tls_ctx;
|
||||||
else
|
else
|
||||||
ctx_container = server_tls_ctx;
|
ctx_container = mm_self->server_tls_ctx;
|
||||||
while (ctx_container != NULL) {
|
while (ctx_container != NULL) {
|
||||||
if (ctx_container->key == io->tls)
|
if (ctx_container->key == io->tls) {
|
||||||
return ctx_container->tls_ctx;
|
return ctx_container->tls_ctx;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Cached context not found - we must create ctx
|
// Cached context not found - we must create ctx
|
||||||
|
|
||||||
|
@ -278,10 +275,8 @@ mm_tls_get_context(mm_io_t *io, int is_client) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SSL_CTX_set_options(ctx, SSL_OP_CIPHER_SERVER_PREFERENCE);
|
SSL_CTX_set_options(ctx, SSL_OP_CIPHER_SERVER_PREFERENCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Place new ctx on top of cache
|
// Place new ctx on top of cache
|
||||||
|
|
||||||
ctx_container = malloc(sizeof(*ctx_container));
|
ctx_container = malloc(sizeof(*ctx_container));
|
||||||
|
@ -289,12 +284,12 @@ mm_tls_get_context(mm_io_t *io, int is_client) {
|
||||||
ctx_container->tls_ctx = ctx;
|
ctx_container->tls_ctx = ctx;
|
||||||
|
|
||||||
if (is_client) {
|
if (is_client) {
|
||||||
ctx_container->next = client_tls_ctx;
|
ctx_container->next = mm_self->client_tls_ctx;
|
||||||
client_tls_ctx = ctx_container;
|
mm_self->client_tls_ctx = ctx_container;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ctx_container->next = server_tls_ctx;
|
ctx_container->next = mm_self->server_tls_ctx;
|
||||||
server_tls_ctx = ctx_container;
|
mm_self->server_tls_ctx = ctx_container;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctx;
|
return ctx;
|
||||||
|
|
Loading…
Reference in New Issue