Skip to content

Commit

Permalink
squash
Browse files Browse the repository at this point in the history
  • Loading branch information
dr7ana committed Jan 15, 2025
1 parent f603ecb commit 2033d6b
Show file tree
Hide file tree
Showing 25 changed files with 181 additions and 227 deletions.
4 changes: 2 additions & 2 deletions llarp/contact/relay_contact_remote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace llarp
log::trace(logcat, "{}B read from file (path:{})!", nread, fname);
_payload.resize(nread);

oxenc::bt_dict_consumer btdc{_payload};
oxenc::bt_dict_consumer btdc{ustring_view{_payload}};
bt_load(btdc);
bt_verify(btdc);
}
Expand All @@ -47,7 +47,7 @@ namespace llarp

bool RemoteRC::verify() const
{
oxenc::bt_dict_consumer btdc{_payload};
oxenc::bt_dict_consumer btdc{ustring_view{_payload}};
bt_verify(btdc);
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion llarp/contact/tag.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <llarp/net/net.hpp>
// #include <llarp/net/net.hpp>
#include <llarp/util/aligned.hpp>

namespace llarp
Expand Down
4 changes: 2 additions & 2 deletions llarp/crypto/crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ namespace llarp
SharedSecret& secret,
const SymmNonce& nonce,
const RouterID& remote,
uspan payload)
std::span<uint8_t> payload)
{
// derive shared key
if (!crypto::dh_client(secret, remote, shared_key, nonce))
Expand All @@ -262,7 +262,7 @@ namespace llarp
SharedSecret& shared,
const PubKey& remote,
const SymmNonce& nonce,
uspan encrypted)
std::span<uint8_t> encrypted)
{
// derive shared secret using shared secret and our secret key (and nonce)
if (!crypto::dh_server(shared, remote, local_sk, nonce))
Expand Down
4 changes: 2 additions & 2 deletions llarp/crypto/crypto.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ namespace llarp
SharedSecret& secret,
const SymmNonce& nonce,
const RouterID& remote,
uspan payload);
std::span<uint8_t> payload);

// void derive_encrypt_outer_wrapping(
// const Ed25519SecretKey& shared_key,
Expand All @@ -85,7 +85,7 @@ namespace llarp
SharedSecret& shared,
const PubKey& remote,
const SymmNonce& nonce,
uspan encrypted);
std::span<uint8_t> encrypted);

std::array<unsigned char, 32> make_scalar(const PubKey& k, uint64_t domain);

Expand Down
4 changes: 2 additions & 2 deletions llarp/crypto/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ namespace llarp
throw std::runtime_error{"Server DH failed -- should this even ever happen?"};
}

void shared_kx_data::encrypt(uspan data)
void shared_kx_data::encrypt(std::span<uint8_t> data)
{
if (!crypto::xchacha20(data.data(), data.size(), shared_secret, nonce))
throw std::runtime_error{"xchacha20 encryption failed -- should this even ever happen?"};
}

// identical methods, separated for clarity of use/logging for now
void shared_kx_data::decrypt(uspan data)
void shared_kx_data::decrypt(std::span<uint8_t> data)
{
if (!crypto::xchacha20(data.data(), data.size(), shared_secret, nonce))
throw std::runtime_error{"xchacha20 decryption failed -- should this even ever happen?"};
Expand Down
12 changes: 6 additions & 6 deletions llarp/crypto/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ namespace llarp
explicit Ed25519PrivateData(const AlignedBuffer<64>& key_and_hash) : AlignedBuffer<64>(key_and_hash) {}

// Returns writeable access to the 32-byte Ed25519 Private Scalar
uspan scalar() { return {data(), 32}; }
std::span<uint8_t> scalar() { return {data(), 32}; }
// Returns readable access to the 32-byte Ed25519 Private Scalar
const_uspan scalar() const { return {data(), 32}; }
uspan scalar() const { return {data(), 32}; }
// Returns writeable access to the 32-byte Ed25519 Signing Hash
uspan signing_hash() { return {data() + 32, 32}; }
std::span<uint8_t> signing_hash() { return {data() + 32, 32}; }
// Returns readable access to the 32-byte Ed25519 Signing Hash
const_uspan signing_hash() const { return {data() + 32, 32}; }
uspan signing_hash() const { return {data() + 32, 32}; }

PubKey to_pubkey() const;

Expand Down Expand Up @@ -125,9 +125,9 @@ namespace llarp

void server_dh(const Ed25519SecretKey& local_sk);

void encrypt(uspan data);
void encrypt(std::span<uint8_t> data);

void decrypt(uspan enc);
void decrypt(std::span<uint8_t> enc);
};

} // namespace llarp
2 changes: 1 addition & 1 deletion llarp/dns/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace llarp::dns
return true;
}

