[tor-commits] [goptlib/master] Parse TOR_PT_SERVER_TRANSPORT_OPTIONS and include in Bindaddr.

dcf at torproject.org dcf at torproject.org
Mon Dec 9 02:49:51 UTC 2013


commit c2a6339b8c560cb49df1d9d703ac042293937034
Author: David Fifield <david at bamsoftware.com>
Date:   Sun Dec 8 02:39:30 2013 -0800

    Parse TOR_PT_SERVER_TRANSPORT_OPTIONS and include in Bindaddr.
---
 pt.go      |   14 +++++++++++++-
 pt_test.go |   12 ++++++------
 2 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/pt.go b/pt.go
index 4f7f167..f389794 100644
--- a/pt.go
+++ b/pt.go
@@ -341,6 +341,9 @@ func ClientSetup(methodNames []string) (ClientInfo, error) {
 type Bindaddr struct {
 	MethodName string
 	Addr       *net.TCPAddr
+	// Options from TOR_PT_SERVER_TRANSPORT_OPTIONS that pertain to this
+	// transport.
+	Options Args
 }
 
 // Resolve an address string into a net.TCPAddr. We are a bit more strict than
@@ -398,10 +401,18 @@ func filterBindaddrs(addrs []Bindaddr, methodNames []string) []Bindaddr {
 
 // 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.
+// 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) {
 	var result []Bindaddr
 
+	// Parse the list of server transport options.
+	serverTransportOptions := getenv("TOR_PT_SERVER_TRANSPORT_OPTIONS")
+	optionsMap, err := parseServerTransportOptions(serverTransportOptions)
+	if err != nil {
+		return nil, envError(fmt.Sprintf("TOR_PT_SERVER_TRANSPORT_OPTIONS: %q: %s", serverTransportOptions, err.Error()))
+	}
+
 	// Get the list of all requested bindaddrs.
 	serverBindaddr, err := getenvRequired("TOR_PT_SERVER_BINDADDR")
 	if err != nil {
@@ -420,6 +431,7 @@ func getServerBindaddrs(methodNames []string) ([]Bindaddr, error) {
 			return nil, envError(fmt.Sprintf("TOR_PT_SERVER_BINDADDR: %q: %s", spec, err.Error()))
 		}
 		bindaddr.Addr = addr
+		bindaddr.Options = optionsMap[bindaddr.MethodName]
 		result = append(result, bindaddr)
 	}
 
diff --git a/pt_test.go b/pt_test.go
index 1d30ff2..1602fa8 100644
--- a/pt_test.go
+++ b/pt_test.go
@@ -280,8 +280,8 @@ func TestGetServerBindaddrs(t *testing.T) {
 			"alpha,beta,gamma",
 			[]string{"alpha", "beta"},
 			[]Bindaddr{
-				{"alpha", &net.TCPAddr{IP: net.ParseIP("1.2.3.4"), Port: 1111}},
-				{"beta", &net.TCPAddr{IP: net.ParseIP("1:2::3:4"), Port: 2222}},
+				{MethodName: "alpha", Addr: &net.TCPAddr{IP: net.ParseIP("1.2.3.4"), Port: 1111}},
+				{MethodName: "beta", Addr: &net.TCPAddr{IP: net.ParseIP("1:2::3:4"), Port: 2222}},
 			},
 		},
 		{
@@ -301,8 +301,8 @@ func TestGetServerBindaddrs(t *testing.T) {
 			"*",
 			[]string{"alpha", "beta"},
 			[]Bindaddr{
-				{"alpha", &net.TCPAddr{IP: net.ParseIP("1.2.3.4"), Port: 1111}},
-				{"beta", &net.TCPAddr{IP: net.ParseIP("1:2::3:4"), Port: 2222}},
+				{MethodName: "alpha", Addr: &net.TCPAddr{IP: net.ParseIP("1.2.3.4"), Port: 1111}},
+				{MethodName: "beta", Addr: &net.TCPAddr{IP: net.ParseIP("1:2::3:4"), Port: 2222}},
 			},
 		},
 		{
@@ -310,8 +310,8 @@ func TestGetServerBindaddrs(t *testing.T) {
 			"trebuchet,ballista",
 			[]string{"trebuchet", "ballista"},
 			[]Bindaddr{
-				{"trebuchet", &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 1984}},
-				{"ballista", &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 4891}},
+				{MethodName: "trebuchet", Addr: &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 1984}},
+				{MethodName: "ballista", Addr: &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 4891}},
 			},
 		},
 	}





More information about the tor-commits mailing list