[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [meek/master] Move address and proxy settings into HelperRoundTripper.



commit 3fe68658f433adb2b8bec215d4daf48e81003cf7
Author: David Fifield <david@xxxxxxxxxxxxxxx>
Date:   Tue Jan 15 00:37:31 2019 -0700

    Move address and proxy settings into HelperRoundTripper.
    
    Copy them into an instance from the global settings, don't read the
    global settings directly.
---
 meek-client/helper.go      | 15 ++++++++++-----
 meek-client/meek-client.go | 22 ++++++++++++++--------
 2 files changed, 24 insertions(+), 13 deletions(-)

diff --git a/meek-client/helper.go b/meek-client/helper.go
index eaaf302..a003bf7 100644
--- a/meek-client/helper.go
+++ b/meek-client/helper.go
@@ -42,8 +42,16 @@ type ProxySpec struct {
 }
 
 type HelperRoundTripper struct {
+	HelperAddr   *net.TCPAddr
 	ReadTimeout  time.Duration
 	WriteTimeout time.Duration
+	proxySpec    *ProxySpec
+}
+
+func (rt *HelperRoundTripper) SetProxy(u *url.URL) error {
+	var err error
+	rt.proxySpec, err = makeProxySpec(u)
+	return err
 }
 
 // Return a ProxySpec suitable for the proxy URL in u.
@@ -87,7 +95,7 @@ func makeProxySpec(u *url.URL) (*ProxySpec, error) {
 }
 
 func (rt *HelperRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
-	s, err := net.DialTCP("tcp", nil, options.HelperAddr)
+	s, err := net.DialTCP("tcp", nil, rt.HelperAddr)
 	if err != nil {
 		return nil, err
 	}
@@ -127,10 +135,7 @@ func (rt *HelperRoundTripper) RoundTrip(req *http.Request) (*http.Response, erro
 		}
 	}
 
-	jsonReq.Proxy, err = makeProxySpec(options.ProxyURL)
-	if err != nil {
-		return nil, err
-	}
+	jsonReq.Proxy = rt.proxySpec
 	encReq, err := json.Marshal(&jsonReq)
 	if err != nil {
 		return nil, err
diff --git a/meek-client/meek-client.go b/meek-client/meek-client.go
index fd16099..9c715a3 100644
--- a/meek-client/meek-client.go
+++ b/meek-client/meek-client.go
@@ -96,10 +96,10 @@ var helperRoundTripper = &HelperRoundTripper{
 
 // Store for command line options.
 var options struct {
-	URL        string
-	Front      string
-	ProxyURL   *url.URL
-	HelperAddr *net.TCPAddr
+	URL       string
+	Front     string
+	ProxyURL  *url.URL
+	UseHelper bool
 }
 
 // When a connection handler starts, +1 is written to this channel; when it
@@ -178,7 +178,7 @@ again:
 // body back into conn.
 func sendRecv(buf []byte, conn net.Conn, info *RequestInfo) (int64, error) {
 	var rt http.RoundTripper = httpRoundTripper
-	if options.HelperAddr != nil {
+	if options.UseHelper {
 		rt = helperRoundTripper
 	}
 	req, err := makeRequest(buf, info)
@@ -346,7 +346,7 @@ func acceptLoop(ln *pt.SocksListener) error {
 // Return an error if this proxy URL doesn't work with the rest of the
 // configuration.
 func checkProxyURL(u *url.URL) error {
-	if options.HelperAddr == nil {
+	if !options.UseHelper {
 		// Without the helper we only support HTTP proxies.
 		if u.Scheme != "http" {
 			return fmt.Errorf("don't understand proxy URL scheme %q", u.Scheme)
@@ -407,11 +407,12 @@ func main() {
 	}
 
 	if helperAddr != "" {
-		options.HelperAddr, err = net.ResolveTCPAddr("tcp", helperAddr)
+		options.UseHelper = true
+		helperRoundTripper.HelperAddr, err = net.ResolveTCPAddr("tcp", helperAddr)
 		if err != nil {
 			log.Fatalf("can't resolve helper address: %s", err)
 		}
-		log.Printf("using helper on %s", options.HelperAddr)
+		log.Printf("using helper on %s", helperRoundTripper.HelperAddr)
 	}
 
 	if proxy != "" {
@@ -439,6 +440,11 @@ func main() {
 		}
 		log.Printf("using proxy %s", options.ProxyURL.String())
 		httpRoundTripper.Proxy = http.ProxyURL(options.ProxyURL)
+		err = helperRoundTripper.SetProxy(options.ProxyURL)
+		if err != nil {
+			pt.ProxyError(err.Error())
+			log.Fatal(fmt.Sprintf("proxy error: %s", err))
+		}
 		if ptInfo.ProxyURL != nil {
 			pt.ProxyDone()
 		}

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits