[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [goptlib/master] Use the argument to ServerSetup only when the "*" list is requested.
commit f9316c52f21767bb5b0cd534d01fdf4efb4716f7
Author: David Fifield <david@xxxxxxxxxxxxxxx>
Date: Sun Jan 12 21:58:35 2014 -0800
Use the argument to ServerSetup only when the "*" list is requested.
Formerly the list always served as an additional filter of methods that
we support. Now, ServerSetup 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 the list of method names is not
known in advance.
https://lists.torproject.org/pipermail/tor-dev/2013-December/005966.html
---
examples/dummy-server/dummy-server.go | 19 ++++++++++++-------
pt.go | 29 +++++++++++++++--------------
pt_test.go | 27 +++++++++++++++++++--------
3 files changed, 46 insertions(+), 29 deletions(-)
diff --git a/examples/dummy-server/dummy-server.go b/examples/dummy-server/dummy-server.go
index 7e8ad96..ea91be9 100644
--- a/examples/dummy-server/dummy-server.go
+++ b/examples/dummy-server/dummy-server.go
@@ -87,14 +87,19 @@ func main() {
listeners := make([]net.Listener, 0)
for _, bindaddr := range ptInfo.Bindaddrs {
- ln, err := net.ListenTCP("tcp", bindaddr.Addr)
- if err != nil {
- pt.SmethodError(bindaddr.MethodName, err.Error())
- continue
+ switch bindaddr.MethodName {
+ case "dummy":
+ ln, err := net.ListenTCP("tcp", bindaddr.Addr)
+ if err != nil {
+ pt.SmethodError(bindaddr.MethodName, err.Error())
+ break
+ }
+ go acceptLoop(ln)
+ pt.Smethod(bindaddr.MethodName, ln.Addr())
+ listeners = append(listeners, ln)
+ default:
+ pt.SmethodError(bindaddr.MethodName, "no such method")
}
- go acceptLoop(ln)
- pt.Smethod(bindaddr.MethodName, ln.Addr())
- listeners = append(listeners, ln)
}
pt.SmethodsDone()
diff --git a/pt.go b/pt.go
index 391b1f5..c77687f 100644
--- a/pt.go
+++ b/pt.go
@@ -427,11 +427,12 @@ func filterBindaddrs(addrs []Bindaddr, methodNames []string) []Bindaddr {
return result
}
-// Return an array of Bindaddrs, those being the contents of
-// TOR_PT_SERVER_BINDADDR, with keys filtered by TOR_PT_SERVER_TRANSPORTS, and
-// further filtered by the methods in methodNames. Transport-specific options
-// from TOR_PT_SERVER_TRANSPORT_OPTIONS are assigned to the Options member.
-func getServerBindaddrs(methodNames []string) ([]Bindaddr, error) {
+// 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) {
var result []Bindaddr
// Parse the list of server transport options.
@@ -468,13 +469,12 @@ func getServerBindaddrs(methodNames []string) ([]Bindaddr, error) {
if err != nil {
return nil, err
}
- if serverTransports != "*" {
+ if serverTransports == "*" {
+ result = filterBindaddrs(result, star)
+ } else {
result = filterBindaddrs(result, strings.Split(serverTransports, ","))
}
- // Finally filter by what we understand.
- result = filterBindaddrs(result, methodNames)
-
return result, nil
}
@@ -525,17 +525,18 @@ type ServerInfo struct {
}
// Check the server pluggable transports environment, emitting an error message
-// 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.
-func ServerSetup(methodNames []string) (info ServerInfo, 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
+// requested bind addresses, the server ORPort and extended ORPort, and reads
+// the auth cookie file. Returns a ServerInfo struct.
+func ServerSetup(star []string) (info ServerInfo, err error) {
ver, err := getManagedTransportVer()
if err != nil {
return
}
line("VERSION", ver)
- info.Bindaddrs, err = getServerBindaddrs(methodNames)
+ info.Bindaddrs, err = getServerBindaddrs(star)
if err != nil {
return
}
diff --git a/pt_test.go b/pt_test.go
index f7e9156..a2abc1f 100644
--- a/pt_test.go
+++ b/pt_test.go
@@ -265,7 +265,7 @@ func TestGetServerBindaddrs(t *testing.T) {
ptServerBindaddr string
ptServerTransports string
ptServerTransportOptions string
- methodNames []string
+ star []string
}{
{
"xxx",
@@ -290,7 +290,7 @@ func TestGetServerBindaddrs(t *testing.T) {
ptServerBindaddr string
ptServerTransports string
ptServerTransportOptions string
- methodNames []string
+ star []string
expected []Bindaddr
}{
{
@@ -315,7 +315,9 @@ func TestGetServerBindaddrs(t *testing.T) {
"alpha,beta,gamma",
"",
[]string{},
- []Bindaddr{},
+ []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",
@@ -328,6 +330,15 @@ func TestGetServerBindaddrs(t *testing.T) {
},
},
{
+ "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{}},
+ },
+ },
+ {
"trebuchet-127.0.0.1:1984,ballista-127.0.0.1:4891",
"trebuchet,ballista",
"trebuchet:secret=nou;trebuchet:cache=/tmp/cache;ballista:secret=yes",
@@ -351,10 +362,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.methodNames)
+ _, err := getServerBindaddrs(test.star)
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.methodNames)
+ test.ptServerBindaddr, test.ptServerTransports, test.ptServerTransportOptions, test.star)
}
}
@@ -362,14 +373,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.methodNames)
+ output, err := getServerBindaddrs(test.star)
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.methodNames, err)
+ test.ptServerBindaddr, test.ptServerTransports, test.ptServerTransportOptions, test.star, 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.methodNames, output, test.expected)
+ test.ptServerBindaddr, test.ptServerTransports, test.ptServerTransportOptions, test.star, output, test.expected)
}
}
}
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits