more client to snode quic fixes

pull/1576/head
Jeff Becker 3 years ago
parent 0ee40c1720
commit 1ea77e6a68
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -119,6 +119,8 @@ namespace llarp
if (not quic) if (not quic)
return false; return false;
quic->receive_packet(tag, buf.underlying); quic->receive_packet(tag, buf.underlying);
m_LastActive = m_Parent->Now();
m_TxRate += buf.underlying.sz;
return true; return true;
} }
// queue overflow // queue overflow

@ -115,10 +115,10 @@ namespace llarp
} }
} }
std::vector<byte_t> data{}; if (not m_Router->ConnectionToRouterAllowed(*rid))
data.resize(payload.sz); return false;
std::copy_n(payload.base, data.size(), data.data());
ObtainSNodeSession(*rid, [data, type](auto session) { ObtainSNodeSession(*rid, [data = payload.copy(), type](auto session) {
if (session and session->IsReady()) if (session and session->IsReady())
{ {
session->SendPacketToRemote(data, type); session->SendPacketToRemote(data, type);
@ -141,20 +141,28 @@ namespace llarp
return false; return false;
if (auto* rid = std::get_if<RouterID>(&addr)) if (auto* rid = std::get_if<RouterID>(&addr))
{ {
ObtainSNodeSession( if (m_SNodeKeys.count(PubKey{*rid}) or m_Router->ConnectionToRouterAllowed(*rid))
*rid, [hook, routerID = *rid](std::shared_ptr<exit::BaseSession> session) { {
if (session and session->IsReady()) ObtainSNodeSession(
{ *rid, [hook, routerID = *rid](std::shared_ptr<exit::BaseSession> session) {
if (auto path = session->GetPathByRouter(routerID)) if (session and session->IsReady())
{ {
hook(service::ConvoTag{path->RXID().as_array()}); if (auto path = session->GetPathByRouter(routerID))
{
hook(service::ConvoTag{path->RXID().as_array()});
}
else
hook(std::nullopt);
} }
else else
hook(std::nullopt); hook(std::nullopt);
} });
else }
hook(std::nullopt); else
}); {
// probably a client
hook(GetBestConvoTagFor(addr));
}
} }
return true; return true;
} }

@ -115,6 +115,15 @@ llarp_buffer_t::read_until(char c_delim, byte_t* result, size_t resultsize)
return 0; return 0;
} }
std::vector<byte_t>
llarp_buffer_t::copy() const
{
std::vector<byte_t> copy;
copy.resize(sz);
std::copy_n(base, sz, copy.data());
return copy;
}
bool bool
operator==(const llarp_buffer_t& buff, const char* c_str) operator==(const llarp_buffer_t& buff, const char* c_str)
{ {

@ -171,6 +171,10 @@ struct llarp_buffer_t
size_t size_t
read_until(char delim, byte_t* result, size_t resultlen); read_until(char delim, byte_t* result, size_t resultlen);
/// make a copy of this buffer
std::vector<byte_t>
copy() const;
private: private:
friend struct ManagedBuffer; friend struct ManagedBuffer;
llarp_buffer_t(const llarp_buffer_t&) = default; llarp_buffer_t(const llarp_buffer_t&) = default;

Loading…
Cancel
Save