]> Cypherpunks.ru repositories - gocheese.git/blobdiff - main.go
UCSPI-TCP support
[gocheese.git] / main.go
diff --git a/main.go b/main.go
index cc30de23dfc84596f7980a2fef81fc370827521c..12a325a93435af81d330f2ff9e844e31da891e13 100644 (file)
--- a/main.go
+++ b/main.go
@@ -90,22 +90,28 @@ var (
                HashAlgoMD5,
        }
 
-       root             = flag.String("root", "./packages", "Path to packages directory")
-       bind             = flag.String("bind", "[::]:8080", "Address to bind to")
-       tlsCert          = flag.String("tls-cert", "", "Path to TLS X.509 certificate")
-       tlsKey           = flag.String("tls-key", "", "Path to TLS X.509 private key")
+       root       = flag.String("root", "./packages", "Path to packages directory")
+       bind       = flag.String("bind", "[::]:8080", "Address to bind to")
+       maxClients = flag.Int("maxclients", 128, "Maximal amount of simultaneous clients")
+       doUCSPI    = flag.Bool("ucspi", false, "Work as UCSPI-TCP service")
+
+       tlsCert = flag.String("tls-cert", "", "Path to TLS X.509 certificate")
+       tlsKey  = flag.String("tls-key", "", "Path to TLS X.509 private key")
+
        norefreshURLPath = flag.String("norefresh", "/norefresh/", "Non-refreshing URL path")
        refreshURLPath   = flag.String("refresh", "/simple/", "Auto-refreshing URL path")
        gpgUpdateURLPath = flag.String("gpgupdate", "/gpgupdate/", "GPG forceful refreshing URL path")
-       pypiURL          = flag.String("pypi", "https://pypi.org/simple/", "Upstream (PyPI) URL")
-       pypiCertHash     = flag.String("pypi-cert-hash", "", "Authenticate upstream by its X.509 certificate's SPKI SHA256 hash")
-       logTimestamped   = flag.Bool("log-timestamped", false, "Prepend timestmap to log messages")
-       passwdPath       = flag.String("passwd", "", "Path to FIFO for upload authentication")
-       passwdCheck      = flag.Bool("passwd-check", false, "Run password checker")
-       fsck             = flag.Bool("fsck", false, "Check integrity of all packages (errors are in stderr)")
-       maxClients       = flag.Int("maxclients", 128, "Maximal amount of simultaneous clients")
-       version          = flag.Bool("version", false, "Print version information")
-       warranty         = flag.Bool("warranty", false, "Print warranty information")
+
+       pypiURL      = flag.String("pypi", "https://pypi.org/simple/", "Upstream (PyPI) URL")
+       pypiCertHash = flag.String("pypi-cert-hash", "", "Authenticate upstream by its X.509 certificate's SPKI SHA256 hash")
+
+       passwdPath  = flag.String("passwd", "", "Path to FIFO for upload authentication")
+       passwdCheck = flag.Bool("passwd-check", false, "Run password checker")
+
+       logTimestamped = flag.Bool("log-timestamped", false, "Prepend timestmap to log messages")
+       fsck           = flag.Bool("fsck", false, "Check integrity of all packages (errors are in stderr)")
+       version        = flag.Bool("version", false, "Print version information")
+       warranty       = flag.Bool("warranty", false, "Print warranty information")
 
        killed        bool
        pypiURLParsed *url.URL
@@ -278,7 +284,9 @@ func main() {
        } else {
                log.SetFlags(log.Lshortfile)
        }
-       log.SetOutput(os.Stdout)
+       if !*doUCSPI {
+               log.SetOutput(os.Stdout)
+       }
 
        if *fsck {
                if !goodIntegrity() {
@@ -340,11 +348,6 @@ func main() {
                }
        }
 
-       ln, err := net.Listen("tcp", *bind)
-       if err != nil {
-               log.Fatal(err)
-       }
-       ln = netutil.LimitListener(ln, *maxClients)
        server := &http.Server{
                ReadTimeout:  time.Minute,
                WriteTimeout: time.Minute,
@@ -355,6 +358,24 @@ func main() {
                http.HandleFunc(*gpgUpdateURLPath, handler)
        }
 
+       if *doUCSPI {
+               server.SetKeepAlivesEnabled(false)
+               ln := &UCSPI{}
+               server.ConnState = connStater
+               err := server.Serve(ln)
+               if _, ok := err.(UCSPIAlreadyAccepted); !ok {
+                       log.Fatalln(err)
+               }
+               UCSPIJob.Wait()
+               return
+       }
+
+       ln, err := net.Listen("tcp", *bind)
+       if err != nil {
+               log.Fatal(err)
+       }
+       ln = netutil.LimitListener(ln, *maxClients)
+
        needsShutdown := make(chan os.Signal, 0)
        exitErr := make(chan error, 0)
        signal.Notify(needsShutdown, syscall.SIGTERM, syscall.SIGINT)