You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.2 KiB

5 years ago
  1. package main
  2. import (
  3. "context"
  4. "fmt"
  5. "log"
  6. "net/http"
  7. "os"
  8. "time"
  9. "github.com/cretz/bine/tor"
  10. "github.com/ipsn/go-libtor"
  11. )
  12. func main() {
  13. ReadConfig(".", "config")
  14. // Start tor with some defaults + elevated verbosity
  15. fmt.Println("Starting and registering onion service, please wait a bit...")
  16. t, err := tor.Start(nil, &tor.StartConf{ProcessCreator: libtor.Creator, DebugWriter: os.Stderr})
  17. if err != nil {
  18. log.Panicf("Failed to start tor: %v", err)
  19. }
  20. defer t.Close()
  21. // Wait at most a few minutes to publish the service
  22. ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
  23. defer cancel()
  24. // Create an onion service to listen on any port but show as 80
  25. onion, err := t.Listen(ctx, &tor.ListenConf{RemotePorts: []int{80}})
  26. if err != nil {
  27. log.Panicf("Failed to create onion service: %v", err)
  28. }
  29. defer onion.Close()
  30. fmt.Printf("Please open a Tor capable browser and navigate to http://%v.onion\n", onion.ID)
  31. // connect to eth
  32. // Ethereum
  33. err = Web3Open()
  34. if err != nil {
  35. log.Fatal(err)
  36. }
  37. // Run a Hello-World HTTP service until terminated
  38. http.Handle("/", http.FileServer(http.Dir("./www")))
  39. http.HandleFunc("/api/purchase", handlePurchase)
  40. http.HandleFunc("/api/txid", handleTxId)
  41. http.Serve(onion, nil)
  42. }