12#ifndef OPENVPN_TRANSPORT_GREMLIN_H
13#define OPENVPN_TRANSPORT_GREMLIN_H
39 const unsigned int delay_ms)
40 :
dur(
Time::Duration::milliseconds(delay_ms)),
48 const bool empty =
events.empty();
78 func(std::move(func_arg))
103 next_event.async_wait([self =
Ptr(
this)](
const openvpn_io::error_code &error)
109 self->events.pop_front();
116 std::deque<std::unique_ptr<EventBase>>
events;
126 const std::vector<std::string> parms =
string::split(config_str,
',');
127 if (parms.size() < 4)
128 throw gremlin_error(
"need at least 4 comma-separated values for send_delay_ms, recv_delay_ms, send_drop_prob, recv_drop_prob[, send_corrupt_prob]");
130 throw gremlin_error(
"send_delay_ms");
132 throw gremlin_error(
"recv_delay_ms");
134 throw gremlin_error(
"send_drop_probability");
136 throw gremlin_error(
"recv_drop_probability");
138 throw gremlin_error(
"send_corrupt_probability");
143 std::ostringstream os;
175 send->queue(std::move(func_arg));
182 recv->queue(std::move(func_arg));
201 if (!
conf->send_corrupt_probability || buf.
size() <= opcode_offset + 1)
203 const unsigned int opcode =
static_cast<unsigned int>(buf.
c_data()[opcode_offset]) >> 3;
204 constexpr unsigned int DATA_V1 = 6;
205 constexpr unsigned int DATA_V2 = 9;
206 if (opcode != DATA_V1 && opcode != DATA_V2)
210 const size_t payload_start = opcode_offset + 1;
211 const size_t idx = payload_start +
ri.
randrange(buf.
size() - payload_start);
232 bool flip(
const unsigned int prob)
std::size_t expires_at(const Time &t)
const T * c_data() const
Returns a const pointer to the start of the buffer.
size_t size() const
Returns the size of the buffer in T objects.
T * data()
Get a mutable pointer to the start of the array.
unsigned int send_delay_ms
std::string to_string() const
unsigned int recv_drop_probability
unsigned int send_corrupt_probability
unsigned int recv_delay_ms
Config(const std::string &config_str)
unsigned int send_drop_probability
SendRecvQueue(openvpn_io::io_context &io_context, const Config::Ptr &conf_arg, const bool tcp_arg)
void recv_queue(F &&func_arg)
bool flip(const unsigned int prob)
void send_queue(F &&func_arg)
void maybe_corrupt_data(Buffer &buf, const size_t opcode_offset)
Maybe flip one bit in an outgoing data-channel packet so the peer's AEAD/HMAC authentication fails.
Reference count base class for objects tracked by RCPtr. Disallows copying and assignment.
T randrange(const T end)
Return a uniformly distributed random number in the range [0, end)
#define OPENVPN_EXCEPTION(C)
std::vector< T > split(const T &str, const typename T::value_type sep, const int maxsplit=-1)
std::string trim_copy(const std::string &str)
bool parse_number(const char *str, T &retval, const bool nondigit_term=false)
virtual const Time & fire_time()=0
virtual ~EventBase()=default
const Time & fire_time() override
Event(Time fire_arg, F &&func_arg)
DelayedQueue(openvpn_io::io_context &io_context, const unsigned int delay_ms)
RCPtr< DelayedQueue > Ptr
std::deque< std::unique_ptr< EventBase > > events