Commit Graph
1182 Commits
Author SHA1 Message Date
Cyrille BéraudandCopilot ce8744862a proxy_client: fetch stored values when retrying a failed subscription
restartListeners() retries a push subscription that failed as a refresh
("refresh": true), and the proxy answers a refresh with no values. But a
failed subscription never received the values stored on the key: they
are only delivered if a later push happens to announce them.

On Android this can drop incoming calls. The account restarts while the
device is in doze, so its subscriptions fail for lack of network; the
connection request of the call is then stored on the key, and the retry
sent on the next connectivity change does not retrieve it. The call only
rings if the proxy pushes again before the caller gives up (dhtnet waits
30 s for an answer): in one reproduction the request was processed 9 s
after the call push, in another run the call failed.

Retry a failed subscription as a full SUBSCRIBE, so the proxy answers
with the values it stores. They go through the listener value cache like
any other, so a value already received is not delivered twice.

Also fix the comment of fillBody(), which described the opposite.

Co-authored-by: Copilot (Claude Opus 5.5) <223556219+Copilot@users.noreply.github.com>
2026-09-26 13:07:17 -04:00
Cyrille BéraudandCopilot b9c8f5e0fd runner: complete pushes received while stopped
Resolve idle-runner push futures immediately under the operation queue lock. A stopped runner has no loop left to execute the queued promise, otherwise consumers can wait indefinitely.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-09-21 16:02:47 -04:00
Adrien BeraudandCopilot 3a383ac873 http: close connections on the io_context thread
asio sockets are not thread-safe. http::Connection::close() used to close
the socket synchronously on the calling thread. Request::cancel() and
Request::~Request() (via terminate()) are called from arbitrary threads
(e.g. DhtProxyClient::stop(), cancelAllListeners(), cancelListen()),
so the close raced with in-flight operations on the io_context thread.

In particular, asio::async_connect's range_connect_op closes and
re-opens the socket when trying the next endpoint (common on mobile
where the IPv6 endpoint fails first). A concurrent close() from another
thread corrupts the epoll reactor's per-descriptor state, leading to
crashes in epoll_reactor::deregister_descriptor / register_descriptor
called from range_connect_op::process.

Dispatch the close to the io_context thread when not already on it.
Also keep the connection alive during the TLS handshake, like every
other asynchronous operation, so that the destructor can never run
while an operation is pending.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-09-04 14:13:20 -04:00
Adrien Beraud 3149fe60c4 proxy: increase OP_MARGIN to 8 hours 2026-09-04 11:04:42 -04:00
Adrien Beraud d5956e0778 proxy: use system_clock for subscriber expiration timeouts
Track subscribe/permanent-put expiration with std::chrono::system_clock
(wall clock) instead of steady_clock in both the proxy client and server,
so persisted expirations survive restarts and map directly to epoch time.

- DhtProxyServer::clock is now system_clock; expireTimer/expireNotifyTimer
  use asio::system_timer.
- DhtProxyClient::refreshSubscriberTimer uses asio::system_timer and
  system_clock::now() for subscriber refresh.
2026-09-04 11:04:42 -04:00
Adrien Beraud 82ab21dc3f crypto: support explicit EC curve generation 2026-09-01 21:34:36 -04:00
Adrien Beraud c211b3c376 dht: persist values with system time 2026-08-05 16:14:15 -04:00
Adrien Beraud 44e1ad839e net: harden fragmented reply completion 2026-08-05 14:29:03 -04:00
Cyrille BéraudandCopilot 0826822a4d net: harden fragmented message reassembly
Key partial messages by source and transaction ID, buffer bounded fragments received before their header, and avoid charging reordered requests twice against rate limits. Cover source collisions, early fragments, empty data and large values.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-08-05 14:29:03 -04:00
Adrien Beraud f98df1d615 crypto: allow signing a revocation list with an explicit CRL number
RevocationList::sign() always overwrote the CRL Number extension: random
on the first signature, incremented afterwards. This leaves no way for a
certificate authority replicated over several devices to keep numbers
unique, since every device branching from the same list mints the same
number for a different content.

Add an optional `number` parameter, used verbatim when non-zero, so
callers can partition the number space (RFC 5280 5.2.3 requires
monotonicity for a given CRL scope and issuer, not globally).

Also fix the default increment path: the extension holds a DER integer
with leading zeros stripped, so reading it straight into an uint64_t only
worked for numbers wide enough to occupy all 8 bytes. Signing a list
numbered 5 produced 0x0500000000000001 instead of 6. Read and write the
number as a big-endian byte string instead, which makes the `endian()`
helper unnecessary.

Add tests covering the default numbering, explicit numbers (including
values with leading zero bytes and the largest positive 8-byte integer),
pack/unpack round-trips, and a device-partitioned numbering scheme.
2026-07-29 13:26:23 -04:00
Adrien Beraud f9332985f5 thread_pool: only include ciso646 on C++<20 2026-07-06 15:45:01 -04:00
Adrien Beraud 732da0e478 default types: add ValueId to TrustRequest 2026-06-11 16:52:03 -04:00
Adrien Béraud 0bb393ec36 http: allow to build Request by std::string url 2026-06-03 19:30:53 -04:00
vx32 947610003b http: allow to build Url from std::string, cleanup 2026-06-03 19:14:32 -04:00
François-Simon Fauteux-Chapleau 7cf3e8b738 thread_pool: notify when task queue becomes empty
This prevents ThreadPool::stop from hanging if it is called with `wait`
set to true (which is notably the case in ThreadPool::join) and the
pool's task queue is non-empty.
2026-05-21 10:17:08 -04:00
Adrien Béraud 8b96652b32 dhtrunner: add signatures for putEncrypted(InfoHash, PkId to, Value&&) 2026-05-18 10:36:48 -04:00
Adrien Béraud 44f2aaa876 remove deprecated APIs 2026-05-11 09:27:56 -04:00
copilot-swe-agent[bot]andaberaud aae1bb2ae5 infohash: fix unaligned memory access on strict-alignment architectures (sparc64)
Agent-Logs-Url: https://github.com/savoirfairelinux/opendht/sessions/d4106989-db2c-4d34-b1ea-4ca2ecab524a

