Skip to content

Commit

Permalink
datagramio tweaking
Browse files Browse the repository at this point in the history
  • Loading branch information
dr7ana committed Dec 11, 2024
1 parent 6d54176 commit d8d794d
Show file tree
Hide file tree
Showing 16 changed files with 260 additions and 210 deletions.
17 changes: 7 additions & 10 deletions llarp/address/ip_packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,12 @@ namespace llarp
return std::nullopt;
}

NetworkPacket IPPacket::make_netpkt()
NetworkPacket IPPacket::make_netpkt() &&
{
return NetworkPacket{oxen::quic::Path{_src_addr, _dst_addr}, bview()};
bstring data{};
data.reserve(_buf.size());
std::memcpy(data.data(), _buf.data(), _buf.size());
return NetworkPacket{oxen::quic::Path{_src_addr, _dst_addr}, std::move(data)};
}

bool IPPacket::load(const uint8_t* buf, size_t len)
Expand Down Expand Up @@ -341,10 +344,7 @@ namespace llarp

std::vector<uint8_t> IPPacket::steal_buffer() &&
{
std::vector<uint8_t> b;
b.resize(size());
_buf.swap(b);
return b;
return std::move(_buf);
}

std::string IPPacket::steal_payload() &&
Expand All @@ -356,10 +356,7 @@ namespace llarp

std::vector<uint8_t> IPPacket::give_buffer()
{
std::vector<uint8_t> b;
b.resize(size());
std::memcpy(b.data(), data(), size());
return b;
return {_buf};
}

std::string IPPacket::to_string()
Expand Down
2 changes: 1 addition & 1 deletion llarp/address/ip_packet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace llarp
static IPPacket from_netpkt(NetworkPacket pkt);
static std::optional<IPPacket> from_buffer(const uint8_t* buf, size_t len);

NetworkPacket make_netpkt();
NetworkPacket make_netpkt() &&;

bool is_ipv4() const { return _is_v4; }

Expand Down
39 changes: 16 additions & 23 deletions llarp/handlers/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ namespace llarp::handlers
// _router.loop()->call_later(10s, [this]() {
// try
// {
// RouterID cpk{oxenc::from_base32z("bx13pza3snxgnccpbz1dpry6zsmspn718f9kyo9sipp3bdc848oy")};
// RouterID cpk{oxenc::from_base32z("6e9wdnd4cj3j3rgc9ze8ctxqj4z976tmu8osbzwgabruabb4u1ky")};
// log::info(logcat, "Beginning session init to client: {}", cpk.to_network_address(false));
// _initiate_session(
// NetworkAddress::from_pubkey(cpk, true), [](ip_v) { log::critical(logcat, "FUCK YEAH");
Expand Down Expand Up @@ -436,7 +436,6 @@ namespace llarp::handlers
bool use_tun)
{
bool ret = true;
// assert(path->is_client_path());

auto inbound = std::make_shared<session::InboundSession>(
initiator, std::move(path), *this, std::move(tag), use_tun, std::move(kx_data));
Expand All @@ -463,7 +462,7 @@ namespace llarp::handlers
else
{
// TODO: if this fails, we should close the session
log::warning(logcat, "TUN devcice failed to route session (remote: {}) to local ip", session->remote());
log::warning(logcat, "TUN device failed to route session (remote: {}) to local ip", session->remote());
ret = false;
}
}
Expand Down Expand Up @@ -491,7 +490,7 @@ namespace llarp::handlers
if (not path or not path->is_ready())
continue;

log::debug(logcat, "Publishing ClientContact to pivot {}", path->pivot_rid());
log::debug(logcat, "Publishing ClientContact on {}", path->hop_string());

ret &= path->publish_client_contact(ecc, [](oxen::quic::message m) {
if (m)
Expand Down Expand Up @@ -562,11 +561,6 @@ namespace llarp::handlers
- 't' : Use Tun interface (bool)
- 'u' : Authentication field
- bt-encoded dict, values TBD
TODO:
- update logic: sessions to relays do not need a shared_kx_data type
- client <-> client rely on symmetric DH across aligned paths
- client <-> relay end at the pivot
*/
void SessionEndpoint::_make_session(
NetworkAddress remote,
Expand Down Expand Up @@ -601,14 +595,24 @@ namespace llarp::handlers
path->send_path_control_message(
"path_control",
std::move(intermediate_payload),
[this, remote, tag, path, hook = std::move(cb), session_keys = std::move(kx_data)](
oxen::quic::message m) mutable {
[this,
remote,
tag,
path,
hook = std::move(cb),
session_keys = std::move(kx_data),
remote_intro = std::move(remote_intro)](oxen::quic::message m) mutable {
if (m)
{
log::critical(logcat, "Call to InitiateSession succeeded!");

auto outbound = std::make_shared<session::OutboundSession>(
remote, *this, std::move(path), std::move(tag), std::move(session_keys));
remote,
*this,
std::move(path),
std::move(tag),
std::move(session_keys),
std::move(remote_intro));

auto [session, _] = _sessions.insert_or_assign(std::move(remote), std::move(outbound));

Expand Down Expand Up @@ -697,17 +701,6 @@ namespace llarp::handlers

auto& pivot = intro.pivot_rid;

// TOTHINK: why would we ever have a path keyed to remote client intro pivot txid?
// if (auto path = _router.path_context()->get_path(intro.pivot_txid))
// {
// log::info(
// logcat,
// "Found path to pivot (rid: {}, tx_id: {}); initiating session!",
// intro.pivot_rid,
// intro.pivot_txid);
// return _make_session(std::move(remote), std::move(path), std::move(cb), is_exit);
// }

log::info(logcat, "Initiating session path-build to remote:{} via pivot:{}", remote, pivot);

auto maybe_hops = aligned_hops_to_remote(pivot);
Expand Down
8 changes: 7 additions & 1 deletion llarp/handlers/tun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <llarp/nodedb.hpp>
#include <llarp/router/route_poker.hpp>
#include <llarp/router/router.hpp>
#include <llarp/util/logging/buffer.hpp>
#include <llarp/util/str.hpp>

namespace llarp::handlers
Expand Down Expand Up @@ -995,7 +996,12 @@ namespace llarp::handlers

if (auto session = _router.session_endpoint()->get_session(remote))
{
log::debug(logcat, "Dispatching outbound packet for session (remote: {})", remote);
log::debug(
logcat,
"Dispatching outbound {}B packet for session (remote: {}): {}",
pkt.size(),
remote,
buffer_printer{pkt.uview()});
session->send_path_data_message(std::move(pkt).steal_payload());
}
else
Expand Down
Loading

0 comments on commit d8d794d

Please sign in to comment.