From patchwork Tue Apr 13 04:17:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxim Cournoyer X-Patchwork-Id: 28480 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 9954227BC73; Tue, 13 Apr 2021 05:18:20 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,T_DKIM_INVALID,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id CD9E227BC72 for ; Tue, 13 Apr 2021 05:18:19 +0100 (BST) Received: from localhost ([::1]:40808 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lWAVH-0007p1-2C for patchwork@mira.cbaines.net; Tue, 13 Apr 2021 00:18:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57044) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lWAV1-0007eD-0V for guix-patches@gnu.org; Tue, 13 Apr 2021 00:18:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:47167) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lWAV0-00065d-Pp for guix-patches@gnu.org; Tue, 13 Apr 2021 00:18:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lWAV0-0004jc-Lj for guix-patches@gnu.org; Tue, 13 Apr 2021 00:18:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#47741] [PATCH 3/3] services: Add opendht. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 13 Apr 2021 04:18:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47741 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 47741@debbugs.gnu.org Cc: Maxim Cournoyer Received: via spool by 47741-submit@debbugs.gnu.org id=B47741.161828747618174 (code B ref 47741); Tue, 13 Apr 2021 04:18:02 +0000 Received: (at 47741) by debbugs.gnu.org; 13 Apr 2021 04:17:56 +0000 Received: from localhost ([127.0.0.1]:58711 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lWAUn-0004iu-Jr for submit@debbugs.gnu.org; Tue, 13 Apr 2021 00:17:56 -0400 Received: from mail-qk1-f176.google.com ([209.85.222.176]:46767) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lWAUl-0004id-1W for 47741@debbugs.gnu.org; Tue, 13 Apr 2021 00:17:47 -0400 Received: by mail-qk1-f176.google.com with SMTP id o17so8192748qkl.13 for <47741@debbugs.gnu.org>; Mon, 12 Apr 2021 21:17:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kEILGjC2wulZFHqmBs6nn0qcsPZswtpeNU3ZDu1lsg0=; b=IO6TjZO69pChoJW9BQcYzdN7Q1Y5R4bvCKUgPOq7W6MTnywqIy6vtD94EEdo9O7Not lk5DThjIGHxXNGwhPaXCKSywLKPdoB0Rk7j0eYsDgH3EBPxUInvLoZt4BN62jc4Rr58y nbwFeq8k/x5jeIgBfGC3Fs5yWUr7cBsm7Bk9Ju7nKvoFDQLvgxYLjvNAN9VG53tE1Bje CfTppXkNLuaFcQ8uYR6O9p6VWpBuO1LbaL7dfaKyPY+eBaUXtglW6gPmxuhqoGS2ZwzR EihgkI96N0Akn0GdZS7c6ad3pYQWUxNjLG6g8TCgQetMbfegC2q+qCNspOAtOTcddYzh A11Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kEILGjC2wulZFHqmBs6nn0qcsPZswtpeNU3ZDu1lsg0=; b=b+U/30+6UDid+SkySzwRm0XAWM8E4hRZIoI4tpLGVgR+qdi0b2ho6nUN/HRRsEGUr6 1iQeDoCz423ImlvsMvoIPd9KAr5Qcu/4inAaa5gvXW3p3967ZiEWTKH4Qodp4d+g2Vq3 A9vrbHYTy4fjY2LEZ3YH18o5L4O6umobkpawJ74ggJ+TiHxnCtHWeLi7HZnwJIWikL+t QHCOjgYAOpI3rKgro2i3iJNzj2g71HikHai0zx83I/vL0EK82n0x5fB/GgZ13rBp1/gz Izi3ZeQlavfMmwX7mV+WuwFf5LqiZOLYICNICpkw7MTY1GtT9rV/FpFIQ8kTPOIOrabl VZVg== X-Gm-Message-State: AOAM531yIapAZcBP6jVew7tnxS2guKQFusTTLjQV4MRTL5R0bU0zhWEz AL1ZhwhzLs4cdxzqu40MZ7Ri0BLeqJE= X-Google-Smtp-Source: ABdhPJwzJp7D0HKoby+WkKIut5I5mpUf/H1+8UHIm81cVCKeqxZDwbtuBz112fpCjukHVN6DtpX6og== X-Received: by 2002:ae9:f719:: with SMTP id s25mr30596226qkg.42.1618287461051; Mon, 12 Apr 2021 21:17:41 -0700 (PDT) Received: from localhost.localdomain (dsl-10-128-209.b2b2c.ca. [72.10.128.209]) by smtp.gmail.com with ESMTPSA id w1sm7414074qto.85.2021.04.12.21.17.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Apr 2021 21:17:40 -0700 (PDT) From: Maxim Cournoyer Date: Tue, 13 Apr 2021 00:17:10 -0400 Message-Id: <20210413041710.1708-3-maxim.cournoyer@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210413041710.1708-1-maxim.cournoyer@gmail.com> References: <20210413041710.1708-1-maxim.cournoyer@gmail.com> 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" X-getmail-retrieved-from-mailbox: Patches * gnu/services/networking.scm (serialize-boolean) (serialize-number, serialize-string): New dummy procedures. (maybe-number, opendht-configuration): New syntaxes. (%opendht-accounts): New variable. (opendht-configuration->command-line-arguments): Likewise. (opendht-shepherd-service, opendht-service-type): New variables. * doc/guix.texi: Document it. --- doc/guix.texi | 84 ++++++++++++++++++++++ gnu/services/networking.scm | 135 +++++++++++++++++++++++++++++++++++- 2 files changed, 218 insertions(+), 1 deletion(-) diff --git a/doc/guix.texi b/doc/guix.texi index 84d8bf50be..d2593b2180 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -16653,6 +16653,90 @@ must be @code{'()} or @code{'("internal")}. detailed discussion of each configuration field. @end deftp +@cindex opendht, distributed hash table network service +@cindex dhtproxy, for use with jami +@defvr {Scheme Variable} opendht-service-type +This is the type of the service running a @uref{https://opendht.net, +OpenDHT} node, @command{dhtnode}. The daemon can be used to host your +own proxy service to the DHT, for example to connect to with Jami, among +other applications. + +The value of this service is a @code{opendht-configuration} object, as +described below. +@end defvr + +@deftp {Data Type} opendht-configuration +This is the data type for the OpenDHT service configuration. + +@c The fields documentation has been auto-generated using the +@c configuration->documentation procedure from (gnu services +@c configuration). +@c TODO: Tweak the tool so that it generates doc that matches our +@c current standard. +Available @code{opendht-configuration} fields are: + +@deftypevr {@code{opendht-configuration} parameter} package opendht +The @code{opendht} package to use. + +@end deftypevr + +@deftypevr {@code{opendht-configuration} parameter} boolean peer-discovery? +Whether to enable the multicast local peer discovery mechanism. + +Defaults to @samp{#f}. + +@end deftypevr + +@deftypevr {@code{opendht-configuration} parameter} boolean enable-logging? +Whether to enable logging messages to syslog. It is disabled by default +as it is rather verbose. + +Defaults to @samp{#f}. + +@end deftypevr + +@deftypevr {@code{opendht-configuration} parameter} boolean debug? +Whether to enable debug-level logging messages. This has no effect if +logging is disabled. + +Defaults to @samp{#f}. + +@end deftypevr + +@deftypevr {@code{opendht-configuration} parameter} maybe-string bootstrap-host +The node host name that is used to make the first connection to the +network. A specific port value can be provided by appending the +@code{:PORT} suffix. By default, it uses the Jami bootstrap nodes, but +any host can be specified here. It's also possible to disable +bootsrapping by setting this to the @code{'disabled} symbol. + +Defaults to @samp{"bootstrap.jami.net:4222"}. + +@end deftypevr + +@deftypevr {@code{opendht-configuration} parameter} maybe-number port +The UDP port to bind to. When set to @code{'disabled}, an available +port is automatically selected. + +Defaults to @samp{4222}. + +@end deftypevr + +@deftypevr {@code{opendht-configuration} parameter} maybe-number proxy-server-port +Spawn a proxy server listening on the specified port. + +Defaults to @samp{disabled}. + +@end deftypevr + +@deftypevr {@code{opendht-configuration} parameter} maybe-number proxy-server-port-tls +Spawn a proxy server listening to TLS connections on the specified port. + +Defaults to @samp{disabled}. + +@end deftypevr +@end deftp + @cindex Tor @defvr {Scheme Variable} tor-service-type This is the type for a service that runs the @uref{https://torproject.org, diff --git a/gnu/services/networking.scm b/gnu/services/networking.scm index 231a9f66c7..8c22f0eec3 100644 --- a/gnu/services/networking.scm +++ b/gnu/services/networking.scm @@ -10,7 +10,7 @@ ;;; Copyright © 2018 Chris Marusich ;;; Copyright © 2018 Arun Isaac ;;; Copyright © 2019 Florian Pelz -;;; Copyright © 2019 Maxim Cournoyer +;;; Copyright © 2019, 2021 Maxim Cournoyer ;;; Copyright © 2019 Sou Bunnbu ;;; Copyright © 2019 Alex Griffin ;;; Copyright © 2020 Brice Waegeneire @@ -108,6 +108,18 @@ inetd-entry inetd-service-type + opendht-configuration + opendht-configuration-peer-discovery? + opendht-configuration-verbose? + opendht-configuration-bootstrap-host + opendht-configuration-port + opendht-configuration-proxy-server-port + opendht-configuration-proxy-server-port-tls + opendht-configuration->command-line-arguments + + opendht-shepherd-service + opendht-service-type + tor-configuration tor-configuration? tor-hidden-service @@ -730,6 +742,127 @@ daemon will keep the system clock synchronized with that of the given servers.") for listening on Internet sockets and spawning the corresponding services on demand."))) + +;;; +;;; OpenDHT, the distributed hash table network used by Jami +;;; + +;;; XXX: These dummy definitions is because there's no way to disable the +;;; serialization code from define-configuration. +(define (serialize-boolean option value) "") +(define (serialize-number option value) "") +(define (serialize-string option value) "") + +(define-maybe number) +(define-maybe string) + +;;; To generate the documentation of the following configuration record, you +;;; can evaluate: (configuration->documentation 'opendht-configuration) +(define-configuration opendht-configuration + (opendht + (package opendht) + "The @code{opendht} package to use.") + (peer-discovery? + (boolean #false) + "Whether to enable the multicast local peer discovery mechanism.") + (enable-logging? + (boolean #false) + "Whether to enable logging messages to syslog. It is disabled by default +as it is rather verbose.") + (debug? + (boolean #false) + "Whether to enable debug-level logging messages. This has no effect if +logging is disabled.") + (bootstrap-host + (maybe-string "bootstrap.jami.net:4222") + "The node host name that is used to make the first connection to the +network. A specific port value can be provided by appending the @code{:PORT} +suffix. By default, it uses the Jami bootstrap nodes, but any host can be +specified here. It's also possible to disable bootstrapping by setting this +to the @code{'disabled} symbol.") + (port + (maybe-number 4222) + "The UDP port to bind to. When set to @code{'disabled}, an available port +is automatically selected.") + (proxy-server-port + (maybe-number 'disabled) + "Spawn a proxy server listening on the specified port.") + (proxy-server-port-tls + (maybe-number 'disabled) + "Spawn a proxy server listening to TLS connections on the specified +port.")) + +(define %opendht-accounts + ;; User account and groups for Tor. + (list (user-group (name "opendht") (system? #t)) + (user-account + (name "opendht") + (group "opendht") + (system? #t) + (comment "OpenDHT daemon user") + (home-directory "/var/empty") + (shell (file-append shadow "/sbin/nologin"))))) + +(define (opendht-configuration->command-line-arguments config) + "Derive the command line arguments to used from CONFIG, an + object." + (match-record config + (opendht bootstrap-host enable-logging? port debug? peer-discovery? + proxy-server-port proxy-server-port-tls) + (let ((dhtnode #~(string-append #$opendht:tools "/bin/dhtnode"))) + `(,dhtnode + "--service" ;non-forking mode + ,@(if (string? bootstrap-host) + (list "--bootstrap" bootstrap-host)) + ,@(if enable-logging? + (list "--syslog") + '()) + ,@(if (number? port) + (list "--port" (number->string port)) + '()) + ,@(if debug? + (list "--verbose") + '()) + ,@(if peer-discovery? + (list "--peer-discovery") + '()) + ,@(if (number? proxy-server-port) + (list "--proxyserver" (number->string proxy-server-port)) + '()) + ,@(if (number? proxy-server-port-tls) + (list "--proxyserverssl" (number->string proxy-server-port-tls)) + '()))))) + +(define (opendht-shepherd-service config) + "Return a running OpenDHT." + (shepherd-service + (documentation "Run an OpenDHT node.") + (provision '(opendht dhtnode dhtproxy)) + (requirement '(user-processes syslogd)) + (start #~(make-forkexec-constructor/container + (list #$@(opendht-configuration->command-line-arguments config)) + #:mappings (list (file-system-mapping + (source "/dev/log") ;for syslog + (target source))) + #:user "opendht")) + (stop #~(make-kill-destructor)))) + +(define opendht-service-type + (service-type + (name 'opendht) + (default-value (opendht-configuration)) + (extensions + (list (service-extension shepherd-root-service-type + (compose list opendht-shepherd-service)) + (service-extension account-service-type + (const %opendht-accounts)))) + (description "Run the OpenDHT @command{dhtnode} command that allows +participating in the distributed hash table based OpenDHT network. The +service can be configured to act as a proxy to the distributed network, which +can be useful for portable devices where minimizing energy consumption is +paramount. OpenDHT was originally based on Kademlia and adapted for +applications in communication. It is used by Jami, for example."))) + ;;; ;;; Tor.