OpenVPN 3 Core Library
Loading...
Searching...
No Matches
generic.hpp
Go to the documentation of this file.
1// OpenVPN -- An application to securely tunnel IP networks
2// over a single port, with support for SSL/TLS-based
3// session authentication and key exchange,
4// packet encryption, packet authentication, and
5// packet compression.
6//
7// Copyright (C) 2012- OpenVPN Inc.
8//
9// SPDX-License-Identifier: MPL-2.0 OR AGPL-3.0-only WITH openvpn3-openssl-exception
10//
11
12#ifndef OPENVPN_CLIENT_ASYNC_RESOLVE_GENERIC_H
13#define OPENVPN_CLIENT_ASYNC_RESOLVE_GENERIC_H
14
16#include <openvpn/common/rc.hpp>
18
19
20namespace openvpn {
21template <typename RESOLVER_TYPE>
22class AsyncResolvable : public virtual RC<thread_unsafe_refcount>
23{
24 private:
26
27 openvpn_io::io_context &io_context;
28 RESOLVER_TYPE resolver;
29
30 public:
31 using resolver_type = RESOLVER_TYPE;
32 using results_type = typename RESOLVER_TYPE::results_type;
33
34 AsyncResolvable(openvpn_io::io_context &io_context_arg)
35 : io_context(io_context_arg),
36 resolver(io_context_arg)
37 {
38 }
39
40 virtual void resolve_callback(const openvpn_io::error_code &error,
41 results_type results) = 0;
42
43 // This implementation assumes that the i/o reactor provides an asynchronous
44 // DNS resolution routine using its own primitives and that doesn't require
45 // us to take care of any non-interruptible opration (i.e. getaddrinfo() in
46 // case of ASIO).
47 //
48 // For example, iOS implements aync_resolve using GCD and CFHost. This
49 // implementation satisfies the constraints mentioned above
50 virtual void async_resolve_name(const std::string &host, const std::string &port)
51 {
52 resolver.async_resolve(host,
53 port,
54 [self = Ptr(this)](const openvpn_io::error_code &error, results_type results)
55 {
57 self->resolve_callback(error, results); });
58 }
59
60 // no-op: needed to provide the same class signature of the ASIO version
62 {
63 }
64
66 {
67 resolver.cancel();
68 }
69};
70} // namespace openvpn
71
72#endif /* OPENVPN_CLIENT_ASYNC_RESOLVE_GENERIC_H */
#define OPENVPN_ASYNC_HANDLER
Definition bigmutex.hpp:36
RESOLVER_TYPE resolver_type
Definition asio.hpp:96
AsyncResolvable(openvpn_io::io_context &io_context_arg)
Definition generic.hpp:34
RCPtr< AsyncResolvable > Ptr
Definition generic.hpp:25
openvpn_io::io_context & io_context
Definition asio.hpp:91
typename RESOLVER_TYPE::results_type results_type
Definition asio.hpp:97
virtual void async_resolve_name(const std::string &host, const std::string &port)
Definition generic.hpp:50
virtual void resolve_callback(const openvpn_io::error_code &error, results_type results)=0
RESOLVER_TYPE resolver
Definition generic.hpp:28
The smart pointer class.
Definition rc.hpp:119
proxy_host_port port
proxy_host_port host