💾 Archived View for clehaxze.tw › gemlog › 2022 › 12-24-christmas-update-gnunetpp.gmi captured on 2024-05-10 at 10:57:13. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-03-20)

-=-=-=-=-=-=-

Christmas update: GNUnet++

home

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.

Coroutine support

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");

CADET support

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;
});

Misc

Next steps

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