bool MessageHeader::decode(std::span<unsigned char> b)
bool MessageHeader::decode(std::span<uint8_t> b)
{
std::memcpy(_data.data(), b.data(), sizeof(_data));
for (auto& d : _data)
Expand Down
4 changes: 2 additions & 2 deletions llarp/dns/message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace llarp

bool Decode(llarp_buffer_t* buf) override;

bool decode(std::span<unsigned char> b) override;
bool decode(std::span<uint8_t> b) override;

nlohmann::json ToJSON() const override;

Expand Down Expand Up @@ -80,7 +80,7 @@ namespace llarp

bool Decode(llarp_buffer_t* buf) override;

bool decode(std::span<unsigned char> /* b */) override { return {}; }; // TODO:
bool decode(std::span<uint8_t> /* b */) override { return {}; }; // TODO:

// Wrapper around Encode that encodes into a new buffer and returns it
std::vector<uint8_t> to_buffer() const;
Expand Down
2 changes: 1 addition & 1 deletion llarp/dns/question.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace llarp::dns

bool Decode(llarp_buffer_t* buf) override;

bool decode(std::span<unsigned char> /* b */) override { return {}; }
bool decode(std::span<uint8_t> /* b */) override { return {}; }

std::string to_string() const;

Expand Down
2 changes: 1 addition & 1 deletion llarp/dns/rr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace llarp::dns

bool Decode(llarp_buffer_t* buf) override;

bool decode(std::span<unsigned char> /* b */) override { return {}; };
bool decode(std::span<uint8_t> /* b */) override { return {}; };

nlohmann::json ToJSON() const override;

Expand Down
2 changes: 1 addition & 1 deletion llarp/dns/serialize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace llarp::dns
/// decode entity from buffer
virtual bool Decode(llarp_buffer_t* buf) = 0;

virtual bool decode(std::span<unsigned char> b) = 0;
virtual bool decode(std::span<uint8_t> b) = 0;

/// convert this whatever into json
virtual nlohmann::json ToJSON() const = 0;
Expand Down
2 changes: 1 addition & 1 deletion llarp/dns/server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace llarp::dns
virtual void send_to(
const oxen::quic::Address& to, const oxen::quic::Address& from, std::vector<uint8_t> data) const
{
send_to(to, from, IPPacket{data.data(), data.size()});
send_to(to, from, IPPacket{std::move(data)});
}

/// stop reading packets and end operation
Expand Down
45 changes: 24 additions & 21 deletions llarp/handlers/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ namespace llarp::handlers
update_and_publish_localcc(get_current_client_intros(), _srv_records);
}

// static std::atomic<bool> testnet_trigger = false;
static std::atomic<bool> testnet_trigger = false;

void SessionEndpoint::start_tickers()
{
Expand All @@ -152,25 +152,24 @@ namespace llarp::handlers
},
true);

// if (not testnet_trigger)
// {
// testnet_trigger = true;

// _router.loop()->call_later(5s, [this]() {
// try
// {
// RouterID cpk{oxenc::from_base32z("4g96taie3et7dbkumk5x6rycskaxxsgjeiunpe61469z1gsbfkuo")};
// 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");
// });
// }
// catch (const std::exception& e)
// {
// log::critical(logcat, "Failed to parse client netaddr: {}", e.what());
// }
// });
// }
if (not testnet_trigger)
{
testnet_trigger = true;

_router.loop()->call_later(5s, [this]() {
try
{
RouterID cpk{oxenc::from_base32z("acit6x8kwxdehpkzrpunw5nb8mf4w5u8tn3ojmxit9rpnhhhp81y")};
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"); });
}
catch (const std::exception& e)
{
log::critical(logcat, "Failed to parse client netaddr: {}", e.what());
}
});
}
}
else
log::info(logcat, "SessionEndpoint configured to NOT publish ClientContact...");
Expand Down Expand Up @@ -630,7 +629,11 @@ namespace llarp::handlers
if (auto maybe_ip = _router.tun_endpoint()->map_session_to_local_ip(session->remote()))
{
log::info(
logcat, "TUN device successfully routing session to remote: {}", session->remote());
logcat,
"TUN device successfully routing session (remote: {}) via local ip: {}",
session->remote(),
std::holds_alternative<ipv4>(*maybe_ip) ? std::get<ipv4>(*maybe_ip).to_string()
: std::get<ipv6>(*maybe_ip).to_string());

