diff options
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/tortls.c | 31 | ||||
-rw-r--r-- | src/common/tortls.h | 1 |
2 files changed, 32 insertions, 0 deletions
diff --git a/src/common/tortls.c b/src/common/tortls.c index 94ca81ba49..8db47a6f21 100644 --- a/src/common/tortls.c +++ b/src/common/tortls.c @@ -222,6 +222,37 @@ ssl_state_to_string(int ssl_state) return buf; } +/** DOCDOC 3116 */ +void +tor_tls_get_state_description(tor_tls_t *tls, char *buf, size_t sz) +{ + const char *ssl_state; + const char *tortls_state; + + if (PREDICT_UNLIKELY(!tls || !tls->ssl)) { + strlcpy(buf, "(No SSL object)", sz); + return; + } + + ssl_state = ssl_state_to_string(tls->ssl->state); + switch (tls->state) { +#define CASE(st) case TOR_TLS_ST_##st: tortls_state = #st ; break + CASE(HANDSHAKE); + CASE(OPEN); + CASE(GOTCLOSE); + CASE(SENTCLOSE); + CASE(CLOSED); + CASE(RENEGOTIATE); + CASE(BUFFEREVENT); +#undef CASE + default: + tortls_state = "unknown"; + break; + } + + tor_snprintf(buf, sz, "%s in %s", ssl_state, tortls_state); +} + void tor_tls_log_one_error(tor_tls_t *tls, unsigned long err, int severity, int domain, const char *doing) diff --git a/src/common/tortls.h b/src/common/tortls.h index ecb5bd2fbe..9b8108b42b 100644 --- a/src/common/tortls.h +++ b/src/common/tortls.h @@ -48,6 +48,7 @@ typedef struct tor_tls_t tor_tls_t; #define TOR_TLS_IS_ERROR(rv) ((rv) < TOR_TLS_CLOSE) const char *tor_tls_err_to_string(int err); +void tor_tls_get_state_description(tor_tls_t *tls, char *buf, size_t sz); void tor_tls_free_all(void); int tor_tls_context_init(int is_public_server, |