[tor-commits] [goptlib/master] Remove IsClient and IsServer; recommend peeking at TOR_PT_CLIENT_TRANSPORTS.

dcf at torproject.org dcf at torproject.org
Mon Jun 2 03:00:02 UTC 2014


commit 610121b00ca09636f61ad9b3ad7ae5b8d4a2bec6
Author: David Fifield <david at bamsoftware.com>
Date:   Sun Jun 1 16:11:21 2014 -0700

    Remove IsClient and IsServer; recommend peeking at TOR_PT_CLIENT_TRANSPORTS.
    
    See discussion on https://trac.torproject.org/projects/tor/ticket/12087.
---
 pt.go      |   30 ++++++++++++++++++------------
 pt_test.go |   24 ------------------------
 2 files changed, 18 insertions(+), 36 deletions(-)

diff --git a/pt.go b/pt.go
index dba6701..8630cae 100644
--- a/pt.go
+++ b/pt.go
@@ -359,6 +359,15 @@ type ClientInfo struct {
 // 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.
+//
+// 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
+// whether the TOR_PT_CLIENT_TRANSPORTS environment variable is set:
+// 	if os.Getenv("TOR_PT_CLIENT_TRANSPORTS") != "" {
+// 		// Client mode; call pt.ClientSetup.
+// 	} else {
+// 		// Server mode; call pt.ServerSetup.
+// 	}
 func ClientSetup(star []string) (info ClientInfo, err error) {
 	ver, err := getManagedTransportVer()
 	if err != nil {
@@ -544,6 +553,15 @@ type ServerInfo struct {
 // 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.
+//
+// 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
+// whether the TOR_PT_CLIENT_TRANSPORTS environment variable is set:
+// 	if os.Getenv("TOR_PT_CLIENT_TRANSPORTS") != "" {
+// 		// Client mode; call pt.ClientSetup.
+// 	} else {
+// 		// Server mode; call pt.ServerSetup.
+// 	}
 func ServerSetup(star []string) (info ServerInfo, err error) {
 	ver, err := getManagedTransportVer()
 	if err != nil {
@@ -829,15 +847,3 @@ func DialOr(info *ServerInfo, addr, methodName string) (*net.TCPConn, error) {
 
 	return s, nil
 }
-
-// IsClient returns true if the enviornment reflects a managed client.
-func IsClient() bool {
-	env := getenv("TOR_PT_CLIENT_TRANSPORTS")
-	return env != ""
-}
-
-// IsServer returns true if the enviornment reflects a managed server.
-func IsServer() bool {
-	env := getenv("TOR_PT_SERVER_TRANSPORTS")
-	return env != ""
-}
diff --git a/pt_test.go b/pt_test.go
index b569352..d6a53e1 100644
--- a/pt_test.go
+++ b/pt_test.go
@@ -796,27 +796,3 @@ func TestMakeStateDir(t *testing.T) {
 		t.Errorf("MakeStateDir with a subdirectory of a file unexpectedly succeded")
 	}
 }
-
-func TestIsClient(t *testing.T) {
-	os.Clearenv()
-	if IsClient() {
-		t.Errorf("empty enviornment unexpectedly appears as a client")
-	}
-
-	os.Setenv("TOR_PT_CLIENT_TRANSPORTS", "dummy")
-	if !IsClient() {
-		t.Errorf("IsClient returned false with TOR_PT_CLIENT_TRANSPORTS set")
-	}
-}
-
-func TestIsServer(t *testing.T) {
-	os.Clearenv()
-	if IsServer() {
-		t.Errorf("empty enviornment unexpectedly appears as a server")
-	}
-
-	os.Setenv("TOR_PT_SERVER_TRANSPORTS", "dummy")
-	if !IsServer() {
-		t.Errorf("IsServer returned false with TOR_PT_SERVER_TRANSPORTS set")
-	}
-}



More information about the tor-commits mailing list