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>
Subject: [bug#52555] [PATCH v3 2/8] publish: Store ERIS encoded blocks to a local block store.
Date: Thu, 29 Dec 2022 18:13:21 +0000	[thread overview]
Message-ID: <20221229181327.758-3-pukkamustard@posteo.net> (raw)
In-Reply-To: <20221229181327.758-1-pukkamustard@posteo.net>

* guix/eris.scm: New file.
* guix/eris/fs-store.scm: New file.
* Makefile.am (MODULES): Add new files.
* guix/scripts/publish.scm (bake-narinfo+nar): Use guix-eris-block-reducer.
---
 Makefile.am              |  2 ++
 guix/eris.scm            | 36 +++++++++++++++++++++
 guix/eris/fs-store.scm   | 67 ++++++++++++++++++++++++++++++++++++++++
 guix/scripts/publish.scm | 14 +++++----
 4 files changed, 113 insertions(+), 6 deletions(-)
 create mode 100644 guix/eris.scm
 create mode 100644 guix/eris/fs-store.scm

diff --git a/Makefile.am b/Makefile.am
index b54288c0fc..c549fc8580 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -132,6 +132,8 @@ MODULES =					\
   guix/least-authority.scm			\
   guix/read-print.scm				\
   guix/ipfs.scm					\
+  guix/eris.scm                                 \
+  guix/eris/fs-store.scm                        \
   guix/platform.scm                             \
   guix/platforms/arm.scm                        \
   guix/platforms/mips.scm                       \
diff --git a/guix/eris.scm b/guix/eris.scm
new file mode 100644
index 0000000000..29d5e7b1db
--- /dev/null
+++ b/guix/eris.scm
@@ -0,0 +1,36 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2022 pukkamustard <pukkamustard@posteo.net>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (guix eris)
+  #:use-module (eris)
+
+  #:use-module (guix config)
+  #:use-module (guix eris fs-store)
+
+  #:export (guix-eris-block-reducer
+
+            %eris-block-store-directory))
+
+(define %eris-block-store-directory
+  (make-parameter
+   (or (getenv "GUIX_ERIS_BLOCK_STORE_DIRECTORY")
+       (string-append %state-directory "/eris"))))
+
+(define (guix-eris-block-reducer)
+  "Returns a block reducer that stores blocks of ERIS encoded content."
+  (eris-fs-store-reducer (%eris-block-store-directory)))
diff --git a/guix/eris/fs-store.scm b/guix/eris/fs-store.scm
new file mode 100644
index 0000000000..2ef7607988
--- /dev/null
+++ b/guix/eris/fs-store.scm
@@ -0,0 +1,67 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2022 pukkamustard <pukkamustard@posteo.net>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (guix eris fs-store)
+  #:use-module (rnrs io ports)
+  #:use-module (guix build utils) ; for mkdir-p
+  #:use-module (eris utils base32)
+
+  #:export (eris-fs-store-reducer
+            eris-fs-store-ref))
+
+;;; Commentary:
+;;;
+;;; This module provides a file-system based store of ERIS encoded blocks.
+;;;
+;;; Code:
+
+(define (eris-fs-store-reducer store-directory)
+  (case-lambda
+    (() (mkdir-p store-directory))
+
+    ((result) result)
+
+    ((_ ref-block)
+     (let* ((ref (car ref-block))
+	    (b32 (base32-encode ref))
+	    (pre (substring b32 0 2))
+	    (suf (substring b32 2))
+	    (pre-dir (string-append store-directory "/" pre))
+	    (path (string-append pre-dir "/" suf))
+	    (block (cdr ref-block)))
+
+       (mkdir-p pre-dir)
+
+       (unless (file-exists? path)
+	 (call-with-output-file path
+	   (lambda (port) (put-bytevector port block))
+	   #:binary #t))
+
+       #t))))
+
+(define (eris-fs-store-ref store-directory)
+  (lambda (ref)
+    (let* ((b32 (base32-encode ref))
+	   (pre (substring b32 0 2))
+	   (suf (substring b32 2))
+	   (path (string-append store-directory "/" pre "/" suf)))
+      (if (file-exists? path)
+	  (call-with-input-file path
+	    (lambda (port) (get-bytevector-all port))
+	    #:binary #t)
+	  #f))))
diff --git a/guix/scripts/publish.scm b/guix/scripts/publish.scm
index 76b5a429f4..7f14e4d4d4 100644
--- a/guix/scripts/publish.scm
+++ b/guix/scripts/publish.scm
@@ -52,6 +52,7 @@ (define-module (guix scripts publish)
   #:use-module (guix base64)
   #:use-module (guix config)
   #:use-module (guix derivations)
+  #:use-module (guix eris)
   #:use-module (gcrypt hash)
   #:use-module (guix pki)
   #:use-module (gcrypt pk-crypto)
@@ -647,12 +648,13 @@ (define (eris-encode-nar compressions)
            (and stat
                 (call-with-input-file nar
                   (lambda (port)
-                    (let ((eris-urn _
-                                    (eris-encode port
-                                                 #:block-size 'large
-                                                 #:block-reducer rcount
-                                                 #:convergence-secret
-                                                 %null-convergence-secret)))
+                    (let ((eris-urn
+                           _ (eris-encode port
+                                          #:block-size 'large
+                                          #:block-reducer
+                                          (guix-eris-block-reducer)
+                                          #:convergence-secret
+                                          %null-convergence-secret)))
                       eris-urn)))))))
 
   (let ((compression (actual-compressions item compressions)))
-- 
2.38.1





  parent reply	other threads:[~2022-12-29 18:49 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   ` pukkamustard [this message]
2023-01-14 18:42     ` 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   ` [bug#52555] [PATCH v4 5/7] eris: Connect with an ERIS Store over CoAP+Unix pukkamustard
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=20221229181327.758-3-pukkamustard@posteo.net \
    --to=pukkamustard@posteo.net \
    --cc=52555@debbugs.gnu.org \
    /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.