Co-authored-by: aberaud <101827+aberaud@users.noreply.github.com>
2026-04-02 16:08:33 -04:00
Pavan Koushik Nellore 593e59e093 proxy: add pushType field and propagate through proxy notifications 2026-04-02 15:03:11 -04:00
Adrien Béraud 99da0be2b7 misc: remove lock mutex template argument 2026-03-15 00:00:33 -04:00
Adrien Béraud 8acafe844d dht: release pending bootstrap after first attempt 2026-03-13 20:39:40 -04:00
Adrien Béraud 55af602026 tests: fix build with GCC 14 2026-03-13 15:32:45 -04:00
Adrien Béraud 603e777c9e dht: refresh token on listen confirmation 2026-03-13 15:10:12 -04:00
Adrien Béraud 4bd796cddd dht: state is connecting if bootstrap is pending 2026-03-13 11:53:32 -04:00
Adrien Béraud f94f072ad6 dht: send token in listen confirmation 2026-03-13 00:53:05 -04:00
Adrien Béraud c51beca374 dht: properly persist expiration time 2026-03-13 00:38:31 -04:00
Adrien Béraud 0eacd7fe6c tools: move to dht::tools namespace 2026-03-13 00:04:49 -04:00
Adrien Béraud b892be092a infohash: make core APIs constexpr
Make Hash default constructor, hex constructor, data(), const
operator[] and fromString constexpr. Change fromString to be
non-throwing: it now uses a validity flag and fills the hash with zeros
on parse error instead of throwing. Add a constexpr toHexArray helper
that returns a std::array<char, N*2> for compile-time hex conversion.
Update tests to include <string_view>, use std::string_view, add
constexpr InfoHash usage and a static_assert for the hex array.
2026-03-08 23:34:50 -04:00
Adrien Béraud 931d79b701 dht: handle out-of-order partial messages 2026-03-08 12:26:23 -04:00
Adrien Béraud 9ad6b3a608 dhtrunner, securedht: mark findCertificate(InfoHash hash) as deprecated 2026-02-27 14:26:39 -05:00
Adrien Béraud 9ebe6e8bb6 tools: pretty print byte count 2026-02-24 00:15:47 -05:00
Adrien Béraud 0263104373 proxy client: implement getLocalStoreSize 2026-02-22 18:55:02 -05:00
Adrien Béraud 0fc7e451e6 dhtrunner: move getNodeInfo implementation to securedht 2026-02-22 17:16:28 -05:00
Adrien Béraud 85cbee0f1a dht: add local storage stats in NodeInfo 2026-02-22 16:27:35 -05:00
Adrien Béraud 724b5e592e dht: use independent storage quota for local values 2026-02-22 16:27:35 -05:00
Adrien Béraud 62243fb4f6 query: optimize msgpack_pack 2026-02-19 21:50:07 -05:00
Adrien Béraud 01eab83a7b value: move filter 2026-02-19 21:44:43 -05:00
Adrien Béraud 2c71662af7 dht_proxy_client: prevent disconnect on local ip change 2026-02-09 15:05:43 -05:00
Adrien Béraud d91f3bdbbd dhtrunner: implement getStorageLimit 2026-02-09 13:26:00 -05:00
Adrien Béraud 73dc55155e utils: make unpackMsg take const Blob& and inline
Change the template unpackMsg to accept a const Blob& to avoid an
unnecessary copy of the Blob argument. Move the non-template unpackMsg
(returning msgpack::unpacked) into the header as an inline function and
remove its out-of-line definition from src/utils.cpp. Update
declarations accordingly.
2026-02-05 21:31:42 -05:00
Adrien Béraud 638ffdc669 logger: add missing header 2026-01-29 22:55:47 -05:00
Adrien Béraud e6836f076f logger: protect children with mutex 2026-01-29 22:38:31 -05:00
Adrien Béraud 76ae1cd6f2 logger: make setFilter match substrings
Allow to filter based on partial tag match
2026-01-27 14:29:43 -05:00
Adrien Béraud c59c0ef64d log: add tag and filter mechanism 2026-01-26 17:31:37 -05:00
Adrien Béraud f9cba71d51 Switch project license from GPL-3.0-or-later to MIT 2026-01-17 22:25:43 -05:00
Adrien Béraud 4fd4745647 update copyright to 2026 2026-01-17 17:09:06 -05:00
Adrien Béraud f55884b7d3 utils: cleanup 2026-01-07 00:14:25 -05:00
Adrien Beraud 9f7e4aaa96 Revert "log: add tag and filter mechanism"
This reverts commit afce0fb0b4.
2025-12-10 12:12:05 -05:00
Adrien Béraud 88f3870f20 dhtrunner: add registerInsecureType method and header file 2025-12-09 09:43:30 -05:00
Adrien Béraud f427f36d9c Add exceptions for missing owner or recipient in unpackValue methods 2025-12-09 09:43:19 -05:00