8 comments

  • Twey 3 hours ago
    It was all going great until I read

    > The design also avoids problems like function coloring and plays well with Rust's ownership rules.

    Async is not I/O. It can be used for I/O, but it's just a way of writing pure, deterministic state machines that keeps a logical flow together instead of scattered over a bunch of transitions.

    Even if you choose to manually compile your async flows into explicit state machines, you still have to deal with ‘function colouring’ (a.k.a. typing): a flow that crosses several state transitions (and may have other disjoint parts of the state updated in the meantime, via other transitions) now has to be rewritten as a (series of) state transitions, and can't be called from a blocking function. If anything, rewriting all your state machines without `async` makes the function colouring ‘problem’ worse, because multi-transition flows are even more different from normal functions.

    • wh33zle 2 hours ago
      In principle, you are right. Async is not I/O. And yes, `async` functions compile to a deterministic state machine.

      The problem is, the moment you use `async`, your state machine reduces down to one API: `poll`. What if I want to change some state in-between two state transitions (i.e. between two `await` points)? Now I have to wire-in a channel to supply that data at the right point or access some shared data via a Mutex.

      Rust's `async` implementation is great if you know everything upfront before you kick off your state machine. The moment you need to do many things concurrently, it can become a real mess.

      Firezone's sans-IO core handles many things concurrently: inbound IP, inbound UDP, WebSocket control messages, TURN allocations, timers, user commands, etc. Having essentially one big struct that I can just call `&mut self` functions on for any one of these inputs makes this very easy to understand, compose and test.

      A few things like TURN request-response handshakes might be easier as an `async` function but in reality, it is not a big deal and the composability you get from it outweighs it in my opinion.

      • wyager 23 minutes ago
        Isn't this the idea behind generalizing `async` to `Generator`? You can set the `R` type parameter to whatever type you want to resume the computation with.
        • wh33zle 2 minutes ago
          Correct! I played around with this in the past. It helps less than you'd think. As soon as you have a generic resume parameter, you can no longer drive the generator with a generic runtime.

          If I am now writing my own runtime / eventloop to advance my state machine anyway, what exactly am I getting from doing that through an abstraction like the Generator trait?

          On top of that, the resume and yield abstraction can get convoluted because a lot of times, you only want to do one or the other, meaning either case needs to support a no-op because a single `yield` always does both.

          Lastly, with all input going through a single type, your state machine then needs to handle every possible input at every yield point. That is a lot of `match` statements and branching.

          I am sure there are better ways to do this and having generators to express custom iterators would be amazing. But for generic state machines, I don't see much of a benefit.

      • hujun236 1 hour ago
        [flagged]
  • monocasa 5 hours ago
    Sweet, this is basically how I design my protocol implementations in rust as well.

    Way more testable, the bulk can be shared between async and blocking IO, it's a lot easier to completely ban unsafe in your dependencies (excepting std and core), etc.

  • temp0826 6 hours ago
    Mullvad spun their own implementation off of boringtun as well (called gotatun[0])

    [0] https://github.com/mullvad/gotatun

  • mlhpdx 3 hours ago
    One of the fundamentally great things about the Wireguard protocol is the simplicity. A small codebase can implement it, and that’s lead to some great libraries and innovation.

    Another great (and subtle) thing is the monotonically increasing sequence number. Note that it isn’t incrementing, like DTLS. This small thing makes it so much easier to implement with efficient concurrency, and event external state (i.e. distributed concurrency).

    That latter bit we’ve done in our own library.

    Edit: typo, don’t -> done

  • asdf88990 5 hours ago
    From their website about their product:

    > Hardware does the heavy lifting.

    > Your operating system and network card take over the repetitive jobs whenever they can. Your CPU gets room to breathe, and your battery stays full longer.

    Where does this operating system run? Where does the power come from to run it if not battery?

    Pure rubbish ai slop.

    While the software might actually be ok upon inspection but this kind of ai slop nonsense copy doesn’t inspire confidence in using their software considering how security critical the vpn is.

    • wh33zle 2 hours ago
      There is actually more thought in it than that.

      The quoted section is meant to explain in layman's terms that we are doing hardware offloading where possible. That means vectorized instructions for encryption and checksum-offloading and packet segmentation in the kernel / hardware driver where supported.

      Being more efficient per packet means that we using less power to move the same amount of data, hence less power draw on mobile platforms.

      Having said that, I agree that it could be better while still not be filled with technical jargon.

      • nostrebored 3 minutes ago
        I don’t think it has much to do with technical jargon. You are making a product for technical people, jargon is fine.

        You should not write things with AI that you expect people to read

    • hxtk 3 hours ago
      I imagine they’re talking about handling network protocols in the kernel or the NIC instead of in userland code, and they’re generally right. It runs off the same battery, but the kernel implementation and especially the (hardware-accelerated) NIC implementations of protocols like TCP and TLS are generally more energy efficient than doing the same amount of IO in userland code.
      • boredatoms 2 hours ago
        I think the point is not if the text can be interpreted charitably, but that the usage of AI text in what is intended for humans to read causes mistrust about where else corners could have been cut, on what is security-critical software
        • asdf88990 2 hours ago
          And even the charitable reading is not a good indicator. There is reason things are getting pulled out of kernel and more and more userland services are used, it is because we have finally come to terms that secure software is hard and better hack as little of it trusted with the whole system as possible.
  • clivedup 3 hours ago
    I've wanted Wireguard on some MCUs. Great!
  • ogrimsby 42 minutes ago
    [flagged]
  • lakeviewterrace 4 hours ago
    WireGuard implementations that are not Jason's reference implementation are stupid and an explicit invitation for issues.

    I will die on this hill.

    WG is like 2k LOC why the fuck do we need 30 different versions? Audit what you have.

    • wh33zle 4 hours ago
      You can't use the Linux kernel implementation as soon as you want to be cross platform and the only official userspace implementation is in Go which is awkward to FFI into from Rust.

      I agree with your point. Use what is out there. We did that by using Cloudflare's boringtun for a long time. But it has limitations that eventually we could no longer work around if we wanted good compile-time safety and performance.

    • clivedup 3 hours ago
      I can use sanstun in no_std environments like on an ESP32.

      Can I do that with Jason's reference implementation?

      Let people build. They might have reasons you haven't foreseen.