unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: "Ludovic Courtès" <ludo@gnu.org>
To: Mathieu Othacehe <othacehe@gnu.org>
Cc: 44800@debbugs.gnu.org
Subject: [bug#44800] [PATCH v2 1/3] Add Avahi support.
Date: Fri, 27 Nov 2020 18:04:44 +0100	[thread overview]
Message-ID: <87k0u6spcj.fsf@gnu.org> (raw)
In-Reply-To: <20201124132145.217751-2-othacehe@gnu.org> (Mathieu Othacehe's message of "Tue, 24 Nov 2020 14:21:43 +0100")

Mathieu Othacehe <othacehe@gnu.org> skribis:

> * guix/avahi.scm: New file.
> * Makefile.am (MODULES): Add it.
> * configure.ac: Add Guile-Avahi dependency.
> * doc/guix.texi (Requirements): Document it.
> * gnu/packages/package-management.scm (guix)[native-inputs]: Add
> "guile-avahi",
> [propagated-inputs]: ditto.
> * guix/self.scm (specification->package): Add guile-avahi.
> (compiled-guix): Ditto.

[...]

> --- a/configure.ac
> +++ b/configure.ac
> @@ -161,6 +161,12 @@ if test "x$have_guile_lzlib" != "xyes"; then
>    AC_MSG_ERROR([Guile-lzlib is missing; please install it.])
>  fi
>  
> +dnl Check for Guile-Avahi.
> +GUILE_MODULE_AVAILABLE([have_guile_avahi], [(avahi)])
> +if test "x$have_guile_avahi" != "xyes"; then
> +  AC_MSG_ERROR([Guile-Avahi is missing; please install it.])
> +fi

I wonder if we could/should make it an optional dependency.

(guix avahi) would need to autoload (avahi), which might be slightly
annoying.

An argument in favor of making it mandatory is that it would help make
the feature more widely used, and thus more widely useful.

> +(define-record-type* <avahi-service>
> +  avahi-service make-avahi-service
> +  avahi-service?
> +  (name avahi-service-name)
> +  (type avahi-service-type)
> +  (interface avahi-service-interface)
> +  (local-address avahi-service-local-address)
> +  (address avahi-service-address)
> +  (port avahi-service-port)
> +  (txt avahi-service-txt))

You could use (srfi srfi-9) ‘define-record-type’ since the extra (guix
records) features are not necessary here.

> +(define* (avahi-publish-service-thread name
> +                                       #:key
> +                                       type port
> +                                       (stop-loop? (const #f))
> +                                       (timeout 100)
> +                                       (txt '()))
> +  "Publish the service TYPE using Avahi, for the given PORT, on all interfaces
> +and for all protocols. Also, advertise the given TXT record list.
> +
> +This procedure starts a new thread running the Avahi event loop.  It exits
> +when STOP-LOOP? procedure returns true."
> +  (define client-callback
> +    (lambda (client state)
> +      (when (eq? state client-state/s-running)
> +        (let ((group (make-entry-group client (const #t))))
> +          (apply
> +           add-entry-group-service! group interface/unspecified
> +           protocol/unspecified '()
> +           name type #f #f port txt)
> +          (commit-entry-group group)))))
> +
> +  (call-with-new-thread
> +   (lambda ()
> +     (let* ((poll (make-simple-poll))
> +            (client (make-client (simple-poll poll)
> +                                 (list
> +                                  client-flag/ignore-user-config)
> +                                 client-callback)))
> +       (while (not (stop-loop?))
> +         (iterate-simple-poll poll timeout))))))

(I wanted to add an API in Guile-Avahi to “invert inversion of control”
so that one could escape callback hell but never got around to
completing it.)

> +(define (interface->ip-address interface)
> +  "Return the local IP address of the given INTERFACE."
> +  (let ((address
> +         (network-interface-address
> +          (socket AF_INET SOCK_STREAM 0) interface)))
> +    (inet-ntop (sockaddr:fam address) (sockaddr:addr address))))

Make sure to close the socket.

Can’t we obtain the IP address without creating a socket actually?  Noob
here.

> +    ;; Handle service resolution events.
> +    (cond ((eq? event resolver-event/found)
> +           (info (G_ "resolved service `~a' at `~a:~a'~%")
> +                 service-name (inet-ntop family address) port)

IWBN to not add UI code in here.

Thanks,
Ludo’.




  reply	other threads:[~2020-11-27 17:05 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-22 15:56 [bug#44800] [PATCH 0/2] publish: Add Avahi support Mathieu Othacehe
2020-11-22 15:56 ` [bug#44802] [PATCH 1/2] " Mathieu Othacehe
2020-11-22 15:56 ` [bug#44801] [PATCH 2/2] publish: Add avahi support Mathieu Othacehe
2020-11-23 22:04 ` [bug#44800] [PATCH 0/2] publish: Add Avahi support zimoun
2020-11-24 13:35   ` Mathieu Othacehe
2020-11-24 13:21 ` [bug#44800] [PATCH v2 0/3] " Mathieu Othacehe
2020-11-24 13:21   ` [bug#44800] [PATCH v2 1/3] " Mathieu Othacehe
2020-11-27 17:04     ` Ludovic Courtès [this message]
2020-11-27 17:09       ` zimoun
2020-11-28 11:02         ` Ludovic Courtès
2020-11-28 18:59           ` zimoun
2020-11-29 14:18       ` Mathieu Othacehe
2020-11-24 13:21   ` [bug#44800] [PATCH v2 2/3] publish: Add avahi support Mathieu Othacehe
2020-11-27 17:12     ` Ludovic Courtès
2020-11-29 14:19       ` Mathieu Othacehe
2020-11-24 13:21   ` [bug#44800] [PATCH v2 3/3] Use substitute servers on the local network Mathieu Othacehe
2020-11-27 17:37     ` Ludovic Courtès
2020-11-29 14:29       ` Mathieu Othacehe
2020-11-30 13:46         ` Ludovic Courtès
2020-12-01  8:43           ` bug#44800: " Mathieu Othacehe
2020-11-27 16:54   ` [bug#44800] [PATCH v2 0/3] publish: Add Avahi support Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87k0u6spcj.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=44800@debbugs.gnu.org \
    --cc=othacehe@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).