summaryrefslogtreecommitdiff
path: root/tests/trantest.h
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-12-29 14:21:20 -0800
committerGarrett D'Amore <garrett@damore.org>2017-12-30 19:05:41 -0800
commit6a50035b242b972c1d9b659ba63e037a0a8afe71 (patch)
treefe2600235a01e72d1e7bd5fad1d5e2ea62aada2e /tests/trantest.h
parenta0364185784895c4bc748a6e6453a132d618c96c (diff)
downloadnng-6a50035b242b972c1d9b659ba63e037a0a8afe71.tar.gz
nng-6a50035b242b972c1d9b659ba63e037a0a8afe71.tar.bz2
nng-6a50035b242b972c1d9b659ba63e037a0a8afe71.zip
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.
Diffstat (limited to 'tests/trantest.h')
-rw-r--r--tests/trantest.h128
1 files changed, 87 insertions, 41 deletions
diff --git a/tests/trantest.h b/tests/trantest.h
index b1b0ff80..324668dd 100644
--- a/tests/trantest.h
+++ b/tests/trantest.h
@@ -26,41 +26,42 @@ typedef int (*trantest_proptest_t)(nng_msg *, nng_listener, nng_dialer);
typedef struct trantest trantest;
struct trantest {
- const char * tmpl;
- char addr[NNG_MAXADDRLEN + 1];
- nng_socket reqsock;
- nng_socket repsock;
- nni_tran * tran;
- nng_dialer dialer;
- nng_listener listener;
+ const char *tmpl;
+ char addr[NNG_MAXADDRLEN + 1];
+ nng_socket reqsock;
+ nng_socket repsock;
+ nni_tran * tran;
int (*init)(struct trantest *);
void (*fini)(struct trantest *);
- int (*dialer_init)(struct trantest *);
- int (*listener_init)(struct trantest *);
+ int (*dialer_init)(struct trantest *, nng_dialer);
+ int (*listener_init)(struct trantest *, nng_listener);
int (*proptest)(nng_msg *, nng_listener, nng_dialer);
void *private; // transport specific private data
};
unsigned trantest_port = 0;
-#ifndef NNG_HAVE_ZEROTIER
+#ifndef NNG_TRANSPORT_ZEROTIER
#define nng_zt_register notransport
#endif
-#ifndef NNG_HAVE_INPROC
+#ifndef NNG_TRANSPORT_INPROC
#define nng_inproc_register notransport
#endif
-#ifndef NNG_HAVE_IPC
+#ifndef NNG_TRANSPORT_IPC
#define nng_ipc_register notransport
#endif
-#ifndef NNG_HAVE_TCP
+#ifndef NNG_TRANSPORT_TCP
#define nng_tcp_register notransport
#endif
-#ifndef NNG_HAVE_TLS
+#ifndef NNG_TRANSPORT_TLS
#define nng_tls_register notransport
#endif
-#ifndef NNG_HAVE_WEBSOCKET
+#ifndef NNG_TRANSPORT_WS
#define nng_ws_register notransport
#endif
+#ifndef NNG_TRANSPORT_WSS
+#define nng_wss_register notransport
+#endif
int
notransport(void)
@@ -76,24 +77,27 @@ notransport(void)
void
trantest_checktran(const char *url)
{
-#ifndef NNG_HAVE_ZEROTIER
- CHKTRAN(url, "zt:");
-#endif
-#ifndef NNG_HAVE_INPROC
+#ifndef NNG_TRANSPORT_INPROC
CHKTRAN(url, "inproc:");
#endif
-#ifndef NNG_HAVE_IPC
+#ifndef NNG_TRANSPORT_IPC
CHKTRAN(url, "ipc:");
#endif
-#ifndef NNG_HAVE_TCP
+#ifndef NNG_TRANSPORT_TCP
CHKTRAN(url, "tcp:");
#endif
-#ifndef NNG_HAVE_TLS
+#ifndef NNG_TRANSPORT_TLS
CHKTRAN(url, "tls+tcp:");
#endif
-#ifndef NNG_HAVE_WEBSOCKET
+#ifndef NNG_TRANSPORT_WS
CHKTRAN(url, "ws:");
#endif
+#ifndef NNG_TRANSPORT_WSS
+ CHKTRAN(url, "wss:");
+#endif
+#ifndef NNG_TRANSPORT_ZEROTIER
+ CHKTRAN(url, "zt:");
+#endif
(void) url;
}
@@ -149,13 +153,53 @@ trantest_fini(trantest *tt)
}
int
-trantest_dial(trantest *tt)
+trantest_dial(trantest *tt, nng_dialer *dp)
{
- So(nng_dialer_create(&tt->dialer, tt->reqsock, tt->addr) == 0);
+ nng_dialer d;
+ int rv;
+ *dp = 0;
+
+ rv = nng_dialer_create(&d, tt->reqsock, tt->addr);
+ if (rv != 0) {
+ return (rv);
+ }
if (tt->dialer_init != NULL) {
- So(tt->dialer_init(tt) == 0);
+ if ((rv = tt->dialer_init(tt, d)) != 0) {
+ nng_dialer_close(d);
+ return (rv);
+ }
+ }
+ if ((rv = nng_dialer_start(d, 0)) != 0) {
+ nng_dialer_close(d);
+ return (rv);
}
- return (nng_dialer_start(tt->dialer, 0));
+ *dp = d;
+ return (0);
+}
+
+int
+trantest_listen(trantest *tt, nng_listener *lp)
+{
+ int rv;
+ nng_listener l;
+ *lp = 0;
+
+ rv = nng_listener_create(&l, tt->repsock, tt->addr);
+ if (rv != 0) {
+ return (rv);
+ }
+ if (tt->listener_init != NULL) {
+ if ((rv = tt->listener_init(tt, l)) != 0) {
+ nng_listener_close(l);
+ return (rv);
+ }
+ }
+ if ((rv = nng_listener_start(l, 0)) != 0) {
+ nng_listener_close(l);
+ return (rv);
+ }
+ *lp = l;
+ return (rv);
}
void
@@ -174,11 +218,11 @@ trantest_conn_refused(trantest *tt)
Convey("Connection refused works", {
nng_dialer d = 0;
- So(nng_dial(tt->reqsock, tt->addr, &d, 0) == NNG_ECONNREFUSED);
+ So(trantest_dial(tt, &d) == NNG_ECONNREFUSED);
So(d == 0);
- So(nng_dial(tt->repsock, tt->addr, &d, 0) == NNG_ECONNREFUSED);
+ So(trantest_dial(tt, &d) == NNG_ECONNREFUSED);
So(d == 0);
- })
+ });
}
void
@@ -187,13 +231,13 @@ trantest_duplicate_listen(trantest *tt)
Convey("Duplicate listen rejected", {
nng_listener l;
int rv;
- rv = nng_listen(tt->repsock, tt->addr, &l, 0);
+ rv = trantest_listen(tt, &l);
So(rv == 0);
So(l != 0);
l = 0;
- So(nng_listen(tt->repsock, tt->addr, &l, 0) == NNG_EADDRINUSE);
+ So(trantest_listen(tt, &l) == NNG_EADDRINUSE);
So(l == 0);
- })
+ });
}
void
@@ -202,11 +246,11 @@ trantest_listen_accept(trantest *tt)
Convey("Listen and accept", {
nng_listener l;
nng_dialer d;
- So(nng_listen(tt->repsock, tt->addr, &l, 0) == 0);
+ So(trantest_listen(tt, &l) == 0);
So(l != 0);
d = 0;
- So(nng_dial(tt->reqsock, tt->addr, &d, 0) == 0);
+ So(trantest_dial(tt, &d) == 0);
So(d != 0);
})
}
@@ -216,6 +260,7 @@ trantest_send_recv(trantest *tt)
{
Convey("Send and recv", {
nng_listener l;
+ nng_dialer d;
nng_msg * send;
nng_msg * recv;
size_t len;
@@ -223,9 +268,10 @@ trantest_send_recv(trantest *tt)
char url[NNG_MAXADDRLEN];
size_t sz;
- So(nng_listen(tt->repsock, tt->addr, &l, 0) == 0);
+ So(trantest_listen(tt, &l) == 0);
So(l != 0);
- So(trantest_dial(tt) == 0);
+ So(trantest_dial(tt, &d) == 0);
+ So(d != 0);
nng_msleep(200); // listener may be behind slightly
@@ -269,9 +315,9 @@ trantest_check_properties(trantest *tt, trantest_proptest_t f)
nng_msg * recv;
int rv;
- So(nng_listen(tt->repsock, tt->addr, &l, 0) == 0);
+ So(trantest_listen(tt, &l) == 0);
So(l != 0);
- So(nng_dial(tt->reqsock, tt->addr, &d, 0) == 0);
+ So(trantest_dial(tt, &d) == 0);
So(d != 0);
nng_msleep(200); // listener may be behind slightly
@@ -311,9 +357,9 @@ trantest_send_recv_large(trantest *tt)
data[i] = nni_random() & 0xff;
}
- So(nng_listen(tt->repsock, tt->addr, &l, 0) == 0);
+ So(trantest_listen(tt, &l) == 0);
So(l != 0);
- So(nng_dial(tt->reqsock, tt->addr, &d, 0) == 0);
+ So(trantest_dial(tt, &d) == 0);
So(d != 0);
nng_msleep(200); // listener may be behind slightly