From 6a50035b242b972c1d9b659ba63e037a0a8afe71 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Fri, 29 Dec 2017 14:21:20 -0800 Subject: fixes #166 Websocket TLS mapping This introduces the wss:// scheme, which is available and works like the ws:// scheme if TLS is enabled in the library. The library modularization is refactored somewhat, to make it easier to use. There is now a single NNG_ENABLE_TLS that enables TLS support under the hood. This also adds a new option for the TLS transport, NNG_OPT_TLS_CONFIG (and a similar one for WSS, NNG_OPT_TLS_WSS_CONFIG) that offer access to the underlying TLS configuration object, which now has a public API to go with it as well. Note that it is also possible to use pure HTTPS using the *private* API, which will be exposed in a public form soon. --- src/core/options.c | 13 +++++++++++++ src/core/options.h | 3 +++ src/core/transport.c | 31 ++++++++++++++++++------------- 3 files changed, 34 insertions(+), 13 deletions(-) (limited to 'src/core') diff --git a/src/core/options.c b/src/core/options.c index 1417d0b3..ef7420d6 100644 --- a/src/core/options.c +++ b/src/core/options.c @@ -186,6 +186,19 @@ nni_getopt_size(size_t u, void *val, size_t *sizep) return (0); } +int +nni_getopt_ptr(void *ptr, void *val, size_t *sizep) +{ + size_t sz = sizeof(ptr); + + if (sz > *sizep) { + sz = *sizep; + } + *sizep = sizeof(ptr); + memcpy(val, &ptr, sz); + return (0); +} + int nni_setopt_buf(nni_msgq *mq, const void *val, size_t sz) { diff --git a/src/core/options.h b/src/core/options.h index d373851f..e9aa16dd 100644 --- a/src/core/options.h +++ b/src/core/options.h @@ -58,6 +58,9 @@ extern int nni_setopt_size(size_t *, const void *, size_t, size_t, size_t); // nni_getopt_size obtains a size_t option. extern int nni_getopt_size(size_t, void *, size_t *); +// nni_getopt_ptr obtains a pointer option. +extern int nni_getopt_ptr(void *, void *, size_t *); + extern int nni_chkopt_ms(const void *, size_t); extern int nni_chkopt_int(const void *, size_t, int, int); extern int nni_chkopt_size(const void *, size_t, size_t, size_t); diff --git a/src/core/transport.c b/src/core/transport.c index 31da773f..9c129a72 100644 --- a/src/core/transport.c +++ b/src/core/transport.c @@ -56,12 +56,12 @@ nni_tran_register(const nni_tran *tran) nni_mtx_lock(&nni_tran_lk); // Check to see if the transport is already registered... NNI_LIST_FOREACH (&nni_tran_list, t) { - if (tran->tran_init == t->t_tran.tran_init) { - nni_mtx_unlock(&nni_tran_lk); - // Same transport, duplicate registration. - return (0); - } if (strcmp(tran->tran_scheme, t->t_tran.tran_scheme) == 0) { + if (tran->tran_init == t->t_tran.tran_init) { + // duplicate. + nni_mtx_unlock(&nni_tran_lk); + return (0); + } nni_mtx_unlock(&nni_tran_lk); return (NNG_ESTATE); } @@ -208,24 +208,29 @@ nni_tran_chkopt(const char *name, const void *v, size_t sz) typedef int (*nni_tran_ctor)(void); +// These are just the statically compiled in constructors. +// In the future we might want to support dynamic additions. static nni_tran_ctor nni_tran_ctors[] = { -#ifdef NNG_HAVE_INPROC +#ifdef NNG_TRANSPORT_INPROC nng_inproc_register, #endif -#ifdef NNG_HAVE_IPC +#ifdef NNG_TRANSPORT_IPC nng_ipc_register, #endif -#ifdef NNG_HAVE_TCP +#ifdef NNG_TRANSPORT_TCP nng_tcp_register, #endif -#ifdef NNG_HAVE_TLS +#ifdef NNG_TRANSPORT_TLS nng_tls_register, #endif -#ifdef NNG_HAVE_ZEROTIER - nng_zt_register, -#endif -#ifdef NNG_HAVE_WEBSOCKET +#ifdef NNG_TRANSPORT_WS nng_ws_register, +#endif +#ifdef NNG_TRANSPORT_WSS + nng_wss_register, +#endif +#ifdef NNG_TRANSPORT_ZEROTIER + nng_zt_register, #endif NULL, }; -- cgit v1.2.3-70-g09d2