Skip to content

Commit 4d9d97d

Browse files
committed
More efficient internals RE path rotation/sessions/clientcontacts
1 parent 4df3e42 commit 4d9d97d

21 files changed

+275
-262
lines changed

llarp/bootstrap.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ namespace llarp
119119
// TESTNET: force load fallbacks
120120
if (/* empty() and */ load_fallbacks)
121121
{
122-
// log::critical(logcat, "BootstrapRC list empty; loading fallbacks...");
123-
log::critical(logcat, "BootstrapRC list force loading fallbacks...");
122+
log::info(logcat, "BootstrapRC list force loading fallbacks...");
124123
auto fallbacks = llarp::load_bootstrap_fallbacks();
125124

126125
if (auto itr = fallbacks.find(RelayContact::ACTIVE_NETID); itr != fallbacks.end())

llarp/contact/client_contact.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ namespace llarp
175175

176176
EncryptedClientContact EncryptedClientContact::deserialize(std::string_view buf)
177177
{
178-
log::info(logcat, "Deserializing EncryptedClientContact...");
178+
log::trace(logcat, "Deserializing EncryptedClientContact...");
179179
return EncryptedClientContact{buf};
180180
}
181181

@@ -271,7 +271,7 @@ namespace llarp
271271
return false;
272272
}
273273

274-
log::info(logcat, "Successfully verified EncryptedClientContact!");
274+
log::trace(logcat, "Successfully verified EncryptedClientContact!");
275275

276276
return true;
277277
}

llarp/contact/client_contact.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace llarp
3232
}
3333

3434
// TESTNET:
35-
inline static constexpr auto CC_PUBLISH_INTERVAL{2min};
35+
inline static constexpr auto CC_PUBLISH_INTERVAL{5min};
3636

