[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug#52555] [PATCH v3 6/8] WIP: eris: Use HTTP to get ERIS blocks.
From: |
pukkamustard |
Subject: |
[bug#52555] [PATCH v3 6/8] WIP: eris: Use HTTP to get ERIS blocks. |
Date: |
Thu, 29 Dec 2022 18:13:25 +0000 |
- guix/eris.scm (guix-eris-block-ref): Refactor from call-with-eris-block-ref
and use eris-http-block-ref.
- guix/eris/fs-store.scm (eris-fs-store-ref): Refactor to take keyword
arguments.
- guix/scripts/substitute.scm (download-nar): Use guix-eris-block-ref.
- guix/scripts/publish.scm (make-request-handler): Use refactored
eris-fs-store-ref.
TODO:
- default value for %eris-peers parameter in (eris)
---
guix/eris.scm | 37 +++++++++++++++++++++++++++++++------
guix/eris/fs-store.scm | 21 ++++++++++-----------
guix/scripts/publish.scm | 9 ++++-----
guix/scripts/substitute.scm | 14 ++++++++------
4 files changed, 53 insertions(+), 28 deletions(-)
diff --git a/guix/eris.scm b/guix/eris.scm
index d9a0914b67..4af17c2807 100644
--- a/guix/eris.scm
+++ b/guix/eris.scm
@@ -21,9 +21,13 @@ (define-module (guix eris)
#:use-module (guix config)
#:use-module (guix eris fs-store)
+ #:use-module (guix eris http)
+
+ #:use-module (web uri)
+ #:use-module (ice-9 match)
#:export (guix-eris-block-reducer
- call-with-eris-block-ref
+ guix-eris-block-ref
%eris-block-store-directory))
@@ -36,8 +40,29 @@ (define (guix-eris-block-reducer)
"Returns a block reducer that stores blocks of ERIS encoded content."
(eris-fs-store-reducer (%eris-block-store-directory)))
-(define (call-with-eris-block-ref f)
- (let ((fs-store-block-ref
- (eris-fs-store-ref
- (%eris-block-store-directory))))
- (f fs-store-block-ref)))
+(define %eris-peers
+ (make-parameter
+ ;; TODO
+ (list (string->uri "http://localhost:8081"))))
+
+(define* (try-in-order ref #:key block-refs)
+ (match block-refs
+ ((block-ref . rest)
+ (let ((block (block-ref ref)))
+ (if block
+ block
+ (try-in-order ref #:block-refs rest))))
+ (() #f)))
+
+(define* (guix-eris-block-ref ref #:key open-connection)
+ (try-in-order
+ ref
+ #:block-refs
+ (list
+ (lambda (ref)
+ (eris-fs-store-ref ref
+ #:store-directory (%eris-block-store-directory)))
+ (lambda (ref)
+ (eris-http-block-ref ref
+ #:host (string->uri "http://localhost:8081")
+ #:open-connection open-connection)))))
diff --git a/guix/eris/fs-store.scm b/guix/eris/fs-store.scm
index 2ef7607988..38f5926280 100644
--- a/guix/eris/fs-store.scm
+++ b/guix/eris/fs-store.scm
@@ -54,14 +54,13 @@ (define (eris-fs-store-reducer store-directory)
#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))))
+(define* (eris-fs-store-ref ref #:key store-directory)
+ (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 15bdf02670..0ce50b2942 100644
--- a/guix/scripts/publish.scm
+++ b/guix/scripts/publish.scm
@@ -1085,13 +1085,12 @@ (define nar-path?
(let ((expected (split-and-decode-uri-path nar-path)))
(cut equal? expected <>)))
- ;; Get ERIS blocks directly from the filesystem store.
- (define eris-block-ref
- (eris-fs-store-ref (%eris-block-store-directory)))
-
;; Create a handler for resolving blake2b URN queries.
(define blake2b-urn-query-ref
- (make-blake2b-urn-query-ref eris-block-ref))
+ (make-blake2b-urn-query-ref
+ (lambda (ref) (eris-fs-store-ref
+ ref
+ #:store-directory (%eris-block-store-directory)))))
(define (handle request body)
(format #t "~a ~a~%"
diff --git a/guix/scripts/substitute.scm b/guix/scripts/substitute.scm
index 8cf011d7e6..14a21f6c37 100755
--- a/guix/scripts/substitute.scm
+++ b/guix/scripts/substitute.scm
@@ -482,12 +482,14 @@ (define (fetch uri)
((urn)
(let ((read-capability (->eris-read-capability uri)))
(if (eris-read-capability? read-capability)
- (call-with-eris-block-ref
- (lambda (block-ref)
- (values (open-eris-input-port
- read-capability
- #:block-ref block-ref)
- #f)))
+ (values
+ (open-eris-input-port
+ read-capability
+ #:block-ref (lambda (ref)
+ (guix-eris-block-ref
+ ref
+ #:open-connection
open-connection-for-uri/cached)))
+ #f)
(leave (G_ "unsupported substitute URI scheme: ~a~%")
(uri->string uri)))))
(else
--
2.38.1
- [bug#52555] [PATCH v3 0/8] Decentralized substitute distribution with ERIS, pukkamustard, 2022/12/29
- [bug#52555] [PATCH v3 2/8] publish: Store ERIS encoded blocks to a local block store., pukkamustard, 2022/12/29
- [bug#52555] [PATCH v3 1/8] publish: Add ERIS URN to narinfo., pukkamustard, 2022/12/29
- [bug#52555] [PATCH v3 3/8] publish: Add HTTP endpoint for resolving ERIS blocks., pukkamustard, 2022/12/29
- [bug#52555] [PATCH v3 4/8] WIP: substitute: Fetch substitutes using ERIS., pukkamustard, 2022/12/29
- [bug#52555] [PATCH v3 5/8] eris/http: Add HTTP block de-referencer., pukkamustard, 2022/12/29
- [bug#52555] [PATCH v3 8/8] eris: Use IPFS to get ERIS blocks., pukkamustard, 2022/12/29
- [bug#52555] [PATCH v3 7/8] eris: Use parameterized %eris-peers when getting blocks., pukkamustard, 2022/12/29
- [bug#52555] [PATCH v3 6/8] WIP: eris: Use HTTP to get ERIS blocks.,
pukkamustard <=