case studies

Ps2P Haskell: Cloud Haskell on GNUnet

Practitioners building P2P applications are quick to discover a void in ergonomic abstractions to do so. A modern OS provides primitives for machine-level concurrent programming and host-to-host communication, but P2P primitives both low-level like distributed concurrency or routing in a partially connected network and high-level like pub-sub, block storage, and authentication — are missing.

Multicore prototyped P2P Haskell, a rapid P2P application development framework that combines Cloud Haskell's distributed programming capabilities with GNUnet's P2P building blocks.

P2P Haskell provides Erlang-style programming on top of an encrypted overlay network. Future work will bring support for services like pub-sub and distributed authentication (reclaimID).

GNUnet meets Cloud Haskell

Our implementation is built of three layers:

  • we auto-generate Haskell bindings to GNUnet with c2hsc,

    a <- newArray "a"
    let a_ = (castPtr a) :: Ptr ()
    r1 <- malloc @C'GNUNET_HashCode
    c'GNUNET_CRYPTO_hash a_ 4 r1
    r1_ <- peek r1
  • wrap them in a well-typed API and integrate GNUnet’s CPS scheduler with the GHC runtime system,

    conf <- G.setup "sampleapp" "gnunet.conf" G.NoLog
    flip runReaderT conf $ G.run $
      CADET.withCadet $ c ->
        CADET.withConnection c "0E49..." (G.hash "myPort") $
          CADET.send "ola!"
  • and finally implement Cloud Haskell’s generic Network.Transport spec in terms of GNUnet’s CADET.

    t <- createTransport $ CADETParameters
      { configPath = "gnunet1.conf" }
    Right e <- newEndPoint t
    Right c <- connect e (EndPointAddress "860X...:q")
    let m = map (C.pack . show) [1..100]
    send c m
    receive e >>= print

We hope our work bridging two disparate academic ecosystems makes P2P programming more accessible to software engineers. GNUnet and Cloud Haskell both represent the state of the art in their respective fields; what can their union bring?


Image credits:

  • The GNUnet System, Christian Grothoff, Habilitation à diriger des recherches, Université de Rennes 1, December 2017
  • Functional programming for the data centre, Jeff Epstein. Masters Thesis, University of Cambridge, 2011