💾 Archived View for clehaxze.tw › gemlog › 2022 › 12-24-christmas-update-gnunetpp.gmi captured on 2023-09-28 at 15:52:51. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-03-20)
-=-=-=-=-=-=-
Two weeks ago I announced GNUnet++, my C++ wrapper for common GNUnet functions. It's christmas time and I'm happy to share that I've made progress.
The last version of GNUnet++ purely runs on callbacks. Which makes advanced usage cumbersome. Now there's full support for coroutines. This means that you can write code like this:
auto gns = std::make_shared<gnunetpp::GNS>(cfg); auto result = co_await gns->lookup("gnunet.org");
And this which would be a nightmare in previous callback APIs. (Well, we can just use an anonymous identity, but you get the point)
auto identity = std::make_shared<gnunetpp::IdentityService>(cfg); auto throwaway = co_await identity->createIdentity("test"); // ... do something with the identity ... co_await identity->deleteIdentity("test");
Yes! I got CADET working!! P2P messaging have not been easier. Took me much effort to bend the system enbough. You can now write code like this:
(client side)
auto cadet = std::make_shared<CADET>(cfg); // Connect to a peer and specify the message type we are willing to receive auto channel = co_await cadet->connect("peerid", "port-name", {GNUNET_MESSAGE_TYPE_CADET_CLI}); channel->onReceive([](const std::string_view data, uint16_t type) { // Do something with the data }); channel->send("Hello world!", GNUNET_MESSAGE_TYPE_CADET_CLI);
The design is heavily inspired by Trantor, a C++14 network library I help maintain. And a massive does of personal preference is added to the mix. For example, server side handlers set to the `cadet` object is treaded as the default handler. If you want to override it, you can do so by a per-channel basis. **This does not apply to client side handlers.**
// set a different handler because.. reasons cadet->setConnectedCallback([](const CADETChannelPtr& channel) { // every once in a while, we'll dump the data to stderr if(rand() % 10 == 0) { channel->setReceiveCallback([](const std::string_view data, uint16_t type) { std::cerr << "I'm a bad person" << std::endl; }); } }); // This is the default message handler cadet->setReceiveCallback([](CADETChannel* channel, const std::string_view data, uint16_t type) { std::cout << data << std::flush; });
A few things I want to do next:
===
Right, I've been goofing on the FS tool a little. You won't believe what I found on there. Literal hentai and dick pics. Classic