From 2ae2673df96fd0c7dfbbed351eab8b36a5d56fe3 Mon Sep 17 00:00:00 2001 From: Mickael Kerjean Date: Fri, 10 May 2019 18:20:00 +1000 Subject: [PATCH] feature (tor): cooking some onions - Unstable --- server/plugin/index.go | 1 - server/plugin/plg_starter_tor/index.go | 36 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 server/plugin/plg_starter_tor/index.go diff --git a/server/plugin/index.go b/server/plugin/index.go index 27a5fe80..78e0e3d7 100644 --- a/server/plugin/index.go +++ b/server/plugin/index.go @@ -2,7 +2,6 @@ package plugin import ( _ "github.com/mickael-kerjean/filestash/server/plugin/plg_starter_http" - _ "github.com/mickael-kerjean/filestash/server/plugin/plg_starter_tor" _ "github.com/mickael-kerjean/filestash/server/plugin/plg_image_light" _ "github.com/mickael-kerjean/filestash/server/plugin/plg_backend_backblaze" _ "github.com/mickael-kerjean/filestash/server/plugin/plg_backend_dav" diff --git a/server/plugin/plg_starter_tor/index.go b/server/plugin/plg_starter_tor/index.go new file mode 100644 index 00000000..50074b24 --- /dev/null +++ b/server/plugin/plg_starter_tor/index.go @@ -0,0 +1,36 @@ +package plg_start_tor + +import ( + "context" + "github.com/cretz/bine/tor" + "github.com/gorilla/mux" + . "github.com/mickael-kerjean/filestash/server/common" + "net/http" + "time" +) + +func init() { + Hooks.Register.Starter(func (r *mux.Router) { + Log.Info("[tor] starting ...") + t, err := tor.Start(nil, nil) + if err != nil { + Log.Error("[tor] Unable to start Tor: %v", err) + return + } + defer t.Close() + listenCtx, listenCancel := context.WithTimeout(context.Background(), 3*time.Minute) + defer listenCancel() + onion, err := t.Listen(listenCtx, &tor.ListenConf{Version3: true, RemotePorts: []int{80}}) + if err != nil { + Log.Error("[tor] Unable to create onion service: %v", err) + return + } + defer onion.Close() + + srv := &http.Server{ + Handler: r, + } + Log.Info("[tor] started on http://%v.onion\n", onion.ID) + srv.Serve(onion) + }) +}