aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/tcp/tcp.c26
-rw-r--r--src/transport/tls/tls.c28
-rw-r--r--src/transport/zerotier/zerotier.c21
3 files changed, 71 insertions, 4 deletions
diff --git a/src/transport/tcp/tcp.c b/src/transport/tcp/tcp.c
index 475a77ff..2a23b88b 100644
--- a/src/transport/tcp/tcp.c
+++ b/src/transport/tcp/tcp.c
@@ -53,6 +53,8 @@ struct nni_tcp_ep {
nni_aio * aio;
nni_aio * user_aio;
nni_url * url;
+ nng_sockaddr bsa; // bound addr
+ int mode;
nni_mtx mtx;
};
@@ -591,6 +593,7 @@ nni_tcp_ep_init(void **epp, nni_url *url, nni_sock *sock, int mode)
return (rv);
}
ep->proto = nni_sock_proto(sock);
+ ep->mode = mode;
*epp = ep;
return (0);
@@ -615,7 +618,7 @@ nni_tcp_ep_bind(void *arg)
int rv;
nni_mtx_lock(&ep->mtx);
- rv = nni_plat_tcp_ep_listen(ep->tep);
+ rv = nni_plat_tcp_ep_listen(ep->tep, &ep->bsa);
nni_mtx_unlock(&ep->mtx);
return (rv);
@@ -734,6 +737,22 @@ nni_tcp_ep_setopt_recvmaxsz(void *arg, const void *v, size_t sz)
}
static int
+nni_tcp_ep_getopt_url(void *arg, void *v, size_t *szp)
+{
+ nni_tcp_ep *ep = arg;
+ char ustr[128];
+ char ipstr[48]; // max for IPv6 addresses including []
+ char portstr[6]; // max for 16-bit port
+
+ if (ep->mode == NNI_EP_MODE_DIAL) {
+ return (nni_getopt_str(ep->url->u_rawurl, v, szp));
+ }
+ nni_plat_tcp_ntop(&ep->bsa, ipstr, portstr);
+ snprintf(ustr, sizeof(ustr), "tcp://%s:%s", ipstr, portstr);
+ return (nni_getopt_str(ustr, v, szp));
+}
+
+static int
nni_tcp_ep_getopt_recvmaxsz(void *arg, void *v, size_t *szp)
{
nni_tcp_ep *ep = arg;
@@ -781,6 +800,11 @@ static nni_tran_ep_option nni_tcp_ep_options[] = {
.eo_setopt = nni_tcp_ep_setopt_recvmaxsz,
},
{
+ .eo_name = NNG_OPT_URL,
+ .eo_getopt = nni_tcp_ep_getopt_url,
+ .eo_setopt = NULL,
+ },
+ {
.eo_name = NNG_OPT_LINGER,
.eo_getopt = nni_tcp_ep_getopt_linger,
.eo_setopt = nni_tcp_ep_setopt_linger,
diff --git a/src/transport/tls/tls.c b/src/transport/tls/tls.c
index f9de3367..cf849373 100644
--- a/src/transport/tls/tls.c
+++ b/src/transport/tls/tls.c
@@ -61,7 +61,9 @@ struct nni_tls_ep {
nni_aio * user_aio;
nni_mtx mtx;
nng_tls_config * cfg;
+ nng_sockaddr bsa;
nni_url * url;
+ int mode;
};
static void nni_tls_pipe_send_cb(void *);
@@ -597,7 +599,8 @@ nni_tls_ep_init(void **epp, nni_url *url, nni_sock *sock, int mode)
return (NNG_ENOMEM);
}
nni_mtx_init(&ep->mtx);
- ep->url = url;
+ ep->url = url;
+ ep->mode = mode;
if (((rv = nni_plat_tcp_ep_init(&ep->tep, &lsa, &rsa, mode)) != 0) ||
((rv = nni_tls_config_init(&ep->cfg, tlsmode)) != 0) ||
@@ -638,7 +641,7 @@ nni_tls_ep_bind(void *arg)
int rv;
nni_mtx_lock(&ep->mtx);
- rv = nni_plat_tcp_ep_listen(ep->tep);
+ rv = nni_plat_tcp_ep_listen(ep->tep, &ep->bsa);
nni_mtx_unlock(&ep->mtx);
return (rv);
@@ -747,6 +750,22 @@ nni_tls_ep_connect(void *arg, nni_aio *aio)
}
static int
+nni_tls_ep_getopt_url(void *arg, void *v, size_t *szp)
+{
+ nni_tls_ep *ep = arg;
+ char ustr[128];
+ char ipstr[48]; // max for IPv6 addresses including []
+ char portstr[6]; // max for 16-bit port
+
+ if (ep->mode == NNI_EP_MODE_DIAL) {
+ return (nni_getopt_str(ep->url->u_rawurl, v, szp));
+ }
+ nni_plat_tcp_ntop(&ep->bsa, ipstr, portstr);
+ snprintf(ustr, sizeof(ustr), "tls+tcp://%s:%s", ipstr, portstr);
+ return (nni_getopt_str(ustr, v, szp));
+}
+
+static int
nni_tls_ep_setopt_recvmaxsz(void *arg, const void *v, size_t sz)
{
nni_tls_ep *ep = arg;
@@ -907,6 +926,11 @@ static nni_tran_ep_option nni_tls_ep_options[] = {
.eo_setopt = nni_tls_ep_setopt_linger,
},
{
+ .eo_name = NNG_OPT_URL,
+ .eo_getopt = nni_tls_ep_getopt_url,
+ .eo_setopt = NULL,
+ },
+ {
.eo_name = NNG_OPT_TLS_CONFIG,
.eo_getopt = tls_getopt_config,
.eo_setopt = tls_setopt_config,
diff --git a/src/transport/zerotier/zerotier.c b/src/transport/zerotier/zerotier.c
index f8ed4626..4a846301 100644
--- a/src/transport/zerotier/zerotier.c
+++ b/src/transport/zerotier/zerotier.c
@@ -230,7 +230,6 @@ struct zt_ep {
uint64_t ze_nwid;
int ze_mode;
int ze_running;
- nni_sockaddr ze_addr;
uint64_t ze_raddr; // remote node address
uint64_t ze_laddr; // local node address
uint16_t ze_proto;
@@ -2557,6 +2556,21 @@ zt_ep_getopt_home(void *arg, void *data, size_t *szp)
}
static int
+zt_ep_getopt_url(void *arg, void *data, size_t *szp)
+{
+ char ustr[64]; // more than plenty
+ zt_ep * ep = arg;
+ uint64_t addr;
+
+ addr = ep->ze_mode == NNI_EP_MODE_DIAL ? ep->ze_raddr : ep->ze_laddr;
+ snprintf(ustr, sizeof(ustr), "zt://%llx.%llx:%u",
+ (unsigned long long) addr >> zt_port_shift,
+ (unsigned long long) ep->ze_nwid,
+ (unsigned) (addr & zt_port_mask));
+ return (nni_getopt_str(ustr, data, szp));
+}
+
+static int
zt_ep_setopt_orbit(void *arg, const void *data, size_t sz)
{
uint64_t moonid;
@@ -2725,6 +2739,11 @@ static nni_tran_ep_option zt_ep_options[] = {
.eo_setopt = zt_ep_setopt_recvmaxsz,
},
{
+ .eo_name = NNG_OPT_URL,
+ .eo_getopt = zt_ep_getopt_url,
+ .eo_setopt = NULL,
+ },
+ {
.eo_name = NNG_OPT_ZT_HOME,
.eo_getopt = zt_ep_getopt_home,
.eo_setopt = zt_ep_setopt_home,