Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tls no extra resolver #1947

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions src/sp/transport/socket/sockfd.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2023 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
// Copyright 2019 Devolutions <info@devolutions.net>
//
Expand Down Expand Up @@ -60,8 +60,8 @@
nng_sockaddr src;
int refcnt; // active pipes
nni_aio *useraio;
nni_aio *connaio;
nni_aio *timeaio;
nni_aio connaio;
nni_aio timeaio;
nni_list busypipes; // busy pipes -- ones passed to socket
nni_list waitpipes; // pipes waiting to match to socket
nni_list negopipes; // pipes busy negotiating
Expand Down Expand Up @@ -666,11 +666,11 @@
return;
}
nni_mtx_unlock(&ep->mtx);
nni_aio_stop(ep->timeaio);
nni_aio_stop(ep->connaio);
nni_aio_stop(&ep->timeaio);
nni_aio_stop(&ep->connaio);
nng_stream_listener_free(ep->listener);
nni_aio_free(ep->timeaio);
nni_aio_free(ep->connaio);
nni_aio_fini(&ep->timeaio);
nni_aio_fini(&ep->connaio);

nni_mtx_fini(&ep->mtx);
NNI_FREE_STRUCT(ep);
Expand All @@ -685,7 +685,7 @@
nni_mtx_lock(&ep->mtx);

ep->closed = true;
nni_aio_close(ep->timeaio);
nni_aio_close(&ep->timeaio);
if (ep->listener != NULL) {
nng_stream_listener_close(ep->listener);
}
Expand All @@ -710,16 +710,16 @@
sfd_tran_timer_cb(void *arg)
{
sfd_tran_ep *ep = arg;
if (nni_aio_result(ep->timeaio) == 0) {
nng_stream_listener_accept(ep->listener, ep->connaio);
if (nni_aio_result(&ep->timeaio) == 0) {
nng_stream_listener_accept(ep->listener, &ep->connaio);

Check warning on line 714 in src/sp/transport/socket/sockfd.c

View check run for this annotation

Codecov / codecov/patch

src/sp/transport/socket/sockfd.c#L714

Added line #L714 was not covered by tests
}
}

static void
sfd_tran_accept_cb(void *arg)
{
sfd_tran_ep *ep = arg;
nni_aio *aio = ep->connaio;
nni_aio *aio = &ep->connaio;
sfd_tran_pipe *p;
int rv;
nng_stream *conn;
Expand All @@ -743,7 +743,7 @@
goto error;
}
sfd_tran_pipe_start(p, conn, ep);
nng_stream_listener_accept(ep->listener, ep->connaio);
nng_stream_listener_accept(ep->listener, &ep->connaio);
nni_mtx_unlock(&ep->mtx);
return;

Expand All @@ -758,12 +758,12 @@

case NNG_ENOMEM:
case NNG_ENOFILES:
nng_sleep_aio(10, ep->timeaio);
nng_sleep_aio(10, &ep->timeaio);

Check warning on line 761 in src/sp/transport/socket/sockfd.c

View check run for this annotation

Codecov / codecov/patch

src/sp/transport/socket/sockfd.c#L761

Added line #L761 was not covered by tests
break;

default:
if (!ep->closed) {
nng_stream_listener_accept(ep->listener, ep->connaio);
nng_stream_listener_accept(ep->listener, &ep->connaio);

Check warning on line 766 in src/sp/transport/socket/sockfd.c

View check run for this annotation

Codecov / codecov/patch

src/sp/transport/socket/sockfd.c#L766

Added line #L766 was not covered by tests
}
break;
}
Expand Down Expand Up @@ -819,13 +819,14 @@
return (rv);
}

if (((rv = nni_aio_alloc(&ep->connaio, sfd_tran_accept_cb, ep)) !=
0) ||
((rv = nni_aio_alloc(&ep->timeaio, sfd_tran_timer_cb, ep)) != 0) ||
((rv = nng_stream_listener_alloc_url(&ep->listener, url)) != 0)) {
nni_aio_init(&ep->connaio, sfd_tran_accept_cb, ep);
nni_aio_init(&ep->timeaio, sfd_tran_timer_cb, ep);

if ((rv = nng_stream_listener_alloc_url(&ep->listener, url)) != 0) {
sfd_tran_ep_fini(ep);
return (rv);
}

#ifdef NNG_ENABLE_STATS
nni_listener_add_stat(nlistener, &ep->st_rcv_max);
#endif
Expand Down Expand Up @@ -911,7 +912,7 @@
ep->useraio = aio;
if (!ep->started) {
ep->started = true;
nng_stream_listener_accept(ep->listener, ep->connaio);
nng_stream_listener_accept(ep->listener, &ep->connaio);
} else {
sfd_tran_ep_match(ep);
}
Expand Down
40 changes: 1 addition & 39 deletions src/sp/transport/tls/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -863,23 +863,8 @@ tlstran_ep_init_listener(void **lp, nng_url *url, nni_listener *nlistener)
{
tlstran_ep *ep;
int rv;
uint16_t af;
char *host = url->u_hostname;
nni_aio *aio;
nni_sock *sock = nni_listener_sock(nlistener);

if (strcmp(url->u_scheme, "tls+tcp") == 0) {
af = NNG_AF_UNSPEC;
} else if (strcmp(url->u_scheme, "tls+tcp4") == 0) {
af = NNG_AF_INET;
#ifdef NNG_ENABLE_IPV6
} else if (strcmp(url->u_scheme, "tls+tcp6") == 0) {
af = NNG_AF_INET6;
#endif
} else {
return (NNG_EADDRINVAL);
}

// Check for invalid URL components.
if ((strlen(url->u_path) != 0) && (strcmp(url->u_path, "/") != 0)) {
return (NNG_EADDRINVAL);
Expand All @@ -890,30 +875,7 @@ tlstran_ep_init_listener(void **lp, nng_url *url, nni_listener *nlistener)
}
if (((rv = tlstran_ep_init(&ep, url, sock)) != 0) ||
((rv = nni_aio_alloc(&ep->connaio, tlstran_accept_cb, ep)) != 0) ||
((rv = nni_aio_alloc(&ep->timeaio, tlstran_timer_cb, ep)) != 0)) {
return (rv);
}

if (strlen(host) == 0) {
host = NULL;
}

// XXX: We are doing lookup at listener initialization. There is
// a valid argument that this should be done at bind time, but that
// would require making bind asynchronous. In some ways this would
// be worse than the cost of just waiting here. We always recommend
// using local IP addresses rather than names when possible.

if ((rv = nni_aio_alloc(&aio, NULL, NULL)) != 0) {
tlstran_ep_fini(ep);
return (rv);
}
nni_resolv_ip(host, url->u_port, af, true, &ep->sa, aio);
nni_aio_wait(aio);
rv = nni_aio_result(aio);
nni_aio_free(aio);

if ((rv != 0) ||
((rv = nni_aio_alloc(&ep->timeaio, tlstran_timer_cb, ep)) != 0) ||
((rv = nng_stream_listener_alloc_url(&ep->listener, url)) != 0)) {
tlstran_ep_fini(ep);
return (rv);
Expand Down
Loading