fully automatic onionv3 reseeds

This commit is contained in:
idk
2019-06-21 01:16:27 -04:00
parent bc91c473c2
commit 16edf4f71e
2 changed files with 64 additions and 10 deletions

View File

@@ -5,6 +5,7 @@ import (
"context"
"crypto/tls"
"io"
"io/ioutil"
"log"
"net"
"net/http"
@@ -13,6 +14,7 @@ import (
"time"
"github.com/cretz/bine/tor"
"github.com/cretz/bine/torutil/ed25519"
"github.com/gorilla/handlers"
"github.com/justinas/alice"
"gopkg.in/throttled/throttled.v2"
@@ -114,7 +116,7 @@ func (srv *Server) ListenAndServeTLS(certFile, keyFile string) error {
return srv.Serve(tlsListener)
}
func (srv *Server) ListenAndServeOnion(startConf *tor.StartConf, listenConf *tor.ListenConf) error {
func (srv *Server) ListenAndServeOnion(startConf *tor.StartConf, listenConf *tor.ListenConf, onionKey string) error {
log.Println("Starting and registering onion service, please wait a couple of minutes...")
tor, err := tor.Start(nil, startConf)
if err != nil {
@@ -128,6 +130,10 @@ func (srv *Server) ListenAndServeOnion(startConf *tor.StartConf, listenConf *tor
if err != nil {
return err
}
err = ioutil.WriteFile(onionKey, []byte(srv.OnionListener.Key.(ed25519.KeyPair).PrivateKey()), 0644)
if err != nil {
return err
}
log.Printf("Onionv3 server started on http://%v.onion\n", srv.OnionListener.ID)
return srv.Serve(srv.OnionListener)
}