mirror of https://github.com/oxen-io/lokinet
* path latency ticks every 5s
* retransmit xmit if we haven't gotten an ack yet (IWP)
This commit is contained in:
parent
9c57be0301
commit
8cfcc101b4
|
@ -211,6 +211,9 @@ namespace llarp
|
|||
bool
|
||||
Expired(llarp_time_t now) const;
|
||||
|
||||
void
|
||||
Tick(llarp_time_t now, llarp_router* r);
|
||||
|
||||
bool
|
||||
SendRoutingMessage(const llarp::routing::IMessage* msg, llarp_router* r);
|
||||
|
||||
|
@ -286,6 +289,10 @@ namespace llarp
|
|||
void
|
||||
BuildPaths();
|
||||
|
||||
/// called from router tick function
|
||||
void
|
||||
TickPaths();
|
||||
|
||||
/// track a path builder with this context
|
||||
void
|
||||
AddPathBuilder(llarp_pathbuilder_context* set);
|
||||
|
|
|
@ -26,6 +26,10 @@ namespace llarp
|
|||
/// @params numPaths the number of paths to maintain
|
||||
PathSet(size_t numPaths);
|
||||
|
||||
/// tick owned paths
|
||||
void
|
||||
Tick(llarp_time_t now, llarp_router* r);
|
||||
|
||||
void
|
||||
RemovePath(Path* path);
|
||||
|
||||
|
|
|
@ -251,6 +251,8 @@ namespace iwp
|
|||
|
||||
std::unordered_map< byte_t, fragment_t > frags;
|
||||
fragment_t lastfrag;
|
||||
llarp_time_t lastAck = 0;
|
||||
llarp_time_t started;
|
||||
|
||||
void
|
||||
clear()
|
||||
|
@ -277,12 +279,14 @@ namespace iwp
|
|||
transit_message(llarp_buffer_t buf, const byte_t *hash, uint64_t id,
|
||||
uint16_t mtu = 1024)
|
||||
{
|
||||
started = llarp_time_now_ms();
|
||||
put_message(buf, hash, id, mtu);
|
||||
}
|
||||
|
||||
// inbound
|
||||
transit_message(const xmit &x) : msginfo(x)
|
||||
{
|
||||
started = llarp_time_now_ms();
|
||||
byte_t fragidx = 0;
|
||||
uint16_t fragsize = x.fragsize();
|
||||
while(fragidx < x.numfrags())
|
||||
|
@ -306,14 +310,21 @@ namespace iwp
|
|||
}
|
||||
++idx;
|
||||
}
|
||||
lastAck = llarp_time_now_ms();
|
||||
}
|
||||
|
||||
bool
|
||||
should_send_ack() const
|
||||
should_send_ack(llarp_time_t now) const
|
||||
{
|
||||
if(msginfo.numfrags() == 0)
|
||||
return true;
|
||||
return status.count() % (1 + (msginfo.numfrags() / 2)) == 0;
|
||||
return now - lastAck > 250;
|
||||
}
|
||||
|
||||
bool
|
||||
should_resend_xmit(llarp_time_t now) const
|
||||
{
|
||||
return lastAck == 0 && now - started > 1000;
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -557,7 +568,7 @@ namespace iwp
|
|||
if(itr == rx.end())
|
||||
{
|
||||
llarp::Warn("no such RX fragment, msgid=", msgid);
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
auto fragsize = itr->second->msginfo.fragsize();
|
||||
if(fragsize != sz - 9)
|
||||
|
@ -578,7 +589,7 @@ namespace iwp
|
|||
push_ackfor(msgid, mask);
|
||||
return inbound_frame_complete(msgid);
|
||||
}
|
||||
else if(itr->second->should_send_ack())
|
||||
else if(itr->second->should_send_ack(llarp_time_now_ms()))
|
||||
{
|
||||
push_ackfor(msgid, mask);
|
||||
}
|
||||
|
@ -597,10 +608,14 @@ namespace iwp
|
|||
}
|
||||
|
||||
void
|
||||
retransmit()
|
||||
retransmit(llarp_time_t now)
|
||||
{
|
||||
for(auto &item : tx)
|
||||
{
|
||||
if(item.second->should_resend_xmit(now))
|
||||
{
|
||||
item.second->generate_xmit(sendqueue, txflags);
|
||||
}
|
||||
item.second->retransmit_frags(sendqueue, txflags);
|
||||
}
|
||||
}
|
||||
|
@ -1947,7 +1962,7 @@ namespace iwp
|
|||
{
|
||||
// llarp::Debug("Tick - pumping and retransmitting because we're
|
||||
// eEstablished");
|
||||
frame.retransmit();
|
||||
frame.retransmit(now);
|
||||
pump();
|
||||
PumpCryptoOutbound();
|
||||
}
|
||||
|
|
|
@ -213,7 +213,7 @@ namespace llarp
|
|||
if(itr->second->Expired(now))
|
||||
{
|
||||
TransitHop* path = itr->second;
|
||||
llarp::Info("transit path expired ", path);
|
||||
llarp::Info("transit path expired ", path->info);
|
||||
removePaths.insert(path);
|
||||
}
|
||||
++itr;
|
||||
|
@ -242,6 +242,14 @@ namespace llarp
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
PathContext::TickPaths()
|
||||
{
|
||||
auto now = llarp_time_now_ms();
|
||||
for(auto& builder : m_PathBuilders)
|
||||
builder->Tick(now, m_Router);
|
||||
}
|
||||
|
||||
void
|
||||
PathContext::AddPathBuilder(llarp_pathbuilder_context* ctx)
|
||||
{
|
||||
|
@ -266,12 +274,7 @@ namespace llarp
|
|||
hops[idx].txID.Randomize();
|
||||
hops[idx].rxID.Randomize();
|
||||
}
|
||||
/*
|
||||
for(size_t idx = (h->numHops - 1); idx > 0; --idx)
|
||||
{
|
||||
hops[idx].txID = hops[idx - 1].rxID;
|
||||
}
|
||||
*/
|
||||
|
||||
for(size_t idx = 0; idx < h->numHops - 1; ++idx)
|
||||
{
|
||||
hops[idx].txID = hops[idx + 1].rxID;
|
||||
|
@ -302,6 +305,20 @@ namespace llarp
|
|||
return hops[0].router.pubkey;
|
||||
}
|
||||
|
||||
void
|
||||
Path::Tick(llarp_time_t now, llarp_router* r)
|
||||
{
|
||||
auto dlt = now - m_LastLatencyTestTime;
|
||||
if(dlt > 5000)
|
||||
{
|
||||
llarp::routing::PathLatencyMessage latency;
|
||||
latency.T = rand();
|
||||
m_LastLatencyTestID = latency.T;
|
||||
m_LastLatencyTestTime = now;
|
||||
SendRoutingMessage(&latency, r);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
Path::HandleUpstream(llarp_buffer_t buf, const TunnelNonce& Y,
|
||||
llarp_router* r)
|
||||
|
@ -391,7 +408,7 @@ namespace llarp
|
|||
{
|
||||
// confirm that we build the path
|
||||
status = ePathEstablished;
|
||||
llarp::Info("path is confirmed rx=", RXID(), " tx=", TXID());
|
||||
llarp::Info("path is confirmed tx=", TXID(), " rx=", RXID());
|
||||
if(m_BuiltHook)
|
||||
m_BuiltHook(this);
|
||||
m_BuiltHook = nullptr;
|
||||
|
@ -401,8 +418,8 @@ namespace llarp
|
|||
m_LastLatencyTestTime = llarp_time_now_ms();
|
||||
return SendRoutingMessage(&latency, r);
|
||||
}
|
||||
llarp::Warn("got unwarrented path confirm message on rx=", RXID(),
|
||||
" tx=", TXID());
|
||||
llarp::Warn("got unwarrented path confirm message on tx=", RXID(),
|
||||
" rx=", RXID());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -413,7 +430,8 @@ namespace llarp
|
|||
if(msg->L == m_LastLatencyTestID)
|
||||
{
|
||||
Latency = llarp_time_now_ms() - m_LastLatencyTestTime;
|
||||
llarp::Info("path latency is ", Latency, " ms");
|
||||
llarp::Info("path latency is ", Latency, " ms for tx=", TXID(),
|
||||
" rx=", RXID());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -15,6 +15,18 @@ namespace llarp
|
|||
return m_Paths.size() < m_NumPaths;
|
||||
}
|
||||
|
||||
void
|
||||
PathSet::Tick(llarp_time_t now, llarp_router* r)
|
||||
{
|
||||
for(auto& item : m_Paths)
|
||||
{
|
||||
if(item.second->status == ePathEstablished)
|
||||
{
|
||||
item.second->Tick(now, r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
PathSet::ExpirePaths(llarp_time_t now)
|
||||
{
|
||||
|
@ -69,7 +81,9 @@ namespace llarp
|
|||
void
|
||||
PathSet::HandlePathBuilt(Path* path)
|
||||
{
|
||||
// TODO: implement me
|
||||
auto dlt = llarp_time_now_ms() - path->buildStarted;
|
||||
llarp::Info("Path build took ", dlt, "ms for tx=", path->TXID(),
|
||||
" rx=", path->RXID());
|
||||
}
|
||||
|
||||
} // namespace path
|
||||
|
|
|
@ -393,6 +393,7 @@ llarp_router::Tick()
|
|||
" nodes, need 3 now (will be 5 later)");
|
||||
}
|
||||
}
|
||||
paths.TickPaths();
|
||||
llarp_link_session_iter iter;
|
||||
iter.user = this;
|
||||
iter.visit = &send_padded_message;
|
||||
|
|
Loading…
Reference in New Issue