OpenVPN 3 Core Library
Loading...
Searching...
No Matches
initprocess.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
// Process-wide static initialization
13
14
#pragma once
15
16
#include <thread>
17
#include <mutex>
18
19
#include <
openvpn/common/size.hpp
>
20
#include <
openvpn/common/base64.hpp
>
21
#include <
openvpn/time/time.hpp
>
22
#include <
openvpn/compress/compress.hpp
>
23
#include <
openvpn/init/cryptoinit.hpp
>
24
#include <
openvpn/init/engineinit.hpp
>
25
26
namespace
openvpn::InitProcess
{
27
class
Init
28
{
29
private
:
30
class
InitImpl
31
{
32
public
:
33
InitImpl
()
34
{
35
// initialize time base
36
Time::reset_base
();
37
38
// initialize compression
39
CompressContext::init_static
();
40
41
// init OpenSSL if included
42
init_openssl
(
"auto"
);
43
44
base64_init_static
();
45
}
46
47
~InitImpl
()
48
{
49
base64_uninit_static
();
50
}
51
52
private
:
53
// SSL library init happens when instantiated
54
crypto_init
crypto_init_
;
55
};
56
57
// process-wide singular instance
58
inline
static
std::weak_ptr<InitImpl>
init_instance
;
// GLOBAL
59
inline
static
std::mutex
the_instance_mutex
;
// GLOBAL
60
61
// istance of this class to refcount
62
std::shared_ptr<InitImpl>
initptr
;
63
64
public
:
65
Init
()
66
{
67
std::lock_guard<std::mutex> lock(
the_instance_mutex
);
68
69
initptr
=
init_instance
.lock();
70
if
(!
initptr
)
71
{
72
initptr
= std::make_shared<InitImpl>();
73
init_instance
=
initptr
;
74
}
75
}
76
77
~Init
()
78
{
79
// explicitly reset smart pointer to make the destructor run under the lock_guard
80
std::lock_guard<std::mutex> lock(
the_instance_mutex
);
81
initptr
.reset();
82
}
83
};
84
85
}
// namespace openvpn::InitProcess
base64.hpp
openvpn::CompressContext::init_static
static void init_static()
Definition
compress.hpp:523
openvpn::InitProcess::Init::InitImpl
Definition
initprocess.hpp:31
openvpn::InitProcess::Init::InitImpl::~InitImpl
~InitImpl()
Definition
initprocess.hpp:47
openvpn::InitProcess::Init::InitImpl::crypto_init_
crypto_init crypto_init_
Definition
initprocess.hpp:54
openvpn::InitProcess::Init::InitImpl::InitImpl
InitImpl()
Definition
initprocess.hpp:33
openvpn::InitProcess::Init
Definition
initprocess.hpp:28
openvpn::InitProcess::Init::init_instance
static std::weak_ptr< InitImpl > init_instance
Definition
initprocess.hpp:58
openvpn::InitProcess::Init::the_instance_mutex
static std::mutex the_instance_mutex
Definition
initprocess.hpp:59
openvpn::InitProcess::Init::initptr
std::shared_ptr< InitImpl > initptr
Definition
initprocess.hpp:62
openvpn::InitProcess::Init::Init
Init()
Definition
initprocess.hpp:65
openvpn::InitProcess::Init::~Init
~Init()
Definition
initprocess.hpp:77
openvpn::TimeType< oulong >::reset_base
static void reset_base()
Definition
time.hpp:425
openvpn::crypto_init
Definition
cryptoinit.hpp:24
compress.hpp
cryptoinit.hpp
engineinit.hpp
openvpn::InitProcess
Definition
ovpncli.hpp:34
openvpn::init_openssl
void init_openssl(const std::string &engine)
Definition
engineinit.hpp:35
openvpn::base64_uninit_static
void base64_uninit_static()
Definition
base64.hpp:310
openvpn::base64_init_static
void base64_init_static()
Definition
base64.hpp:302
size.hpp
time.hpp
openvpn
init
initprocess.hpp
Generated by
1.9.8