Skip to content

Commit

Permalink
who? never heard of em
Browse files Browse the repository at this point in the history
  • Loading branch information
dr7ana committed Oct 22, 2024
1 parent 827ff5b commit d236b46
Show file tree
Hide file tree
Showing 66 changed files with 215 additions and 2,902 deletions.
7 changes: 0 additions & 7 deletions daemon/lokinet.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#include <llarp.hpp>
#include <llarp/config/config.hpp> // for ensure_config
// #include <llarp/constants/files.hpp>
#include <llarp/constants/platform.hpp>
#include <llarp/constants/version.hpp>
#include <llarp/ev/loop.hpp>
#include <llarp/util/exceptions.hpp>
// #include <llarp/util/logging.hpp>
#include <llarp/util/lokinet_init.h>
#include <llarp/util/thread/threading.hpp>

Expand All @@ -14,14 +12,9 @@
#include <oxen/log.hpp>

#include <csignal>
// #include <cstdlib>
// #include <iostream>
#include <memory>
// #include <optional>
#include <stdexcept>
// #include <string>
#include <thread>
// #include <utility>

#ifdef _WIN32
#include <llarp/win32/service_manager.hpp>
Expand Down
27 changes: 10 additions & 17 deletions llarp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,13 @@ lokinet_add_library(lokinet-cryptography
# Functional objects use by lokinet-core and other libraries
# needed by vpn/ router/ rpc/ handlers/ net/ link/
lokinet_add_library(lokinet-core-utils
# endpoint_base.cpp

auth/file_auth.cpp
auth/rpc_auth.cpp
auth/session_auth.cpp

handlers/session.cpp
handlers/tun.cpp

service/identity.cpp
service/info.cpp
service/intro.cpp # path
service/intro_set.cpp
service/name.cpp

vpn/egres_packet_router.cpp
)

Expand All @@ -46,8 +38,6 @@ lokinet_add_library(lokinet-core

router/router.cpp
router/route_poker.cpp

service/types.cpp

session/session.cpp
)
Expand Down Expand Up @@ -86,38 +76,41 @@ lokinet_add_library(lokinet-contact

contact/contactdb.cpp

contact/keys.cpp

contact/relay_contact.cpp
contact/relay_contact_local.cpp
contact/relay_contact_remote.cpp

contact/router_id.cpp

contact/sns.cpp

contact/tag.cpp
)

# Addressing and event loop files used by lokinet-core and other libraries
# needed by rpc/ link/ service/ config/ path/ dht/
# needed by rpc/ link/ config/ path/ dht/
lokinet_add_library(lokinet-addressing
address/address.cpp
address/ip_packet.cpp
address/ip_range.cpp
address/keys.cpp
address/utils.cpp

ev/loop.cpp
ev/tcp.cpp
ev/types.cpp
ev/udp.cpp

net/ip.cpp
net/net_int.cpp
# net/ip.cpp
# net/net_int.cpp

router_version.cpp # to be deleted shortly

service/tag.cpp
)

# lokinet-platform holds all platform specific code
lokinet_add_library(lokinet-platform
net/interface_info.cpp
# net/interface_info.cpp
vpn/packet_router.cpp
vpn/platform.cpp
)
Expand Down
4 changes: 2 additions & 2 deletions llarp/address/address.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#pragma once

#include "keys.hpp"
#include "utils.hpp"

#include <llarp/contact/keys.hpp>
#include <llarp/contact/router_id.hpp>
#include <llarp/service/name.hpp>
#include <llarp/contact/sns.hpp>
#include <llarp/util/aligned.hpp>
#include <llarp/util/concept.hpp>

Expand Down
2 changes: 0 additions & 2 deletions llarp/apple/context_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#include <llarp/util/logging/buffer.hpp>
#include <llarp/util/logging/callback_sink.hpp>

// #include <uvw/loop.h>

#include <cassert>
#include <cstdint>
#include <cstring>
Expand Down
2 changes: 1 addition & 1 deletion llarp/auth/auth.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

#include <llarp/address/address.hpp>
#include <llarp/contact/router_id.hpp>
#include <llarp/contact/tag.hpp>
#include <llarp/crypto/types.hpp>
#include <llarp/service/tag.hpp>
#include <llarp/util/concept.hpp>
#include <llarp/util/str.hpp>
#include <llarp/util/thread/threading.hpp>
Expand Down
15 changes: 7 additions & 8 deletions llarp/config/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

#include <llarp/constants/platform.hpp>
#include <llarp/constants/version.hpp>
#include <llarp/net/ip.hpp>
#include <llarp/service/name.hpp>
#include <llarp/contact/sns.hpp>
#include <llarp/util/file.hpp>
#include <llarp/util/formattable.hpp>

Expand Down Expand Up @@ -266,7 +265,7 @@ namespace llarp
const auto addr = arg.substr(0, pos);
auto auth = arg.substr(pos + 1);

if (service::is_valid_ons(addr))
if (is_valid_ons(addr))
{
ons_auth_tokens.emplace(std::move(addr), std::move(auth));
}
Expand Down Expand Up @@ -333,7 +332,7 @@ namespace llarp
if (pos != std::string::npos)
arg = arg.substr(0, pos);

if (service::is_valid_ons(arg))
if (is_valid_ons(arg))
ons_ranges.emplace(std::move(arg), std::move(*range));
else if (auto maybe_raddr = NetworkAddress::from_network_addr(arg); maybe_raddr)
ranges.emplace(std::move(*maybe_raddr), std::move(*range));
Expand Down Expand Up @@ -662,7 +661,7 @@ namespace llarp
if (pos != std::string::npos)
arg = arg.substr(0, pos);

if (service::is_valid_ons(arg))
if (is_valid_ons(arg))
_ons_ranges.emplace(std::move(arg), std::move(*range));
else if (auto maybe_raddr = NetworkAddress::from_network_addr(arg); maybe_raddr)
_exit_ranges.emplace(std::move(*maybe_raddr), std::move(*range));
Expand Down Expand Up @@ -702,7 +701,7 @@ namespace llarp
const auto addr = arg.substr(0, pos);
auto auth = arg.substr(pos + 1);

if (service::is_valid_ons(addr))
if (is_valid_ons(addr))
{
ons_exit_auths.emplace(std::move(addr), std::move(auth));
}
Expand Down Expand Up @@ -826,7 +825,7 @@ namespace llarp
auto addr_arg = arg.substr(0, pos);
auto ip_arg = arg.substr(pos + 1);

if (service::is_valid_ons(addr_arg))
if (is_valid_ons(addr_arg))
throw std::invalid_argument{"`mapaddr` cannot take an ONS entry: {}"_format(arg)};

if (auto maybe_raddr = NetworkAddress::from_network_addr(std::move(addr_arg)); maybe_raddr)
Expand Down Expand Up @@ -998,7 +997,7 @@ namespace llarp
continue;
}