3737
/** ClientContact
3838
On the wire we encode the data as a dict containing:

llarp/contact/contactdb.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace llarp
3636
{
3737
_router.loop()->call_later(approximate_time(5s, 5), [&]() {
3838
purge_ccs();
39-
log::debug(logcat, "ContactDB starting purge ticker..");
39+
log::trace(logcat, "ContactDB starting purge ticker..");
4040
_purge_ticker = _router.loop()->call_every(
4141
5min, [this]() mutable { purge_ccs(); }, true);
4242
});
@@ -66,7 +66,7 @@ namespace llarp
6666
}
6767

6868
if (n)
69-
log::info(logcat, "{} expired ClientContacts purged!", n);
69+
log::debug(logcat, "{} expired ClientContacts purged!", n);
7070
}
7171

7272
void ContactDB::put_cc(EncryptedClientContact enc)

llarp/handlers/session.cpp

+17-17
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ namespace llarp::handlers
8080
path::PathHandler::tick(now);
8181
}
8282

83-
bool SessionEndpoint::stop(bool send_close)
83+
void SessionEndpoint::stop(bool send_close)
8484
{
8585
log::trace(logcat, "{} called", __PRETTY_FUNCTION__);
8686

@@ -98,7 +98,6 @@ namespace llarp::handlers
9898

9999
_router.loop()->call([&]() mutable {
100100
_sessions.for_each([](std::shared_ptr<session::BaseSession>& s) { s->send_path_close(); });
101-
102101
prom.set_value();
103102
});
104103

@@ -108,7 +107,7 @@ namespace llarp::handlers
108107

109108
_sessions.clear_sessions();
110109

111-
return path::PathHandler::stop();
110+
path::PathHandler::stop();
112111
}
113112

114113
void SessionEndpoint::configure()
@@ -132,18 +131,18 @@ namespace llarp::handlers
132131
client_contact.SRVs = _srv_records;
133132
}
134133

135-
if (use_tokens = not net_config.auth_static_tokens.empty(); use_tokens)
134+
if (_use_tokens = not net_config.auth_static_tokens.empty(); _use_tokens)
136135
_static_auth_tokens.merge(net_config.auth_static_tokens);
137136

138-
if (use_whitelist = not net_config.auth_whitelist.empty(); use_whitelist)
137+
if (_use_whitelist = not net_config.auth_whitelist.empty(); _use_whitelist)
139138
_auth_whitelist.merge(net_config.auth_whitelist);
140139

141140
_if_name = *net_config._if_name;
142141
_local_range = *net_config._local_ip_range;
143142
_local_addr = *net_config._local_addr;
144143
_local_base_ip = *net_config._local_base_ip;
145144

146-
_is_v4 = _local_range.is_ipv4();
145+
_ipv6_enabled = net_config.enable_ipv6;
147146

148147
// TESTNET: TODO: check if ipv6 is disabled
149148
for (auto& [addr, range] : net_config._exit_ranges)
@@ -159,8 +158,9 @@ namespace llarp::handlers
159158
// always accept ipv4 (currently)
160159
uint8_t protoflags = meta::to_underlying(protocol_flag::IPV4);
161160

162-
if (!_is_v4)
161+
if (_ipv6_enabled)
163162
protoflags |= meta::to_underlying(protocol_flag::IPV6);
163+
164164
// if we are a full client, we accept standard and tunneled (QUICTUN) traffic
165165
if (_router.using_tun_if())
166166
protoflags |= meta::to_underlying(protocol_flag::QUICTUN);
@@ -192,7 +192,7 @@ namespace llarp::handlers
192192

193193
void SessionEndpoint::rotate_paths()
194194
{
195-
log::debug(logcat, "{} called", __PRETTY_FUNCTION__);
195+
log::trace(logcat, "{} called", __PRETTY_FUNCTION__);
196196

197197
Lock_t l{paths_mutex};
198198

@@ -208,6 +208,7 @@ namespace llarp::handlers
208208
[this](auto new_path) mutable {
209209
path_build_succeeded(new_path);
210210
drop_oldest_path();
211+
log::info(logcat, "SessionEndpoint successfully rotated in new path: {}", new_path->to_string());
211212
update_and_publish_localcc();
212213
},
213214
[this](auto new_path, int ec) mutable { path_build_failed(std::move(new_path), ec); });
@@ -240,17 +241,11 @@ namespace llarp::handlers
240241
size_t count{0};
241242
log::debug(logcat, "SessionEndpoint building {} paths to random remotes (needed: {})", n, num_paths_desired);
242243

243-
// TESTNET: ensure one path is built to pivot
244-
// RouterID pivot{oxenc::from_base32z("55fxrybf3jtausbnmxpgwcsz9t8qkf5pr8t5f4xyto4omjrkorpy")};
245-
// count += build_path_aligned_to_remote(pivot);
246-
247244
while (count < n)
248245
count += build_path_to_random();
249246

250247
if (count == n)
251-
{
252248
log::debug(logcat, "SessionEndpoint successfully initiated {} path-builds", n);
253-
}
254249
else
255250
log::warning(logcat, "SessionEndpoint only initiated {} path-builds (needed: {})", count, n);
256251
}
@@ -270,7 +265,12 @@ namespace llarp::handlers
270265
_router.loop()->call_later(approximate_time(5s, 5), [&]() {
271266
update_and_publish_localcc();
272267
_cc_publisher = _router.loop()->call_every(
273-
CC_PUBLISH_INTERVAL, [this]() mutable { update_and_publish_localcc(); }, true);
268+
CC_PUBLISH_INTERVAL,
269+
[/* this */]() mutable {
270+
log::critical(logcat, "TESTNET: Skipping ClientContact publish!");
271+
// update_and_publish_localcc();
272+
},
273+
true);
274274
});
275275
}
276276
else
@@ -523,10 +523,10 @@ namespace llarp::handlers
523523
{
524524
bool ret{true};
525525

526-
if (use_tokens)
526+
if (_use_tokens)
527527
ret &= _static_auth_tokens.contains(*maybe_auth);
528528

529-
if (use_whitelist)
529+
if (_use_whitelist)
530530
ret &= _auth_whitelist.contains(remote);
531531

532532
return ret;

llarp/handlers/session.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,16 @@ namespace llarp
5151
// whitelist for authenticating inbound sessions
5252
std::unordered_set<NetworkAddress> _auth_whitelist;
5353

54-
bool use_tokens{false};
55-
bool use_whitelist{false};
54+
bool _use_tokens{false};
55+
bool _use_whitelist{false};
5656

5757
IPRange _local_range;
5858
oxen::quic::Address _local_addr;
5959
ip_v _local_base_ip;
6060
ip_v _next_ip;
6161
std::string _if_name;
6262

63-
bool _is_v4;
63+
bool _ipv6_enabled{};
6464

6565
std::optional<std::string_view> fetch_auth_token(const NetworkAddress& remote) const;
6666

@@ -86,7 +86,7 @@ namespace llarp
8686

8787
void configure();
8888

89-
bool stop(bool send_close = false) override;
89+
void stop(bool send_close = false) override;
9090

9191
void build_more(size_t n = 0) override;
9292

llarp/handlers/tun.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ namespace llarp::handlers
4242

4343
/// list of strict connect addresses for hooks
4444
// std::vector<IpAddress> _strict_connect_addrs;
45+
4546
/// use v6?
4647
bool ipv6_enabled{};
4748

llarp/link/link_manager.cpp

+4-21
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ namespace llarp
665665
std::move(func));
666666
rv)
667667
{
668-
log::info(logcat, "Begun establishing connection to {}", remote_addr);
668+
log::debug(logcat, "Begun establishing connection to {}", remote_addr);
669669
return;
670670
}
671671

@@ -693,7 +693,7 @@ namespace llarp
693693
KeyedAddress{rid.to_view(), remote_addr}, rid, std::move(on_open), std::move(on_close));
694694
rv)
695695
{
696-
log::info(logcat, "Begun establishing connection to {}", remote_addr);
696+
log::debug(logcat, "Begun establishing connection to {}", remote_addr);
697697
return;
698698
}
699699
log::warning(logcat, "Failed to begin establishing connection to {}", remote_addr);
@@ -707,7 +707,7 @@ namespace llarp
707707

