tordam

A library for peer discovery inside the Tor network
git clone https://git.parazyd.org/tordam
Log | Files | Refs | README | LICENSE

commit 3012518656357a46673a8e8923904a47db798641
parent c3cd139062b5450dbf4e37bf51415fb3ba75a590
Author: parazyd <parazyd@dyne.org>
Date:   Tue, 12 Dec 2017 13:07:02 +0100

Implement more control over the HTTP server.

Diffstat:
Mcmd/dam-dir/main.go | 17++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/cmd/dam-dir/main.go b/cmd/dam-dir/main.go @@ -150,6 +150,7 @@ func handleElse(rw http.ResponseWriter, request *http.Request) { func main() { var wg sync.WaitGroup + // Chdir to our working directory. if _, err := os.Stat(lib.Cwd); os.IsNotExist(err) { err := os.Mkdir(lib.Cwd, 0700) lib.CheckError(err) @@ -162,12 +163,18 @@ func main() { startRedis() } - http.HandleFunc("/announce", handlePost) - http.HandleFunc("/", handleElse) - + mux := http.NewServeMux() + mux.HandleFunc("/announce", handlePost) + mux.HandleFunc("/", handleElse) + srv := &http.Server{ + Addr: ListenAddress, + Handler: mux, + ReadTimeout: 30 * time.Second, + WriteTimeout: 30 * time.Second, + } wg.Add(1) - go http.ListenAndServe(ListenAddress, nil) + go srv.ListenAndServe() log.Println("Listening on", ListenAddress) - wg.Wait() + os.Exit(1) }