jech / galene

The Galène videoconference server
https://galene.org
MIT License
944 stars 130 forks source link

Feature request: listening on a unix socket #141

Closed Kerl13 closed 2 years ago

Kerl13 commented 2 years ago

Unless I missed something it seems that galene's -http argument expects an ADDR/PORT pair. I would like to make it bind to a unix socket instead. Is there a way to achieve that at the moment? And if not, do you have interest in such a feature?


Long story:

My end goal would be to:

so that nginx handles the SSL/TLS logic instead of galene and I have clean urls without port numbers. At the moment I achieve something similar using -http 127.0.0.1:8443 instead but I like unix sockets as they allow to give meaningful file names instead of random port numbers.

By the way, do you see any counter indication to such a setup?


Thanks for you time and for making galene! Cheers

jech commented 2 years ago

Please try this patch (completely untested), and let me know if it does what you want.

diff --git a/webserver/webserver.go b/webserver/webserver.go
index 95642c5..9085c35 100644
--- a/webserver/webserver.go
+++ b/webserver/webserver.go
@@ -9,6 +9,7 @@ import (
    "html"
    "io"
    "log"
+   "net"
    "net/http"
    "net/url"
    "os"
@@ -72,12 +73,21 @@ func Serve(address string, dataDir string) error {

    server.Store(s)

-   var err error
+   proto := "tcp"
+   if strings.HasPrefix(address, "/") {
+       proto = "unix"
+   }
+
+   listener, err := net.Listen(proto, address)
+   if err != nil {
+       return err
+   }
+   defer listener.Close()

    if !Insecure {
-       err = s.ListenAndServeTLS("", "")
+       err = s.ServeTLS(listener, "", "")
    } else {
-       err = s.ListenAndServe()
+       err = s.Serve(listener)
    }

    if err == http.ErrServerClosed {
Kerl13 commented 2 years ago

It does exactly what I want, thanks!

jech commented 2 years ago

Fixed by dcb370677ff6bf1a6f091fa9860cc5723c22818b.