Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extra closure methods #43

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/quic/connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ namespace oxen::quic
virtual int last_cleared() const = 0;
virtual int datagram_bufsize() const = 0;

virtual void close_connection() = 0;

virtual ~connection_interface() = default;

#ifndef NDEBUG
Expand Down Expand Up @@ -189,6 +191,8 @@ namespace oxen::quic

void send_datagram(bstring_view data, std::shared_ptr<void> keep_alive = nullptr) override;

void close_connection() override;

private:
// private Constructor (publicly construct via `make_conn` instead, so that we can properly
// set up the shared_from_this shenanigans).
Expand Down
2 changes: 2 additions & 0 deletions include/quic/endpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ namespace oxen::quic

void close_connection(Connection& conn, int code = NGTCP2_NO_ERROR, std::string_view msg = "NO_ERROR"sv);

void close_connection(ConnectionID cid, int code = NGTCP2_NO_ERROR, std::string_view msg = "NO_ERROR"sv);
tewinget marked this conversation as resolved.
Show resolved Hide resolved

const Address& local() { return _local; }

bool is_accepting() const { return _accepting_inbound; }
Expand Down
5 changes: 5 additions & 0 deletions src/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ namespace oxen::quic
event_active(packet_io_trigger.get(), 0, 0);
}

void Connection::close_connection()
{
_endpoint.call([this]() { _endpoint.close_connection(*this); });
}

void Connection::handle_conn_packet(const Packet& pkt)
{
if (auto rv = ngtcp2_conn_in_closing_period(*this); rv != 0)
Expand Down
11 changes: 11 additions & 0 deletions src/endpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,17 @@ namespace oxen::quic
return;
}

void Endpoint::close_connection(ConnectionID cid, int code, std::string_view msg)
{
for (auto& [scid, conn] : conns)
{
if (scid == cid)
return close_connection(*conn, code, msg);
}

log::warning(log_cat, "Could not find connection (CID: {}) for closure", cid);
}

void Endpoint::close_connection(Connection& conn, int code, std::string_view msg)
{
log::debug(log_cat, "Closing connection (CID: {})", *conn.scid().data);
Expand Down