Skip to content

Commit

Permalink
following up before Tom meeting
Browse files Browse the repository at this point in the history
  • Loading branch information
dr7ana committed Oct 4, 2023
1 parent f35f7fe commit c3f157d
Show file tree
Hide file tree
Showing 19 changed files with 478 additions and 201 deletions.
8 changes: 4 additions & 4 deletions llarp/exit/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,14 @@ namespace llarp::exit
const static auto roles = llarp::path::ePathRoleExit | llarp::path::ePathRoleSVC;
if (p->SupportsAnyRoles(roles))
{
llarp::LogInfo(p->Name(), " closing exit path");
llarp::LogInfo(p->name(), " closing exit path");
routing::CloseExitMessage msg;
if (msg.Sign(m_ExitIdentity) && p->SendExitClose(msg, router))
{
p->ClearRoles(roles);
}
else
llarp::LogWarn(p->Name(), " failed to send exit close message");
llarp::LogWarn(p->name(), " failed to send exit close message");
}
};
ForEachPath(sendExitClose);
Expand All @@ -180,10 +180,10 @@ namespace llarp::exit
auto sendExitClose = [&](const path::Path_ptr p) {
if (p->SupportsAnyRoles(path::ePathRoleExit))
{
LogInfo(p->Name(), " closing exit path");
LogInfo(p->name(), " closing exit path");
routing::CloseExitMessage msg;
if (!(msg.Sign(m_ExitIdentity) && p->SendExitClose(msg, router)))
LogWarn(p->Name(), " failed to send exit close message");
LogWarn(p->name(), " failed to send exit close message");
}
};
ForEachPath(sendExitClose);
Expand Down
4 changes: 2 additions & 2 deletions llarp/exit/session.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ namespace llarp
std::string
Name() const override;

virtual void
void
SendPacketToRemote(const llarp_buffer_t& pkt, service::ProtocolType t) override;

protected:
Expand Down Expand Up @@ -239,7 +239,7 @@ namespace llarp
std::string
Name() const override;

virtual void
void
SendPacketToRemote(const llarp_buffer_t& pkt, service::ProtocolType t) override;

protected:
Expand Down
174 changes: 154 additions & 20 deletions llarp/link/link_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,24 @@ namespace llarp
std::string body,
std::function<void(oxen::quic::message m)> func)
{
// TODO: ask jason

if (not func and rpc_responses.count(endpoint))
{
func = [&](oxen::quic::message m) {
return std::invoke(rpc_responses[endpoint], this, std::move(m));
};
}

// if (func)
// {
// func = [this, f = std::move(func)](oxen::quic::message m){
// router.loop()->call([&](){
// f(m);
// });
// };
// }

return send_control_message_impl(remote, std::move(endpoint), std::move(body), std::move(func));
}

Expand All @@ -211,22 +222,14 @@ namespace llarp
if (is_stopping)
return false;

// DISCUSS: uncomment this if we want to excecute two callbacks
// auto cb = [this, f = std::move(func), endpoint](oxen::quic::message m) {
// f(m);

// if (auto itr = rpc_responses.find(endpoint); itr != rpc_responses.end())
// std::invoke(itr->second, this, std::move(m));
// };

if (auto conn = ep.get_conn(remote); conn)
{
conn->control_stream->command(endpoint, body, std::move(func));
return true;
}

router.loop()->call([&]() {
auto pending = PendingControlMessage(body, endpoint, func);
router.loop()->call([this, remote, endpoint, body, f = std::move(func)]() {
auto pending = PendingControlMessage(body, endpoint, f);

auto [itr, b] = pending_conn_msg_queue.emplace(remote, MessageQueue());
itr->second.push_back(std::move(pending));
Expand Down Expand Up @@ -547,7 +550,7 @@ namespace llarp
router.rpc_client()->lookup_ons_hash(
name_hash, [this, msg = std::move(m)](std::optional<service::EncryptedName> maybe) mutable {
if (maybe.has_value())
msg.respond(serialize_response({{"NAME", maybe->ciphertext.c_str()}}));
msg.respond(serialize_response({{"NAME", maybe->ciphertext}}));
else
msg.respond(serialize_response({{"STATUS", FindNameMessage::NOT_FOUND}}), true);
});
Expand Down Expand Up @@ -600,14 +603,14 @@ namespace llarp
LinkManager::handle_find_router(oxen::quic::message m)
{
std::string target_key;
uint64_t is_exploratory, is_iterative;
bool is_exploratory, is_iterative;

try
{
oxenc::bt_dict_consumer btdc{m.body()};

is_exploratory = btdc.require<uint64_t>("E");
is_iterative = btdc.require<uint64_t>("I");
is_exploratory = btdc.require<bool>("E");
is_iterative = btdc.require<bool>("I");
target_key = btdc.require<std::string>("K");
}
catch (const std::exception& e)
Expand Down Expand Up @@ -642,8 +645,7 @@ namespace llarp
}

m.respond(
serialize_response(
{{"STATUS", FindRouterMessage::RETRY_EXP}, {"RECIPIENT", neighbors.c_str()}}),
serialize_response({{"STATUS", FindRouterMessage::RETRY_EXP}, {"RECIPIENT", neighbors}}),
true);
}
else
Expand All @@ -661,7 +663,7 @@ namespace llarp
}
else
{
m.respond(serialize_response({{"RC", closest_rc.ToString().c_str()}}));
m.respond(serialize_response({{"RC", closest_rc.ToString()}}));
}
}
else if (not is_iterative)
Expand Down Expand Up @@ -735,6 +737,7 @@ namespace llarp
}

