[Pkg-privacy-commits] [obfs4proxy] 53/151: Revert "Use the new goptlib goodies."

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 12:59:38 UTC 2015


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch master
in repository obfs4proxy.

commit 7dd875fe4cd214a7678e701adfd2a8bde7882e4d
Author: Yawning Angel <yawning at schwanenlied.me>
Date:   Wed May 21 18:28:50 2014 +0000

    Revert "Use the new goptlib goodies."
    
    This reverts commit 8d61c6bcc67e7acc5604f87ca2a7c7ec43fc46de.
    
    On second thought, don't do this.  API not final, and some of the stuff
    might not be a good idea after all.
---
 obfs4proxy/obfs4proxy.go | 47 +++++++++++++++++++++++++++++++++++++----------
 1 file changed, 37 insertions(+), 10 deletions(-)

diff --git a/obfs4proxy/obfs4proxy.go b/obfs4proxy/obfs4proxy.go
index 9a9083d..3ad8785 100644
--- a/obfs4proxy/obfs4proxy.go
+++ b/obfs4proxy/obfs4proxy.go
@@ -69,7 +69,6 @@ const (
 	obfs4LogFile = "obfs4proxy.log"
 )
 
-var enableLogging bool
 var unsafeLogging bool
 var ptListeners []net.Listener
 
@@ -173,8 +172,6 @@ func serverSetup() bool {
 		return launch
 	}
 
-	ptInitializeLogging(ptServerInfo.StateLocation)
-
 	for _, bindaddr := range ptServerInfo.Bindaddrs {
 		switch bindaddr.MethodName {
 		case obfs4Method:
@@ -292,8 +289,6 @@ func clientSetup() bool {
 		return launch
 	}
 
-	ptInitializeLogging(ptClientInfo.StateLocation)
-
 	for _, methodName := range ptClientInfo.MethodNames {
 		switch methodName {
 		case obfs4Method:
@@ -315,8 +310,37 @@ func clientSetup() bool {
 	return launch
 }
 
-func ptInitializeLogging(dir string) {
-	if enableLogging {
+func ptIsClient() bool {
+	env := os.Getenv("TOR_PT_CLIENT_TRANSPORTS")
+	return env != ""
+}
+
+func ptIsServer() bool {
+	env := os.Getenv("TOR_PT_SERVER_TRANSPORTS")
+	return env != ""
+}
+
+func ptGetStateDir() (dir string, err error) {
+	dir = os.Getenv("TOR_PT_STATE_LOCATION")
+	if dir == "" {
+		return
+	}
+
+	err = os.MkdirAll(dir, 0755)
+	if err != nil {
+		log.Fatalf("[ERROR] Failed to create path: %s", err)
+	}
+
+	return
+}
+
+func ptInitializeLogging(enable bool) {
+	if enable {
+		dir, err := ptGetStateDir()
+		if err != nil || dir == "" {
+			return
+		}
+
 		f, err := os.OpenFile(path.Join(dir, obfs4LogFile), os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600)
 		if err != nil {
 			log.Fatalf("[ERROR] Failed to open log file: %s", err)
@@ -370,7 +394,7 @@ func generateServerParams(id string) {
 func main() {
 	// Some command line args.
 	genParams := flag.String("genServerParams", "", "Generate server params given a bridge fingerprint.")
-	flag.BoolVar(&enableLogging, "enableLogging", false, "Log to TOR_PT_STATE_LOCATION/obfs4proxy.log")
+	doLogging := flag.Bool("enableLogging", false, "Log to TOR_PT_STATE_LOCATION/obfs4proxy.log")
 	flag.BoolVar(&unsafeLogging, "unsafeLogging", false, "Disable the address scrubber")
 	flag.Parse()
 	if *genParams != "" {
@@ -378,11 +402,14 @@ func main() {
 		os.Exit(0)
 	}
 
+	// Initialize pt logging.
+	ptInitializeLogging(*doLogging)
+
 	// Go through the pt protocol and initialize client or server mode.
 	launched := false
-	if pt.IsClient() {
+	if ptIsClient() {
 		launched = clientSetup()
-	} else if pt.IsServer() {
+	} else if ptIsServer() {
 		launched = serverSetup()
 	}
 	if !launched {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/obfs4proxy.git



More information about the Pkg-privacy-commits mailing list