diff options
| -rw-r--r-- | src/core/defs.h | 1 | ||||
| -rw-r--r-- | src/core/endpt.c | 33 | ||||
| -rw-r--r-- | src/core/endpt.h | 9 | ||||
| -rw-r--r-- | src/core/nng_impl.h | 5 | ||||
| -rw-r--r-- | src/core/pipe.c | 6 | ||||
| -rw-r--r-- | src/core/transport.c | 12 | ||||
| -rw-r--r-- | src/core/transport.h | 4 | ||||
| -rw-r--r-- | src/core/url.c | 27 | ||||
| -rw-r--r-- | src/core/url.h | 3 | ||||
| -rw-r--r-- | src/supplemental/http/client.c | 15 | ||||
| -rw-r--r-- | src/supplemental/http/http.h | 5 | ||||
| -rw-r--r-- | src/supplemental/http/server.c | 47 | ||||
| -rw-r--r-- | src/supplemental/websocket/websocket.c | 21 | ||||
| -rw-r--r-- | src/supplemental/websocket/websocket.h | 4 | ||||
| -rw-r--r-- | src/transport/inproc/inproc.c | 11 | ||||
| -rw-r--r-- | src/transport/ipc/ipc.c | 11 | ||||
| -rw-r--r-- | src/transport/tcp/tcp.c | 13 | ||||
| -rw-r--r-- | src/transport/tls/tls.c | 17 | ||||
| -rw-r--r-- | src/transport/ws/websocket.c | 9 | ||||
| -rw-r--r-- | src/transport/zerotier/zerotier.c | 13 | ||||
| -rw-r--r-- | tests/httpclient.c | 5 | ||||
| -rw-r--r-- | tests/httpserver.c | 32 | ||||
| -rw-r--r-- | tests/tls.c | 61 | ||||
| -rw-r--r-- | tests/trantest.h | 5 | ||||
| -rw-r--r-- | tests/wssfile.c | 11 |
25 files changed, 167 insertions, 213 deletions
diff --git a/src/core/defs.h b/src/core/defs.h index 3a714f85..d4a8a740 100644 --- a/src/core/defs.h +++ b/src/core/defs.h @@ -43,6 +43,7 @@ typedef struct nni_tran_ep nni_tran_ep; typedef struct nni_tran_ep_option nni_tran_ep_option; typedef struct nni_tran_pipe nni_tran_pipe; typedef struct nni_tran_pipe_option nni_tran_pipe_option; +typedef struct nni_url nni_url; typedef struct nni_proto_sock_ops nni_proto_sock_ops; typedef struct nni_proto_pipe_ops nni_proto_pipe_ops; diff --git a/src/core/endpt.c b/src/core/endpt.c index 57e4bc62..cfabcc87 100644 --- a/src/core/endpt.c +++ b/src/core/endpt.c @@ -21,7 +21,7 @@ struct nni_ep { uint64_t ep_id; // endpoint id nni_list_node ep_node; // per socket list nni_sock * ep_sock; - char ep_url[NNG_MAXADDRLEN]; + nni_url * ep_url; int ep_mode; int ep_started; int ep_closed; // full shutdown @@ -82,12 +82,6 @@ nni_ep_id(nni_ep *ep) return ((uint32_t) ep->ep_id); } -const char * -nni_ep_url(nni_ep *ep) -{ - return (ep->ep_url); -} - static void nni_ep_destroy(nni_ep *ep) { @@ -119,26 +113,31 @@ nni_ep_destroy(nni_ep *ep) nni_mtx_unlock(&ep->ep_mtx); nni_cv_fini(&ep->ep_cv); nni_mtx_fini(&ep->ep_mtx); + nni_url_free(ep->ep_url); NNI_FREE_STRUCT(ep); } static int -nni_ep_create(nni_ep **epp, nni_sock *s, const char *url, int mode) +nni_ep_create(nni_ep **epp, nni_sock *s, const char *urlstr, int mode) { nni_tran *tran; nni_ep * ep; int rv; + nni_url * url; + if ((rv = nni_url_parse(&url, urlstr)) != 0) { + return (rv); + } if ((tran = nni_tran_find(url)) == NULL) { + nni_url_free(url); return (NNG_ENOTSUP); } - if (strlen(url) >= NNG_MAXADDRLEN) { - return (NNG_EINVAL); - } if ((ep = NNI_ALLOC_STRUCT(ep)) == NULL) { + nni_url_free(url); return (NNG_ENOMEM); } + ep->ep_url = url; ep->ep_closed = 0; ep->ep_started = 0; ep->ep_data = NULL; @@ -152,8 +151,6 @@ nni_ep_create(nni_ep **epp, nni_sock *s, const char *url, int mode) // dereference on hot paths. ep->ep_ops = *tran->tran_ep; - (void) nni_strlcpy(ep->ep_url, url, sizeof(ep->ep_url)); - NNI_LIST_NODE_INIT(&ep->ep_node); nni_pipe_ep_list_init(&ep->ep_pipes); @@ -177,15 +174,15 @@ nni_ep_create(nni_ep **epp, nni_sock *s, const char *url, int mode) } int -nni_ep_create_dialer(nni_ep **epp, nni_sock *s, const char *url) +nni_ep_create_dialer(nni_ep **epp, nni_sock *s, const char *urlstr) { - return (nni_ep_create(epp, s, url, NNI_EP_MODE_DIAL)); + return (nni_ep_create(epp, s, urlstr, NNI_EP_MODE_DIAL)); } int -nni_ep_create_listener(nni_ep **epp, nni_sock *s, const char *url) +nni_ep_create_listener(nni_ep **epp, nni_sock *s, const char *urlstr) { - return (nni_ep_create(epp, s, url, NNI_EP_MODE_LISTEN)); + return (nni_ep_create(epp, s, urlstr, NNI_EP_MODE_LISTEN)); } int @@ -622,7 +619,7 @@ nni_ep_getopt(nni_ep *ep, const char *name, void *valp, size_t *szp) nni_tran_ep_option *eo; if (strcmp(name, NNG_OPT_URL) == 0) { - return (nni_getopt_str(ep->ep_url, valp, szp)); + return (nni_getopt_str(ep->ep_url->u_rawurl, valp, szp)); } for (eo = ep->ep_ops.ep_options; eo && eo->eo_name; eo++) { diff --git a/src/core/endpt.h b/src/core/endpt.h index f5ad09ee..df4f345b 100644 --- a/src/core/endpt.h +++ b/src/core/endpt.h @@ -1,6 +1,6 @@ // -// Copyright 2017 Garrett D'Amore <garrett@damore.org> -// Copyright 2017 Capitar IT Group BV <info@capitar.com> +// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -30,9 +30,8 @@ extern void nni_ep_list_init(nni_list *); extern int nni_ep_setopt(nni_ep *, const char *, const void *, size_t); extern int nni_ep_getopt(nni_ep *, const char *, void *, size_t *); extern int nni_ep_pipe_add(nni_ep *ep, nni_pipe *); -extern void nni_ep_pipe_remove(nni_ep *, nni_pipe *); -extern const char *nni_ep_url(nni_ep *); -extern int nni_ep_mode(nni_ep *); +extern void nni_ep_pipe_remove(nni_ep *, nni_pipe *); +extern int nni_ep_mode(nni_ep *); // Endpoint modes. Currently used by transports. Remove this when we make // transport dialers and listeners explicit. diff --git a/src/core/nng_impl.h b/src/core/nng_impl.h index ea8512bb..5c750ec7 100644 --- a/src/core/nng_impl.h +++ b/src/core/nng_impl.h @@ -44,10 +44,13 @@ #include "core/taskq.h" #include "core/thread.h" #include "core/timer.h" -#include "core/transport.h" #include "core/url.h" +// transport needs to come after url +#include "core/transport.h" + // These have to come after the others - particularly transport.h + #include "core/endpt.h" #include "core/pipe.h" #include "core/socket.h" diff --git a/src/core/pipe.c b/src/core/pipe.c index 77ceaa4f..66e7ae87 100644 --- a/src/core/pipe.c +++ b/src/core/pipe.c @@ -1,6 +1,6 @@ // -// Copyright 2017 Garrett D'Amore <garrett@damore.org> -// Copyright 2017 Capitar IT Group BV <info@capitar.com> +// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -29,7 +29,6 @@ struct nni_pipe { int p_reap; int p_stop; int p_refcnt; - const char * p_url; nni_mtx p_mtx; nni_cv p_cv; nni_list_node p_reap_node; @@ -268,7 +267,6 @@ nni_pipe_create(nni_ep *ep, void *tdata) p->p_proto_data = NULL; p->p_ep = ep; p->p_sock = sock; - p->p_url = nni_ep_url(ep); NNI_LIST_NODE_INIT(&p->p_reap_node); NNI_LIST_NODE_INIT(&p->p_sock_node); diff --git a/src/core/transport.c b/src/core/transport.c index 0891ec8c..38f88c4d 100644 --- a/src/core/transport.c +++ b/src/core/transport.c @@ -26,7 +26,6 @@ extern nni_tran nni_ipc_tran; typedef struct nni_transport { nni_tran t_tran; - char t_prefix[16]; // e.g. "tcp://" or "tls+tcp://" nni_list_node t_node; } nni_transport; @@ -72,13 +71,6 @@ nni_tran_register(const nni_tran *tran) } t->t_tran = *tran; - sz = sizeof(t->t_prefix); - if ((nni_strlcpy(t->t_prefix, tran->tran_scheme, sz) >= sz) || - (nni_strlcat(t->t_prefix, "://", sz) >= sz)) { - nni_mtx_unlock(&nni_tran_lk); - NNI_FREE_STRUCT(t); - return (NNG_EINVAL); - } if ((rv = t->t_tran.tran_init()) != 0) { nni_mtx_unlock(&nni_tran_lk); NNI_FREE_STRUCT(t); @@ -90,14 +82,14 @@ nni_tran_register(const nni_tran *tran) } nni_tran * -nni_tran_find(const char *addr) +nni_tran_find(nni_url *url) { // address is of the form "<scheme>://blah..." nni_transport *t; nni_mtx_lock(&nni_tran_lk); NNI_LIST_FOREACH (&nni_tran_list, t) { - if (strncmp(addr, t->t_prefix, strlen(t->t_prefix)) == 0) { + if (strcmp(url->u_scheme, t->t_tran.tran_scheme) == 0) { nni_mtx_unlock(&nni_tran_lk); return (&t->t_tran); } diff --git a/src/core/transport.h b/src/core/transport.h index 9a6dc31d..0ca9c409 100644 --- a/src/core/transport.h +++ b/src/core/transport.h @@ -76,7 +76,7 @@ struct nni_tran_ep_option { struct nni_tran_ep { // ep_init creates a vanilla endpoint. The value created is // used for the first argument for all other endpoint functions. - int (*ep_init)(void **, const char *, nni_sock *, int); + int (*ep_init)(void **, nni_url *, nni_sock *, int); // ep_fini frees the resources associated with the endpoint. // The endpoint will already have been closed. @@ -164,7 +164,7 @@ struct nni_tran_pipe { // These APIs are used by the framework internally, and not for use by // transport implementations. -extern nni_tran *nni_tran_find(const char *); +extern nni_tran *nni_tran_find(nni_url *); extern int nni_tran_chkopt(const char *, const void *, size_t); extern int nni_tran_sys_init(void); extern void nni_tran_sys_fini(void); diff --git a/src/core/url.c b/src/core/url.c index a5b4fd06..3d8898bd 100644 --- a/src/core/url.c +++ b/src/core/url.c @@ -453,4 +453,31 @@ nni_url_free(nni_url *url) nni_strfree(url->u_fragment); nni_strfree(url->u_rawpath); NNI_FREE_STRUCT(url); +} + +int +nni_url_clone(nni_url **dstp, const nni_url *src) +{ + nni_url *dst; + + if ((dst = NNI_ALLOC_STRUCT(dst)) == NULL) { + return (NNG_ENOMEM); + } +#define URL_COPYSTR(d, s) ((s != NULL) && ((d = nni_strdup(s)) == NULL)) + if (URL_COPYSTR(dst->u_rawurl, src->u_rawurl) || + URL_COPYSTR(dst->u_scheme, src->u_scheme) || + URL_COPYSTR(dst->u_userinfo, src->u_userinfo) || + URL_COPYSTR(dst->u_host, src->u_host) || + URL_COPYSTR(dst->u_hostname, src->u_hostname) || + URL_COPYSTR(dst->u_port, src->u_port) || + URL_COPYSTR(dst->u_rawpath, src->u_rawpath) || + URL_COPYSTR(dst->u_path, src->u_path) || + URL_COPYSTR(dst->u_query, src->u_query) || + URL_COPYSTR(dst->u_fragment, src->u_fragment)) { + nni_url_free(dst); + return (NNG_ENOMEM); + } +#undef URL_COPYSTR + *dstp = dst; + return (0); }
\ No newline at end of file diff --git a/src/core/url.h b/src/core/url.h index f99d6eb4..27aec445 100644 --- a/src/core/url.h +++ b/src/core/url.h @@ -11,8 +11,6 @@ #ifndef CORE_URL_H #define CORE_URL_H -typedef struct nni_url nni_url; - struct nni_url { char *u_rawurl; // never NULL char *u_scheme; // never NULL @@ -28,5 +26,6 @@ struct nni_url { extern int nni_url_parse(nni_url **, const char *path); extern void nni_url_free(nni_url *); +extern int nni_url_clone(nni_url **, const nni_url *); #endif // CORE_URL_H diff --git a/src/supplemental/http/client.c b/src/supplemental/http/client.c index 7542043d..4c54a708 100644 --- a/src/supplemental/http/client.c +++ b/src/supplemental/http/client.c @@ -24,7 +24,6 @@ struct nni_http_client { bool closed; nng_tls_config * tls; nni_aio * connaio; - nni_url * url; nni_plat_tcp_ep *tep; }; @@ -92,30 +91,21 @@ nni_http_client_fini(nni_http_client *c) nni_tls_config_fini(c->tls); } #endif - if (c->url != NULL) { - nni_url_free(c->url); - } NNI_FREE_STRUCT(c); } int -nni_http_client_init(nni_http_client **cp, const char *urlstr) +nni_http_client_init(nni_http_client **cp, nni_url *url) { int rv; - nni_url * url; nni_http_client *c; nni_aio * aio; nni_sockaddr sa; char * host; char * port; - if ((rv = nni_url_parse(&url, urlstr)) != 0) { - return (rv); - } - if (strlen(url->u_hostname) == 0) { // We require a valid hostname. - nni_url_free(url); return (NNG_EADDRINVAL); } if ((strcmp(url->u_scheme, "http") != 0) && @@ -132,7 +122,6 @@ nni_http_client_init(nni_http_client **cp, const char *urlstr) // imagines the ability to create a tcp dialer that does the // necessary DNS lookups, etc. all asynchronously. if ((rv = nni_aio_init(&aio, NULL, NULL)) != 0) { - nni_url_free(url); return (rv); } aio->a_addr = &sa; @@ -143,7 +132,6 @@ nni_http_client_init(nni_http_client **cp, const char *urlstr) rv = nni_aio_result(aio); nni_aio_fini(aio); if (rv != 0) { - nni_url_free(url); return (rv); } @@ -152,7 +140,6 @@ nni_http_client_init(nni_http_client **cp, const char *urlstr) } nni_mtx_init(&c->mtx); nni_aio_list_init(&c->aios); - c->url = url; #ifdef NNG_SUPP_TLS if ((strcmp(url->u_scheme, "https") == 0) || diff --git a/src/supplemental/http/http.h b/src/supplemental/http/http.h index 08156714..93a94049 100644 --- a/src/supplemental/http/http.h +++ b/src/supplemental/http/http.h @@ -174,7 +174,7 @@ typedef struct nni_http_handler nni_http_handler; // a restricted binding is required, we recommend using a URL consisting // of an empty host name, such as http:// or https:// -- this would // convert to binding to the default port on all interfaces on the host. -extern int nni_http_server_init(nni_http_server **, const char *); +extern int nni_http_server_init(nni_http_server **, nni_url *); // nni_http_server_fini drops the reference count on the server, and // if this was the last reference, closes down the server and frees @@ -325,8 +325,7 @@ extern void *nni_http_handler_get_data(nni_http_handler *, unsigned); typedef struct nni_http_client nni_http_client; -// https vs. http; would also allow us to defer DNS lookups til later. -extern int nni_http_client_init(nni_http_client **, const char *); +extern int nni_http_client_init(nni_http_client **, nni_url *); extern void nni_http_client_fini(nni_http_client *); // nni_http_client_set_tls sets the TLS configuration. This wipes out diff --git a/src/supplemental/http/server.c b/src/supplemental/http/server.c index 88a3bd1a..ecb544ea 100644 --- a/src/supplemental/http/server.c +++ b/src/supplemental/http/server.c @@ -69,7 +69,8 @@ struct nni_http_server { nng_tls_config * tls; nni_aio * accaio; nni_plat_tcp_ep *tep; - nni_url * url; + char * port; + char * hostname; }; int @@ -789,9 +790,6 @@ http_server_fini(nni_http_server *s) nni_http_handler_fini(h); } nni_mtx_unlock(&s->mtx); - if (s->url != NULL) { - nni_url_free(s->url); - } #ifdef NNG_SUPP_TLS if (s->tls != NULL) { nni_tls_config_fini(s->tls); @@ -800,6 +798,8 @@ http_server_fini(nni_http_server *s) nni_aio_fini(s->accaio); nni_cv_fini(&s->cv); nni_mtx_fini(&s->mtx); + nni_strfree(s->hostname); + nni_strfree(s->port); NNI_FREE_STRUCT(s); } @@ -820,15 +820,9 @@ http_server_init(nni_http_server **serverp, nni_url *url) { nni_http_server *s; int rv; - const char * host; const char * port; nni_aio * aio; - host = url->u_hostname; - if (strlen(host) == 0) { - host = NULL; - } - port = url->u_port; if ((strcmp(url->u_scheme, "http") != 0) && #ifdef NNG_SUPP_TLS @@ -836,14 +830,11 @@ http_server_init(nni_http_server **serverp, nni_url *url) (strcmp(url->u_scheme, "wss") != 0) && #endif (strcmp(url->u_scheme, "ws") != 0)) { - nni_url_free(url); return (NNG_EADDRINVAL); } if ((s = NNI_ALLOC_STRUCT(s)) == NULL) { - nni_url_free(url); return (NNG_ENOMEM); } - s->url = url; nni_mtx_init(&s->mtx); nni_cv_init(&s->cv, &s->mtx); NNI_LIST_INIT(&s->handlers, nni_http_handler, node); @@ -852,6 +843,18 @@ http_server_init(nni_http_server **serverp, nni_url *url) http_server_fini(s); return (rv); } + + if ((strlen(url->u_port)) && + ((s->port = nni_strdup(url->u_port)) == NULL)) { + http_server_fini(s); + return (NNG_ENOMEM); + } + if ((strlen(url->u_hostname)) && + ((s->hostname = nni_strdup(url->u_hostname)) == NULL)) { + http_server_fini(s); + return (NNG_ENOMEM); + } + #ifdef NNG_SUPP_TLS if ((strcmp(url->u_scheme, "https") == 0) || (strcmp(url->u_scheme, "wss") == 0)) { @@ -872,9 +875,7 @@ http_server_init(nni_http_server **serverp, nni_url *url) return (rv); } aio->a_addr = &s->addr; - host = (strlen(url->u_hostname) != 0) ? url->u_hostname : NULL; - port = (strlen(url->u_port) != 0) ? url->u_port : NULL; - nni_plat_tcp_resolv(host, port, NNG_AF_UNSPEC, true, aio); + nni_plat_tcp_resolv(s->hostname, s->port, NNG_AF_UNSPEC, true, aio); nni_aio_wait(aio); rv = nni_aio_result(aio); nni_aio_fini(aio); @@ -888,23 +889,17 @@ http_server_init(nni_http_server **serverp, nni_url *url) } int -nni_http_server_init(nni_http_server **serverp, const char *urlstr) +nni_http_server_init(nni_http_server **serverp, nni_url *url) { int rv; nni_http_server *s; - nni_url * url; - - if ((rv = nni_url_parse(&url, urlstr)) != 0) { - return (rv); - } nni_initialize(&http_server_initializer); nni_mtx_lock(&http_servers_lk); NNI_LIST_FOREACH (&http_servers, s) { - if ((strcmp(url->u_port, s->url->u_port) == 0) && - (strcmp(url->u_hostname, s->url->u_hostname) == 0)) { - nni_url_free(url); + if ((strcmp(url->u_port, s->port) == 0) && + (strcmp(url->u_hostname, s->hostname) == 0)) { *serverp = s; s->refcnt++; nni_mtx_unlock(&http_servers_lk); @@ -916,8 +911,6 @@ nni_http_server_init(nni_http_server **serverp, const char *urlstr) if ((rv = http_server_init(&s, url)) == 0) { nni_list_append(&http_servers, s); *serverp = s; - } else { - nni_url_free(url); } nni_mtx_unlock(&http_servers_lk); diff --git a/src/supplemental/websocket/websocket.c b/src/supplemental/websocket/websocket.c index df404b81..8e75490b 100644 --- a/src/supplemental/websocket/websocket.c +++ b/src/supplemental/websocket/websocket.c @@ -1522,12 +1522,11 @@ err: } int -nni_ws_listener_init(nni_ws_listener **wslp, const char *addr) +nni_ws_listener_init(nni_ws_listener **wslp, nni_url *url) { nni_ws_listener *l; int rv; char * host; - char * serv; if ((l = NNI_ALLOC_STRUCT(l)) == NULL) { return (NNG_ENOMEM); @@ -1539,7 +1538,8 @@ nni_ws_listener_init(nni_ws_listener **wslp, const char *addr) NNI_LIST_INIT(&l->pend, nni_ws, node); NNI_LIST_INIT(&l->reply, nni_ws, node); - if ((rv = nni_url_parse(&l->url, addr)) != 0) { + // make a private copy of the url structure. + if ((rv = nni_url_clone(&l->url, url)) != 0) { nni_ws_listener_fini(l); return (rv); } @@ -1548,12 +1548,7 @@ nni_ws_listener_init(nni_ws_listener **wslp, const char *addr) if (strlen(host) == 0) { host = NULL; } - serv = l->url->u_port; - if (strlen(serv) == 0) { - serv = (strcmp(l->url->u_scheme, "wss") == 0) ? "443" : "80"; - } - - rv = nni_http_handler_init(&l->handler, l->url->u_path, ws_handler); + rv = nni_http_handler_init(&l->handler, url->u_path, ws_handler); if (rv != 0) { nni_ws_listener_fini(l); return (rv); @@ -1561,7 +1556,7 @@ nni_ws_listener_init(nni_ws_listener **wslp, const char *addr) if (((rv = nni_http_handler_set_host(l->handler, host)) != 0) || ((rv = nni_http_handler_set_data(l->handler, l, 0)) != 0) || - ((rv = nni_http_server_init(&l->server, addr)) != 0)) { + ((rv = nni_http_server_init(&l->server, url)) != 0)) { nni_ws_listener_fini(l); return (rv); } @@ -1841,7 +1836,7 @@ nni_ws_dialer_fini(nni_ws_dialer *d) } int -nni_ws_dialer_init(nni_ws_dialer **dp, const char *addr) +nni_ws_dialer_init(nni_ws_dialer **dp, nni_url *url) { nni_ws_dialer *d; int rv; @@ -1853,12 +1848,12 @@ nni_ws_dialer_init(nni_ws_dialer **dp, const char *addr) NNI_LIST_INIT(&d->wspend, nni_ws, node); nni_mtx_init(&d->mtx); - if ((rv = nni_url_parse(&d->url, addr)) != 0) { + if ((rv = nni_url_clone(&d->url, url)) != 0) { nni_ws_dialer_fini(d); return (rv); } - if ((rv = nni_http_client_init(&d->client, addr)) != 0) { + if ((rv = nni_http_client_init(&d->client, url)) != 0) { nni_ws_dialer_fini(d); return (rv); } diff --git a/src/supplemental/websocket/websocket.h b/src/supplemental/websocket/websocket.h index ddd09b72..2cabb9cc 100644 --- a/src/supplemental/websocket/websocket.h +++ b/src/supplemental/websocket/websocket.h @@ -29,7 +29,7 @@ typedef int (*nni_ws_listen_hook)(void *, nni_http_req *, nni_http_res *); // on INADDR_ANY port 80, with path "/". For connect side, INADDR_ANY // makes no sense. (TBD: return NNG_EADDRINVAL, or try loopback?) -extern int nni_ws_listener_init(nni_ws_listener **, const char *); +extern int nni_ws_listener_init(nni_ws_listener **, nni_url *); extern void nni_ws_listener_fini(nni_ws_listener *); extern void nni_ws_listener_close(nni_ws_listener *); extern int nni_ws_listener_proto(nni_ws_listener *, const char *); @@ -40,7 +40,7 @@ extern void nni_ws_listener_hook( extern int nni_ws_listener_set_tls(nni_ws_listener *, nng_tls_config *); extern int nni_ws_listener_get_tls(nni_ws_listener *, nng_tls_config **s); -extern int nni_ws_dialer_init(nni_ws_dialer **, const char *); +extern int nni_ws_dialer_init(nni_ws_dialer **, nni_url *); extern void nni_ws_dialer_fini(nni_ws_dialer *); extern void nni_ws_dialer_close(nni_ws_dialer *); extern int nni_ws_dialer_proto(nni_ws_dialer *, const char *); diff --git a/src/transport/inproc/inproc.c b/src/transport/inproc/inproc.c index 5b52e80a..4cd1c97d 100644 --- a/src/transport/inproc/inproc.c +++ b/src/transport/inproc/inproc.c @@ -47,7 +47,7 @@ struct nni_inproc_pair { }; struct nni_inproc_ep { - char addr[NNG_MAXADDRLEN + 1]; + const char * addr; int mode; nni_list_node node; uint16_t proto; @@ -190,13 +190,10 @@ nni_inproc_pipe_get_addr(void *arg, void *buf, size_t *szp) } static int -nni_inproc_ep_init(void **epp, const char *url, nni_sock *sock, int mode) +nni_inproc_ep_init(void **epp, nni_url *url, nni_sock *sock, int mode) { nni_inproc_ep *ep; - if (strlen(url) > NNG_MAXADDRLEN - 1) { - return (NNG_EINVAL); - } if ((ep = NNI_ALLOC_STRUCT(ep)) == NULL) { return (NNG_ENOMEM); } @@ -206,8 +203,8 @@ nni_inproc_ep_init(void **epp, const char *url, nni_sock *sock, int mode) NNI_LIST_INIT(&ep->clients, nni_inproc_ep, node); nni_aio_list_init(&ep->aios); - (void) snprintf(ep->addr, sizeof(ep->addr), "%s", url); - *epp = ep; + ep->addr = url->u_rawurl; // we match on the full URL. + *epp = ep; return (0); } diff --git a/src/transport/ipc/ipc.c b/src/transport/ipc/ipc.c index 84292bb8..62751d86 100644 --- a/src/transport/ipc/ipc.c +++ b/src/transport/ipc/ipc.c @@ -529,17 +529,16 @@ nni_ipc_ep_fini(void *arg) } static int -nni_ipc_ep_init(void **epp, const char *url, nni_sock *sock, int mode) +nni_ipc_ep_init(void **epp, nni_url *url, nni_sock *sock, int mode) { nni_ipc_ep *ep; int rv; size_t sz; - if (strncmp(url, "ipc://", strlen("ipc://")) != 0) { - return (NNG_EADDRINVAL); + if (((url->u_host != NULL) && (strlen(url->u_host) > 0)) || + (url->u_userinfo != NULL)) { + return (NNG_EINVAL); } - url += strlen("ipc://"); - if ((ep = NNI_ALLOC_STRUCT(ep)) == NULL) { return (NNG_ENOMEM); } @@ -547,7 +546,7 @@ nni_ipc_ep_init(void **epp, const char *url, nni_sock *sock, int mode) sz = sizeof(ep->sa.s_un.s_path.sa_path); ep->sa.s_un.s_path.sa_family = NNG_AF_IPC; - if (nni_strlcpy(ep->sa.s_un.s_path.sa_path, url, sz) >= sz) { + if (nni_strlcpy(ep->sa.s_un.s_path.sa_path, url->u_path, sz) >= sz) { NNI_FREE_STRUCT(ep); return (NNG_EADDRINVAL); } diff --git a/src/transport/tcp/tcp.c b/src/transport/tcp/tcp.c index 9110e31c..0a123a79 100644 --- a/src/transport/tcp/tcp.c +++ b/src/transport/tcp/tcp.c @@ -527,14 +527,13 @@ nni_tcp_ep_fini(void *arg) if (ep->tep != NULL) { nni_plat_tcp_ep_fini(ep->tep); } - nni_url_free(ep->url); nni_aio_fini(ep->aio); nni_mtx_fini(&ep->mtx); NNI_FREE_STRUCT(ep); } static int -nni_tcp_ep_init(void **epp, const char *addr, nni_sock *sock, int mode) +nni_tcp_ep_init(void **epp, nni_url *url, nni_sock *sock, int mode) { nni_tcp_ep * ep; int rv; @@ -543,24 +542,17 @@ nni_tcp_ep_init(void **epp, const char *addr, nni_sock *sock, int mode) nni_sockaddr rsa, lsa; nni_aio * aio; int passive; - nni_url * url; - if ((rv = nni_url_parse(&url, addr)) != 0) { - return (rv); - } // Check for invalid URL components. if ((strlen(url->u_path) != 0) && (strcmp(url->u_path, "/") != 0)) { - nni_url_free(url); return (NNG_EADDRINVAL); } if ((url->u_fragment != NULL) || (url->u_userinfo != NULL) || (url->u_query != NULL)) { - nni_url_free(url); return (NNG_EADDRINVAL); } if ((rv = nni_aio_init(&aio, NULL, NULL)) != 0) { - nni_url_free(url); return (rv); } @@ -582,7 +574,6 @@ nni_tcp_ep_init(void **epp, const char *addr, nni_sock *sock, int mode) lsa.s_un.s_family = NNG_AF_UNSPEC; aio->a_addr = &rsa; if ((host == NULL) || (serv == NULL)) { - nni_url_free(url); nni_aio_fini(aio); return (NNG_EADDRINVAL); } @@ -595,7 +586,6 @@ nni_tcp_ep_init(void **epp, const char *addr, nni_sock *sock, int mode) nni_plat_tcp_resolv(host, serv, NNG_AF_UNSPEC, passive, aio); nni_aio_wait(aio); if ((rv = nni_aio_result(aio)) != 0) { - nni_url_free(url); nni_aio_fini(aio); return (rv); } @@ -603,7 +593,6 @@ nni_tcp_ep_init(void **epp, const char *addr, nni_sock *sock, int mode) nni_aio_fini(aio); if ((ep = NNI_ALLOC_STRUCT(ep)) == NULL) { - nni_url_free(url); return (NNG_ENOMEM); } nni_mtx_init(&ep->mtx); diff --git a/src/transport/tls/tls.c b/src/transport/tls/tls.c index 753a1e75..6bc884e7 100644 --- a/src/transport/tls/tls.c +++ b/src/transport/tls/tls.c @@ -537,16 +537,13 @@ nni_tls_ep_fini(void *arg) if (ep->cfg) { nni_tls_config_fini(ep->cfg); } - if (ep->url) { - nni_url_free(ep->url); - } nni_aio_fini(ep->aio); nni_mtx_fini(&ep->mtx); NNI_FREE_STRUCT(ep); } static int -nni_tls_ep_init(void **epp, const char *addr, nni_sock *sock, int mode) +nni_tls_ep_init(void **epp, nni_url *url, nni_sock *sock, int mode) { nni_tls_ep * ep; int rv; @@ -557,26 +554,17 @@ nni_tls_ep_init(void **epp, const char *addr, nni_sock *sock, int mode) int passive; nng_tls_mode tlsmode; nng_tls_auth_mode authmode; - nni_url * url; - - // Parse the URLs first. - if ((rv = nni_url_parse(&url, addr)) != 0) { - return (rv); - } // Check for invalid URL components. if ((strlen(url->u_path) != 0) && (strcmp(url->u_path, "/") != 0)) { - nni_url_free(url); return (NNG_EADDRINVAL); } if ((url->u_fragment != NULL) || (url->u_userinfo != NULL) || (url->u_query != NULL)) { - nni_url_free(url); return (NNG_EADDRINVAL); } if ((rv = nni_aio_init(&aio, NULL, NULL)) != 0) { - nni_url_free(url); return (rv); } @@ -598,7 +586,6 @@ nni_tls_ep_init(void **epp, const char *addr, nni_sock *sock, int mode) lsa.s_un.s_family = NNG_AF_UNSPEC; aio->a_addr = &rsa; if ((host == NULL) || (serv == NULL)) { - nni_url_free(url); nni_aio_fini(aio); return (NNG_EADDRINVAL); } @@ -615,14 +602,12 @@ nni_tls_ep_init(void **epp, const char *addr, nni_sock *sock, int mode) nni_plat_tcp_resolv(host, serv, NNG_AF_UNSPEC, passive, aio); nni_aio_wait(aio); if ((rv = nni_aio_result(aio)) != 0) { - nni_url_free(url); nni_aio_fini(aio); return (rv); } nni_aio_fini(aio); if ((ep = NNI_ALLOC_STRUCT(ep)) == NULL) { - nni_url_free(url); return (NNG_ENOMEM); } nni_mtx_init(&ep->mtx); diff --git a/src/transport/ws/websocket.c b/src/transport/ws/websocket.c index 4db4bc72..aead6f59 100644 --- a/src/transport/ws/websocket.c +++ b/src/transport/ws/websocket.c @@ -30,8 +30,7 @@ typedef struct ws_hdr { } ws_hdr; struct ws_ep { - int mode; // NNI_EP_MODE_DIAL or NNI_EP_MODE_LISTEN - char * addr; + int mode; // NNI_EP_MODE_DIAL or NNI_EP_MODE_LISTEN uint16_t lproto; // local protocol uint16_t rproto; // remote protocol size_t rcvmax; @@ -605,7 +604,6 @@ ws_ep_fini(void *arg) nni_strfree(hdr->value); NNI_FREE_STRUCT(hdr); } - nni_strfree(ep->addr); nni_strfree(ep->protoname); nni_mtx_fini(&ep->mtx); NNI_FREE_STRUCT(ep); @@ -694,7 +692,7 @@ ws_ep_acc_cb(void *arg) } static int -ws_ep_init(void **epp, const char *url, nni_sock *sock, int mode) +ws_ep_init(void **epp, nni_url *url, nni_sock *sock, int mode) { ws_ep * ep; const char *pname; @@ -721,9 +719,6 @@ ws_ep_init(void **epp, const char *url, nni_sock *sock, int mode) rv = nni_ws_listener_init(&ep->listener, url); } - if ((rv == 0) && ((ep->addr = nni_strdup(url)) == NULL)) { - rv = NNG_ENOMEM; - } if ((rv != 0) || ((rv = nni_aio_init(&ep->connaio, ws_ep_conn_cb, ep)) != 0) || ((rv = nni_aio_init(&ep->accaio, ws_ep_acc_cb, ep)) != 0) || diff --git a/src/transport/zerotier/zerotier.c b/src/transport/zerotier/zerotier.c index cef31a29..2522138f 100644 --- a/src/transport/zerotier/zerotier.c +++ b/src/transport/zerotier/zerotier.c @@ -225,7 +225,6 @@ struct zt_creq { struct zt_ep { nni_list_node ze_link; - char ze_url[NNG_MAXADDRLEN]; char ze_home[NNG_MAXADDRLEN]; // should be enough zt_node * ze_ztn; uint64_t ze_nwid; @@ -2100,7 +2099,7 @@ zt_parsedec(const char **sp, uint64_t *valp) } static int -zt_ep_init(void **epp, const char *url, nni_sock *sock, int mode) +zt_ep_init(void **epp, nni_url *url, nni_sock *sock, int mode) { zt_ep * ep; size_t sz; @@ -2127,24 +2126,18 @@ zt_ep_init(void **epp, const char *url, nni_sock *sock, int mode) ep->ze_ping_count = zt_ping_count; ep->ze_ping_time = zt_ping_time; ep->ze_proto = nni_sock_proto(sock); - sz = sizeof(ep->ze_url); nni_aio_list_init(&ep->ze_aios); - if ((strncmp(url, "zt://", strlen("zt://")) != 0) || - (nni_strlcpy(ep->ze_url, url, sz) >= sz)) { - zt_ep_fini(ep); - return (NNG_EADDRINVAL); - } rv = nni_aio_init(&ep->ze_creq_aio, zt_ep_conn_req_cb, ep); if (rv != 0) { zt_ep_fini(ep); return (rv); } - u = url + strlen("zt://"); - // Parse the URL. + u = url->u_rawurl + strlen("zt://"); + // Parse the URL. switch (mode) { case NNI_EP_MODE_DIAL: // We require zt://<nwid>/<remotenode>:<port> diff --git a/tests/httpclient.c b/tests/httpclient.c index 76a3566b..b58dc81f 100644 --- a/tests/httpclient.c +++ b/tests/httpclient.c @@ -34,11 +34,13 @@ TestMain("HTTP Client", { nni_aio * iaio; nni_http_client *cli; nni_http * http; + nni_url * url; So(nng_aio_alloc(&aio, NULL, NULL) == 0); iaio = (nni_aio *) aio; - So(nni_http_client_init(&cli, "http://httpbin.org") == 0); + So(nni_url_parse(&url, "http://httpbin.org") == 0); + So(nni_http_client_init(&cli, url) == 0); nni_http_client_connect(cli, iaio); nng_aio_wait(aio); So(nng_aio_result(aio) == 0); @@ -47,6 +49,7 @@ TestMain("HTTP Client", { nni_http_client_fini(cli); nni_http_fini(http); nng_aio_free(aio); + nni_url_free(url); }); Convey("We can initiate a message", { diff --git a/tests/httpserver.c b/tests/httpserver.c index 0d3f3710..f7ab377c 100644 --- a/tests/httpserver.c +++ b/tests/httpserver.c @@ -49,7 +49,7 @@ httpget(const char *addr, void **datap, size_t *sizep, uint16_t *statp, ((rv = nni_aio_init(&aio, NULL, NULL)) != 0) || ((rv = nni_http_req_init(&req)) != 0) || ((rv = nni_http_res_init(&res)) != 0) || - ((rv = nni_http_client_init(&cli, addr)) != 0)) { + ((rv = nni_http_client_init(&cli, url)) != 0)) { goto fail; } nni_http_client_connect(cli, aio); @@ -143,12 +143,15 @@ TestMain("HTTP Client", { Convey("We can start an HTTP server", { nni_aio *aio; char portbuf[16]; - char url[32]; + char urlstr[32]; + nni_url *url; trantest_next_address(portbuf, "%u"); - snprintf(url, sizeof(url), "http://127.0.0.1:%s", portbuf); + snprintf( + urlstr, sizeof(urlstr), "http://127.0.0.1:%s", portbuf); + So(nni_url_parse(&url, urlstr) == 0); So(nni_aio_init(&aio, NULL, NULL) == 0); So(nni_http_server_init(&s, url) == 0); @@ -156,6 +159,7 @@ TestMain("HTTP Client", { Reset({ nni_aio_fini(aio); nni_http_server_fini(s); + nni_url_free(url); }); So(nni_http_handler_init_static(&h, "/home.html", doc1, @@ -247,7 +251,8 @@ TestMain("HTTP Client", { Convey("Directory serving works", { nni_aio *aio; char portbuf[16]; - char url[32]; + char urlstr[32]; + nni_url *url; char * tmpdir; char * workdir; char * file1; @@ -256,10 +261,8 @@ TestMain("HTTP Client", { char * subdir1; char * subdir2; - trantest_next_address(portbuf, "%u"); - - snprintf(url, sizeof(url), "http://127.0.0.1:%s", portbuf); - + trantest_next_address(urlstr, "http://127.0.0.1:%u"); + So(nni_url_parse(&url, urlstr) == 0); So(nni_aio_init(&aio, NULL, NULL) == 0); So(nni_http_server_init(&s, url) == 0); So((tmpdir = nni_plat_temp_dir()) != NULL); @@ -290,6 +293,7 @@ TestMain("HTTP Client", { nni_strfree(file3); nni_strfree(subdir1); nni_strfree(subdir2); + nni_url_free(url); }); So(nni_http_handler_init_directory(&h, "/docs", workdir) == 0); @@ -305,7 +309,7 @@ TestMain("HTTP Client", { char * ctype; snprintf(fullurl, sizeof(fullurl), - "%s/docs/subdir1/index.html", url); + "%s/docs/subdir1/index.html", urlstr); So(httpget(fullurl, &data, &size, &stat, &ctype) == 0); So(stat == NNI_HTTP_STATUS_OK); So(size == strlen(doc1)); @@ -322,8 +326,8 @@ TestMain("HTTP Client", { uint16_t stat; char * ctype; - snprintf( - fullurl, sizeof(fullurl), "%s/docs/subdir2", url); + snprintf(fullurl, sizeof(fullurl), "%s/docs/subdir2", + urlstr); So(httpget(fullurl, &data, &size, &stat, &ctype) == 0); So(stat == NNI_HTTP_STATUS_OK); So(size == strlen(doc3)); @@ -340,8 +344,8 @@ TestMain("HTTP Client", { uint16_t stat; char * ctype; - snprintf( - fullurl, sizeof(fullurl), "%s/docs/file.txt", url); + snprintf(fullurl, sizeof(fullurl), "%s/docs/file.txt", + urlstr); So(httpget(fullurl, &data, &size, &stat, &ctype) == 0); So(stat == NNI_HTTP_STATUS_OK); So(size == strlen(doc2)); @@ -358,7 +362,7 @@ TestMain("HTTP Client", { uint16_t stat; char * ctype; - snprintf(fullurl, sizeof(fullurl), "%s/docs/", url); + snprintf(fullurl, sizeof(fullurl), "%s/docs/", urlstr); So(httpget(fullurl, &data, &size, &stat, &ctype) == 0); So(stat == NNI_HTTP_STATUS_NOT_FOUND); So(size == 0); diff --git a/tests/tls.c b/tests/tls.c index 1196aab3..c977d57f 100644 --- a/tests/tls.c +++ b/tests/tls.c @@ -29,47 +29,27 @@ // // Generated using openssl: // -// % openssl ecparam -name secp521r1 -noout -genkey -out key.key -// % openssl req -new -key key.key -out cert.csr -// % openssl x509 -req -in cert.csr -days 36500 -out cert.crt -signkey key.key +// % openssl rsa -genkey -out key.key +// % openssl req -new -key key.key -out cert.csr -sha256 +// % openssl x509 -req -in cert.csr -days 36500 -out cert.crt +// -signkey key.key -sha256 // // Relevant metadata: // // Certificate: -// Data: +// Data: // Version: 1 (0x0) -// Serial Number: 9808857926806240008 (0x882010509b8f7b08) -// Signature Algorithm: ecdsa-with-SHA1 -// Issuer: C=US, ST=CA, L=San Diego, O=nanomsg, CN=127.0.0.1 +// Serial Number: 17127835813110005400 (0xedb24becc3a2be98) +// Signature Algorithm: sha256WithRSAEncryption +// Issuer: C=US, ST=CA, L=San Diego, O=nanomsg.org, CN=localhost // Validity -// Not Before: Nov 17 20:08:06 2017 GMT -// Not After : Oct 24 20:08:06 2117 GMT -// Subject: C=US, ST=CA, L=San Diego, O=nanomsg, CN=127.0.0.1 +// Not Before: Jan 11 22:34:35 2018 GMT +// Not After : Dec 18 22:34:35 2117 GMT +// Subject: C=US, ST=CA, L=San Diego, O=nanomsg.org, CN=localhost +// Subject Public Key Info: +// Public Key Algorithm: rsaEncryption +// Public-Key: (2048 bit) // -static const char eccert[] = - "-----BEGIN CERTIFICATE-----\n" - "MIICIjCCAYMCCQDaC9ARg31kIjAKBggqhkjOPQQDAjBUMQswCQYDVQQGEwJVUzEL\n" - "MAkGA1UECAwCQ0ExEjAQBgNVBAcMCVNhbiBEaWVnbzEQMA4GA1UECgwHbmFub21z\n" - "ZzESMBAGA1UEAwwJMTI3LjAuMC4xMCAXDTE3MTExNzIwMjczMloYDzIxMTcxMDI0\n" - "MjAyNzMyWjBUMQswCQYDVQQGEwJVUzELMAkGA1UECAwCQ0ExEjAQBgNVBAcMCVNh\n" - "biBEaWVnbzEQMA4GA1UECgwHbmFub21zZzESMBAGA1UEAwwJMTI3LjAuMC4xMIGb\n" - "MBAGByqGSM49AgEGBSuBBAAjA4GGAAQAN7vDK6GEiSguMsOuhfOvGyiVc37Sog0b\n" - "UkpaiS6+SagTmXFSN1Rgh9isxKFYJvcCtAko3v0I8rAVQucdhf5B3hEBMQlbBIuM\n" - "rMKT6ZQJ+eiwyb4O3Scgd7DoL3tc/kOqijwB/5hJ4sZdquDKP5DDFe5fAf4MNtzY\n" - "4C+iApWlKq/LoXkwCgYIKoZIzj0EAwIDgYwAMIGIAkIBOuJAWmNSdd6Ovmr6Ebg3\n" - "UF9ZrsNwARd9BfYbBk5OQhUOjCLB6d8aLi49WOm1WoRvOS5PaVvmvSfNhaw8b5nV\n" - "hnYCQgC+EmJ6C3bEcZrndhfbqvCaOGkc7/SrKhC6fS7mJW4wL90QUV9WjQ2Ll6X5\n" - "PxkSj7s0SvD6T8j7rju5LDgkdZc35A==\n" - "-----END CERTIFICATE-----\n"; - -static const char eckey[] = - "-----BEGIN EC PRIVATE KEY-----\n" - "MIHcAgEBBEIB20OHMntU2UJW2yuQn2f+bLsuhTT5KRGorcocnqxatWLvxuF1cfUA\n" - "TjQxRRS6BIUvFt1fMIklp9qedJF00JHy4qWgBwYFK4EEACOhgYkDgYYABAA3u8Mr\n" - "oYSJKC4yw66F868bKJVzftKiDRtSSlqJLr5JqBOZcVI3VGCH2KzEoVgm9wK0CSje\n" - "/QjysBVC5x2F/kHeEQExCVsEi4yswpPplAn56LDJvg7dJyB3sOgve1z+Q6qKPAH/\n" - "mEnixl2q4Mo/kMMV7l8B/gw23NjgL6IClaUqr8uheQ==\n" - "-----END EC PRIVATE KEY-----\n"; static const char cert[] = "-----BEGIN CERTIFICATE-----\n" @@ -92,6 +72,7 @@ static const char cert[] = "dFMXOO1rleU0lWAJcXWOWHH3er0fivu2ISL8fRjjikYvhRGxtkwC0kPDa2Ntzgd3\n" "Hsg=\n" "-----END CERTIFICATE-----\n"; + static const char key[] = "-----BEGIN RSA PRIVATE KEY-----\n" "MIIEpQIBAAKCAQEAzL6B3RJ3zoZhtz04+mAuas+jeYYJnMH+BGZKK+PkdUOYQziq\n" @@ -377,6 +358,7 @@ TestMain("TLS Transport", { nng_msg * msg; nng_pipe p; int v; + nng_dialer d; So(nng_pair_open(&s1) == 0); So(nng_pair_open(&s2) == 0); @@ -392,11 +374,14 @@ TestMain("TLS Transport", { // reset port back one trantest_prev_address(addr, "tls+tcp://127.0.0.1:%u"); - So(nng_setopt_int(s2, NNG_OPT_TLS_AUTH_MODE, - NNG_TLS_AUTH_MODE_OPTIONAL) == 0); So(nng_setopt_ms(s2, NNG_OPT_RECVTIMEO, 200) == 0); - So(nng_dial(s2, addr, NULL, 0) == 0); - nng_msleep(100); + So(nng_dialer_create(&d, s2, addr) == 0); + So(init_dialer_tls_file(NULL, d) == 0); + So(nng_dialer_setopt_int(d, NNG_OPT_TLS_AUTH_MODE, + NNG_TLS_AUTH_MODE_OPTIONAL) == 0); + So(nng_dialer_setopt_string( + d, NNG_OPT_TLS_SERVER_NAME, "example.com") == 0); + So(nng_dialer_start(d, 0) == 0); So(nng_send(s1, "hello", 6, 0) == 0); So(nng_recvmsg(s2, &msg, 0) == 0); diff --git a/tests/trantest.h b/tests/trantest.h index c85b3429..80f59ff9 100644 --- a/tests/trantest.h +++ b/tests/trantest.h @@ -137,7 +137,10 @@ trantest_init(trantest *tt, const char *addr) So(nng_req_open(&tt->reqsock) == 0); So(nng_rep_open(&tt->repsock) == 0); - tt->tran = nni_tran_find(addr); + nni_url *url; + So(nni_url_parse(&url, tt->addr) == 0); + tt->tran = nni_tran_find(url); + nni_url_free(url); So(tt->tran != NULL); #else ConveySkip("Missing REQ or REP protocols"); diff --git a/tests/wssfile.c b/tests/wssfile.c index 28cdf6b6..73bc1cdb 100644 --- a/tests/wssfile.c +++ b/tests/wssfile.c @@ -295,6 +295,7 @@ TestMain("WebSocket Secure (TLS) Transport (file based)", { nng_socket s1; nng_socket s2; nng_listener l; + nng_dialer d; char addr[NNG_MAXADDRLEN]; nng_msg * msg; nng_pipe p; @@ -314,10 +315,20 @@ TestMain("WebSocket Secure (TLS) Transport (file based)", { // reset port back one trantest_prev_address(addr, "wss://127.0.0.1:%u/test"); + So(nng_setopt_ms(s2, NNG_OPT_RECVTIMEO, 200) == 0); + So(nng_dialer_create(&d, s2, addr) == 0); + So(init_dialer_wss_file(NULL, d) == 0); + So(nng_dialer_setopt_int(d, NNG_OPT_TLS_AUTH_MODE, + NNG_TLS_AUTH_MODE_OPTIONAL) == 0); + So(nng_dialer_setopt_string( + d, NNG_OPT_TLS_SERVER_NAME, "example.com") == 0); + So(nng_dialer_start(d, 0) == 0); +#if 0 So(nng_setopt_int(s2, NNG_OPT_TLS_AUTH_MODE, NNG_TLS_AUTH_MODE_OPTIONAL) == 0); So(nng_setopt_ms(s2, NNG_OPT_RECVTIMEO, 200) == 0); So(nng_dial(s2, addr, NULL, 0) == 0); +#endif nng_msleep(100); So(nng_send(s1, "hello", 6, 0) == 0); |