RouterID target{reinterpret_cast<uint8_t*>(payload.data())};

if (status == FindRouterMessage::RETRY_EXP)
{
log::critical(link_cat, "FindRouterMessage failed, retrying as exploratory!");
Expand Down Expand Up @@ -1034,6 +1037,36 @@ namespace llarp
}
}

void
LinkManager::handle_path_build(oxen::quic::message m)
{
try
{
oxenc::bt_dict_consumer btdc{m.body()};
}
catch (const std::exception& e)
{
log::warning(link_cat, "Exception: {}", e.what());
m.respond(serialize_response({{"STATUS", "EXCEPTION"}}), true);
return;
}
}

void
LinkManager::handle_path_build_response(oxen::quic::message m)
{
try
{
oxenc::bt_dict_consumer btdc{m.body()};
}
catch (const std::exception& e)
{
log::warning(link_cat, "Exception: {}", e.what());
// m.respond(serialize_response({{"STATUS", "EXCEPTION"}}), true);
return;
}
}

void
LinkManager::handle_path_confirm(oxen::quic::message m)
{
Expand All @@ -1049,6 +1082,21 @@ namespace llarp
}
}

void
LinkManager::handle_path_confirm_response(oxen::quic::message m)
{
try
{
oxenc::bt_dict_consumer btdc{m.body()};
}
catch (const std::exception& e)
{
log::warning(link_cat, "Exception: {}", e.what());
// m.respond(serialize_response({{"STATUS", "EXCEPTION"}}), true);
return;
}
}

void
LinkManager::handle_path_latency(oxen::quic::message m)
{
Expand All @@ -1065,7 +1113,37 @@ namespace llarp
}

void
LinkManager::handle_update_exit(oxen::quic::message m)
LinkManager::handle_path_latency_response(oxen::quic::message m)
{
try
{
oxenc::bt_dict_consumer btdc{m.body()};
}
catch (const std::exception& e)
{
log::warning(link_cat, "Exception: {}", e.what());
// m.respond(serialize_response({{"STATUS", "EXCEPTION"}}), true);
return;
}
}

void
LinkManager::handle_path_transfer(oxen::quic::message m)
{
try
{
oxenc::bt_dict_consumer btdc{m.body()};
}
catch (const std::exception& e)
{
log::warning(link_cat, "Exception: {}", e.what());
m.respond(serialize_response({{"STATUS", "EXCEPTION"}}), true);
return;
}
}

void
LinkManager::handle_path_transfer_response(oxen::quic::message m)
{
try
{
Expand Down Expand Up @@ -1108,6 +1186,51 @@ namespace llarp
// auto handler = router.path_context().GetByDownstream(target, tx_id);
}

void
LinkManager::handle_obtain_exit_response(oxen::quic::message m)
{
try
{
oxenc::bt_dict_consumer btdc{m.body()};
}
catch (const std::exception& e)
{
log::warning(link_cat, "Exception: {}", e.what());
m.respond(serialize_response({{"STATUS", "EXCEPTION"}}), true);
return;
}
}

void
LinkManager::handle_update_exit(oxen::quic::message m)
{
try
{
oxenc::bt_dict_consumer btdc{m.body()};
}
catch (const std::exception& e)
{
log::warning(link_cat, "Exception: {}", e.what());
m.respond(serialize_response({{"STATUS", "EXCEPTION"}}), true);
return;
}
}

void
LinkManager::handle_update_exit_response(oxen::quic::message m)
{
try
{
oxenc::bt_dict_consumer btdc{m.body()};
}
catch (const std::exception& e)
{
log::warning(link_cat, "Exception: {}", e.what());
m.respond(serialize_response({{"STATUS", "EXCEPTION"}}), true);
return;
}
}

void
LinkManager::handle_close_exit(oxen::quic::message m)
{
Expand All @@ -1124,6 +1247,17 @@ namespace llarp
}

void
LinkManager::handle_path_build(oxen::quic::message)
{}
LinkManager::handle_close_exit_response(oxen::quic::message m)
{
try
{
oxenc::bt_dict_consumer btdc{m.body()};
}
catch (const std::exception& e)
{
log::warning(link_cat, "Exception: {}", e.what());
m.respond(serialize_response({{"STATUS", "EXCEPTION"}}), true);
return;
}
}
} // namespace llarp
4 changes: 3 additions & 1 deletion llarp/link/link_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,11 @@ namespace llarp

// Path messages
void handle_path_build(oxen::quic::message); // relay
void handle_relay_status(oxen::quic::message); // relay
void handle_path_confirm(oxen::quic::message); // relay
void handle_path_latency(oxen::quic::message); // relay
void handle_path_transfer(oxen::quic::message); // relay
void handle_relay_commit(oxen::quic::message); // relay
void handle_relay_status(oxen::quic::message); // relay

// Exit messages
void handle_obtain_exit(oxen::quic::message); // relay
Expand All @@ -319,6 +320,7 @@ namespace llarp

// Path responses
void handle_path_build_response(oxen::quic::message);
void handle_relay_commit_response(oxen::quic::message);
void handle_relay_status_response(oxen::quic::message);
void handle_path_confirm_response(oxen::quic::message);
void handle_path_latency_response(oxen::quic::message);
Expand Down
1 change: 1 addition & 0 deletions llarp/messages/common.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <llarp/crypto/crypto.hpp>
#include <llarp/dht/key.hpp>
#include <llarp/path/path_types.hpp>
#include <llarp/router_id.hpp>
Expand Down

0 comments on commit c3f157d

Please sign in to comment.