Skip to content

Commit 0ec41c0

Browse files
committed
squash
1 parent 44b8416 commit 0ec41c0

File tree

9 files changed

+79
-69
lines changed

9 files changed

+79
-69
lines changed

llarp/handlers/session.cpp

+13-12
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ namespace llarp::handlers
5757
new_path->to_string());
5858

5959
s->recv_path_switch(std::move(remote_pivot_txid), std::move(new_path));
60+
return true;
6061
}
6162

6263
return false;
@@ -717,7 +718,7 @@ namespace llarp::handlers
717718
NetworkAddress initiator,
718719
HopID remote_pivot_txid,
719720
std::shared_ptr<session_path_interface> path,
720-
std::optional<shared_kx_data> kx_data,
721+
shared_kx_data kx_data,
721722
bool use_tun)
722723
{
723724
auto tag = session_tag::make(protoflags);
@@ -895,7 +896,7 @@ namespace llarp::handlers
895896
return;
896897
}
897898

898-
log::trace(logcat, "Remote client has provided session tag: {}", tag);
899+
log::debug(logcat, "Remote client has provided session tag: {}", tag);
899900

900901
auto session = std::make_shared<session::OutboundClientSession>(
901902
remote,
@@ -967,20 +968,22 @@ namespace llarp::handlers
967968
void SessionEndpoint::_make_relay_session(
968969
RemoteRC rc, NetworkAddress remote, std::shared_ptr<path::Path> path, on_session_init_hook cb)
969970
{
971+
auto pivot_txid = path->pivot_txid();
970972
std::string payload = InitiateSession::serialize(
971-
_router.local_rid(),
972-
path->pivot_txid(),
973-
path->pivot_txid(),
974-
fetch_auth_token(remote),
975-
_router.using_tun_if());
973+
_router.local_rid(), pivot_txid, pivot_txid, fetch_auth_token(remote), _router.using_tun_if());
976974

977975
log::trace(logcat, "payload: {}", buffer_printer{payload});
978976

979977
path->send_path_control_message(
980978
"session_init",
981979
std::move(payload),
982-
[this, rc = std::move(rc), remote, path, hook = std::move(cb), session_keys = path->hops.back().kx](
983-
oxen::quic::message m) mutable {
980+
[this,
981+
rc = std::move(rc),
982+
remote,
983+
path,
984+
pivot_txid,
985+
hook = std::move(cb),
986+
session_keys = path->hops.back().kx](oxen::quic::message m) mutable {
984987
if (m)
985988
{
986989
log::debug(logcat, "Call to initiate OutboundRelaySession succeeded!");
@@ -997,9 +1000,7 @@ namespace llarp::handlers
9971000
return;
9981001
}
9991002

1000-
log::trace(logcat, "Remote relay has provided session tag: {}", tag);
1001-
1002-
auto pivot_txid = path->pivot_txid();
1003+
log::debug(logcat, "Remote relay has provided session tag: {}", tag);
10031004

10041005
auto session = std::make_shared<session::OutboundRelaySession>(
10051006
remote, *this, std::move(path), std::move(tag), std::move(pivot_txid), std::move(session_keys));

llarp/handlers/session.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ namespace llarp
161161
NetworkAddress initiator,
162162
HopID remote_pivot_txid,
163163
std::shared_ptr<session_path_interface> path,
164-
std::optional<shared_kx_data> kx_data,
164+
shared_kx_data kx_data,
165165
bool use_tun);
166166

167167
// lookup SNS address to return "{pubkey}.loki" hidden service or exit node operated on a remote client

llarp/link/link_manager.cpp

+21-22
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ namespace llarp
10841084

10851085
void LinkManager::handle_fetch_router_ids(oxen::quic::message m)
10861086
{
1087-
log::debug(logcat, "Handling FetchRIDs request...");
1087+
log::trace(logcat, "Handling FetchRIDs request...");
10881088
// this handler should not be registered for clients
10891089
assert(_router.is_service_node());
10901090

@@ -1105,7 +1105,7 @@ namespace llarp
11051105

11061106
if (source != local)
11071107
{
1108-
log::info(logcat, "Relaying FetchRID request (body: {}) to intended target RID:{}", m.body(), source);
1108+
log::trace(logcat, "Relaying FetchRID request (body: {}) to intended target RID:{}", m.body(), source);
11091109

11101110
auto payload = FetchRID::serialize(source);
11111111
send_control_message(
@@ -1134,7 +1134,7 @@ namespace llarp
11341134
return sig;
11351135
});
11361136

1137-
log::info(logcat, "Returning ALL ({}) locally held RIDs to FetchRIDs request!", known_rids.size());
1137+
log::debug(logcat, "Returning ALL ({}) locally held RIDs to FetchRIDs request!", known_rids.size());
11381138
m.respond(std::move(btdp).str());
11391139
}
11401140

@@ -1420,7 +1420,7 @@ namespace llarp
14201420
}
14211421

14221422
_router.path_context()->put_transit_hop(std::move(hop));
1423-
return m.respond(messages::OK_RESPONSE, false);
1423+
return m.respond(messages::OK_RESPONSE);
14241424
}
14251425

14261426
// rotate our frame to the back
@@ -1662,9 +1662,12 @@ namespace llarp
16621662
hop.kx.shared_secret,
16631663
nonce,
16641664
hop.kx.xor_nonce);
1665-
}
16661665

