Sever tunnel links earlier

When we get an error on the tcp connection immediately sever the link to
the quic tunnel so that it doesn't keep trying to forward data to it.
pull/1576/head
Jason Rhinelander 3 years ago committed by Jeff Becker
parent 73572b317b
commit 233cb86191
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -242,7 +242,8 @@ namespace llarp::quic
void
data(std::shared_ptr<void> data);
// Variation of data() that holds the pointer in a weak_ptr instead of a shared_ptr.
// Variation of data() that holds the pointer in a weak_ptr instead of a shared_ptr. (Note that
// setting this replaces data() and vice versa).
void
weak_data(std::weak_ptr<void> data);

@ -56,7 +56,8 @@ namespace llarp::quic
on_incoming_data(Stream& stream, bstring_view bdata)
{
auto tcp = stream.data<uvw::TCPHandle>();
assert(tcp);
if (!tcp) return; // TCP connection is gone, which would have already sent a stream close, so just drop it.
std::string_view data{reinterpret_cast<const char*>(bdata.data()), bdata.size()};
auto peer = tcp->peer();
LogTrace(peer.ip, ":", peer.port, " ← lokinet ", buffer_printer{data});
@ -90,7 +91,11 @@ namespace llarp::quic
tcp.on<uvw::CloseEvent>([](auto&, uvw::TCPHandle& c) {
// This fires sometime after we call `close()` to signal that the close is done.
LogError("Connection closed to ", c.peer().ip, ":", c.peer().port, "; closing quic stream");
c.data<Stream>()->close();
if (auto stream = c.data<Stream>())
{
stream->close();
stream->data(nullptr);
}
c.data(nullptr);
});
tcp.on<uvw::EndEvent>([](auto&, uvw::TCPHandle& c) {
@ -109,10 +114,12 @@ namespace llarp::quic
":",
tcp.peer().port,
", shutting down quic stream");
// Failed to open connection, so close the quic stream
auto stream = tcp.data<Stream>();
if (stream)
if (auto stream = tcp.data<Stream>())
{
stream->close(tunnel::ERROR_TCP);
stream->data(nullptr);
tcp.data(nullptr);
}
tcp.closeReset();
});
tcp.on<uvw::DataEvent>(on_outgoing_data);

Loading…
Cancel
Save