aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-03-19 16:02:37 -0700
committerGarrett D'Amore <garrett@damore.org>2018-03-20 09:53:58 -0700
commit9ca901c1b70b17d851426483d9f54611cfa8e395 (patch)
treea26b11e16f505ccdc77b5ac6681e0f9de705ff20 /src/transport
parent9b886a9999247d87c9f6d389c3e65a4bd39be010 (diff)
downloadnng-9ca901c1b70b17d851426483d9f54611cfa8e395.tar.gz
nng-9ca901c1b70b17d851426483d9f54611cfa8e395.tar.bz2
nng-9ca901c1b70b17d851426483d9f54611cfa8e395.zip
fixes #296 Typed options should validate option type
fixes #302 nng_dialer/listener/pipe_getopt_sockaddr desired This adds plumbing to pass and check the type of options all the way through. NNG_ZT_OPT_ORBIT is type UINT64, but you can use the untyped form to pass two of them if needed. No typed access for retrieving strings yet. I think this should allocate a pointer and copy that out, but that's for later.
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/inproc/inproc.c20
-rw-r--r--src/transport/ipc/ipc.c22
-rw-r--r--src/transport/tcp/tcp.c23
-rw-r--r--src/transport/tls/tls.c34
-rw-r--r--src/transport/ws/websocket.c57
-rw-r--r--src/transport/zerotier/zerotier.c57
6 files changed, 176 insertions, 37 deletions
diff --git a/src/transport/inproc/inproc.c b/src/transport/inproc/inproc.c
index 375d8bdd..14457623 100644
--- a/src/transport/inproc/inproc.c
+++ b/src/transport/inproc/inproc.c
@@ -421,10 +421,20 @@ nni_inproc_ep_accept(void *arg, nni_aio *aio)
}
static nni_tran_pipe_option nni_inproc_pipe_options[] = {
- { NNG_OPT_LOCADDR, nni_inproc_pipe_get_addr },
- { NNG_OPT_REMADDR, nni_inproc_pipe_get_addr },
+ {
+ .po_name = NNG_OPT_LOCADDR,
+ .po_type = NNI_TYPE_SOCKADDR,
+ .po_getopt = nni_inproc_pipe_get_addr,
+ },
+ {
+ .po_name = NNG_OPT_REMADDR,
+ .po_type = NNI_TYPE_SOCKADDR,
+ .po_getopt = nni_inproc_pipe_get_addr,
+ },
// terminate list
- { NULL, NULL },
+ {
+ .po_name = NULL,
+ },
};
static nni_tran_pipe nni_inproc_pipe_ops = {
@@ -438,7 +448,9 @@ static nni_tran_pipe nni_inproc_pipe_ops = {
static nni_tran_ep_option nni_inproc_ep_options[] = {
// terminate list
- { NULL, NULL, NULL },
+ {
+ .eo_name = NULL,
+ },
};
static nni_tran_ep nni_inproc_ep_ops = {
diff --git a/src/transport/ipc/ipc.c b/src/transport/ipc/ipc.c
index fa59f0fe..9f95c2a9 100644
--- a/src/transport/ipc/ipc.c
+++ b/src/transport/ipc/ipc.c
@@ -703,10 +703,20 @@ nni_ipc_ep_get_addr(void *arg, void *data, size_t *szp)
}
static nni_tran_pipe_option nni_ipc_pipe_options[] = {
- { NNG_OPT_REMADDR, nni_ipc_pipe_get_addr },
- { NNG_OPT_LOCADDR, nni_ipc_pipe_get_addr },
+ {
+ .po_name = NNG_OPT_REMADDR,
+ .po_type = NNI_TYPE_SOCKADDR,
+ .po_getopt = nni_ipc_pipe_get_addr,
+ },
+ {
+ .po_name = NNG_OPT_LOCADDR,
+ .po_type = NNI_TYPE_SOCKADDR,
+ .po_getopt = nni_ipc_pipe_get_addr,
+ },
// terminate list
- { NULL, NULL },
+ {
+ .po_name = NULL,
+ },
};
static nni_tran_pipe nni_ipc_pipe_ops = {
@@ -722,16 +732,20 @@ static nni_tran_pipe nni_ipc_pipe_ops = {
static nni_tran_ep_option nni_ipc_ep_options[] = {
{
.eo_name = NNG_OPT_RECVMAXSZ,
+ .eo_type = NNI_TYPE_SIZE,
.eo_getopt = nni_ipc_ep_getopt_recvmaxsz,
.eo_setopt = nni_ipc_ep_setopt_recvmaxsz,
},
{
.eo_name = NNG_OPT_LOCADDR,
+ .eo_type = NNI_TYPE_SOCKADDR,
.eo_getopt = nni_ipc_ep_get_addr,
.eo_setopt = NULL,
},
// terminate list
- { NULL, NULL, NULL },
+ {
+ .eo_name = NULL,
+ },
};
static nni_tran_ep nni_ipc_ep_ops = {
diff --git a/src/transport/tcp/tcp.c b/src/transport/tcp/tcp.c
index a74f1097..5741beea 100644
--- a/src/transport/tcp/tcp.c
+++ b/src/transport/tcp/tcp.c
@@ -776,10 +776,20 @@ nni_tcp_ep_getopt_linger(void *arg, void *v, size_t *szp)
}
static nni_tran_pipe_option nni_tcp_pipe_options[] = {
- { NNG_OPT_LOCADDR, nni_tcp_pipe_getopt_locaddr },
- { NNG_OPT_REMADDR, nni_tcp_pipe_getopt_remaddr },
+ {
+ .po_name = NNG_OPT_LOCADDR,
+ .po_type = NNI_TYPE_SOCKADDR,
+ .po_getopt = nni_tcp_pipe_getopt_locaddr,
+ },
+ {
+ .po_name = NNG_OPT_REMADDR,
+ .po_type = NNI_TYPE_SOCKADDR,
+ .po_getopt = nni_tcp_pipe_getopt_remaddr,
+ },
// terminate list
- { NULL, NULL }
+ {
+ .po_name = NULL,
+ },
};
static nni_tran_pipe nni_tcp_pipe_ops = {
@@ -795,21 +805,26 @@ static nni_tran_pipe nni_tcp_pipe_ops = {
static nni_tran_ep_option nni_tcp_ep_options[] = {
{
.eo_name = NNG_OPT_RECVMAXSZ,
+ .eo_type = NNI_TYPE_SIZE,
.eo_getopt = nni_tcp_ep_getopt_recvmaxsz,
.eo_setopt = nni_tcp_ep_setopt_recvmaxsz,
},
{
.eo_name = NNG_OPT_URL,
+ .eo_type = NNI_TYPE_STRING,
.eo_getopt = nni_tcp_ep_getopt_url,
.eo_setopt = NULL,
},
{
.eo_name = NNG_OPT_LINGER,
+ .eo_type = NNI_TYPE_DURATION,
.eo_getopt = nni_tcp_ep_getopt_linger,
.eo_setopt = nni_tcp_ep_setopt_linger,
},
// terminate list
- { NULL, NULL, NULL },
+ {
+ .eo_name = NULL,
+ },
};
static nni_tran_ep nni_tcp_ep_ops = {
diff --git a/src/transport/tls/tls.c b/src/transport/tls/tls.c
index 59066f5f..9299ba2d 100644
--- a/src/transport/tls/tls.c
+++ b/src/transport/tls/tls.c
@@ -896,11 +896,25 @@ tls_getopt_verified(void *arg, void *v, size_t *szp)
}
static nni_tran_pipe_option nni_tls_pipe_options[] = {
- { NNG_OPT_LOCADDR, nni_tls_pipe_getopt_locaddr },
- { NNG_OPT_REMADDR, nni_tls_pipe_getopt_remaddr },
- { NNG_OPT_TLS_VERIFIED, tls_getopt_verified },
+ {
+ .po_name = NNG_OPT_LOCADDR,
+ .po_type = NNI_TYPE_SOCKADDR,
+ .po_getopt = nni_tls_pipe_getopt_locaddr,
+ },
+ {
+ .po_name = NNG_OPT_REMADDR,
+ .po_type = NNI_TYPE_SOCKADDR,
+ .po_getopt = nni_tls_pipe_getopt_remaddr,
+ },
+ {
+ .po_name = NNG_OPT_TLS_VERIFIED,
+ .po_type = NNI_TYPE_BOOL,
+ .po_getopt = tls_getopt_verified,
+ },
// terminate list
- { NULL, NULL }
+ {
+ .po_name = NULL,
+ },
};
static nni_tran_pipe nni_tls_pipe_ops = {
@@ -916,46 +930,56 @@ static nni_tran_pipe nni_tls_pipe_ops = {
static nni_tran_ep_option nni_tls_ep_options[] = {
{
.eo_name = NNG_OPT_RECVMAXSZ,
+ .eo_type = NNI_TYPE_SIZE,
.eo_getopt = nni_tls_ep_getopt_recvmaxsz,
.eo_setopt = nni_tls_ep_setopt_recvmaxsz,
},
{
.eo_name = NNG_OPT_LINGER,
+ .eo_type = NNI_TYPE_DURATION,
.eo_getopt = nni_tls_ep_getopt_linger,
.eo_setopt = nni_tls_ep_setopt_linger,
},
{
.eo_name = NNG_OPT_URL,
+ .eo_type = NNI_TYPE_STRING,
.eo_getopt = nni_tls_ep_getopt_url,
.eo_setopt = NULL,
},
{
.eo_name = NNG_OPT_TLS_CONFIG,
+ .eo_type = NNI_TYPE_POINTER,
.eo_getopt = tls_getopt_config,
.eo_setopt = tls_setopt_config,
},
{
.eo_name = NNG_OPT_TLS_CERT_KEY_FILE,
+ .eo_type = NNI_TYPE_STRING,
.eo_getopt = NULL,
.eo_setopt = tls_setopt_cert_key_file,
},
{
.eo_name = NNG_OPT_TLS_CA_FILE,
+ .eo_type = NNI_TYPE_STRING,
.eo_getopt = NULL,
.eo_setopt = tls_setopt_ca_file,
},
{
.eo_name = NNG_OPT_TLS_AUTH_MODE,
+ .eo_type = NNI_TYPE_INT32, // enum really
.eo_getopt = NULL,
.eo_setopt = tls_setopt_auth_mode,
},
{
.eo_name = NNG_OPT_TLS_SERVER_NAME,
+ .eo_type = NNI_TYPE_STRING,
.eo_getopt = NULL,
.eo_setopt = tls_setopt_server_name,
},
// terminate list
- { NULL, NULL, NULL },
+ {
+ .eo_name = NULL,
+ },
};
static nni_tran_ep nni_tls_ep_ops = {
diff --git a/src/transport/ws/websocket.c b/src/transport/ws/websocket.c
index 2aeb6e29..1b862d73 100644
--- a/src/transport/ws/websocket.c
+++ b/src/transport/ws/websocket.c
@@ -537,16 +537,35 @@ ws_pipe_getopt_tls_verified(void *arg, void *v, size_t *szp)
static nni_tran_pipe_option ws_pipe_options[] = {
- // clang-format off
- { NNG_OPT_LOCADDR, ws_pipe_getopt_locaddr },
- { NNG_OPT_REMADDR, ws_pipe_getopt_remaddr },
- { NNG_OPT_WS_REQUEST_HEADERS, ws_pipe_getopt_reqhdrs },
- { NNG_OPT_WS_RESPONSE_HEADERS, ws_pipe_getopt_reshdrs },
- { NNG_OPT_TLS_VERIFIED, ws_pipe_getopt_tls_verified },
- // clang-format on
-
+ {
+ .po_name = NNG_OPT_LOCADDR,
+ .po_type = NNI_TYPE_SOCKADDR,
+ .po_getopt = ws_pipe_getopt_locaddr,
+ },
+ {
+ .po_name = NNG_OPT_REMADDR,
+ .po_type = NNI_TYPE_SOCKADDR,
+ .po_getopt = ws_pipe_getopt_remaddr,
+ },
+ {
+ .po_name = NNG_OPT_WS_REQUEST_HEADERS,
+ .po_type = NNI_TYPE_STRING,
+ .po_getopt = ws_pipe_getopt_reqhdrs,
+ },
+ {
+ .po_name = NNG_OPT_WS_RESPONSE_HEADERS,
+ .po_type = NNI_TYPE_STRING,
+ .po_getopt = ws_pipe_getopt_reshdrs,
+ },
+ {
+ .po_name = NNG_OPT_TLS_VERIFIED,
+ .po_type = NNI_TYPE_BOOL,
+ .po_getopt = ws_pipe_getopt_tls_verified,
+ },
// terminate list
- { NULL, NULL }
+ {
+ .po_name = NULL,
+ }
};
static nni_tran_pipe ws_pipe_ops = {
@@ -561,22 +580,26 @@ static nni_tran_pipe ws_pipe_ops = {
static nni_tran_ep_option ws_ep_options[] = {
{
.eo_name = NNG_OPT_RECVMAXSZ,
+ .eo_type = NNI_TYPE_SIZE,
.eo_getopt = ws_ep_getopt_recvmaxsz,
.eo_setopt = ws_ep_setopt_recvmaxsz,
},
{
.eo_name = NNG_OPT_WS_REQUEST_HEADERS,
+ .eo_type = NNI_TYPE_STRING,
.eo_getopt = NULL,
.eo_setopt = ws_ep_setopt_reqhdrs,
},
{
.eo_name = NNG_OPT_WS_RESPONSE_HEADERS,
+ .eo_type = NNI_TYPE_STRING,
.eo_getopt = NULL,
.eo_setopt = ws_ep_setopt_reshdrs,
},
-
// terminate list
- { NULL, NULL, NULL },
+ {
+ .eo_name = NULL,
+ },
};
static void
@@ -910,46 +933,56 @@ wss_ep_setopt_tls_server_name(void *arg, const void *v, size_t sz)
static nni_tran_ep_option wss_ep_options[] = {
{
.eo_name = NNG_OPT_RECVMAXSZ,
+ .eo_type = NNI_TYPE_SIZE,
.eo_getopt = ws_ep_getopt_recvmaxsz,
.eo_setopt = ws_ep_setopt_recvmaxsz,
},
{
.eo_name = NNG_OPT_WS_REQUEST_HEADERS,
+ .eo_type = NNI_TYPE_STRING,
.eo_getopt = NULL,
.eo_setopt = ws_ep_setopt_reqhdrs,
},
{
.eo_name = NNG_OPT_WS_RESPONSE_HEADERS,
+ .eo_type = NNI_TYPE_STRING,
.eo_getopt = NULL,
.eo_setopt = ws_ep_setopt_reshdrs,
},
{
.eo_name = NNG_OPT_TLS_CONFIG,
+ .eo_type = NNI_TYPE_POINTER,
.eo_getopt = wss_ep_getopt_tlsconfig,
.eo_setopt = wss_ep_setopt_tlsconfig,
},
{
.eo_name = NNG_OPT_TLS_CERT_KEY_FILE,
+ .eo_type = NNI_TYPE_STRING,
.eo_getopt = NULL,
.eo_setopt = wss_ep_setopt_tls_cert_key_file,
},
{
.eo_name = NNG_OPT_TLS_CA_FILE,
+ .eo_type = NNI_TYPE_STRING,
.eo_getopt = NULL,
.eo_setopt = wss_ep_setopt_tls_ca_file,
},
{
.eo_name = NNG_OPT_TLS_AUTH_MODE,
+ .eo_type = NNI_TYPE_INT32,
.eo_getopt = NULL,
.eo_setopt = wss_ep_setopt_tls_auth_mode,
},
{
.eo_name = NNG_OPT_TLS_SERVER_NAME,
+ .eo_type = NNI_TYPE_STRING,
.eo_getopt = NULL,
.eo_setopt = wss_ep_setopt_tls_server_name,
},
// terminate list
- { NULL, NULL, NULL },
+ {
+ .eo_name = NULL,
+ },
};
static nni_tran_ep wss_ep_ops = {
diff --git a/src/transport/zerotier/zerotier.c b/src/transport/zerotier/zerotier.c
index 2a427ca0..98dbe2bd 100644
--- a/src/transport/zerotier/zerotier.c
+++ b/src/transport/zerotier/zerotier.c
@@ -2776,14 +2776,40 @@ zt_pipe_getopt_mtu(void *arg, void *data, size_t *szp)
}
static nni_tran_pipe_option zt_pipe_options[] = {
- { NNG_OPT_LOCADDR, zt_pipe_getopt_locaddr },
- { NNG_OPT_REMADDR, zt_pipe_getopt_remaddr },
- { NNG_OPT_ZT_MTU, zt_pipe_getopt_mtu },
- { NNG_OPT_ZT_NWID, zt_pipe_get_nwid },
- { NNG_OPT_ZT_NODE, zt_pipe_get_node },
- { NNG_OPT_RECVMAXSZ, zt_pipe_get_recvmaxsz },
+ {
+ .po_name = NNG_OPT_LOCADDR,
+ .po_type = NNI_TYPE_SOCKADDR,
+ .po_getopt = zt_pipe_getopt_locaddr,
+ },
+ {
+ .po_name = NNG_OPT_REMADDR,
+ .po_type = NNI_TYPE_SOCKADDR,
+ .po_getopt = zt_pipe_getopt_remaddr,
+ },
+ {
+ .po_name = NNG_OPT_ZT_MTU,
+ .po_type = NNI_TYPE_SIZE,
+ .po_getopt = zt_pipe_getopt_mtu,
+ },
+ {
+ .po_name = NNG_OPT_ZT_NWID,
+ .po_type = NNI_TYPE_UINT64,
+ .po_getopt = zt_pipe_get_nwid,
+ },
+ {
+ .po_name = NNG_OPT_ZT_NODE,
+ .po_type = NNI_TYPE_UINT64,
+ .po_getopt = zt_pipe_get_node,
+ },
+ {
+ .po_name = NNG_OPT_RECVMAXSZ,
+ .po_type = NNI_TYPE_SIZE,
+ .po_getopt = zt_pipe_get_recvmaxsz,
+ },
// terminate list
- { NULL, NULL },
+ {
+ .po_name = NULL,
+ },
};
static nni_tran_pipe zt_pipe_ops = {
@@ -2799,71 +2825,86 @@ static nni_tran_pipe zt_pipe_ops = {
static nni_tran_ep_option zt_ep_options[] = {
{
.eo_name = NNG_OPT_RECVMAXSZ,
+ .eo_type = NNI_TYPE_SIZE,
.eo_getopt = zt_ep_getopt_recvmaxsz,
.eo_setopt = zt_ep_setopt_recvmaxsz,
},
{
.eo_name = NNG_OPT_URL,
+ .eo_type = NNI_TYPE_STRING,
.eo_getopt = zt_ep_getopt_url,
.eo_setopt = NULL,
},
{
.eo_name = NNG_OPT_ZT_HOME,
+ .eo_type = NNI_TYPE_STRING,
.eo_getopt = zt_ep_getopt_home,
.eo_setopt = zt_ep_setopt_home,
},
{
.eo_name = NNG_OPT_ZT_NODE,
+ .eo_type = NNI_TYPE_UINT64,
.eo_getopt = zt_ep_getopt_node,
.eo_setopt = NULL,
},
{
.eo_name = NNG_OPT_ZT_NWID,
+ .eo_type = NNI_TYPE_UINT64,
.eo_getopt = zt_ep_getopt_nwid,
.eo_setopt = NULL,
},
{
.eo_name = NNG_OPT_ZT_NETWORK_STATUS,
+ .eo_type = NNI_TYPE_INT32, // enumeration really
.eo_getopt = zt_ep_getopt_network_status,
.eo_setopt = NULL,
},
{
.eo_name = NNG_OPT_ZT_NETWORK_NAME,
+ .eo_type = NNI_TYPE_STRING,
.eo_getopt = zt_ep_getopt_network_name,
.eo_setopt = NULL,
},
{
.eo_name = NNG_OPT_ZT_PING_TIME,
+ .eo_type = NNI_TYPE_DURATION,
.eo_getopt = zt_ep_getopt_ping_time,
.eo_setopt = zt_ep_setopt_ping_time,
},
{
.eo_name = NNG_OPT_ZT_PING_TRIES,
+ .eo_type = NNI_TYPE_INT32,
.eo_getopt = zt_ep_getopt_ping_tries,
.eo_setopt = zt_ep_setopt_ping_tries,
},
{
.eo_name = NNG_OPT_ZT_CONN_TIME,
+ .eo_type = NNI_TYPE_DURATION,
.eo_getopt = zt_ep_getopt_conn_time,
.eo_setopt = zt_ep_setopt_conn_time,
},
{
.eo_name = NNG_OPT_ZT_CONN_TRIES,
+ .eo_type = NNI_TYPE_INT32,
.eo_getopt = zt_ep_getopt_conn_tries,
.eo_setopt = zt_ep_setopt_conn_tries,
},
{
.eo_name = NNG_OPT_ZT_ORBIT,
+ .eo_type = NNI_TYPE_UINT64, // use opaque for two
.eo_getopt = NULL,
.eo_setopt = zt_ep_setopt_orbit,
},
{
.eo_name = NNG_OPT_ZT_DEORBIT,
+ .eo_type = NNI_TYPE_UINT64,
.eo_getopt = NULL,
.eo_setopt = zt_ep_setopt_deorbit,
},
// terminate list
- { NULL, NULL, NULL },
+ {
+ .eo_name = NULL,
+ },
};
static nni_tran_ep zt_ep_ops = {