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:
26 {
27 }
28
29 CoarseTime(const Time::Duration &pre, const Time::Duration &post)
30 : pre_(pre), post_(post)
31 {
32 }
33
34 void init(const Time::Duration &pre, const Time::Duration &post)
35 {
36 pre_ = pre;
37 post_ = post;
38 }
39
40 void reset(const Time &t)
41 {
42 time_ = t;
43 }
44 void reset()
45 {
46 time_.reset();
47 }
48
49 bool similar(const Time &t) const
50 {
51 if (time_.defined())
52 {
53 if (t >= time_)
54 return (t - time_) <= post_;
55 else
56 return (time_ - t) <= pre_;
57 }
58 else
59 return false;
60 }
61
62 private:
64 Time::Duration pre_;
65 Time::Duration post_;
66};
67
68} // namespace openvpn
69
70#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:283