mirror of
https://github.com/oxen-io/lokinet
synced 2023-12-14 06:53:00 +01:00
* pad messages under 1KB to 1KB to reduce jitter
* fix race
This commit is contained in:
parent
dbe4a35230
commit
e23d3a8eda
8 changed files with 34 additions and 10 deletions
|
@ -12,8 +12,12 @@
|
|||
|
||||
struct llarp_link
|
||||
{
|
||||
/*
|
||||
typedef std::mutex mtx_t;
|
||||
typedef std::lock_guard< mtx_t > lock_t;
|
||||
*/
|
||||
typedef llarp::util::DummyMutex mtx_t;
|
||||
typedef llarp::util::DummyLock lock_t;
|
||||
|
||||
llarp_router *router;
|
||||
llarp_crypto *crypto;
|
||||
|
@ -76,21 +80,21 @@ struct llarp_link
|
|||
bool
|
||||
has_intro_from(const llarp::Addr &from)
|
||||
{
|
||||
std::unique_lock< std::mutex > lock(m_PendingSessions_Mutex);
|
||||
lock_t lock(m_PendingSessions_Mutex);
|
||||
return m_PendingSessions.find(from) != m_PendingSessions.end();
|
||||
}
|
||||
|
||||
void
|
||||
put_intro_from(llarp_link_session *s)
|
||||
{
|
||||
std::unique_lock< std::mutex > lock(m_PendingSessions_Mutex);
|
||||
lock_t lock(m_PendingSessions_Mutex);
|
||||
m_PendingSessions[s->addr] = s;
|
||||
}
|
||||
|
||||
void
|
||||
remove_intro_from(const llarp::Addr &from)
|
||||
{
|
||||
std::unique_lock< std::mutex > lock(m_PendingSessions_Mutex);
|
||||
lock_t lock(m_PendingSessions_Mutex);
|
||||
m_PendingSessions.erase(from);
|
||||
}
|
||||
|
||||
|
|
|
@ -84,9 +84,10 @@ namespace llarp
|
|||
tag = tag.substr(pos + 1);
|
||||
*/
|
||||
ss << std::put_time(std::localtime(&t), "%F %T") << " " << tag;
|
||||
/*
|
||||
auto sz = tag.size() % 8;
|
||||
while(sz--)
|
||||
ss << " ";
|
||||
ss << " "; */
|
||||
ss << "\t";
|
||||
LogAppend(ss, std::forward< TArgs >(args)...);
|
||||
ss << (char)27 << "[0;0m";
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#define MAXHOPS (8)
|
||||
#define DEFAULT_PATH_LIFETIME (10 * 60 * 1000)
|
||||
#define PATH_BUILD_TIMEOUT (30 * 1000)
|
||||
#define MESSAGE_PAD_SIZE (1024)
|
||||
|
||||
struct llarp_path_hop
|
||||
{
|
||||
|
|
|
@ -282,7 +282,6 @@ void
|
|||
llarp_link_session::done()
|
||||
{
|
||||
auto logic = serv->logic;
|
||||
serv->remove_intro_from(addr);
|
||||
if(establish_job_id)
|
||||
{
|
||||
llarp_logic_remove_call(logic, establish_job_id);
|
||||
|
|
|
@ -65,6 +65,8 @@ transit_message::ack(uint32_t bitmask)
|
|||
bool
|
||||
transit_message::should_send_ack(llarp_time_t now) const
|
||||
{
|
||||
if(now < started)
|
||||
return false;
|
||||
if(msginfo.numfrags() == 0)
|
||||
return true;
|
||||
if(status.count() == 0)
|
||||
|
@ -75,12 +77,16 @@ transit_message::should_send_ack(llarp_time_t now) const
|
|||
bool
|
||||
transit_message::should_resend_xmit(llarp_time_t now) const
|
||||
{
|
||||
if(now < started)
|
||||
return false;
|
||||
return lastAck == 0 && now - started > 500;
|
||||
}
|
||||
|
||||
bool
|
||||
transit_message::should_resend_frags(llarp_time_t now) const
|
||||
{
|
||||
if(now < started)
|
||||
return false;
|
||||
return lastAck > 0 && now - lastAck > 250 && !completed();
|
||||
}
|
||||
|
||||
|
|
|
@ -406,12 +406,18 @@ namespace llarp
|
|||
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
|
||||
if(!msg->BEncode(&buf))
|
||||
return false;
|
||||
// rewind
|
||||
buf.sz = buf.cur - buf.base;
|
||||
buf.cur = buf.base;
|
||||
// make nonce
|
||||
TunnelNonce N;
|
||||
N.Randomize();
|
||||
buf.sz = buf.cur - buf.base;
|
||||
// pad smaller messages
|
||||
if(buf.sz < MESSAGE_PAD_SIZE)
|
||||
{
|
||||
// randomize padding
|
||||
r->crypto.randbytes(buf.cur, MESSAGE_PAD_SIZE - buf.sz);
|
||||
buf.sz = MESSAGE_PAD_SIZE;
|
||||
}
|
||||
buf.cur = buf.base;
|
||||
llarp::LogInfo("send ", buf.sz, " bytes via ", TXID(), " on ", Upstream(),
|
||||
" to ", Endpoint());
|
||||
return HandleUpstream(buf, N, r);
|
||||
|
|
|
@ -39,6 +39,7 @@ namespace llarp
|
|||
if(strbuf.sz != 1)
|
||||
return false;
|
||||
self->key = *strbuf.cur;
|
||||
llarp::LogInfo("handle messgae ", self->key);
|
||||
switch(self->key)
|
||||
{
|
||||
case 'L':
|
||||
|
|
|
@ -56,8 +56,14 @@ namespace llarp
|
|||
}
|
||||
TunnelNonce N;
|
||||
N.Randomize();
|
||||
// rewind
|
||||
buf.sz = buf.cur - buf.base;
|
||||
// pad smaller messages
|
||||
if(buf.sz < MESSAGE_PAD_SIZE)
|
||||
{
|
||||
// randomize padding
|
||||
r->crypto.randbytes(buf.cur, MESSAGE_PAD_SIZE - buf.sz);
|
||||
buf.sz = MESSAGE_PAD_SIZE;
|
||||
}
|
||||
buf.cur = buf.base;
|
||||
llarp::LogInfo("Send ", buf.sz,
|
||||
" bytes routing message from trasnit hop");
|
||||
|
|
Loading…
Reference in a new issue