all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: pukkamustard <pukkamustard@posteo.net>
To: 52555@debbugs.gnu.org
Cc: pukkamustard <pukkamustard@posteo.net>,
	ludo@gnu.org, maximedevos@telenet.be,
	"Christopher Baines" <guix@cbaines.net>,
	"Josselin Poiret" <dev@jpoiret.xyz>,
	"Ludovic Courtès" <ludo@gnu.org>,
	"Mathieu Othacehe" <othacehe@gnu.org>,
	"Ricardo Wurmus" <rekado@elephly.net>,
	"Simon Tournier" <zimon.toutoune@gmail.com>,
	"Tobias Geerinckx-Rice" <me@tobias.gr>
Subject: [bug#52555] [PATCH v4 5/7] eris: Connect with an ERIS Store over CoAP+Unix.
Date: Thu, 28 Dec 2023 09:40:08 +0000	[thread overview]
Message-ID: <cd7432fcc871296d8a14b902e65190669ef89d62.1703316055.git.pukkamustard@posteo.net> (raw)
In-Reply-To: <cover.1703316055.git.pukkamustard@posteo.net>

* guix/eris.scm (open-coap-unix-socket): New procedure.
  (guix-eris-block-reducer): Handle coap+unix URIs.
* guix/publish.scm (bake-narinfo+nar): Start a fibers scheduler when encoding
item with ERIS.
---
 guix/eris.scm            | 63 ++++++++++++++++++++++++++++++----------
 guix/scripts/publish.scm |  9 +++++-
 2 files changed, 56 insertions(+), 16 deletions(-)

diff --git a/guix/eris.scm b/guix/eris.scm
index d98a9a62bd..3fbedd0cb7 100644
--- a/guix/eris.scm
+++ b/guix/eris.scm
@@ -21,8 +21,11 @@ (define-module (guix eris)
   #:use-module (eris)
   #:use-module (eris fs)
   #:use-module (eris sqlite)
+  #:use-module (eris coap)
   #:use-module (eris read-capability)
 
+  #:use-module (coap tcp)
+
   #:use-module (web uri)
   #:use-module (ice-9 match)
   #:use-module (srfi srfi-171)
@@ -42,27 +45,57 @@ (define %eris-store-url
 (define %guix-eris-convergence-secret
   (make-parameter %null-convergence-secret))
 
+(define (open-coap-unix-socket path)
+  (let ((sock (socket PF_UNIX SOCK_STREAM 0)))
+    ;; Release FD on exec
+    (fcntl sock F_SETFD FD_CLOEXEC)
+    ;; Set to non-blocking
+    (fcntl sock F_SETFL (logior O_NONBLOCK (fcntl sock F_GETFL)))
+    ;; Connect
+    (connect sock AF_UNIX path)
+
+    ;; Initialize the CoAP connection
+    (open-socket-for-uri #f
+                         #:socket sock
+                         ;; Allow up to 64 in-flight requests
+                         #:nstart 64)))
+
 (define (guix-eris-block-reducer)
   "Returns an ERIS block reducer."
-  (if (uri? (%eris-store-url))
-      (match (uri-scheme (%eris-store-url))
+  (let ((store-url (%eris-store-url)))
+    (if (uri? store-url)
+        (match (uri-scheme store-url)
+
+          ;; Store blocks in an SQLite database (see
+          ;; https://eris.codeberg.page/eer/sqlite.xml)
+          ('sqlite
+           (eris-sqlite-block-reducer (uri-path store-url)))
 
-        ;; Store blocks in an SQLite database (see
-        ;; https://eris.codeberg.page/eer/sqlite.xml)
-        ('sqlite
-         (eris-sqlite-block-reducer (uri-path (%eris-store-url))))
+          ;; Connect to a CoAP ERIS store over a Unix socket
+          ('coap+unix
+           ;; Wrap the eris-coap-block-reducer to close the provided connection.
+           (let ((ecbr (eris-coap-block-reducer
+                      (build-uri 'coap #:path ".well-known/eris")
+                      #:nstart 64
+                      #:connection (open-coap-unix-socket
+                                    (uri-path store-url)))))
+             (case-lambda
+               (() (ecbr))
+               ((conn ref-block) (ecbr conn ref-block))
+               ((conn)
+                (ecbr conn)
+                (close-port conn)))))
 
-        ;; TODO
-        ;; ('coap+unix #f)
-        ;; ('coap+tcp #f)
+          ;; TODO
+          ;; ('coap+tcp #f)
 
-        (_ (error "Don't know how to handle ERIS store URL "
-                  (uri->string (%eris-store-url)))))
+          (_ (error "Don't know how to handle ERIS store URL "
+                    (uri->string (%eris-store-url)))))
 
-      ;; If no ERIS store URL is provided we just compute the ERIS URN without
-      ;; storing the blocks anywhere. As dummy block-reducer we use `rcount` from
-      ;; SRFI-171 that counts the number of blocks.
-      rcount))
+        ;; If no ERIS store URL is provided we just compute the ERIS URN without
+        ;; storing the blocks anywhere. As dummy block-reducer we use `rcount` from
+        ;; SRFI-171 that counts the number of blocks.
+        rcount)))
 
 (define* (eris-encode-store-item item)
   "Encodes the store item ITEM using ERIS and returns the read capability as
diff --git a/guix/scripts/publish.scm b/guix/scripts/publish.scm
index 2e7138f3c7..0b61354327 100644
--- a/guix/scripts/publish.scm
+++ b/guix/scripts/publish.scm
@@ -54,6 +54,7 @@ (define-module (guix scripts publish)
   #:use-module (guix store)
   #:use-module ((guix serialization) #:select (write-file))
   #:use-module (guix eris)
+  #:use-module (fibers)
   #:use-module (zlib)
   #:autoload   (lzlib) (call-with-lzip-output-port
                         make-lzip-output-port)
@@ -655,7 +656,13 @@ (define* (bake-narinfo+nar cache item
 
   (let ((compression (actual-compressions item compressions))
         (eris-urn (if eris?
-                      (eris-encode-store-item item)
+                      ;; Encode with fibers.
+                      ;; XXX: There seems to be some buggy interactions when
+                      ;; running a fibers scheduler and connecting to the
+                      ;; store.
+                      (run-fibers (lambda ()
+                                    (eris-encode-store-item item))
+                                  #:drain? #t)
                       #f)))
 
     (for-each (cut compress-nar cache item <>) compressions)
-- 
2.41.0





  parent reply	other threads:[~2023-12-28  9:41 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-16 16:17 [bug#52555] [RFC PATCH 0/3] Decentralized substitute distribution with ERIS pukkamustard
2021-12-16 16:20 ` [bug#52555] [RFC PATCH 1/3] publish: Add ERIS URN to narinfo pukkamustard
2021-12-16 16:20   ` [bug#52555] [RFC PATCH 2/3] WIP: gnu: guile-eris: Update to unreleased git version pukkamustard
2021-12-16 16:20   ` [bug#52555] [RFC PATCH 3/3] publish: Add IPFS support pukkamustard
2021-12-20 16:25 ` [bug#52555] [RFC PATCH 0/3] Decentralized substitute distribution with ERIS Ludovic Courtès
2021-12-23 11:42   ` pukkamustard
2021-12-24 14:48     ` Ludovic Courtès
2022-01-25 19:21 ` [bug#52555] [RFC PATCH v2 0/5] " pukkamustard
2022-01-25 19:21   ` [bug#52555] [RFC PATCH v2 1/5] WIP: gnu: guile-eris: Update to unreleased git version pukkamustard
2022-01-25 19:21   ` [bug#52555] [RFC PATCH v2 2/5] publish: Add ERIS URN to narinfo pukkamustard
2022-01-29 21:09     ` Maxime Devos
2022-01-29 21:15     ` Maxime Devos
2022-02-02 10:16       ` pukkamustard
2022-01-25 19:21   ` [bug#52555] [RFC PATCH v2 3/5] Add (guix eris) pukkamustard
2022-01-29 21:23     ` Maxime Devos
2022-02-02 10:28       ` pukkamustard
2022-02-02 15:36         ` Maxime Devos
2022-01-29 21:24     ` Maxime Devos
2022-01-25 19:22   ` [bug#52555] [RFC PATCH v2 4/5] publish: Add support for storing ERIS encoded blocks to IPFS pukkamustard
2022-01-29 21:28     ` Maxime Devos
2022-02-02 10:24       ` pukkamustard
2022-01-25 19:22   ` [bug#52555] [RFC PATCH v2 5/5] substitute: Fetch substitutes using ERIS pukkamustard
2022-01-29 21:29     ` Maxime Devos
2022-02-02 10:11       ` pukkamustard
2022-01-29 21:33     ` Maxime Devos
2022-01-29 21:38     ` Maxime Devos
2022-01-29 21:40       ` Maxime Devos
2022-01-29 21:40     ` Maxime Devos
2022-02-02 10:38       ` pukkamustard
2022-01-29 21:00   ` [bug#52555] [RFC PATCH v2 0/5] Decentralized substitute distribution with ERIS Maxime Devos
2022-02-02  9:50     ` pukkamustard
2022-01-29 21:08   ` Maxime Devos
2022-02-02  9:56     ` pukkamustard
2022-02-02 11:09       ` Maxime Devos
2022-01-29 21:52   ` Maxime Devos
2022-02-02 11:10     ` pukkamustard
2022-02-03 20:36       ` Maxime Devos
2022-02-04 10:20         ` pukkamustard
2022-01-30 11:46   ` Maxime Devos
2022-02-02 10:51     ` pukkamustard
2022-02-02 11:27       ` Maxime Devos
2022-02-02 12:42         ` pukkamustard
2022-02-02 15:07           ` Maxime Devos
2022-02-02 15:27           ` Maxime Devos
2022-02-04 16:16       ` Maxime Devos
2022-12-29 18:13 ` [bug#52555] [PATCH v3 0/8] " pukkamustard
2022-12-29 18:13   ` [bug#52555] [PATCH v3 1/8] publish: Add ERIS URN to narinfo pukkamustard
2023-01-14 18:34     ` [bug#52555] [RFC PATCH 0/3] Decentralized substitute distribution with ERIS Ludovic Courtès
2022-12-29 18:13   ` [bug#52555] [PATCH v3 2/8] publish: Store ERIS encoded blocks to a local block store pukkamustard
2023-01-14 18:42     ` [bug#52555] [RFC PATCH 0/3] Decentralized substitute distribution with ERIS Ludovic Courtès
2022-12-29 18:13   ` [bug#52555] [PATCH v3 3/8] publish: Add HTTP endpoint for resolving ERIS blocks pukkamustard
2022-12-29 18:13   ` [bug#52555] [PATCH v3 4/8] WIP: substitute: Fetch substitutes using ERIS pukkamustard
2022-12-29 18:13   ` [bug#52555] [PATCH v3 5/8] eris/http: Add HTTP block de-referencer pukkamustard
2022-12-29 18:13   ` [bug#52555] [PATCH v3 6/8] WIP: eris: Use HTTP to get ERIS blocks pukkamustard
2022-12-29 18:13   ` [bug#52555] [PATCH v3 7/8] eris: Use parameterized %eris-peers when getting blocks pukkamustard
2022-12-29 18:13   ` [bug#52555] [PATCH v3 8/8] eris: Use IPFS to get ERIS blocks pukkamustard
2023-01-14 18:25   ` [bug#52555] [RFC PATCH 0/3] Decentralized substitute distribution with ERIS Ludovic Courtès
2023-12-28  9:40 ` [bug#52555] [PATCH v4 0/7] " pukkamustard
2023-12-28  9:40   ` [bug#52555] [PATCH v4 1/7] narinfo: Add ERIS field pukkamustard
2023-12-28  9:40   ` [bug#52555] [PATCH v4 2/7] gnu: Add guile-coap pukkamustard
2023-12-28  9:40   ` [bug#52555] [PATCH v4 3/7] gnu: guile-eris: Update to 1.2.0-dev pukkamustard
2023-12-28  9:40   ` [bug#52555] [PATCH v4 4/7] publish: Add ERIS URN to narinfo pukkamustard
2023-12-28  9:40   ` pukkamustard [this message]
2023-12-28  9:40   ` [bug#52555] [PATCH v4 6/7] substitute: Decode substitutes using ERIS pukkamustard
2023-12-28  9:40   ` [bug#52555] [PATCH v4 7/7] gnu: Add kapla pukkamustard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cd7432fcc871296d8a14b902e65190669ef89d62.1703316055.git.pukkamustard@posteo.net \
    --to=pukkamustard@posteo.net \
    --cc=52555@debbugs.gnu.org \
    --cc=dev@jpoiret.xyz \
    --cc=guix@cbaines.net \
    --cc=ludo@gnu.org \
    --cc=maximedevos@telenet.be \
    --cc=me@tobias.gr \
    --cc=othacehe@gnu.org \
    --cc=rekado@elephly.net \
    --cc=zimon.toutoune@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.