[tor-commits] [goptlib/master] Remove everything having to do with the "*" transport specification.

dcf at torproject.org dcf at torproject.org
Sun Jun 28 03:50:47 UTC 2015


commit 65fc8d72eccd82237562744ddc85760d426561d8
Author: David Fifield <david at bamsoftware.com>
Date:   Sat Jun 27 20:48:25 2015 -0700

    Remove everything having to do with the "*" transport specification.
    
    It was never implemented and is no longer part of the specification:
    https://trac.torproject.org/projects/tor/ticket/15612
    
    The arguments to ClientSetup and ServerSetup that were solely to handle
    "*" are now documented as unused.
---
 examples/dummy-client/dummy-client.go |    2 +-
 examples/dummy-server/dummy-server.go |    2 +-
 pt.go                                 |   60 +++++++++---------
 pt_test.go                            |  108 +++++++++------------------------
 4 files changed, 61 insertions(+), 111 deletions(-)

diff --git a/examples/dummy-client/dummy-client.go b/examples/dummy-client/dummy-client.go
index 045a8f2..74843fd 100644
--- a/examples/dummy-client/dummy-client.go
+++ b/examples/dummy-client/dummy-client.go
@@ -83,7 +83,7 @@ func acceptLoop(ln *pt.SocksListener) error {
 func main() {
 	var err error
 
-	ptInfo, err = pt.ClientSetup([]string{"dummy"})
+	ptInfo, err = pt.ClientSetup(nil)
 	if err != nil {
 		os.Exit(1)
 	}
diff --git a/examples/dummy-server/dummy-server.go b/examples/dummy-server/dummy-server.go
index 70251ea..933630b 100644
--- a/examples/dummy-server/dummy-server.go
+++ b/examples/dummy-server/dummy-server.go
@@ -80,7 +80,7 @@ func acceptLoop(ln net.Listener) error {
 func main() {
 	var err error
 
-	ptInfo, err = pt.ServerSetup([]string{"dummy"})
+	ptInfo, err = pt.ServerSetup(nil)
 	if err != nil {
 		os.Exit(1)
 	}
diff --git a/pt.go b/pt.go
index a8c815e..d2aedca 100644
--- a/pt.go
+++ b/pt.go
@@ -35,7 +35,7 @@
 // 	...
 // 	func main() {
 // 		var err error
-// 		ptInfo, err = pt.ClientSetup([]string{"foo"})
+// 		ptInfo, err = pt.ClientSetup(nil)
 // 		if err != nil {
 // 			os.Exit(1)
 // 		}
@@ -92,7 +92,7 @@
 // 	...
 // 	func main() {
 // 		var err error
-// 		ptInfo, err = pt.ServerSetup([]string{"foo"})
+// 		ptInfo, err = pt.ServerSetup(nil)
 // 		if err != nil {
 // 			os.Exit(1)
 // 		}
@@ -377,17 +377,13 @@ func MakeStateDir() (string, error) {
 	return dir, err
 }
 
-// Get the intersection of the method names offered by Tor and those in
-// methodNames. This function reads the environment variable
-// TOR_PT_CLIENT_TRANSPORTS.
-func getClientTransports(star []string) ([]string, error) {
+// Get the list of method names requested by Tor. This function reads the
+// environment variable TOR_PT_CLIENT_TRANSPORTS.
+func getClientTransports() ([]string, error) {
 	clientTransports, err := getenvRequired("TOR_PT_CLIENT_TRANSPORTS")
 	if err != nil {
 		return nil, err
 	}
-	if clientTransports == "*" {
-		return star, nil
-	}
 	return strings.Split(clientTransports, ","), nil
 }
 
@@ -436,9 +432,8 @@ type ClientInfo struct {
 }
 
 // Check the client pluggable transports environment, emitting an error message
-// and returning a non-nil error if any error is encountered. star is the list
-// of method names to use in case "*" is requested by Tor. Returns a ClientInfo
-// struct.
+// and returning a non-nil error if any error is encountered. Returns a
+// ClientInfo struct.
 //
 // If your program needs to know whether to call ClientSetup or ServerSetup
 // (i.e., if the same program can be run as either a client or a server), check
@@ -448,14 +443,20 @@ type ClientInfo struct {
 // 	} else {
 // 		// Server mode; call pt.ServerSetup.
 // 	}
-func ClientSetup(star []string) (info ClientInfo, err error) {
+//
+// Always pass nil for the unused single parameter. In the past, the parameter
+// was a list of transport names to use in case Tor requested "*". That feature
+// was never implemented and has been removed from the pluggable transports
+// specification.
+// https://trac.torproject.org/projects/tor/ticket/15612
+func ClientSetup(_ []string) (info ClientInfo, err error) {
 	ver, err := getManagedTransportVer()
 	if err != nil {
 		return
 	}
 	line("VERSION", ver)
 
-	info.MethodNames, err = getClientTransports(star)
+	info.MethodNames, err = getClientTransports()
 	if err != nil {
 		return
 	}
@@ -537,11 +538,9 @@ func filterBindaddrs(addrs []Bindaddr, methodNames []string) []Bindaddr {
 }
 
 // Return an array of Bindaddrs, being the contents of TOR_PT_SERVER_BINDADDR
-// with keys filtered by TOR_PT_SERVER_TRANSPORTS. If TOR_PT_SERVER_TRANSPORTS
-// is "*", then keys are filtered by the entries in star instead.
-// Transport-specific options from TOR_PT_SERVER_TRANSPORT_OPTIONS are assigned
-// to the Options member.
-func getServerBindaddrs(star []string) ([]Bindaddr, error) {
+// with keys filtered by TOR_PT_SERVER_TRANSPORTS. Transport-specific options
+// from TOR_PT_SERVER_TRANSPORT_OPTIONS are assigned to the Options member.
+func getServerBindaddrs() ([]Bindaddr, error) {
 	var result []Bindaddr
 
 	// Parse the list of server transport options.
@@ -578,11 +577,7 @@ func getServerBindaddrs(star []string) ([]Bindaddr, error) {
 	if err != nil {
 		return nil, err
 	}
-	if serverTransports == "*" {
-		result = filterBindaddrs(result, star)
-	} else {
-		result = filterBindaddrs(result, strings.Split(serverTransports, ","))
-	}
+	result = filterBindaddrs(result, strings.Split(serverTransports, ","))
 
 	return result, nil
 }
@@ -634,10 +629,9 @@ type ServerInfo struct {
 }
 
 // Check the server pluggable transports environment, emitting an error message
-// and returning a non-nil error if any error is encountered. star is the list
-// of method names to use in case "*" is requested by Tor. Resolves the various
-// requested bind addresses, the server ORPort and extended ORPort, and reads
-// the auth cookie file. Returns a ServerInfo struct.
+// and returning a non-nil error if any error is encountered. Resolves the
+// various requested bind addresses, the server ORPort and extended ORPort, and
+// reads the auth cookie file. Returns a ServerInfo struct.
 //
 // If your program needs to know whether to call ClientSetup or ServerSetup
 // (i.e., if the same program can be run as either a client or a server), check
@@ -647,14 +641,20 @@ type ServerInfo struct {
 // 	} else {
 // 		// Server mode; call pt.ServerSetup.
 // 	}
-func ServerSetup(star []string) (info ServerInfo, err error) {
+//
+// Always pass nil for the unused single parameter. In the past, the parameter
+// was a list of transport names to use in case Tor requested "*". That feature
+// was never implemented and has been removed from the pluggable transports
+// specification.
+// https://trac.torproject.org/projects/tor/ticket/15612
+func ServerSetup(_ []string) (info ServerInfo, err error) {
 	ver, err := getManagedTransportVer()
 	if err != nil {
 		return
 	}
 	line("VERSION", ver)
 
-	info.Bindaddrs, err = getServerBindaddrs(star)
+	info.Bindaddrs, err = getServerBindaddrs()
 	if err != nil {
 		return
 	}
diff --git a/pt_test.go b/pt_test.go
index 8470383..93fa491 100644
--- a/pt_test.go
+++ b/pt_test.go
@@ -139,81 +139,51 @@ func tcpAddrsEqual(a, b *net.TCPAddr) bool {
 func TestGetClientTransports(t *testing.T) {
 	tests := [...]struct {
 		ptClientTransports string
-		star               []string
 		expected           []string
 	}{
 		{
-			"*",
-			[]string{},
-			[]string{},
-		},
-		{
-			"*",
-			[]string{"alpha", "beta", "gamma"},
-			[]string{"alpha", "beta", "gamma"},
-		},
-		{
-			"alpha,beta,gamma",
-			[]string{"alpha", "beta", "gamma"},
-			[]string{"alpha", "beta", "gamma"},
+			"alpha",
+			[]string{"alpha"},
 		},
 		{
 			"alpha,beta",
-			[]string{"alpha", "beta", "gamma"},
 			[]string{"alpha", "beta"},
 		},
 		{
-			"alpha",
-			[]string{"alpha", "beta", "gamma"},
-			[]string{"alpha"},
-		},
-		{
 			"alpha,beta,gamma",
-			[]string{},
 			[]string{"alpha", "beta", "gamma"},
 		},
+		// In the past, "*" meant to return all known transport names.
+		// But now it has no special meaning.
+		// https://trac.torproject.org/projects/tor/ticket/15612
 		{
-			"alpha,beta",
-			[]string{},
-			[]string{"alpha", "beta"},
-		},
-		{
-			"alpha",
-			[]string{},
-			[]string{"alpha"},
+			"*",
+			[]string{"*"},
 		},
-		// my reading of pt-spec.txt says that "*" has special meaning
-		// only when it is the entirety of the environment variable.
 		{
 			"alpha,*,gamma",
-			[]string{"alpha", "beta", "gamma"},
 			[]string{"alpha", "*", "gamma"},
 		},
-		{
-			"alpha",
-			[]string{"beta"},
-			[]string{"alpha"},
-		},
 	}
 
 	Stdout = ioutil.Discard
 
 	os.Clearenv()
-	_, err := getClientTransports([]string{"alpha", "beta", "gamma"})
+	_, err := getClientTransports()
 	if err == nil {
 		t.Errorf("empty environment unexpectedly succeeded")
 	}
 
 	for _, test := range tests {
 		os.Setenv("TOR_PT_CLIENT_TRANSPORTS", test.ptClientTransports)
-		output, err := getClientTransports(test.star)
+		output, err := getClientTransports()
 		if err != nil {
 			t.Errorf("TOR_PT_CLIENT_TRANSPORTS=%q unexpectedly returned an error: %s",
 				test.ptClientTransports, err)
 		}
 		if !stringSetsEqual(output, test.expected) {
-			t.Errorf("TOR_PT_CLIENT_TRANSPORTS=%q %q → %q (expected %q)",
-				test.ptClientTransports, test.star, output, test.expected)
+			t.Errorf("TOR_PT_CLIENT_TRANSPORTS=%q → %q (expected %q)",
+				test.ptClientTransports, output, test.expected)
 		}
 	}
 }
@@ -296,48 +266,41 @@ func TestGetServerBindaddrs(t *testing.T) {
 		ptServerBindaddr         string
 		ptServerTransports       string
 		ptServerTransportOptions string
-		star                     []string
 	}{
 		// bad TOR_PT_SERVER_BINDADDR
 		{
 			"alpha",
 			"alpha",
 			"",
-			[]string{"alpha", "beta", "gamma"},
 		},
 		{
 			"alpha-1.2.3.4",
 			"alpha",
 			"",
-			[]string{"alpha", "beta", "gamma"},
 		},
 		// missing TOR_PT_SERVER_TRANSPORTS
 		{
 			"alpha-1.2.3.4:1111",
 			"",
 			"alpha:key=value",
-			[]string{"alpha"},
 		},
 		// bad TOR_PT_SERVER_TRANSPORT_OPTIONS
 		{
 			"alpha-1.2.3.4:1111",
 			"alpha",
 			"key=value",
-			[]string{"alpha"},
 		},
 	}
 	goodTests := [...]struct {
 		ptServerBindaddr         string
 		ptServerTransports       string
 		ptServerTransportOptions string
-		star                     []string
 		expected                 []Bindaddr
 	}{
 		{
 			"alpha-1.2.3.4:1111,beta-[1:2::3:4]:2222",
 			"alpha,beta,gamma",
 			"alpha:k1=v1,beta:k2=v2,gamma:k3=v3",
-			[]string{"alpha", "beta"},
 			[]Bindaddr{
 				{"alpha", &net.TCPAddr{IP: net.ParseIP("1.2.3.4"), Port: 1111}, Args{"k1": []string{"v1"}}},
 				{"beta", &net.TCPAddr{IP: net.ParseIP("1:2::3:4"), Port: 2222}, Args{"k2": []string{"v2"}}},
@@ -347,33 +310,12 @@ func TestGetServerBindaddrs(t *testing.T) {
 			"alpha-1.2.3.4:1111",
 			"xxx",
 			"",
-			[]string{"alpha", "beta", "gamma"},
 			[]Bindaddr{},
 		},
 		{
 			"alpha-1.2.3.4:1111",
 			"alpha,beta,gamma",
 			"",
-			[]string{},
-			[]Bindaddr{
-				{"alpha", &net.TCPAddr{IP: net.ParseIP("1.2.3.4"), Port: 1111}, Args{}},
-			},
-		},
-		{
-			"alpha-1.2.3.4:1111,beta-[1:2::3:4]:2222",
-			"*",
-			"",
-			[]string{"alpha", "beta"},
-			[]Bindaddr{
-				{"alpha", &net.TCPAddr{IP: net.ParseIP("1.2.3.4"), Port: 1111}, Args{}},
-				{"beta", &net.TCPAddr{IP: net.ParseIP("1:2::3:4"), Port: 2222}, Args{}},
-			},
-		},
-		{
-			"alpha-1.2.3.4:1111,beta-[1:2::3:4]:2222",
-			"*",
-			"",
-			[]string{"alpha", "gamma"},
 			[]Bindaddr{
 				{"alpha", &net.TCPAddr{IP: net.ParseIP("1.2.3.4"), Port: 1111}, Args{}},
 			},
@@ -382,18 +324,26 @@ func TestGetServerBindaddrs(t *testing.T) {
 			"trebuchet-127.0.0.1:1984,ballista-127.0.0.1:4891",
 			"trebuchet,ballista",
 			"trebuchet:secret=nou;trebuchet:cache=/tmp/cache;ballista:secret=yes",
-			[]string{"trebuchet", "ballista"},
 			[]Bindaddr{
 				{"trebuchet", &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 1984}, Args{"secret": []string{"nou"}, "cache": []string{"/tmp/cache"}}},
 				{"ballista", &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 4891}, Args{"secret": []string{"yes"}}},
 			},
 		},
+		// In the past, "*" meant to return all known transport names.
+		// But now it has no special meaning.
+		// https://trac.torproject.org/projects/tor/ticket/15612
+		{
+			"alpha-1.2.3.4:1111,beta-[1:2::3:4]:2222",
+			"*",
+			"",
+			[]Bindaddr{},
+		},
 	}
 
 	Stdout = ioutil.Discard
 
 	os.Clearenv()
-	_, err := getServerBindaddrs([]string{"alpha", "beta", "gamma"})
+	_, err := getServerBindaddrs()
 	if err == nil {
 		t.Errorf("empty environment unexpectedly succeeded")
 	}
@@ -402,10 +352,10 @@ func TestGetServerBindaddrs(t *testing.T) {
 		os.Setenv("TOR_PT_SERVER_BINDADDR", test.ptServerBindaddr)
 		os.Setenv("TOR_PT_SERVER_TRANSPORTS", test.ptServerTransports)
 		os.Setenv("TOR_PT_SERVER_TRANSPORT_OPTIONS", test.ptServerTransportOptions)
-		_, err := getServerBindaddrs(test.star)
+		_, err := getServerBindaddrs()
 		if err == nil {
-			t.Errorf("TOR_PT_SERVER_BINDADDR=%q TOR_PT_SERVER_TRANSPORTS=%q TOR_PT_SERVER_TRANSPORT_OPTIONS=%q %q unexpectedly succeeded",
-				test.ptServerBindaddr, test.ptServerTransports, test.ptServerTransportOptions, test.star)
+			t.Errorf("TOR_PT_SERVER_BINDADDR=%q TOR_PT_SERVER_TRANSPORTS=%q TOR_PT_SERVER_TRANSPORT_OPTIONS=%q unexpectedly succeeded",
+				test.ptServerBindaddr, test.ptServerTransports, test.ptServerTransportOptions)
 		}
 	}
 
@@ -413,14 +363,14 @@ func TestGetServerBindaddrs(t *testing.T) {
 		os.Setenv("TOR_PT_SERVER_BINDADDR", test.ptServerBindaddr)
 		os.Setenv("TOR_PT_SERVER_TRANSPORTS", test.ptServerTransports)
 		os.Setenv("TOR_PT_SERVER_TRANSPORT_OPTIONS", test.ptServerTransportOptions)
-		output, err := getServerBindaddrs(test.star)
+		output, err := getServerBindaddrs()
 		if err != nil {
-			t.Errorf("TOR_PT_SERVER_BINDADDR=%q TOR_PT_SERVER_TRANSPORTS=%q TOR_PT_SERVER_TRANSPORT_OPTIONS=%q %q unexpectedly returned an error: %s",
-				test.ptServerBindaddr, test.ptServerTransports, test.ptServerTransportOptions, test.star, err)
+			t.Errorf("TOR_PT_SERVER_BINDADDR=%q TOR_PT_SERVER_TRANSPORTS=%q TOR_PT_SERVER_TRANSPORT_OPTIONS=%q unexpectedly returned an error: %s",
+				test.ptServerBindaddr, test.ptServerTransports, test.ptServerTransportOptions, err)
 		}
 		if !bindaddrSetsEqual(output, test.expected) {
-			t.Errorf("TOR_PT_SERVER_BINDADDR=%q TOR_PT_SERVER_TRANSPORTS=%q TOR_PT_SERVER_TRANSPORT_OPTIONS=%q %q → %q (expected %q)",
-				test.ptServerBindaddr, test.ptServerTransports, test.ptServerTransportOptions, test.star, output, test.expected)
+			t.Errorf("TOR_PT_SERVER_BINDADDR=%q TOR_PT_SERVER_TRANSPORTS=%q TOR_PT_SERVER_TRANSPORT_OPTIONS=%q → %q (expected %q)",
+				test.ptServerBindaddr, test.ptServerTransports, test.ptServerTransportOptions, output, test.expected)
 		}
 	}
 }



More information about the tor-commits mailing list