return hook(*maybe_ip);
}
Expand Down
8 changes: 4 additions & 4 deletions llarp/handlers/tun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ namespace llarp::handlers

auto& net_conf = _router.config()->network;

_traffic_policy = net_conf.traffic_policy;
_exit_policy = net_conf.traffic_policy;
_base_ipv6_range = net_conf._base_ipv6_range;

if (net_conf.path_alignment_timeout)
Expand Down Expand Up @@ -947,7 +947,7 @@ namespace llarp::handlers
ip_v src, dest;
auto pkt_is_ipv4 = pkt.is_ipv4();

log::trace(logcat, "outbound packet: {}: {}", pkt.info_line(), buffer_printer{pkt.uview()});
log::debug(logcat, "outbound packet: {}: {}", pkt.info_line(), buffer_printer{pkt.uview()});

if (pkt_is_ipv4)
{
Expand Down Expand Up @@ -1074,7 +1074,7 @@ namespace llarp::handlers
{
log::info(logcat, "inbound exit session pkt: {}", pkt.info_line());
// we are receiving traffic from a session to a local exit node
if (not is_allowing_traffic(pkt))
if (not _exit_policy->allow_ip_traffic(pkt))
return false;

if (pkt_is_ipv4)
Expand Down Expand Up @@ -1114,7 +1114,7 @@ namespace llarp::handlers

bool TunEndpoint::is_allowing_traffic(const IPPacket& pkt) const
{
return _traffic_policy ? _traffic_policy->allow_ip_traffic(pkt) : true;
return _exit_policy ? _exit_policy->allow_ip_traffic(pkt) : true;
}

bool TunEndpoint::has_mapping_to_remote(const NetworkAddress& addr) const
Expand Down
13 changes: 2 additions & 11 deletions llarp/handlers/tun.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace llarp::handlers

std::shared_ptr<vpn::PacketRouter> _packet_router;

std::optional<net::ExitPolicy> _traffic_policy = std::nullopt;
std::optional<net::ExitPolicy> _exit_policy = std::nullopt;

/// a file to load / store the ephemeral address map to
std::optional<fs::path> _persisting_addr_file = std::nullopt;
Expand Down Expand Up @@ -125,7 +125,7 @@ namespace llarp::handlers

bool has_if_addr() const { return true; }

std::optional<net::ExitPolicy> get_traffic_policy() const { return _traffic_policy; }
std::optional<net::ExitPolicy> get_traffic_policy() const { return _exit_policy; }

std::chrono::milliseconds get_path_alignment_timeout() const { return _path_alignment_timeout; }

Expand All @@ -144,15 +144,6 @@ namespace llarp::handlers

void start_poller();

// protected:
struct WritePacket
{
uint64_t seqno;
IPPacket pkt;

bool operator>(const WritePacket& other) const { return seqno > other.seqno; }
};

// Stores assigned IP's for each session in/out of this lokinet instance
// - Reserved local addresses is directly pre-loaded from config
// - Persisting address map is directly pre-loaded from config
Expand Down
5 changes: 3 additions & 2 deletions llarp/link/link_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace llarp
{
static auto logcat = llarp::log::Cat("lquic");

static constexpr auto static_shared_key = "Lokinet static shared secret key"_usv;
static constexpr auto static_shared_key = "Lokinet static shared secret key"_usp;

static static_secret make_static_secret(const Ed25519SecretKey& sk)
{
Expand Down Expand Up @@ -1470,7 +1470,8 @@ namespace llarp

try
{
std::tie(hop_id, nonce, payload) = ONION::deserialize_hop(oxenc::bt_dict_consumer{message});
std::tie(hop_id, nonce, payload) =
ONION::deserialize_hop(oxenc::bt_dict_consumer{bstring_view{message}});
}
catch (const std::exception& e)
{
Expand Down
4 changes: 1 addition & 3 deletions llarp/messages/exit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ namespace llarp
{
/*
TODO:
- ADD PUBKEY FIELD OR AT LEAST SEE WHY LINKMANAGER::HANDLE_OBTAIN_EXIT() LOOKS FOR ONE
- change these parameters to ustringviews and ustrings where needed after bumping oxenc
- change these parameters to uspans where needed after bumping oxenc
- change std::string sig(64, '\0') --> std::array<unsigned char, 64> sig
*/

Expand Down
Loading

0 comments on commit 2033d6b

Please sign in to comment.