Skip to content

Commit ed332a0

Browse files
committedFeb 23, 2025·
WIP: relay sessions almost complete
1 parent d4e0d57 commit ed332a0

25 files changed

+592
-411
lines changed
 

‎daemon/lokinet-cntrl.cpp

+14-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ namespace
1919
Runtime CLI subcommands:
2020
- list
2121
- refresh
22-
- init
23-
- status
24-
- close
22+
- instance
23+
- init
24+
- status
25+
- close
26+
- stop
2527
*/
2628

2729
struct cli_opts
@@ -153,6 +155,15 @@ namespace
153155
rpc->close(index, std::move(pubkey));
154156
});
155157

158+
auto* halt_subcom = instance_subcom->add_subcommand("halt", "Immediately halt lokinet instance");
159+
160+
halt_subcom->callback([&]() {
161+
if (not address.empty())
162+
rpc->halt(omq::address{std::move(address)});
163+
else
164+
rpc->halt(index);
165+
});
166+
156167
// notify startup successful
157168
runtime_data->running = true;
158169
p.set_value();

‎daemon/utils.cpp

+30-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ namespace llarp::controller
4343

4444
nlohmann::json req;
4545
req["pk"] = remote;
46-
req["x"] = false;
4746

4847
if (auto it = _binds.find(src); it != _binds.end())
4948
_omq->request(
@@ -110,6 +109,26 @@ namespace llarp::controller
110109
logcat, "Could not find connection ID to RPC bind {} for `session_close` command", src.full_address());
111110
}
112111

112+
void rpc_controller::_halt(omq::address src)
113+
{
114+
log::info(logcat, "Instructing lokinet instance (bind:{}) to halt", src.full_address());
115+
116+
if (auto it = _binds.find(src); it != _binds.end())
117+
{
118+
_omq->request(it->second.cid, "llarp.halt", [&](bool success, std::vector<std::string> data) {
119+
if (success)
120+
{
121+
auto res = nlohmann::json::parse(data[0]);
122+
log::info(logcat, "RPC call to halt instance succeeded: {}", res.dump());
123+
}
124+
else
125+
log::critical(logcat, "RPC call to halt instance failed!");
126+
});
127+
}
128+
else
129+
log::critical(logcat, "Could not find connection ID to RPC bind {} for `halt` command", src.full_address());
130+
}
131+
113132
bool rpc_controller::_omq_connect(const std::vector<std::string>& bind_addrs)
114133
{
115134
int i = 0;
@@ -197,4 +216,14 @@ namespace llarp::controller
197216
else
198217
log::warning(logcat, "Could not find instance with given index: {}", idx);
199218
}
219+
220+
void rpc_controller::halt(omq::address src) { return _halt(std::move(src)); }
221+
222+
void rpc_controller::halt(size_t idx)
223+
{
224+
if (auto it = _indexes.find(idx); it != _indexes.end())
225+
_halt(it->second);
226+
else
227+
log::warning(logcat, "Could not find instance with given index: {}", idx);
228+
}
200229
} // namespace llarp::controller

‎daemon/utils.hpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ namespace llarp::controller
4444
void _initiate(omq::address src, std::string remote);
4545
void _status(omq::address src);
4646
void _close(omq::address src, std::string remote);
47+
void _halt(omq::address src);
4748

4849
bool _omq_connect(const std::vector<std::string>& bind_addrs);
4950

@@ -54,16 +55,16 @@ namespace llarp::controller
5455

5556
void refresh();
5657

57-
void initiate(size_t idx, std::string remote);
58-
5958
void initiate(omq::address src, std::string remote);
59+
void initiate(size_t idx, std::string remote);
6060

6161
void status(omq::address src);
62-
6362
void status(size_t idx);
6463

6564
void close(omq::address src, std::string remote);
66-
6765
void close(size_t idx, std::string remote);
66+
67+
void halt(omq::address src);
68+
void halt(size_t idx);
6869
};
6970
} // namespace llarp::controller

‎llarp/address/address.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ namespace llarp
1212

1313
if (arg.ends_with(TLD::SNODE))
1414
{
15+
arg.remove_suffix(TLD::SNODE.size());
1516
ret = NetworkAddress{arg, TLD::SNODE};
1617
}
1718
else if (arg.ends_with(TLD::LOKI))
1819
{
20+
arg.remove_suffix(TLD::LOKI.size());
1921
ret = NetworkAddress{arg, TLD::LOKI};
2022
}
2123
else
@@ -31,7 +33,7 @@ namespace llarp
3133

3234
NetworkAddress::NetworkAddress(std::string_view arg, std::string_view tld) : _tld{tld}
3335
{
34-
if (not _pubkey.from_string(arg.substr(0, _tld.size())))
36+
if (not _pubkey.from_string(oxenc::from_base32z(arg)))
3537
throw std::invalid_argument{"Invalid pubkey passed to NetworkAddress constructor: {}"_format(arg)};
3638

3739
_is_client = tld == TLD::LOKI;

‎llarp/contact/client_contact.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ namespace llarp
121121
}
122122
}
123123

124-
session_tag ClientContact::generate_session_tag() const { return session_tag::make(protos & proto_mask); }
124+
session_tag ClientContact::generate_session_tag() const { return session_tag::make(protos); }
125125

126126
bool ClientContact::is_expired(std::chrono::milliseconds now) const
127127
{

‎llarp/contact/tag.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace llarp
1414
log::trace(logcat, "new session tag generated: {}", buffer_printer{buf});
1515
}
1616

17-
session_tag session_tag::make(uint8_t protocol) { return session_tag{protocol}; }
17+
session_tag session_tag::make(uint8_t protos) { return session_tag{static_cast<uint8_t>(protos & proto_mask)}; }
1818

1919
std::tuple<bool, bool> session_tag::proto_bits() const
2020
{

‎llarp/ev/types.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,14 @@ namespace llarp
203203
bool LinuxPoller::start()
204204
{
205205
auto rv = event_add(ev.get(), nullptr) == 0;
206-
log::info(logcat, "Linux poller {} watching FD {}", rv ? "successfully began" : "failed to start", fd);
206+
log::debug(logcat, "Linux poller {} watching FD {}", rv ? "successfully began" : "failed to start", fd);
207207
return rv;
208208
}
209209

210210
bool LinuxPoller::stop()
211211
{
212212
auto rv = event_del(ev.get());
213-
log::info(logcat, "Linux poller {} watching FD {}", rv ? "successfully stopped" : "failed to stop", fd);
213+
log::debug(logcat, "Linux poller {} watching FD {}", rv ? "successfully stopped" : "failed to stop", fd);
214214
return rv;
215215
}
216216
} // namespace llarp

0 commit comments

Comments
 (0)