aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorChristine Dodrill <me@christine.website>2019-04-01 14:35:45 -0700
committerChristine Dodrill <me@christine.website>2019-04-01 14:36:04 -0700
commit2a8414f5bf04b1f686188e2148f8a10276e712a3 (patch)
tree4abe7011cfcfe3cef1f55e327093c6f0e72c5d2b /cmd
parentf06f021f402270951f849dde7bee3f3340b8a1d5 (diff)
downloadx-2a8414f5bf04b1f686188e2148f8a10276e712a3.tar.xz
x-2a8414f5bf04b1f686188e2148f8a10276e712a3.zip
cmd/tor2web: new caching tor2web proxy
Diffstat (limited to 'cmd')
-rw-r--r--cmd/tor2web/main.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/cmd/tor2web/main.go b/cmd/tor2web/main.go
new file mode 100644
index 0000000..a5e79d6
--- /dev/null
+++ b/cmd/tor2web/main.go
@@ -0,0 +1,57 @@
+package main
+
+import (
+ "context"
+ "flag"
+ "log"
+ "net/http"
+ "net/http/httputil"
+
+ "github.com/birkelund/boltdbcache"
+ "github.com/gregjones/httpcache"
+ "golang.org/x/net/proxy"
+ "within.website/ln"
+ "within.website/ln/opname"
+)
+
+var (
+ dbLoc = flag.String("db-loc", "./cache.db", "cache location on disk (boltdb)")
+ torSocksAddr = flag.String("tor-socks-addr", "127.0.0.1:9050", "tor socks address")
+ httpPort = flag.String("port", "80", "HTTP port")
+ httpsPort = flag.String("https-port", "443", "HTTPS port")
+ tlsCert = flag.String("tls-cert", "/etc/within/star.onion.cert.pem", "tls cert location on disk")
+ tlsKey = flag.String("tls-key", "/etc/within/star.onion.key.pem", "tls key location on disk")
+)
+
+func main() {
+ ctx := opname.With(context.Background(), "main")
+ // Create a socks5 dialer
+ dialer, err := proxy.SOCKS5("tcp", "127.0.0.1:9050", nil, proxy.Direct)
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ // Setup HTTP transport
+ tr := &http.Transport{
+ Dial: dialer.Dial,
+ }
+
+ c, err := boltdbcache.New(*dbLoc, boltdbcache.WithBucketName("darkweb"))
+ if err != nil {
+ ln.FatalErr(ctx, err)
+ }
+
+ ttr := httpcache.NewTransport(c)
+ ttr.Transport = tr
+
+ rp := &httputil.ReverseProxy{
+ Transport: ttr,
+ Director: func(r *http.Request) {
+ r.URL.Scheme = "http"
+ r.URL.Host = r.Host
+ },
+ }
+
+ go ln.FatalErr(ctx, http.ListenAndServe(":"+*httpPort, rp))
+ ln.FatalErr(ctx, http.ListenAndServeTLS(":"+*httpsPort, *tlsCert, *tlsKey, rp))
+}