if (service::is_valid_ons(*arg))
if (is_valid_ons(*arg))
{
log::warning(logcat, "{}: {}", addrmap_errorstr, "cannot accept ONS names!");
continue;
Expand Down
1 change: 0 additions & 1 deletion llarp/config/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <llarp/crypto/types.hpp>
#include <llarp/dns/srv_data.hpp>
#include <llarp/net/net.hpp>
#include <llarp/net/net_int.hpp>
#include <llarp/net/traffic_policy.hpp>
#include <llarp/util/logging.hpp>
#include <llarp/util/str.hpp>
Expand Down
13 changes: 0 additions & 13 deletions llarp/contact/client_contact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,6 @@ namespace llarp
return btdp.view().size();
}

// void ClientContact::bt_decode(std::string_view buf)
// {
// try
// {
// bt_decode(oxenc::bt_dict_consumer{buf});
// }
// catch (const std::exception& e)
// {
// log::critical(logcat, "ClientContact deserialization failed: {}", e.what());
// throw;
// }
// }

void ClientContact::bt_decode(oxenc::bt_dict_consumer&& btdc)
{
pubkey.from_string(btdc.require<std::string_view>("a"));
Expand Down
1 change: 0 additions & 1 deletion llarp/contact/client_contact.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <llarp/net/net.hpp>
#include <llarp/net/traffic_policy.hpp>
#include <llarp/router_version.hpp>
#include <llarp/service/types.hpp>
#include <llarp/util/aligned.hpp>
#include <llarp/util/buffer.hpp>
#include <llarp/util/file.hpp>
Expand Down
32 changes: 2 additions & 30 deletions llarp/contact/contactdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace llarp
ContactDB::ContactDB(Router& r) : _router{r}, _local_key{dht::Key_t::derive_from_rid(r.local_rid())}
{
timer_keepalive = std::make_shared<int>(0);
_introset_nodes = std::make_unique<dht::Bucket<dht::ISNode>>(_local_key, llarp::randint);
_cc_nodes = std::make_unique<dht::Bucket<dht::CCNode>>(_local_key, llarp::randint);
}

std::optional<ClientContact> ContactDB::get_decrypted_cc(RouterID remote) const
Expand All @@ -33,40 +33,12 @@ namespace llarp
return enc;
}

