Skip to content

feat(http_client): move to opendht's builtin HTTP proxy - #34

Open
jaja360 wants to merge 3 commits into
sim590:masterfrom
jaja360:add_systemd_dht
Open

feat(http_client): move to opendht's builtin HTTP proxy#34
jaja360 wants to merge 3 commits into
sim590:masterfrom
jaja360:add_systemd_dht

Conversation

@jaja360

@jaja360 jaja360 commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

This pull request introduces significant improvements to how dpaste interacts with OpenDHT, providing a more robust and efficient DHT proxy setup. The main changes include adding support for an optional persistent local OpenDHT proxy via a systemd user unit, updating documentation and configuration to reflect this, and refactoring HTTP client interactions to use a new JSON-based API with base64 encoding. Additionally, installation scripts are updated to install the new systemd unit.

DHT Proxy Integration and Systemd Unit:

  • Added a new dpaste-dhtnode.service systemd user unit to run a persistent local OpenDHT proxy, and updated installation scripts (CMakeLists.txt, Makefile.am) to install this unit. [1] [2] [3] [4]
  • Updated documentation in README.md and doc/dpaste.1 to describe how to enable and use the systemd DHT proxy, and clarified the configuration file's host and port settings. [1] [2]

Configuration and Documentation Updates:

  • Updated config/dpaste.conf to clarify that the host and port refer to the OpenDHT DhtProxyServer endpoint.

Codebase Changes for Proxy Support:

  • Refactored the Bin class in src/bin.cpp/src/bin.h to only start a local DHT node if the proxy is unavailable, avoiding unnecessary node startups. Introduced ensureNodeRunning() and a node_running_ flag. [1] [2] [3] [4] [5]

HTTP Client Refactoring:

  • Rewrote HttpClient in src/http_client.cpp to use a new JSON API for the proxy, including base64 encoding/decoding for data transmission, and improved error handling and compatibility with the proxy server. [1] [2] [3]

These changes collectively improve performance, reliability, and usability for users who wish to run a persistent DHT proxy, and modernize the client-server communication protocol.

@sim590
sim590 self-requested a review September 4, 2026 04:48
@sim590 sim590 added this to the 0.5.0 milestone Sep 4, 2026
@sim590 sim590 linked an issue Sep 4, 2026 that may be closed by this pull request
@sim590 sim590 added the roadmap This issue/PR references an item on the roadmap label Sep 4, 2026
@sim590 sim590 modified the milestones: 0.5.0, 1.0.0 Sep 7, 2026
@sim590 sim590 added the breakscompat This change breaks compatibility label Sep 7, 2026
@sim590 sim590 changed the title perf: add a persistant systemd DHT node feat(http_client): move to opendht's builtin HTTP proxy Sep 7, 2026
@sim590 sim590 modified the milestones: 1.0.0, 0.5.0 Sep 7, 2026
Comment thread src/http_client.cpp Outdated
Comment thread src/http_client.cpp Outdated
Comment thread src/http_client.cpp
{"data", encoded_data},
{"utype", Node::DPASTE_USER_TYPE}
}.dump();
req.setOpt(curlpp::Options::PostFields(body));

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use curlpp::Options::PostFields instead of keeping curlpp::options::HttpPost? You also create a temporary body variable instead of simply create the form parts in-place as we were doing before with curlpp::FormParts::Content which was taking care of creating the dictionary of values by itself. It's not a dealbreaker, but why not use the same approach that we were using before?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proxy POST requires raw JSON PostFields, not multipart HttpPost.

Comment thread config/dpaste.conf Outdated
Comment thread config/dpaste.conf Outdated
Comment thread src/bin.h Outdated
Comment thread src/bin.cpp Outdated
Comment thread src/http_client.cpp Outdated
Comment thread src/http_client.cpp
std::stringstream response, oss;
req.setOpt<curlpp::options::Url>(HTTP_PROTO+
host+"/"+dht::InfoHash::get(code).toString()
+"?user_type="+dpaste::Node::DPASTE_USER_TYPE

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You removed the user_type spec from the URL. That makes it so the get operation on the DHT node service's side won't have this spec and it will then pull more values than it should. This usertype spec is used in the DHT protocol to filter out values so requests are as light as possible and also per-application specific.

I know that you are filtering values out afterwards, but at this point it's too late, network traffic was wasted for no reason.

Let's keep this network level optimization.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is the migration to OpenDHT’s DhtProxyServer: its new GET /key/<hash> handler ignores query parameters entirely. Adding ?user_type=dpaste back would look correct but provide no DHT-level filtering.

Comment thread src/http_client.cpp
d.decode(iss, oss);
std::istringstream lines(response.str());
std::string line;
while (std::getline(lines, line)) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How to be sure that parsing line by line the output of the service will lead to valid JSON content? We can't know. The server's response should rather be parsed in its entirety.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we are reading NDJSON files. By definition, each line is a valid JSON document.

Comment thread systemd/dpaste-dhtnode.service Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breakscompat This change breaks compatibility enhancement roadmap This issue/PR references an item on the roadmap

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make use of OpenDHT's proxy

2 participants