[tor-commits] [goptlib/master] Add StateLocation to ClientInfo/ServerInfo.

yawning at torproject.org yawning at torproject.org
Wed May 21 09:33:48 UTC 2014


commit 15b960d55905877a840fe605a41a8139bffb5329
Author: Yawning Angel <yawning at schwanenlied.me>
Date:   Wed May 21 09:31:00 2014 +0000

    Add StateLocation to ClientInfo/ServerInfo.
    
    Per the pt spec, this is always set, the only place where managed
    proxies should store files, and should be created by proxies if missing.
    The implementation does all of these things.
---
 pt.go |   34 +++++++++++++++++++++++++++++++---
 1 file changed, 31 insertions(+), 3 deletions(-)

diff --git a/pt.go b/pt.go
index 3bd50a8..7f6c0a7 100644
--- a/pt.go
+++ b/pt.go
@@ -322,6 +322,22 @@ func getManagedTransportVer() (string, error) {
 	return "", versionError("no-version")
 }
 
+// Get the pluggable transport state location offered by Tor, and create it if
+// missing.  This function reads the enviornment variable
+// TOR_PT_STATE_LOCATION.
+func getStateLocation() (string, error) {
+	stateLocation, err := getenvRequired("TOR_PT_STATE_LOCATION")
+	if err != nil {
+		return "", err
+	}
+	err = os.MkdirAll(stateLocation, 0700)
+	if err != nil {
+		return "", envError(fmt.Sprintf("error creating TOR_PT_STATE_LOCATION: %s", err))
+	}
+
+	return stateLocation, nil
+}
+
 // Get the intersection of the method names offered by Tor and those in
 // methodNames. This function reads the environment variable
 // TOR_PT_CLIENT_TRANSPORTS.
@@ -337,9 +353,10 @@ func getClientTransports(star []string) ([]string, error) {
 }
 
 // This structure is returned by ClientSetup. It consists of a list of method
-// names.
+// names and the state location.
 type ClientInfo struct {
-	MethodNames []string
+	MethodNames   []string
+	StateLocation string
 }
 
 // Check the client pluggable transports environment, emitting an error message
@@ -353,6 +370,11 @@ func ClientSetup(star []string) (info ClientInfo, err error) {
 	}
 	line("VERSION", ver)
 
+	info.StateLocation, err = getStateLocation()
+	if err != nil {
+		return
+	}
+
 	info.MethodNames, err = getClientTransports(star)
 	if err != nil {
 		return
@@ -518,12 +540,13 @@ func readAuthCookieFile(filename string) ([]byte, error) {
 
 // This structure is returned by ServerSetup. It consists of a list of
 // Bindaddrs, an address for the ORPort, an address for the extended ORPort (if
-// any), and an authentication cookie (if any).
+// any), an authentication cookie (if any), and the state location.
 type ServerInfo struct {
 	Bindaddrs      []Bindaddr
 	OrAddr         *net.TCPAddr
 	ExtendedOrAddr *net.TCPAddr
 	AuthCookie     []byte
+	StateLocation  string
 }
 
 // Check the server pluggable transports environment, emitting an error message
@@ -538,6 +561,11 @@ func ServerSetup(star []string) (info ServerInfo, err error) {
 	}
 	line("VERSION", ver)
 
+	info.StateLocation, err = getStateLocation()
+	if err != nil {
+		return
+	}
+
 	info.Bindaddrs, err = getServerBindaddrs(star)
 	if err != nil {
 		return



More information about the tor-commits mailing list