708708
void LinkManager::close_all_links()
709709
{
710-
log::info(logcat, "Closing all connections...");
710+
log::debug(logcat, "Closing all connections...");
711711

712712
std::promise<void> p;
713713
auto f = p.get_future();
@@ -735,7 +735,6 @@ namespace llarp
735735
is_stopping = true;
736736
quic->set_shutdown_immediate();
737737
quic.reset();
738-
// ep.reset();
739738
}
740739

741740
void LinkManager::set_conn_persist(const RouterID& remote, std::chrono::milliseconds until)
@@ -1034,17 +1033,6 @@ namespace llarp
10341033
});
10351034
}
10361035

1037-
[[deprecated]] void LinkManager::fetch_router_ids(
1038-
const RouterID& via, std::string payload, bt_control_response_hook func)
1039-
{
1040-
// this handler should not be registered for service nodes
1041-
assert(not _router.is_service_node());
1042-
1043-
log::trace(logcat, "payload: {}", payload);
1044-
1045-
send_control_message(via, "fetch_rids", std::move(payload), std::move(func));
1046-
}
1047-
10481036
void LinkManager::handle_fetch_router_ids(oxen::quic::message m)
10491037
{
10501038
log::debug(logcat, "Handling FetchRIDs request...");
@@ -1189,8 +1177,7 @@ namespace llarp
11891177
_router.contact_db().put_cc(std::move(enc));
11901178

11911179
if (session->is_outbound())
1192-
std::dynamic_pointer_cast<session::OutboundSession>(session)->update_remote_intros(
1193-
std::move(*intro).take_intros());
1180+
session::OutboundSession::upcast(session)->update_remote_intros(std::move(*intro).take_intros());
11941181

11951182
return m.respond(messages::OK_RESPONSE);
11961183
}
@@ -1215,10 +1202,6 @@ namespace llarp
12151202
auto closest_rcs = _router.node_db()->find_many_closest_to(dht_key, path::DEFAULT_PATHS_HELD);
12161203
const auto& closest_peer = closest_rcs.begin()->router_id();
12171204

1218-
// TESTNET: testing this method
1219-
auto other_closest = _router.node_db()->find_closest_to(dht_key).router_id();
1220-
log::info(logcat, "First-closest and closest are {}EQUAL", closest_peer == other_closest ? "" : "NOT ");
1221-
12221205
for (const auto& rc : closest_rcs)
12231206
{
12241207
auto& _rid = rc.router_id();

llarp/link/link_manager.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ namespace llarp
178178

179179
void fetch_router_ids(const RouterID& via, bt_control_send_hook send_hook);
180180

181-
void fetch_router_ids(const RouterID& via, std::string payload, bt_control_response_hook func);
181+
// void fetch_router_ids(const RouterID& via, std::string payload, bt_control_response_hook func);
182182

183183
void handle_fetch_router_ids(oxen::quic::message);
184184

@@ -325,7 +325,7 @@ namespace llarp
325325
[this, itr, rid, ep = std::move(ep), body = std::move(body), func = std::move(func)](
326326
oxen::quic::connection_interface& ci) mutable {
327327
auto& control_stream = itr->second->control_stream;
328-
log::debug(
328+
log::trace(
329329
logcat,
330330
"{} dispatching {} on outbound connection to remote (rid:{})",
331331
_is_service_node ? "Relay" : "Client",
@@ -343,7 +343,7 @@ namespace llarp
343343
itr->second =
344344
std::make_shared<link::Connection>(std::move(conn_interface), std::move(control_stream));
345345

346-
log::info(logcat, "Outbound connection to RID:{} added to service conns...", rid);
346+
log::trace(logcat, "Outbound connection to RID:{} added to service conns...", rid);
347347
return true;
348348
}
349349
catch (const std::exception& e)
@@ -388,7 +388,7 @@ namespace llarp
388388
itr->second =
389389
std::make_shared<link::Connection>(std::move(conn_interface), std::move(control_stream));
390390

391-
log::info(logcat, "Outbound connection to RID:{} added to service conns...", rid.short_string());
391+
log::trace(logcat, "Outbound connection to RID:{} added to service conns...", rid.short_string());
392392
return true;
393393
}
394394
catch (...)

llarp/net/posix.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,10 @@ namespace llarp::net
9292
oxen::quic::Address addr{i->ifa_addr};
9393
auto nma = reinterpret_cast<sockaddr_in*>(i->ifa_netmask)->sin_addr.s_addr;
9494
auto m = std::popcount(nma);
95-
log::debug(
95+
log::trace(
9696
logcat, "Adding {} {} (mask={}) to current ranges", addr.is_ipv4() ? "ipv4" : "ipv6", addr, m);
9797
current_ranges.emplace_back(std::move(addr), std::move(m));
98+
// current_ranges.emplace_back(std::move(addr), std::popcount(nma));
9899
}
99100
});
100101

0 commit comments

Comments
 (0)