diff options
| author | davy wybiral <davy.wybiral@gmail.com> | 2019-07-03 16:46:59 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-07-03 16:46:59 -0500 |
| commit | d38a88be8e94873187c3b82e9b3827faa3875541 (patch) | |
| tree | a50e298a413d813805617814e3a9b68e2b8ae77c /pkg/app/app.go | |
| parent | 6b8d872d680d019827cc45881186cce3f83f764a (diff) | |
Tor (#12)
* added tor support
* change text
Diffstat (limited to 'pkg/app/app.go')
| -rw-r--r-- | pkg/app/app.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/pkg/app/app.go b/pkg/app/app.go index 22ad91f..57c0aa4 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -16,6 +16,7 @@ import ( "github.com/gorilla/feeds" "github.com/gorilla/mux" "github.com/wybiral/tube/pkg/media" + "github.com/wybiral/tube/pkg/onionkey" ) // App represents main application. @@ -24,6 +25,7 @@ type App struct { Library *media.Library Watcher *fsnotify.Watcher Templates *template.Template + Tor *tor Listener net.Listener Router *mux.Router } @@ -52,6 +54,14 @@ func NewApp(cfg *Config) (*App, error) { a.Listener = ln // Setup Templates a.Templates = template.Must(template.ParseGlob("templates/*")) + // Setup Tor + if cfg.Tor.Enable { + t, err := newTor(cfg.Tor) + if err != nil { + return nil, err + } + a.Tor = t + } // Setup Router r := mux.NewRouter().StrictSlash(true) r.HandleFunc("/", a.indexHandler).Methods("GET") @@ -74,6 +84,27 @@ func NewApp(cfg *Config) (*App, error) { // Run imports the library and starts server. func (a *App) Run() error { + if a.Tor != nil { + var err error + cs := a.Config.Server + key := a.Tor.OnionKey + if key == nil { + key, err = onionkey.GenerateKey() + if err != nil { + return err + } + } + onion, err := key.Onion() + if err != nil { + return err + } + onion.Ports[80] = fmt.Sprintf("%s:%d", cs.Host, cs.Port) + err = a.Tor.Controller.AddOnion(onion) + if err != nil { + return err + } + log.Printf("Onion service: http://%s.onion", onion.ServiceID) + } for _, pc := range a.Config.Library { p := &media.Path{ Path: pc.Path, |
