From 53c439e584eb81b62d49a83a2b29c8745f5656fd Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Sat, 4 Jun 2022 02:28:48 +0530 Subject: socket: Introduce types. will be a universal type to specify IP addresses, ports and Unix sockets across all guix-forge services. * guix/forge/socket.scm: New file. * doc/forge.skb (Reference): Document and . --- doc/forge.skb | 11 +++++++++++ guix/forge/socket.scm | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 guix/forge/socket.scm diff --git a/doc/forge.skb b/doc/forge.skb index 7aa7939..5c46412 100644 --- a/doc/forge.skb +++ b/doc/forge.skb @@ -240,6 +240,17 @@ unused unused, and may be deprecated in the future.])) (record-field "trigger?" [If ,(code [#t]), this job is run on every commit. Else, it must be manually set up to run some other way.])) + (record-documentation "guix/forge/socket.scm" ' + (record-field "ip" + [IP address, either IPv4 or IPv6, as a string. The loopback +address is ,(code ["127.0.0.1"]) and ,(code ["::1"]) for IPv4 and IPv6 +respectively. The any address is ,(code ["0.0.0.0"]) and ,(code +["::"]) for IPv4 and IPv6 respectively.]) + (record-field "port" + [Port number to listen on.])) + (record-documentation "guix/forge/socket.scm" ' + (record-field "path" + [Path to socket file.])) (record-documentation "guix/forge/webhook.scm" ' (record-field "package" [,(code [webhook]) package to use]) diff --git a/guix/forge/socket.scm b/guix/forge/socket.scm new file mode 100644 index 0000000..4098112 --- /dev/null +++ b/guix/forge/socket.scm @@ -0,0 +1,52 @@ +;;; guix-forge --- Guix software forge meta-service +;;; Copyright © 2022 Arun Isaac +;;; +;;; This file is part of guix-forge. +;;; +;;; guix-forge is free software: you can redistribute it and/or modify +;;; it under the terms of the GNU General Public License as published +;;; by the Free Software Foundation, either version 3 of the License, +;;; or (at your option) any later version. +;;; +;;; guix-forge is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;;; General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with guix-forge. If not, see +;;; . + +(define-module (forge socket) + #:use-module (guix records) + #:export ( + forge-ip-socket + forge-ip-socket? + forge-ip-socket-ip + forge-ip-socket-port + ipv4-address? + ipv6-address? + + forge-unix-socket + forge-unix-socket? + forge-unix-socket-path)) + +(define-record-type* + forge-ip-socket make-forge-ip-socket + forge-ip-socket? + (ip forge-ip-socket-ip + (default "127.0.0.1")) + (port forge-ip-socket-port)) + +(define (ipv4-address? address) + "Return #t if ADDRESS is an IPv4 address. Else, return #f." + (string-contains? address ".")) + +(define (ipv6-address? address) + "Return #t if ADDRESS is an IPv6 address. Else, return #f." + (string-contains? address ":")) + +(define-record-type* + forge-unix-socket make-forge-unix-socket + forge-unix-socket? + (path forge-unix-socket-path)) -- cgit v1.2.3