odissey: add tls support for auto-cancel
#include "od_cancel.h"
#include "od_fe.h"
#include "od_be.h"
+#include "od_tls.h"
static inline int
od_cancel_cmp(od_server_t *server, void *arg)
@@ -56,7 +57,8 @@ int od_cancel_of(od_pooler_t *pooler,
/* resolve server address */
machine_io_t resolver_context = machine_create_io(pooler->env);
if (resolver_context == NULL) {
- od_error(&pooler->od->log, NULL, "failed to resolve %s:%d",
+ od_error(&pooler->od->log, NULL,
+ "failed to resolve %s:%d",
server_scheme->host,
server_scheme->port);
return -1;
@@ -69,7 +71,8 @@ int od_cancel_of(od_pooler_t *pooler,
server_scheme->host, port, NULL, &ai, 0);
machine_close(resolver_context);
if (rc < 0) {
- od_error(&pooler->od->log, NULL, "failed to resolve %s:%d",
+ od_error(&pooler->od->log, NULL,
+ "failed to resolve %s:%d",
server_scheme->host,
server_scheme->port);
return -1;
@@ -84,19 +87,47 @@ int od_cancel_of(od_pooler_t *pooler,
rc = machine_connect(io, ai->ai_addr, 0);
freeaddrinfo(ai);
if (rc < 0) {
- od_error(&pooler->od->log, NULL, "(cancel) failed to connect to %s:%d",
+ od_error(&pooler->od->log, NULL,
+ "(cancel) failed to connect to %s:%d",
server_scheme->host,
server_scheme->port);
machine_close(io);
return -1;
}
- /* send cancel and disconnect */
so_stream_t stream;
so_stream_init(&stream);
+
+ /* handle tls connection */
+ machine_tls_t tls = NULL;
+ if (server_scheme->tls_verify != OD_TDISABLE) {
+ tls = od_tlsbe(pooler->env, server_scheme);
+ if (tls == NULL) {
+ od_error(&pooler->od->log, NULL,
+ "(cancel) failed to create tls context",
+ server_scheme->host,
+ server_scheme->port);
+ machine_close(io);
+ return -1;
+ }
+ rc = od_tlsbe_connect(pooler->env, io, tls,
+ &stream,
+ &pooler->od->log, "(cancel)",
+ server_scheme);
+ if (rc == -1) {
+ machine_close(io);
+ machine_free_tls(tls);
+ so_stream_free(&stream);
+ return -1;
+ }
+ }
+
+ /* send cancel and disconnect */
rc = so_fewrite_cancel(&stream, key->key_pid, key->key);
if (rc == -1) {
machine_close(io);
+ if (tls)
+ machine_free_tls(tls);
so_stream_free(&stream);
return -1;
}
@@ -106,6 +137,8 @@ int od_cancel_of(od_pooler_t *pooler,
machine_error(io));
}
machine_close(io);
+ if (tls)
+ machine_free_tls(tls);
so_stream_free(&stream);
return 0;
}
