Closed aayushsinha44 closed 4 years ago
You can check how I did it in https://github.com/ipsn/go-torfluxdb/blob/master/proxy/proxy.go#L26
TL;DR: In tor.ListenConf
you can specify the private key to use, which will cause the same URL to be generated every time. Without the key, Tor just generates a new ephemeral random key that it discards afterwards.
Each time i run the code, i get different onion url. How to keep the onion url same?
Code:
package demo
import ( "context" "fmt" "log" "net/http" "os" "time"
)
var creator = libtor.Creator
type LibTorWrapper struct{}
func (LibTorWrapper) New(ctx context.Context, args ...string) (process.Process, error) { return creator.New(ctx, args...) }
// Run starts up an embedded Tor process, starts a hidden onion service on a new // goroutine and returns the onion address. We're cheating here and not caring // about actually cleaning up after ourselves. func Run(datadir string) string { // Start tor with some defaults + elevated verbosity fmt.Println("Starting and registering onion service, please wait a bit...") t, err := tor.Start(nil, &tor.StartConf{ProcessCreator: LibTorWrapper{}, DebugWriter: os.Stderr, DataDir: datadir}) if err != nil { log.Panicf("Failed to start tor: %v", err) } // Wait at most a few minutes to publish the service ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute) defer cancel()
}