commit 5db12aacc1d56a713a1701a192f987dfccec7363 Author: David Fifield david@bamsoftware.com Date: Sun Jan 12 22:38:21 2014 -0800
Use the argument to ClientSetup only when the "*" list is requested.
Formerly the list always served as an additional filter of methods that we support. Now, ClientSetup always returns all the method names requested by Tor, unless "*" is requested, in which case the given method name list is returned.
This change is to enable the case where for "*" you want to return something other than the full list of transports you support.
https://lists.torproject.org/pipermail/tor-dev/2013-December/005966.html --- examples/dummy-client/dummy-client.go | 19 ++++++++++++------- pt.go | 25 +++++++++---------------- pt_test.go | 22 ++++++++++++++++------ 3 files changed, 37 insertions(+), 29 deletions(-)
diff --git a/examples/dummy-client/dummy-client.go b/examples/dummy-client/dummy-client.go index a0fa488..64f1ec1 100644 --- a/examples/dummy-client/dummy-client.go +++ b/examples/dummy-client/dummy-client.go @@ -90,14 +90,19 @@ func main() {
listeners := make([]net.Listener, 0) for _, methodName := range ptInfo.MethodNames { - ln, err := pt.ListenSocks("tcp", "127.0.0.1:0") - if err != nil { - pt.CmethodError(methodName, err.Error()) - continue + switch methodName { + case "dummy": + ln, err := pt.ListenSocks("tcp", "127.0.0.1:0") + if err != nil { + pt.CmethodError(methodName, err.Error()) + break + } + go acceptLoop(ln) + pt.Cmethod(methodName, ln.Version(), ln.Addr()) + listeners = append(listeners, ln) + default: + pt.CmethodError(methodName, "no such method") } - go acceptLoop(ln) - pt.Cmethod(methodName, ln.Version(), ln.Addr()) - listeners = append(listeners, ln) } pt.CmethodsDone()
diff --git a/pt.go b/pt.go index c77687f..024eec9 100644 --- a/pt.go +++ b/pt.go @@ -315,24 +315,16 @@ func getManagedTransportVer() (string, error) { // 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(methodNames []string) ([]string, error) { +func getClientTransports(star []string) ([]string, error) { clientTransports, err := getenvRequired("TOR_PT_CLIENT_TRANSPORTS") if err != nil { return nil, err } if clientTransports == "*" { - return methodNames, nil - } - result := make([]string, 0) - for _, requested := range strings.Split(clientTransports, ",") { - for _, methodName := range methodNames { - if requested == methodName { - result = append(result, methodName) - break - } - } + return star, nil + } else { + return strings.Split(clientTransports, ","), nil } - return result, nil }
// This structure is returned by ClientSetup. It consists of a list of method @@ -342,16 +334,17 @@ type ClientInfo struct { }
// Check the client pluggable transports environment, emitting an error message -// and returning a non-nil error if any error is encountered. Returns a -// ClientInfo struct. -func ClientSetup(methodNames []string) (info ClientInfo, err error) { +// 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 +// Returns a ClientInfo struct. +func ClientSetup(star []string) (info ClientInfo, err error) { ver, err := getManagedTransportVer() if err != nil { return } line("VERSION", ver)
- info.MethodNames, err = getClientTransports(methodNames) + info.MethodNames, err = getClientTransports(star) if err != nil { return } diff --git a/pt_test.go b/pt_test.go index a2abc1f..7e74f2b 100644 --- a/pt_test.go +++ b/pt_test.go @@ -118,7 +118,7 @@ func tcpAddrsEqual(a, b *net.TCPAddr) bool { func TestGetClientTransports(t *testing.T) { tests := [...]struct { ptServerClientTransports string - methodNames []string + star []string expected []string }{ { @@ -147,21 +147,31 @@ func TestGetClientTransports(t *testing.T) { []string{"alpha"}, }, { + "alpha,beta,gamma", + []string{}, + []string{"alpha", "beta", "gamma"}, + }, + { "alpha,beta", - []string{"alpha", "beta", "alpha"}, + []string{}, []string{"alpha", "beta"}, }, + { + "alpha", + []string{}, + []string{"alpha"}, + }, // 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"}, + []string{"alpha", "*", "gamma"}, }, { "alpha", []string{"beta"}, - []string{}, + []string{"alpha"}, }, }
@@ -175,14 +185,14 @@ func TestGetClientTransports(t *testing.T) {
for _, test := range tests { os.Setenv("TOR_PT_CLIENT_TRANSPORTS", test.ptServerClientTransports) - output, err := getClientTransports(test.methodNames) + output, err := getClientTransports(test.star) if err != nil { t.Errorf("TOR_PT_CLIENT_TRANSPORTS=%q unexpectedly returned an error: %s", test.ptServerClientTransports, err) } if !stringSetsEqual(output, test.expected) { t.Errorf("TOR_PT_CLIENT_TRANSPORTS=%q %q → %q (expected %q)", - test.ptServerClientTransports, test.methodNames, output, test.expected) + test.ptServerClientTransports, test.star, output, test.expected) } } }
tor-commits@lists.torproject.org