2018-07-09 04:12:43 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-07-20 04:50:28 +00:00
|
|
|
#include <llarp/buffer.h>
|
|
|
|
#include <llarp/time.h>
|
2018-08-17 19:49:58 +00:00
|
|
|
#include <memory>
|
2018-07-09 04:12:43 +00:00
|
|
|
#include <queue>
|
|
|
|
|
|
|
|
struct sendbuf_t
|
|
|
|
{
|
|
|
|
sendbuf_t(size_t s) : sz(s)
|
|
|
|
{
|
2018-07-11 16:11:19 +00:00
|
|
|
_buf = new byte_t[s];
|
2018-07-09 04:12:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~sendbuf_t()
|
|
|
|
{
|
2018-07-11 16:11:19 +00:00
|
|
|
if(_buf)
|
|
|
|
delete[] _buf;
|
2018-07-09 04:12:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t sz;
|
|
|
|
|
2018-07-20 04:50:28 +00:00
|
|
|
byte_t priority = 255;
|
|
|
|
|
2018-07-09 04:12:43 +00:00
|
|
|
size_t
|
|
|
|
size() const
|
|
|
|
{
|
|
|
|
return sz;
|
|
|
|
}
|
|
|
|
|
|
|
|
byte_t *
|
|
|
|
data()
|
|
|
|
{
|
2018-07-11 16:11:19 +00:00
|
|
|
return _buf;
|
2018-07-09 04:12:43 +00:00
|
|
|
}
|
2018-07-11 16:11:19 +00:00
|
|
|
|
2018-07-20 04:50:28 +00:00
|
|
|
llarp_buffer_t
|
|
|
|
Buffer()
|
|
|
|
{
|
|
|
|
llarp_buffer_t buf;
|
|
|
|
buf.base = _buf;
|
|
|
|
buf.sz = sz;
|
|
|
|
buf.cur = buf.base;
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct GetTime
|
|
|
|
{
|
|
|
|
llarp_time_t
|
|
|
|
operator()(const sendbuf_t *buf) const
|
|
|
|
{
|
|
|
|
return buf->timestamp;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PutTime
|
|
|
|
{
|
|
|
|
void
|
2018-08-17 19:49:58 +00:00
|
|
|
operator()(sendbuf_t *buf) const
|
2018-07-20 04:50:28 +00:00
|
|
|
{
|
|
|
|
buf->timestamp = llarp_time_now_ms();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Compare
|
|
|
|
{
|
|
|
|
bool
|
2018-08-23 12:26:31 +00:00
|
|
|
operator()(const sendbuf_t *left, const sendbuf_t *right) const
|
2018-07-20 04:50:28 +00:00
|
|
|
{
|
2018-08-23 12:26:31 +00:00
|
|
|
return left->timestamp < right->timestamp;
|
2018-07-20 04:50:28 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
llarp_time_t timestamp = 0;
|
|
|
|
|
2018-07-11 16:11:19 +00:00
|
|
|
private:
|
|
|
|
byte_t *_buf = nullptr;
|
2018-07-09 04:12:43 +00:00
|
|
|
};
|