1667-
log::trace(logcat, "Received path data for local client: {}", buffer_printer{payload});
1666+
auto [_t, _d] = PATH::DATA::deserialize_inner(std::string{payload});
1667+
1668+
log::debug(logcat, "tag:{} | data:{}", _t, buffer_printer{_d});
1669+
log::debug(logcat, "xchacha20 -> {}", buffer_printer{payload});
1670+
}
16681671

16691672
return handle_path_session_data(std::move(payload));
16701673
}
@@ -1689,12 +1692,9 @@ namespace llarp
16891692
std::optional<std::pair<RouterID, HopID>> next_ids = std::nullopt;
16901693
std::string next_payload;
16911694

1692-
log::trace(
1693-
logcat,
1694-
"We are {} hop for path data: {}: {}",
1695-
hop->terminal_hop ? "terminal" : "intermediate",
1696-
hop->to_string(),
1697-
buffer_printer{payload});
1695+
log::debug(logcat, "We are {} hop for path data", hop->terminal_hop ? "terminal" : "intermediate");
1696+
1697+
log::trace(logcat, "Path data: {}", buffer_printer{payload});
16981698

16991699
// if terminal hop, pass to the correct path expecting to receive this message
17001700
if (hop->terminal_hop)
@@ -1714,12 +1714,6 @@ namespace llarp
17141714
return;
17151715
}
17161716

1717-
if (hop_id == ihid)
1718-
{
1719-
log::debug(logcat, "Received path data for local relay: {}", buffer_printer{intermediate});
1720-
return handle_path_session_data(std::move(intermediate));
1721-
}
1722-
17231717
log::trace(logcat, "Inbound path rxid:{}, outbound path txid:{}", hop_id, ihid);
17241718

17251719
auto next_hop = _router.path_context()->get_transit_hop(ihid);
@@ -1730,10 +1724,15 @@ namespace llarp
17301724
return;
17311725
}
17321726

1733-
log::trace(logcat, "Bridging path data message to hop: {}", next_hop->to_string());
1734-
17351727
next_ids = next_hop->next_id(ihid);
17361728

1729+
if (hop_id == next_ids->second)
1730+
{
1731+
log::trace(logcat, "Received path data for local relay: {}", buffer_printer{intermediate});
1732+
return handle_path_session_data(std::move(intermediate));
1733+
}
1734+
1735+
log::debug(logcat, "Bridging path data message to hop: {}", next_hop->to_string());
17371736
onion_nonce ^= next_hop->kx.xor_nonce;
17381737

