Skip to content

Commit

Permalink
who actually even knows (squash)
Browse files Browse the repository at this point in the history
- do not use hops with the same /24 masked ip-address
- RPC find_cc endpoint
  • Loading branch information
dr7ana committed Nov 14, 2024
1 parent 78ce7bd commit 97410d5
Show file tree
Hide file tree
Showing 25 changed files with 186 additions and 189 deletions.
2 changes: 1 addition & 1 deletion llarp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ target_link_libraries(lokinet-wire PUBLIC lokinet-addressing)
target_link_libraries(lokinet-dns PUBLIC lokinet-utils lokinet-cryptography lokinet-config)
target_link_libraries(lokinet-nodedb PUBLIC lokinet-addressing lokinet-cryptography)
target_link_libraries(lokinet-platform PUBLIC lokinet-cryptography)
target_link_libraries(lokinet-rpc PUBLIC lokinet-wire)
target_link_libraries(lokinet-rpc PUBLIC lokinet-wire lokinet-contact)
target_link_libraries(lokinet-addressing PUBLIC lokinet-utils lokinet-cryptography lokinet-contact)
target_link_libraries(lokinet-wire PUBLIC lokinet-cryptography)
target_link_libraries(lokinet-config PUBLIC lokinet-cryptography)
Expand Down
3 changes: 2 additions & 1 deletion llarp/config/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1544,7 +1544,8 @@ namespace llarp
{
(void)params;

constexpr Default DefaultUniqueCIDR{32};
constexpr Default DefaultUniqueCIDR{24};

conf.define_option<int>(
"paths",
"unique-range-size",
Expand Down
2 changes: 1 addition & 1 deletion llarp/constants/path.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace llarp::path
constexpr std::size_t PAD_SIZE = 128;
/// default path lifetime in ms;
// TESTNET: reduced value
constexpr std::chrono::milliseconds DEFAULT_LIFETIME{5min};
constexpr std::chrono::milliseconds DEFAULT_LIFETIME{10min};
/// minimum intro lifetime we will advertise
constexpr std::chrono::milliseconds MIN_INTRO_LIFETIME = DEFAULT_LIFETIME / 2;
/// number of slices of path lifetime to spread intros out via
Expand Down
1 change: 0 additions & 1 deletion llarp/contact/keys.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

/** TODO:
- re-configure string_view and ustring_view methods after deprecating RouterID
*/

namespace llarp
Expand Down
16 changes: 5 additions & 11 deletions llarp/contact/relay_contact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,6 @@ namespace llarp
{"identity", _router_id.to_string()},
{"address", _addr.to_string()}};

// if (routerVersion)
// {
// obj["routerVersion"] = routerVersion->to_string();
// }
// std::vector<nlohmann::json> srv;
// for (const auto& record : srvRecords)
// {
// srv.emplace_back(record.ExtractStatus());
// }
// obj["srvRecords"] = srv;

return obj;
}

Expand All @@ -144,6 +133,11 @@ namespace llarp
return _addr.is_addressable();
}

bool RelayContact::has_ip_overlap(const RelayContact& other, uint8_t netmask) const
{
return (_addr.to_ipv4() / netmask).contains(other._addr.to_ipv4());
}

bool RelayContact::is_outdated(std::chrono::milliseconds now) const
{
return now >= _timestamp.time_since_epoch() + OUTDATED_AGE;
Expand Down
2 changes: 2 additions & 0 deletions llarp/contact/relay_contact.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ namespace llarp

bool is_public_addressable() const;

bool has_ip_overlap(const RelayContact& other, uint8_t netmask) const;

/// does this RC expire soon? default delta is 1 minute
bool expires_within_delta(std::chrono::milliseconds now, std::chrono::milliseconds dlt = 1min) const;

Expand Down
14 changes: 14 additions & 0 deletions llarp/handlers/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace llarp::handlers
return _router.loop();
}

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

void SessionEndpoint::tick(std::chrono::milliseconds now)
{
log::trace(logcat, "{} called", __PRETTY_FUNCTION__);
Expand All @@ -30,6 +32,18 @@ namespace llarp::handlers
_sessions.tick_outbounds(now);

path::PathHandler::tick(now);

// if (not testnet_trigger)
// {
// testnet_trigger = true;
// if (auto rclient =
// NetworkAddress::from_network_addr("4odrxxn5rekt99yb5jqksb3gncpb91s1ue56kpx58p3doen5cxey.loki"sv))
// {
// initiate_remote_exit_session(*rclient, [](ip_v) { log::critical(logcat, "FUCK YEAH"); });
// }
// else
// log::critical(logcat, "Failed to parse client netaddr!");
// }
}

