OpenVPN 3 Core Library
Loading...
Searching...
No Matches
relrecv.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// Receiver side of reliability layer
13
14#ifndef OPENVPN_RELIABLE_RELRECV_H
15#define OPENVPN_RELIABLE_RELRECV_H
16
21
22namespace openvpn {
23
24template <typename PACKET>
26{
27 public:
28 OPENVPN_SIMPLE_EXCEPTION(rel_next_sequenced_not_ready);
29
31
32 class Message : public ReliableMessageBase<PACKET>
33 {
35 };
36
40 ReliableRecvTemplate(const id_t span, id_t start_at = 0)
41 {
42 init(span, start_at);
43 }
44
45 void init(const id_t span, id_t start_at = 0)
46 {
47 window_.init(start_at, span);
48 }
49
50 // Call with unsequenced packet off of the wire.
51 // Will return receive flags below.
52 enum
53 {
54 ACK_TO_SENDER = (1 << 0), // ACK for this packet should be returned to sender
55 IN_WINDOW = (1 << 1) // Packet is in-window (otherwise, packet is dropped)
56 };
57 unsigned int receive(const PACKET &packet, const id_t id)
58 {
59 unsigned int rflags;
60 if (window_.in_window(id))
61 {
62 Message &m = window_.ref_by_id(id);
63 m.id_ = id;
64 m.packet = packet;
65 rflags = ACK_TO_SENDER | IN_WINDOW;
66 }
67 else
68 rflags = window_.pre_window(id) ? ACK_TO_SENDER : 0;
69 return rflags;
70 }
71
72 // Return true if next_sequenced() is ready to return next message
73 bool ready() const
74 {
75 return window_.head_defined();
76 }
77
78 // Return next message in sequence.
79 // Requires that ready() returns true.
81 {
82 return window_.ref_head();
83 }
84
85 // Call after message returned by receive is ready to
86 // be disposed of.
87 void advance()
88 {
89 window_.rm_head_nocheck();
90 }
91
92 private:
94};
95
96} // namespace openvpn
97
98#endif // OPENVPN_RELIABLE_RELRECV_H
OPENVPN_SIMPLE_EXCEPTION(rel_next_sequenced_not_ready)
void init(const id_t span, id_t start_at=0)
Definition relrecv.hpp:45
unsigned int receive(const PACKET &packet, const id_t id)
Definition relrecv.hpp:57
ReliableRecvTemplate(const id_t span, id_t start_at=0)
Definition relrecv.hpp:40
MessageWindow< Message, id_t > window_
Definition relrecv.hpp:93
std::uint32_t id_t
Definition relcommon.hpp:22
Support deferred server-side state creation when client connects.
Definition ovpncli.cpp:95