17391738
crypto::onion(
@@ -1828,7 +1827,7 @@ namespace llarp
18281827
HopID remote_pivot_txid;
18291828
HopID local_pivot_txid;
18301829
bool use_tun{};
1831-
std::optional<shared_kx_data> kx_data = std::nullopt;
1830+
shared_kx_data kx_data;
18321831
std::optional<std::string> maybe_auth = std::nullopt;
18331832

18341833
try
@@ -1911,7 +1910,7 @@ namespace llarp
19111910
if (auto tag = _router.session_endpoint()->prefigure_session(
19121911
std::move(initiator), std::move(remote_pivot_txid), std::move(pi), std::move(kx_data), use_tun))
19131912
{
1914-
log::debug(logcat, "InboundSession configured successfully!");
1913+
log::debug(logcat, "InboundSession (tag:{}) configured successfully!", *tag);
19151914
return m.respond(InitiateSession::serialize_response(*tag));
19161915
}
19171916

llarp/messages/path.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ namespace llarp
2929
- 'n' : Symmetric nonce used to encrypt the layer
3030
- 'x' : Encrypted payload transmitted to next recipient
3131
*/
32-
// template <oxenc::string_like K, oxenc::string_like T>
33-
// inline static std::string serialize_hop(K key, const SymmNonce& nonce, T encrypted)
3432
inline static std::string serialize_hop(
3533
std::string_view key, const SymmNonce& nonce, const std::string& encrypted)
3634
{

llarp/net/ip_packet.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,12 @@ namespace llarp
292292
auto ip_hdr_sz = _header->header_len * 4;
293293
size_t pkt_size = (ICMP_HEADER_SIZE + ip_hdr_sz) * 2;
294294

295+
if (pkt_size < MIN_PACKET_SIZE)
296+
return std::nullopt;
297+
295298
IPPacket pkt{pkt_size};
296299

297-
pkt._header->version = 4;
300+
pkt._header->version = 0x04;
298301
pkt._header->header_len = 0x05;
299302
pkt._header->service_type = 0;
300303
pkt._header->checksum = 0;

llarp/path/path_handler.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ namespace llarp::path
615615
}
616616
}
617617

618-
log::debug(logcat, "Building path -> {} :{}", path->to_string(), path->hop_string());
618+
log::debug(logcat, "Building -> {}", path->to_string());
619619

620620
return path;
621621
}
@@ -752,9 +752,6 @@ namespace llarp::path
752752

753753
assert(new_path);
754754

755-
auto payload = build2(new_path);
756-
auto upstream = new_path->upstream_rid();
757-
758755
return path_build_onepass(
759756
std::move(new_path),
760757
[cb, remote_intro](auto new_path) mutable { return cb(std::move(new_path), std::move(remote_intro)); },

llarp/path/transit_hop.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,21 @@ namespace llarp::path
119119
return _parent._router.send_control_message(
120120
_downstream,
121121
"path_control",
122-
ONION::serialize_hop(_downstream.to_view(), SymmNonce::make_random(), std::move(inner_payload)),
122+
ONION::serialize_hop(_rxid.to_view(), SymmNonce::make_random(), std::move(inner_payload)),
123123
std::move(func));
124124
}
125125

126126
bool SessionHop::send_path_data_message(std::string body)
127127
{
128+
auto nonce = crypto::onion(
129+
reinterpret_cast<unsigned char*>(body.data()),
130+
body.size(),
131+
kx.shared_secret,
132+
SymmNonce::make_random(),
133+
kx.xor_nonce);
134+
128135
return _parent._router.send_data_message(
129-
_downstream, ONION::serialize_hop(_downstream.to_view(), SymmNonce::make_random(), std::move(body)));
136+
_downstream, ONION::serialize_hop(_rxid.to_view(), nonce, std::move(body)));
130137
}
131138

132139
std::string SessionHop::to_string() const

llarp/session/session.cpp

+26-21
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ namespace llarp::session
2424
session_tag _t,
2525
bool use_tun,
2626
bool is_outbound,
27-
std::optional<shared_kx_data> kx_data)
27+
shared_kx_data kx_data)
2828
: _r{r},
2929
_parent{parent},
3030
_tag{std::move(_t)},
3131
_remote{std::move(remote)},
32-
session_keys{std::move(kx_data)},
32+
session_keys{std::make_unique<shared_kx_data>(std::move(kx_data))},
3333
_remote_pivot_txid{std::move(remote_pivot_txid)},
3434
_use_tun{use_tun},
3535
_is_outbound{is_outbound},
@@ -69,8 +69,8 @@ namespace llarp::session
6969

7070
bool BaseSession::send_path_data_message(std::string data)
7171
{
72-
if (session_keys.has_value())
73-
session_keys->encrypt(data);
72+
log::debug(logcat, "{} called", __PRETTY_FUNCTION__);
73+
session_keys->encrypt(data);
7474

7575
auto inner_payload = PATH::DATA::serialize_inner(std::move(data), _tag);
7676
auto intermediate_payload = PATH::DATA::serialize_intermediate(std::move(inner_payload), _remote_pivot_txid);
@@ -80,8 +80,7 @@ namespace llarp::session
8080

8181
void BaseSession::recv_path_data_message(std::vector<uint8_t> data)
8282
{
83-
if (session_keys.has_value())
84-
session_keys->decrypt(data);
83+
session_keys->decrypt(data);
8584

8685
if (_recv_dgram)
8786
_recv_dgram(std::move(data));
@@ -105,12 +104,7 @@ namespace llarp::session
105104

106105
void BaseSession::set_remote_pivot_tx(HopID new_remote_txid)
107106
{
108-
log::debug(
109-
logcat,
110-
"Setting new pivot txID for remote ({}) [ old:{} | new:{} ] ",
111-
_remote,
112-
_remote_pivot_txid,
113-
new_remote_txid);
107+
log::debug(logcat, "Setting new pivot txID for remote ({}) [ new:{} ]", _remote, new_remote_txid);
114108
_remote_pivot_txid = std::move(new_remote_txid);
115109
}
116110

@@ -280,7 +274,7 @@ namespace llarp::session
280274

281275
std::shared_ptr<path::Path> OutboundRelaySession::current_path()
282276
{
283-
return std::static_pointer_cast<path::Path>(_current_path);
277+
return std::dynamic_pointer_cast<path::Path>(_current_path);
284278
}
285279

286280
std::shared_ptr<OutboundRelaySession> OutboundRelaySession::downcast(const std::shared_ptr<BaseSession>& b)
@@ -300,7 +294,17 @@ namespace llarp::session
300294

301295
bool OutboundRelaySession::send_path_data_message(std::string data)
302296
{
303-
return _current_path->send_path_data_message(std::move(data));
297+
log::debug(logcat, "{} called", __PRETTY_FUNCTION__);
298+
// session_keys->encrypt(data);
299+
300+
// return BaseSession::send_path_data_message(std::move(data));
301+
// return _current_path->send_path_data_message(std::move(data));
302+
session_keys->encrypt(data);
303+
304+
auto inner_payload = PATH::DATA::serialize_inner(std::move(data), _tag);
305+
auto intermediate_payload = PATH::DATA::serialize_intermediate(std::move(inner_payload), _remote_pivot_txid);
306+
307+
return _current_path->send_path_data_message(std::move(intermediate_payload));
304308
}
305309

306310
void OutboundRelaySession::rotate_paths()
@@ -456,9 +460,9 @@ namespace llarp::session
456460
if (_is_exit_session and _is_snode_session)
457461
throw std::runtime_error{"Cannot create OutboundSession for a remote exit and remote service node!"};
458462

459-
_path_rotater = _router.loop()->call_every(path::PATH_ROTATION_INTERVAL, [this]() mutable { rotate_paths(); });
463+
// _path_rotater = _router.loop()->call_every(path::PATH_ROTATION_INTERVAL, [this]() mutable { rotate_paths();
464+
// }); add_path(current_path());
460465

461-
add_path(current_path());
462466
populate_intro_map(std::move(_remote_intros));
463467

464468
log::debug(
@@ -811,7 +815,7 @@ namespace llarp::session
811815
HopID remote_pivot_txid,
812816
session_tag _t,
813817
bool use_tun,
814-
std::optional<shared_kx_data> kx_data)
818+
shared_kx_data kx_data)
815819
: BaseSession{
816820
parent._router,
817821
std::move(_p),
@@ -848,7 +852,7 @@ namespace llarp::session
848852
HopID remote_pivot_txid,
849853
session_tag _t,
850854
bool use_tun,
851-
std::optional<shared_kx_data> kx_data)
855+
shared_kx_data kx_data)
852856
: InboundClientSession{
853857
std::move(remote),
854858
std::move(_p),
@@ -870,13 +874,14 @@ namespace llarp::session
870874
std::string method, std::string body, bt_control_response_hook func)
871875
{
872876
return _current_path->send_path_control_message(std::move(method), std::move(body), std::move(func));
873-
// auto payload = PATH::CONTROL::serialize(std::move(method), std::move(body));
874-
// return _current_path->send_path_control_message("path_control", std::move(payload), std::move(func));
875877
}
876878

877879
bool InboundRelaySession::send_path_data_message(std::string data)
878880
{
879-
return _current_path->send_path_data_message(std::move(data));
881+
log::trace(logcat, "{} called", __PRETTY_FUNCTION__);
882+
session_keys->encrypt(data);
883+
884+
return _current_path->send_path_data_message(PATH::DATA::serialize_inner(std::move(data), _tag));
880885
}
881886

882887
} // namespace llarp::session

0 commit comments

Comments
 (0)