Add more checks and logging

Most of the logging here is Trace level so needs a Debug build to not
get compiled away.
pull/1576/head
Jason Rhinelander 3 years ago committed by Jeff Becker
parent 44fc941c32
commit 183abd58aa
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -185,9 +185,15 @@ namespace llarp::quic
std::memcpy(&buf_[header_size], data.data(), data.size());
bstring_view outgoing{buf_.data(), outgoing_len};
service_endpoint.SendToOrQueue(to, outgoing, service::ProtocolType::QUIC);
LogDebug("[", to, "]: sent ", outgoing.size(), " bytes");
LogTrace("Full quic data: ", buffer_printer{outgoing});
if (service_endpoint.SendToOrQueue(to, outgoing, service::ProtocolType::QUIC))
{
LogDebug("[", to, "]: sent ", outgoing.size(), " bytes");
LogTrace("Full quic data: ", buffer_printer{outgoing});
}
else
{
LogDebug("Failed to send to quic endpoint ", to, "; was sending ", outgoing.size(), "B");
}
return {};
}

@ -603,6 +603,7 @@ namespace llarp::quic
quic::Endpoint* ep = nullptr;
if (type == CLIENT_TO_SERVER)
{
LogTrace("packet is client-to-server from client pport ", pseudo_port);
// Client-to-server: the header port is the return port
remote.setPort(pseudo_port);
if (!server_)
@ -614,6 +615,7 @@ namespace llarp::quic
}
else if (type == SERVER_TO_CLIENT)
{
LogTrace("packet is server-to-client to client pport ", pseudo_port);
// Server-to-client: the header port tells us which client tunnel this is going to
if (auto it = client_tunnels_.find(pseudo_port); it != client_tunnels_.end())
ep = it->second.client.get();
@ -627,7 +629,10 @@ namespace llarp::quic
// The server doesn't send back the port because we already know it 1-to-1 from our outgoing
// connection.
if (auto conn = static_cast<quic::Client&>(*ep).get_connection())
{
remote.setPort(conn->path.remote.port());
LogTrace("remote port is ", remote.getPort());
}
else
{
LogWarn("Incoming quic to a quic::Client without an active quic::Connection; dropping");

@ -1355,18 +1355,22 @@ namespace llarp
Endpoint::SendToOrQueue(ConvoTag tag, const llarp_buffer_t& pkt, ProtocolType t)
{
if (tag.IsZero())
{
LogWarn("SendToOrQueue failed: convo tag is zero");
return false;
LogWarn("sent to tag T=", tag);
}
if (auto maybe = GetEndpointWithConvoTag(tag))
{
return SendToOrQueue(*maybe, pkt, t);
}
LogDebug("SendToOrQueue failed: no endpoint for convo tag ", tag);
return false;
}
bool
Endpoint::SendToOrQueue(const RouterID& addr, const llarp_buffer_t& buf, ProtocolType t)
{
LogTrace("SendToOrQueue: sending to snode ", addr);
auto pkt = std::make_shared<net::IPPacket>();
if (!pkt->Load(buf))
return false;
@ -1484,13 +1488,18 @@ namespace llarp
bool
Endpoint::SendToOrQueue(const Address& remote, const llarp_buffer_t& data, ProtocolType t)
{
LogTrace("SendToOrQueue: sending to address ", remote);
if (data.sz == 0)
{
LogTrace("SendToOrQueue: dropping because data.sz == 0");
return false;
// inbound converstation
}
// inbound conversation
const auto now = Now();
if (HasInboundConvo(remote))
{
LogTrace("Have inbound convo");
auto transfer = std::make_shared<routing::PathTransferMessage>();
ProtocolFrame& f = transfer->T;
f.R = 0;
@ -1562,25 +1571,34 @@ namespace llarp
});
return true;
}
else
{
LogTrace("SendToOrQueue failed to return via inbound: no path");
}
}
else
{
LogWarn("Have inbound convo but get-best returned none; bug?");
}
}
else
{
LogTrace("Not an inbound convo");
auto& sessions = m_state->m_RemoteSessions;
auto range = sessions.equal_range(remote);
auto itr = range.first;
while (itr != range.second)
for (auto itr = range.first; itr != range.second; ++itr)
{
if (itr->second->ReadyToSend())
{
LogTrace("Found an inbound session to use to reach ", remote);
itr->second->AsyncEncryptAndSendTo(data, t);
return true;
}
++itr;
}
// if we want to make an outbound session
if (WantsOutboundSession(remote))
{
LogTrace("Making an outbound session and queuing the data");
// add pending traffic
auto& traffic = m_state->m_PendingTraffic;
traffic[remote].emplace_back(data, t);
@ -1603,6 +1621,10 @@ namespace llarp
1500ms);
return true;
}
else
{
LogDebug("SendOrQueue failed: no inbound/outbound sessions");
}
}
return false;
}

Loading…
Cancel
Save