bool SessionEndpoint::stop(bool send_close)
Expand Down
1 change: 0 additions & 1 deletion llarp/handlers/tun.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <llarp/address/map.hpp>
#include <llarp/dns/server.hpp>
#include <llarp/net/net.hpp>
#include <llarp/util/priority_queue.hpp>
#include <llarp/util/thread/threading.hpp>
#include <llarp/vpn/packet_router.hpp>
#include <llarp/vpn/platform.hpp>
Expand Down
1 change: 0 additions & 1 deletion llarp/link/link_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <llarp/util/compare_ptr.hpp>
#include <llarp/util/decaying_hashset.hpp>
#include <llarp/util/logging.hpp>
#include <llarp/util/priority_queue.hpp>

#include <oxen/quic.hpp>
#include <oxen/quic/format.hpp>
Expand Down
14 changes: 7 additions & 7 deletions llarp/nodedb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,14 @@ namespace llarp
return false;
}

// TODO: make this its own ticker
// purge_rcs(now);
return true;
}

void NodeDB::purge_rcs(std::chrono::milliseconds now)
{
remove_if([&](const RemoteRC& rc) -> bool {
// don't purge bootstrap nodes from nodedb
if (is_bootstrap_node(rc.router_id()))
if (is_bootstrap_node(rc))
{
log::trace(logcat, "Not removing {}: is bootstrap node", rc.router_id());
return false;
Expand Down Expand Up @@ -189,6 +187,7 @@ namespace llarp
log::debug(logcat, "Skipping check on {}: don't have whitelist yet", rc.router_id());
return false;
}

// if we have no whitelist enabled or we have
// the whitelist enabled and we got the whitelist
// check against the whitelist and remove if it's not
Expand All @@ -198,6 +197,7 @@ namespace llarp
log::debug(logcat, "Removing {}: not a valid router", rc.router_id());
return true;
}

return false;
});

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

if (process_fetched_rcs(*result))
{
log::info(logcat, "Accumulated RID's accepted by trust model");
log::info(logcat, "Accumulated RC's accepted by trust model");
return stop_rc_fetch(true);
}

Expand Down Expand Up @@ -565,9 +565,9 @@ namespace llarp
reselect_router_id_sources(fail_sources);
}

bool NodeDB::is_bootstrap_node(RouterID rid) const
bool NodeDB::is_bootstrap_node(const RemoteRC& rc) const
{
return has_bootstraps() ? _bootstraps.contains(rid) : false;
return has_bootstraps() ? _bootstraps.contains(rc) : false;
}

void NodeDB::start_tickers()
Expand All @@ -580,7 +580,7 @@ namespace llarp
});

_purge_ticker = _router.loop()->call_every(
5min, [this]() { purge_rcs(); }, not _needs_bootstrap);
PURGE_INTERVAL, [this]() mutable { purge_rcs(); }, not _needs_bootstrap);

if (not _is_service_node)
{
Expand Down
13 changes: 4 additions & 9 deletions llarp/nodedb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ namespace llarp
// TESTNET: the following constants have been shortened for testing purposes

inline constexpr auto FETCH_INTERVAL{10min};
inline constexpr auto PURGE_INTERVAL{5min};
inline constexpr auto FLUSH_INTERVAL{15min};

/* RC Fetch Constants */
// fallback to bootstrap if we have less than this many RCs
Expand Down Expand Up @@ -62,9 +64,6 @@ namespace llarp
// threshold amount of verifications to promote an unconfirmed rc/rid
inline constexpr int CONFIRMATION_THRESHOLD{3};

inline constexpr auto PURGE_INTERVAL{1min};
inline constexpr auto FLUSH_INTERVAL{15min};

template <
typename ID_t,
std::enable_if_t<std::is_same_v<ID_t, RouterID> || std::is_same_v<ID_t, RemoteRC>, int> = 0>
Expand Down Expand Up @@ -93,12 +92,9 @@ namespace llarp

Router& _router;
const fs::path _root;
// const std::function<void(std::function<void()>)> _disk_hook;

bool _is_service_node{false};

std::chrono::milliseconds _next_flush_time{};

/******** RouterID/RelayContacts ********/

using Lock_t = util::NullLock;
Expand Down Expand Up @@ -198,8 +194,7 @@ namespace llarp
return std::make_shared<NodeDB>(std::move(rootdir), r);
}

