[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug#52555] [PATCH v3 5/8] eris/http: Add HTTP block de-referencer.
From: |
pukkamustard |
Subject: |
[bug#52555] [PATCH v3 5/8] eris/http: Add HTTP block de-referencer. |
Date: |
Thu, 29 Dec 2022 18:13:24 +0000 |
* guix/eris/http.scm (eris-http-block-ref): New procedure.
---
guix/eris/http.scm | 46 ++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 44 insertions(+), 2 deletions(-)
diff --git a/guix/eris/http.scm b/guix/eris/http.scm
index a8a9520197..354d3be3be 100644
--- a/guix/eris/http.scm
+++ b/guix/eris/http.scm
@@ -18,11 +18,17 @@
(define-module (guix eris http)
#:use-module (eris utils base32)
+
#:use-module (web uri)
+ #:use-module (web client)
+ #:use-module (web response)
- #:use-module (srfi srfi-2)
+ #:use-module (rnrs base)
+ #:use-module (srfi srfi-2) ; and-let*
+ #:use-module (srfi srfi-71) ; extended let-syntax for multiple values
- #:export (make-blake2b-urn-query-ref))
+ #:export (make-blake2b-urn-query-ref
+ eris-http-block-ref))
(define blake2b-uri-path-regexp
(make-regexp "^blake2b:" regexp/icase))
@@ -38,3 +44,39 @@ (define (make-blake2b-urn-query-ref block-ref)
(blake2b-ref (base32-decode
(string-drop (uri-path urn) 8))))
(block-ref blake2b-ref))))
+
+(define (make-blake2b-urn ref)
+ (string-append "urn:blake2b:" (base32-encode ref)))
+
+(define (make-request-uri host ref)
+ (build-uri (uri-scheme host)
+ #:userinfo (uri-userinfo host)
+ #:host (uri-host host)
+ #:port (uri-port host)
+ #:path "/uri-res/N2R"
+ #:query (make-blake2b-urn ref)))
+
+(define* (eris-http-block-ref
+ ref
+ #:key host
+ (open-connection (lambda (host) (open-socket-for-uri host))))
+
+ (let* ((uri (make-request-uri host ref))
+ (_ (format #t "URI: ~a\n" uri))
+ (response body
+ (http-get uri
+ #:decode-body? #f
+ #:port (open-connection host)
+ #:keep-alive? #t)))
+ (if (eqv? (response-code response) 200)
+ body
+ #f)))
+
+;; (use-modules (eris)
+;; (rnrs bytevectors))
+
+;; (bytevector?
+;; (eris-http-block-ref
+;; (base32-decode
+;; "4ACQM2Q5IB3DBHGKHM2WRTAXDBPMVZ7F6MG2TUXZ5QOJHW7P4N7Q")
+;; #:host (string->uri "http://localhost:8081")))
--
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 <=
- [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, 2022/12/29