From patchwork Thu Dec 28 09:40:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: pukkamustard X-Patchwork-Id: 58130 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 8596527BBE2; Thu, 28 Dec 2023 09:41:44 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id A557C27BBEA for ; Thu, 28 Dec 2023 09:41:43 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rImt3-0007eD-Cq; Thu, 28 Dec 2023 04:41:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rImt1-0007d5-4z for guix-patches@gnu.org; Thu, 28 Dec 2023 04:41:07 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rImt0-000838-RU; Thu, 28 Dec 2023 04:41:06 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rImsy-0005lZ-17; Thu, 28 Dec 2023 04:41:04 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#52555] [PATCH v4 5/7] eris: Connect with an ERIS Store over CoAP+Unix. Resent-From: pukkamustard Original-Sender: "Debbugs-submit" Resent-CC: guix@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, rekado@elephly.net, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Thu, 28 Dec 2023 09:41:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 52555 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 52555@debbugs.gnu.org Cc: pukkamustard , ludo@gnu.org, maximedevos@telenet.be, Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by 52555-submit@debbugs.gnu.org id=B52555.170375644022065 (code B ref 52555); Thu, 28 Dec 2023 09:41:03 +0000 Received: (at 52555) by debbugs.gnu.org; 28 Dec 2023 09:40:40 +0000 Received: from localhost ([127.0.0.1]:38524 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rImsa-0005jj-4K for submit@debbugs.gnu.org; Thu, 28 Dec 2023 04:40:40 -0500 Received: from mout02.posteo.de ([185.67.36.66]:38673) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rImsW-0005iS-3U for 52555@debbugs.gnu.org; Thu, 28 Dec 2023 04:40:36 -0500 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 16657240104 for <52555@debbugs.gnu.org>; Thu, 28 Dec 2023 10:40:31 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1703756431; bh=MpsZR+/mCFO0Zar2E/8aRpMlNeo5yh3syt0Ter6cMiw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version: Content-Transfer-Encoding:From; b=B87bev7hDLjGtYTHgZDQzkIxu1aVihuiG90xoP16QlBpSGABWOsK3zKNacwdSSvKz f6zbwqZ0xRl4YPuviLTiF/hOmmm3AGa749vIV19QMQ0RqhjM6pV/cq93VYpRQOiqKY xsQHOzMxPfhBHpDsq6N+HzlUzgfLt74CScBrnoQ0rdL80zcCTC8e5C4lA4R4wLauGo v2AEDh+26Rccv4yC2MpMfsfArCYlve1V5VYqTPsEBGEpQem4FH7NmSNA/bZOPxOv56 PqSa95Raz1ppzndV7QziSOlD7DaB+XvgeXodWzSysweyYtkF4lPSGq/T1yu50O9PjV zeH6ghbQTxucw== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4T13Qk21ZPz6tn4; Thu, 28 Dec 2023 10:40:30 +0100 (CET) From: pukkamustard Date: Thu, 28 Dec 2023 09:40:08 +0000 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * 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)