explicit NodeDB(fs::path rootdir, Router* r)
: _router{*r}, _root{std::move(rootdir)}, _next_flush_time{time_now_ms() + FLUSH_INTERVAL}
explicit NodeDB(fs::path rootdir, Router* r) : _router{*r}, _root{std::move(rootdir)}
{
_ensure_skiplist(_root);
rid_result_counters.clear();
Expand Down Expand Up @@ -242,7 +237,7 @@ namespace llarp
bool is_bootstrapping() const { return _is_bootstrapping; }
bool needs_bootstrap() const { return _needs_bootstrap; }
bool bootstrap_completed() const { return not(_is_bootstrapping or _needs_bootstrap); }
bool is_bootstrap_node(RouterID rid) const;
bool is_bootstrap_node(const RemoteRC& rc) const;
void purge_rcs(std::chrono::milliseconds now = llarp::time_now_ms());

// Bootstrap fallback fetching
Expand Down
81 changes: 1 addition & 80 deletions llarp/path/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,6 @@ namespace llarp::path
return nullptr;
}

// std::shared_ptr<TransitHop> Path::local_hop()
// {
// return _local_hop;
// }

// const std::shared_ptr<TransitHop>& Path::local_hop() const
// {
// return _local_hop;
// }

RouterID Path::upstream_rid()
{
return hops.front().router_id();
Expand Down Expand Up @@ -339,22 +329,6 @@ namespace llarp::path
return obj;
}

bool Path::SendLatencyMessage(Router*)
{
// const auto now = r->now();
// // send path latency test
// routing::PathLatencyMessage latency{};
// latency.sent_time = randint();
// latency.sequence_number = NextSeqNo();
// m_LastLatencyTestID = latency.sent_time;
// m_LastLatencyTestTime = now;
// LogDebug(name(), " send latency test id=", latency.sent_time);
// if (not SendRoutingMessage(latency, r))
// return false;
// FlushUpstream(r);
return true;
}

bool Path::update_exit(uint64_t)
{
// TODO: do we still want this concept?
Expand All @@ -372,60 +346,7 @@ namespace llarp::path
if (_is_linked)
{
}

// m_LastRXRate = m_RXRate;
// m_LastTXRate = m_TXRate;

// m_RXRate = 0;
// m_TXRate = 0;

// if (_status == PathStatus::BUILDING)
// {
// if (buildStarted == 0s)
// return;
// if (now >= buildStarted)
// {
// const auto dlt = now - buildStarted;
// if (dlt >= path::BUILD_TIMEOUT)
// {
// LogWarn(name(), " waited for ", to_string(dlt), " and no path was built");
// r->router_profiling().MarkPathFail(this);
// EnterState(PathStatus::EXPIRED, now);
// return;
// }
// }
// }
// check to see if this path is dead
// if (_status == PathStatus::ESTABLISHED)
// {
// auto dlt = now - last_latency_test;
// if (dlt > path::LATENCY_INTERVAL && last_latency_test_id == 0)
// {
// SendLatencyMessage(r);
// // latency test FEC
// r->loop()->call_later(2s, [self = shared_from_this(), r]() {
// if (self->last_latency_test_id)
// self->SendLatencyMessage(r);
// });
// return;
// }
// dlt = now - last_recv_msg;
// if (dlt >= path::ALIVE_TIMEOUT)
// {
// LogWarn(name(), " waited for ", to_string(dlt), " and path looks dead");
// r->router_profiling().MarkPathFail(this);
// EnterState(PathStatus::TIMEOUT, now);
// }
// }
// if (_status == PathStatus::IGNORE and now - last_recv_msg >= path::ALIVE_TIMEOUT)
// {
// // clean up this path as we dont use it anymore
// EnterState(PathStatus::EXPIRED, now);
// }
}

/// how long we wait for a path to become active again after it times out
// constexpr auto PathReanimationTimeout = 45s;
}

void Path::set_established()
{
Expand Down
2 changes: 0 additions & 2 deletions llarp/path/path.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,6 @@ namespace llarp

void populate_internals(const std::vector<RemoteRC>& _hops);

bool SendLatencyMessage(Router* r);

/// call obtained exit hooks
bool InformExitResult(std::chrono::milliseconds b);

Expand Down
Loading

0 comments on commit 97410d5

Please sign in to comment.