25#ifndef JOIN_CRYPTO_DTLS_WRAPPER_HPP
26#define JOIN_CRYPTO_DTLS_WRAPPER_HPP
36 template <
class Protocol>
37 class BasicDtlsWrapper :
public BasicTls<Protocol>
56 int nread = SSL_read (this->
_ssl.get (), buf,
static_cast<int> (len));
62 if (endpoint !=
nullptr)
64 BIO* rbio = SSL_get_rbio (this->
_ssl.get ());
71 struct sockaddr_storage sa;
72 socklen_t sa_len =
sizeof (
struct sockaddr_storage);
73 if (BIO_dgram_get_peer (rbio, &sa) <= 0)
79 *endpoint =
Endpoint (
reinterpret_cast<struct sockaddr*
> (&sa), sa_len);
85 return this->
_socket.readFrom (buf, len, endpoint);
99 BIO* wbio = SSL_get_wbio (this->
_ssl.get ());
106 struct sockaddr_storage sa;
107 socklen_t sa_len =
sizeof (
struct sockaddr_storage);
108 if (BIO_dgram_get_peer (wbio, &sa) <= 0)
114 Endpoint remote (
reinterpret_cast<struct sockaddr*
> (&sa), sa_len);
115 if (remote != endpoint)
121 int nwritten = SSL_write (this->
_ssl.get (), buf,
static_cast<int> (len));
130 return this->
_socket.writeTo (buf, len, endpoint);
ssize_t writeTo(const char *buf, size_t len, const Endpoint &endpoint) noexcept
write data on the socket.
Definition dtls_wrapper.hpp:95
typename BasicTls< Protocol >::Endpoint Endpoint
Definition dtls_wrapper.hpp:40
int ttl() const noexcept
returns the Time-To-Live value.
Definition dtls_wrapper.hpp:137
ssize_t readFrom(char *buf, size_t len, Endpoint *endpoint=nullptr) noexcept
read data on the socket.
Definition dtls_wrapper.hpp:52
basic TLS/DTLS decorator.
Definition tls.hpp:55
BasicTls(TlsContext ctx, Mode mode=Mode::NonBlocking) noexcept
create a TLS decorator with an internally created socket.
Definition tls.hpp:69
int handleTlsError(int result) noexcept
handle TLS error.
Definition tls.hpp:913
UnderlyingSocket _socket
verify certificate revocation using CRL.
Definition tls.hpp:1200
typename Protocol::Endpoint Endpoint
Definition tls.hpp:61
SslPtr _ssl
TLS handle.
Definition tls.hpp:1206
Definition acceptor.hpp:32
std::error_code make_error_code(join::Errc code) noexcept
Create an std::error_code object.
Definition error.cpp:195