Subject: [bug#52555] [PATCH v3 7/8] eris: Use parameterized %eris-peers when getting blocks.

From: pukkamustard <[email-masked]>
Date: Thu, 29 Dec 2022 18:13:26 +0000

---
 guix/eris.scm | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/guix/eris.scm b/guix/eris.scm
index 4af17c2807..d56643bec4 100644
--- a/guix/eris.scm
+++ b/guix/eris.scm
@@ -54,15 +54,30 @@ (define* (try-in-order ref #:key block-refs)
            (try-in-order ref #:block-refs rest))))
     (() #f)))
 
+(define* (peer->block-ref peer #:key open-connection)
+  (case (uri-scheme peer)
+
+    ((http https)
+     (lambda (ref)
+       (eris-http-block-ref ref
+                            #:host peer
+                            #:open-connection open-connection)))
+
+    ;; unsupported ERIS peer URL
+    (else (lambda (_) #f))))
+
 (define* (guix-eris-block-ref ref #:key open-connection)
   (try-in-order
    ref
    #:block-refs
-   (list
+   (cons
+
+    ;; first try and get block from local block store
     (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)))))
+
+    ;; then try peers
+    (map (lambda (peer)
+           (peer->block-ref peer #:open-connection open-connection))
+         (%eris-peers)))))
-- 
2.38.1