aboutsummaryrefslogtreecommitdiff
path: root/src/transport/tls
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2020-11-15 17:47:54 -0800
committerGarrett D'Amore <garrett@damore.org>2020-11-15 17:47:54 -0800
commit249932f3a208260f6b9c99d778b22d51cfabe87b (patch)
tree4fd4826127e9c225d5232c39d4ae1db89b539689 /src/transport/tls
parenteb328da56c3fc7167b536dcb206df0abb0f4a9b9 (diff)
downloadnng-249932f3a208260f6b9c99d778b22d51cfabe87b.tar.gz
nng-249932f3a208260f6b9c99d778b22d51cfabe87b.tar.bz2
nng-249932f3a208260f6b9c99d778b22d51cfabe87b.zip
fixes #1071 tran_chkopt can be cleaned up
This is a sweeping cleanup of the transport logic around options, and also harmonizes the names used when setting or getting options. Additionally, legacy methods are now moved into a separate file and can be elided via CMake or a preprocessor define. Fundamentally, the ability to set to transport options via the socket is deprecated; there are numerous problems with this and my earlier approaches to deal with this have been somewhat misguided. Further these approaches will not work with future protocol work that is planned (were some options need to be negotiated with peers at the time of connection establishment.) Documentation has been updated to reflect this. The test suites still make rather broad use of the older APIs, and will be converted later.
Diffstat (limited to 'src/transport/tls')
-rw-r--r--src/transport/tls/tls.c53
1 files changed, 11 insertions, 42 deletions
diff --git a/src/transport/tls/tls.c b/src/transport/tls/tls.c
index ae5d86ec..62393d22 100644
--- a/src/transport/tls/tls.c
+++ b/src/transport/tls/tls.c
@@ -883,7 +883,7 @@ tlstran_ep_init_dialer(void **dp, nni_url *url, nni_dialer *ndialer)
return (rv);
}
if ((srcsa.s_family != NNG_AF_UNSPEC) &&
- ((rv = nni_stream_dialer_setx(ep->dialer, NNG_OPT_LOCADDR, &srcsa,
+ ((rv = nni_stream_dialer_set(ep->dialer, NNG_OPT_LOCADDR, &srcsa,
sizeof(srcsa), NNI_TYPE_SOCKADDR)) != 0)) {
tlstran_ep_fini(ep);
return (rv);
@@ -952,7 +952,7 @@ tlstran_ep_init_listener(void **lp, nni_url *url, nni_listener *nlistener)
if ((rv != 0) ||
((rv = nng_stream_listener_alloc_url(&ep->listener, url)) != 0) ||
- ((rv = nni_stream_listener_setx(ep->listener,
+ ((rv = nni_stream_listener_set(ep->listener,
NNG_OPT_TLS_AUTH_MODE, &ep->authmode, sizeof(ep->authmode),
NNI_TYPE_INT32)) != 0)) {
tlstran_ep_fini(ep);
@@ -1128,19 +1128,12 @@ tlstran_pipe_getopt(
tlstran_pipe *p = arg;
int rv;
- if ((rv = nni_stream_getx(p->tls, name, buf, szp, t)) == NNG_ENOTSUP) {
+ if ((rv = nni_stream_get(p->tls, name, buf, szp, t)) == NNG_ENOTSUP) {
rv = nni_getopt(tlstran_pipe_opts, name, p, buf, szp, t);
}
return (rv);
}
-static int
-tlstran_check_recvmaxsz(const void *v, size_t sz, nni_type t)
-{
- size_t val;
- return (nni_copyin_size(&val, v, sz, 0, NNI_MAXSZ, t));
-}
-
static nni_tran_pipe_ops tlstran_pipe_ops = {
.p_init = tlstran_pipe_init,
.p_fini = tlstran_pipe_fini,
@@ -1168,16 +1161,6 @@ static nni_option tlstran_ep_options[] = {
},
};
-static nni_chkoption tlstran_checkopts[] = {
- {
- .o_name = NNG_OPT_RECVMAXSZ,
- .o_check = tlstran_check_recvmaxsz,
- },
- {
- .o_name = NULL,
- },
-};
-
static int
tlstran_dialer_getopt(
void *arg, const char *name, void *buf, size_t *szp, nni_type t)
@@ -1185,7 +1168,7 @@ tlstran_dialer_getopt(
int rv;
tlstran_ep *ep = arg;
- rv = nni_stream_dialer_getx(ep->dialer, name, buf, szp, t);
+ rv = nni_stream_dialer_get(ep->dialer, name, buf, szp, t);
if (rv == NNG_ENOTSUP) {
rv = nni_getopt(tlstran_ep_options, name, ep, buf, szp, t);
}
@@ -1199,7 +1182,7 @@ tlstran_dialer_setopt(
int rv;
tlstran_ep *ep = arg;
- rv = nni_stream_dialer_setx(
+ rv = nni_stream_dialer_set(
ep != NULL ? ep->dialer : NULL, name, buf, sz, t);
if (rv == NNG_ENOTSUP) {
rv = nni_setopt(tlstran_ep_options, name, ep, buf, sz, t);
@@ -1208,13 +1191,13 @@ tlstran_dialer_setopt(
}
static int
-tlstran_listener_getopt(
+tlstran_listener_get(
void *arg, const char *name, void *buf, size_t *szp, nni_type t)
{
int rv;
tlstran_ep *ep = arg;
- rv = nni_stream_listener_getx(ep->listener, name, buf, szp, t);
+ rv = nni_stream_listener_get(ep->listener, name, buf, szp, t);
if (rv == NNG_ENOTSUP) {
rv = nni_getopt(tlstran_ep_options, name, ep, buf, szp, t);
}
@@ -1222,13 +1205,13 @@ tlstran_listener_getopt(
}
static int
-tlstran_listener_setopt(
+tlstran_listener_set(
void *arg, const char *name, const void *buf, size_t sz, nni_type t)
{
int rv;
tlstran_ep *ep = arg;
- rv = nni_stream_listener_setx(
+ rv = nni_stream_listener_set(
ep != NULL ? ep->listener : NULL, name, buf, sz, t);
if (rv == NNG_ENOTSUP) {
rv = nni_setopt(tlstran_ep_options, name, ep, buf, sz, t);
@@ -1236,17 +1219,6 @@ tlstran_listener_setopt(
return (rv);
}
-static int
-tlstran_checkopt(const char *name, const void *buf, size_t sz, nni_type t)
-{
- int rv;
- rv = nni_chkopt(tlstran_checkopts, name, buf, sz, t);
- if (rv == NNG_ENOTSUP) {
- rv = nni_stream_checkopt("tls+tcp", name, buf, sz, t);
- }
- return (rv);
-}
-
static nni_tran_dialer_ops tlstran_dialer_ops = {
.d_init = tlstran_ep_init_dialer,
.d_fini = tlstran_ep_fini,
@@ -1262,8 +1234,8 @@ static nni_tran_listener_ops tlstran_listener_ops = {
.l_bind = tlstran_ep_bind,
.l_accept = tlstran_ep_accept,
.l_close = tlstran_ep_close,
- .l_getopt = tlstran_listener_getopt,
- .l_setopt = tlstran_listener_setopt,
+ .l_getopt = tlstran_listener_get,
+ .l_setopt = tlstran_listener_set,
};
static nni_tran tls_tran = {
@@ -1274,7 +1246,6 @@ static nni_tran tls_tran = {
.tran_pipe = &tlstran_pipe_ops,
.tran_init = tlstran_init,
.tran_fini = tlstran_fini,
- .tran_checkopt = tlstran_checkopt,
};
static nni_tran tls4_tran = {
@@ -1285,7 +1256,6 @@ static nni_tran tls4_tran = {
.tran_pipe = &tlstran_pipe_ops,
.tran_init = tlstran_init,
.tran_fini = tlstran_fini,
- .tran_checkopt = tlstran_checkopt,
};
static nni_tran tls6_tran = {
@@ -1296,7 +1266,6 @@ static nni_tran tls6_tran = {
.tran_pipe = &tlstran_pipe_ops,
.tran_init = tlstran_init,
.tran_fini = tlstran_fini,
- .tran_checkopt = tlstran_checkopt,
};
int