12#ifndef OPENVPN_TRANSPORT_GREMLIN_H
13#define OPENVPN_TRANSPORT_GREMLIN_H
38 const unsigned int delay_ms)
39 :
dur(
Time::Duration::milliseconds(delay_ms)),
47 const bool empty =
events.empty();
77 func(std::move(func_arg))
102 next_event.async_wait([self =
Ptr(
this)](
const openvpn_io::error_code &error)
108 self->events.pop_front();
115 std::deque<std::unique_ptr<EventBase>>
events;
125 const std::vector<std::string> parms =
string::split(config_str,
',');
126 if (parms.size() < 4)
127 throw gremlin_error(
"need 4 comma-separated values for send_delay_ms, recv_delay_ms, send_drop_prob, recv_drop_prob");
129 throw gremlin_error(
"send_delay_ms");
131 throw gremlin_error(
"recv_delay_ms");
133 throw gremlin_error(
"send_drop_probability");
135 throw gremlin_error(
"recv_drop_probability");
140 std::ostringstream
os;
168 send->queue(std::move(func_arg));
175 recv->queue(std::move(func_arg));
195 bool flip(
const unsigned int prob)
std::size_t expires_at(const Time &t)
unsigned int send_delay_ms
std::string to_string() const
unsigned int recv_drop_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)
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