commit c1482145a738b9378ee6a5f7067544bea7414f34
Author: Yawning Angel <yawn...@schwanenlied.me>
Date:   Wed May 21 08:06:36 2014 +0000

    Add IsClient and IsServer.
    
    Both methods only examine TOR_PT_[CLIENT,SERVER]_TRANSPORTS, so they
    are not substitues for ClientSetup/ServerSetup.  However that check is
    sufficient for determining which Setup routine to run in the first
    place.
---
 pt.go      |   12 ++++++++++++
 pt_test.go |   24 ++++++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/pt.go b/pt.go
index 92bb0f5..3bd50a8 100644
--- a/pt.go
+++ b/pt.go
@@ -816,3 +816,15 @@ 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 aa3ad04..5689405 100644
--- a/pt_test.go
+++ b/pt_test.go
@@ -737,3 +737,27 @@ func TestExtOrPortSetup(t *testing.T) {
        testExtOrPortSetupIndividual(t, "", methodName)
        testExtOrPortSetupIndividual(t, addr, methodName)
 }
+
+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")
+       }
+}

_______________________________________________
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits

Reply via email to