std::optional<service::IntroSetOld> ContactDB::get_decrypted_introset(RouterID remote) const
{
std::optional<service::IntroSetOld> ret = std::nullopt;

if (auto encrypted = get_encrypted_introset(dht::Key_t::derive_from_rid(remote));
auto intro = encrypted->decrypt(remote))
ret = *intro;

return ret;
}

std::optional<service::EncryptedIntroSet> ContactDB::get_encrypted_introset(const dht::Key_t& key) const
{
std::optional<service::EncryptedIntroSet> enc = std::nullopt;

auto& introsets = _introset_nodes->nodes;

if (auto itr = introsets.find(key); itr != introsets.end() && not itr->second.introset.is_expired())
enc = itr->second.introset;

return enc;
}

nlohmann::json ContactDB::ExtractStatus() const
{
nlohmann::json obj{{"services", _introset_nodes->ExtractStatus()}, {"local_key", _local_key.ToHex()}};
nlohmann::json obj{{"known_client_intros", _cc_nodes->ExtractStatus()}, {"local_key", _local_key.ToHex()}};
return obj;
}

void ContactDB::put_intro(service::EncryptedIntroSet enc)
{
_introset_nodes->put_node(std::move(enc));
}

void ContactDB::put_cc(EncryptedClientContact enc)
{
_cc_nodes->put_node(enc);
Expand Down
11 changes: 0 additions & 11 deletions llarp/contact/contactdb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ namespace llarp
Router& _router;
const dht::Key_t _local_key;

// holds introsets for remote services
std::unique_ptr<dht::Bucket<dht::ISNode>> _introset_nodes;

std::unique_ptr<dht::Bucket<dht::CCNode>> _cc_nodes;

public:
Expand All @@ -32,18 +29,10 @@ namespace llarp

std::optional<EncryptedClientContact> get_encrypted_cc(const dht::Key_t& key) const;

std::optional<service::IntroSetOld> get_decrypted_introset(RouterID remote) const;

std::optional<service::EncryptedIntroSet> get_encrypted_introset(const dht::Key_t& key) const;

nlohmann::json ExtractStatus() const;

void put_intro(service::EncryptedIntroSet enc);

void put_cc(EncryptedClientContact enc);

dht::Bucket<dht::ISNode>* services() const { return _introset_nodes.get(); }

Router* router() const { return &_router; }
};

Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion llarp/contact/router_id.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <llarp/address/keys.hpp>
#include <llarp/contact/keys.hpp>
#include <llarp/crypto/types.hpp>
#include <llarp/util/formattable.hpp>

Expand Down
Loading

0 comments on commit d236b46

Please sign in to comment.