[tor-commits] [meek/master] Use the new TOR_PT_PROXY interface from #12125.

dcf at torproject.org dcf at torproject.org
Sun Jun 28 03:02:30 UTC 2015


commit eafbc1d735f8980180bf8d3afb57440470a537c7
Author: David Fifield <david at bamsoftware.com>
Date:   Wed Jun 24 13:48:38 2015 -0700

    Use the new TOR_PT_PROXY interface from #12125.
---
 meek-client/meek-client.go |   17 ++++------
 meek-client/proxy.go       |   52 ----------------------------
 meek-client/proxy_test.go  |   81 --------------------------------------------
 3 files changed, 6 insertions(+), 144 deletions(-)

diff --git a/meek-client/meek-client.go b/meek-client/meek-client.go
index 7ac6eae..6198d37 100644
--- a/meek-client/meek-client.go
+++ b/meek-client/meek-client.go
@@ -389,8 +389,8 @@ func main() {
 
 	// We make a copy of DefaultTransport because we want the default Dial
 	// and TLSHandshakeTimeout settings. But we want to disable the default
-	// ProxyFromEnvironment setting. Proxy is overridden below if proxyURL
-	// is set.
+	// ProxyFromEnvironment setting. Proxy is overridden below if
+	// options.ProxyURL is set.
 	httpTransport = *http.DefaultTransport.(*http.Transport)
 	httpTransport.Proxy = nil
 
@@ -398,27 +398,22 @@ func main() {
 	if err != nil {
 		log.Fatalf("error in ClientSetup: %s", err)
 	}
-	ptProxyURL, err := PtGetProxyURL()
-	if err != nil {
-		PtProxyError(err.Error())
-		log.Fatalf("can't get managed proxy configuration: %s", err)
-	}
 
 	// Command-line proxy overrides managed configuration.
 	if options.ProxyURL == nil {
-		options.ProxyURL = ptProxyURL
+		options.ProxyURL = ptInfo.ProxyURL
 	}
 	// Check whether we support this kind of proxy.
 	if options.ProxyURL != nil {
 		err = checkProxyURL(options.ProxyURL)
 		if err != nil {
-			PtProxyError(err.Error())
+			pt.ProxyError(err.Error())
 			log.Fatal(fmt.Sprintf("proxy error: %s", err))
 		}
 		log.Printf("using proxy %s", options.ProxyURL.String())
 		httpTransport.Proxy = http.ProxyURL(options.ProxyURL)
-		if ptProxyURL != nil {
-			PtProxyDone()
+		if ptInfo.ProxyURL != nil {
+			pt.ProxyDone()
 		}
 	}
 
diff --git a/meek-client/proxy.go b/meek-client/proxy.go
deleted file mode 100644
index 9b7f27d..0000000
--- a/meek-client/proxy.go
+++ /dev/null
@@ -1,52 +0,0 @@
-package main
-
-import (
-	"fmt"
-	"net/url"
-	"os"
-)
-
-import "git.torproject.org/pluggable-transports/goptlib.git"
-
-// The code in this file has to do with configuring an upstream proxy, whether
-// through the command line or the managed interface of proposal 232
-// (TOR_PT_PROXY).
-//
-// https://gitweb.torproject.org/torspec.git/tree/proposals/232-pluggable-transports-through-proxy.txt
-
-// Get the upstream proxy URL. Returns nil if no proxy is requested. The
-// function ensures that the Scheme and Host fields are set; i.e., that the URL
-// is absolute. This function reads the environment variable TOR_PT_PROXY.
-//
-// This function doesn't check that the scheme is one of Tor's supported proxy
-// schemes; that is, one of "http", "socks5", or "socks4a". The caller must be
-// able to handle any returned scheme (which may be by calling PtProxyError if
-// it doesn't know how to handle the scheme).
-func PtGetProxyURL() (*url.URL, error) {
-	rawurl := os.Getenv("TOR_PT_PROXY")
-	if rawurl == "" {
-		return nil, nil
-	}
-	u, err := url.Parse(rawurl)
-	if err != nil {
-		return nil, err
-	}
-	if u.Scheme == "" {
-		return nil, fmt.Errorf("missing scheme")
-	}
-	if u.Host == "" {
-		return nil, fmt.Errorf("missing host")
-	}
-	return u, nil
-}
-
-// Emit a PROXY-ERROR line with explanation text.
-func PtProxyError(msg string) {
-	fmt.Fprintf(pt.Stdout, "PROXY-ERROR %s\n", msg)
-}
-
-// Emit a PROXY DONE line. Call this after parsing the return value of
-// PtGetProxyURL.
-func PtProxyDone() {
-	fmt.Fprintf(pt.Stdout, "PROXY DONE\n")
-}
diff --git a/meek-client/proxy_test.go b/meek-client/proxy_test.go
deleted file mode 100644
index 77123b9..0000000
--- a/meek-client/proxy_test.go
+++ /dev/null
@@ -1,81 +0,0 @@
-package main
-
-import (
-	"os"
-	"testing"
-)
-
-func TestGetProxyURL(t *testing.T) {
-	badTests := [...]string{
-		"bogus",
-		"http:",
-		"://127.0.0.1",
-		"//127.0.0.1",
-		"http:127.0.0.1",
-		"://[::1]",
-		"//[::1]",
-		"http:[::1]",
-		"://localhost",
-		"//localhost",
-		"http:localhost",
-	}
-	goodTests := [...]struct {
-		input, expected string
-	}{
-		{"http://127.0.0.1", "http://127.0.0.1"},
-		{"http://127.0.0.1:8080", "http://127.0.0.1:8080"},
-		{"http://127.0.0.1:8080/", "http://127.0.0.1:8080/"},
-		{"http://127.0.0.1:8080/path", "http://127.0.0.1:8080/path"},
-		{"http://[::1]", "http://[::1]"},
-		{"http://[::1]:8080", "http://[::1]:8080"},
-		{"http://[::1]:8080/", "http://[::1]:8080/"},
-		{"http://[::1]:8080/path", "http://[::1]:8080/path"},
-		{"http://localhost", "http://localhost"},
-		{"http://localhost:8080", "http://localhost:8080"},
-		{"http://localhost:8080/", "http://localhost:8080/"},
-		{"http://localhost:8080/path", "http://localhost:8080/path"},
-		{"http://user@localhost:8080", "http://user@localhost:8080"},
-		{"http://user:password@localhost:8080", "http://user:password@localhost:8080"},
-		{"socks5://localhost:1080", "socks5://localhost:1080"},
-		{"socks4a://localhost:1080", "socks4a://localhost:1080"},
-		{"unknown://localhost/whatever", "unknown://localhost/whatever"},
-	}
-	/*
-		No port: reject; or infer from scheme?
-			http://localhost
-			socks4a://localhost
-			socks5://localhost
-		Port without host: probably reject?
-			http://:8080
-			socks4a://:1080
-			socks5://:1080
-	*/
-
-	os.Clearenv()
-	u, err := PtGetProxyURL()
-	if err != nil {
-		t.Errorf("empty environment unexpectedly returned an error: %s", err)
-	}
-	if u != nil {
-		t.Errorf("empty environment returned %q", u)
-	}
-
-	for _, input := range badTests {
-		os.Setenv("TOR_PT_PROXY", input)
-		u, err = PtGetProxyURL()
-		if err == nil {
-			t.Errorf("TOR_PT_PROXY=%q unexpectedly succeeded and returned %q", input, u)
-		}
-	}
-
-	for _, test := range goodTests {
-		os.Setenv("TOR_PT_PROXY", test.input)
-		u, err := PtGetProxyURL()
-		if err != nil {
-			t.Errorf("TOR_PT_PROXY=%q unexpectedly returned an error: %s", test.input, err)
-		}
-		if u == nil || u.String() != test.expected {
-			t.Errorf("TOR_PT_PROXY=%q → %q (expected %q)", test.input, u, test.expected)
-		}
-	}
-}



More information about the tor-commits mailing list