OpenVPN 3 Core Library
Loading...
Searching...
No Matches
coarsetime.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_TIME_COARSETIME_H
13#define OPENVPN_TIME_COARSETIME_H
14
15#include <openvpn/time/time.hpp>
16
17namespace openvpn {
18
19// Used to compare two time objects within the accuracy limits
20// defined by pre and post.
21
23{
24 public:
25 CoarseTime() = default;
26
27 CoarseTime(const Time::Duration &pre, const Time::Duration &post)
28 : pre_(pre), post_(post)
29 {
30 }
31
32 void init(const Time::Duration &pre, const Time::Duration &post)
33 {
34 pre_ = pre;
35 post_ = post;
36 }
37
38 void reset(const Time &t)
39 {
40 time_ = t;
41 }
42 void reset()
43 {
44 time_.reset();
45 }
46
47 bool similar(const Time &t) const
48 {
49 if (time_.defined())
50 {
51 if (t >= time_)
52 return (t - time_) <= post_;
53 return (time_ - t) <= pre_;
54 }
55 return false;
56 }
57
58 private:
60 Time::Duration pre_;
61 Time::Duration post_;
62};
63
64} // namespace openvpn
65
66#endif // OPENVPN_TIME_COARSETIME_H
bool similar(const Time &t) const
CoarseTime(const Time::Duration &pre, const Time::Duration &post)
void init(const Time::Duration &pre, const Time::Duration &post)
void reset(const Time &t)
Time::Duration post_
Time::Duration pre_
bool defined() const
Definition time.hpp:280