[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [websocket/master] Use new goptlib ServerSetup and ClientSetup.



commit 0ea3a5f82ea4dd846d75b17860633504ba110c04
Author: David Fifield <david@xxxxxxxxxxxxxxx>
Date:   Sun Jan 12 23:01:47 2014 -0800

    Use new goptlib ServerSetup and ClientSetup.
---
 websocket-client/websocket-client.go |   30 +++++++++++++++---------------
 websocket-server/websocket-server.go |   19 ++++++++++++-------
 2 files changed, 27 insertions(+), 22 deletions(-)

diff --git a/websocket-client/websocket-client.go b/websocket-client/websocket-client.go
index 228cb1c..fe38c9d 100644
--- a/websocket-client/websocket-client.go
+++ b/websocket-client/websocket-client.go
@@ -187,13 +187,12 @@ func startListener(addrStr string) (*pt.SocksListener, error) {
 
 func main() {
 	var logFilename string
-	var socksAddrStrs = []string{"127.0.0.1:0"}
-	var socksArg string
+	var socksAddrStr string
 	var err error
 
 	flag.Usage = usage
 	flag.StringVar(&logFilename, "log", "", "log file to write to")
-	flag.StringVar(&socksArg, "socks", "", "address on which to listen for SOCKS connections")
+	flag.StringVar(&socksAddrStr, "socks", "127.0.0.1:0", "address on which to listen for SOCKS connections")
 	flag.Parse()
 
 	if logFilename != "" {
@@ -205,10 +204,6 @@ func main() {
 		logFile = f
 	}
 
-	if socksArg != "" {
-		socksAddrStrs = []string{socksArg}
-	}
-
 	log("starting")
 	ptInfo, err = pt.ClientSetup([]string{ptMethodName})
 	if err != nil {
@@ -217,15 +212,20 @@ func main() {
 	}
 
 	listeners := make([]net.Listener, 0)
-	for _, socksAddrStr := range socksAddrStrs {
-		ln, err := startListener(socksAddrStr)
-		if err != nil {
-			pt.CmethodError(ptMethodName, err.Error())
-			continue
+	for _, methodName := range ptInfo.MethodNames {
+		switch methodName {
+		case ptMethodName:
+			ln, err := startListener(socksAddrStr)
+			if err != nil {
+				pt.CmethodError(ptMethodName, err.Error())
+				break
+			}
+			pt.Cmethod(ptMethodName, ln.Version(), ln.Addr())
+			log("listening on %s", ln.Addr().String())
+			listeners = append(listeners, ln)
+		default:
+			pt.CmethodError(methodName, "no such method")
 		}
-		pt.Cmethod(ptMethodName, ln.Version(), ln.Addr())
-		log("listening on %s", ln.Addr().String())
-		listeners = append(listeners, ln)
 	}
 	pt.CmethodsDone()
 
diff --git a/websocket-server/websocket-server.go b/websocket-server/websocket-server.go
index 64ae7b4..4120df8 100644
--- a/websocket-server/websocket-server.go
+++ b/websocket-server/websocket-server.go
@@ -243,14 +243,19 @@ func main() {
 			bindaddr.Addr.Port = port
 		}
 
-		ln, err := startListener(bindaddr.Addr)
-		if err != nil {
-			pt.SmethodError(bindaddr.MethodName, err.Error())
-			continue
+		switch bindaddr.MethodName {
+		case ptMethodName:
+			ln, err := startListener(bindaddr.Addr)
+			if err != nil {
+				pt.SmethodError(bindaddr.MethodName, err.Error())
+				break
+			}
+			pt.Smethod(bindaddr.MethodName, ln.Addr())
+			log("listening on %s", ln.Addr().String())
+			listeners = append(listeners, ln)
+		default:
+			pt.SmethodError(bindaddr.MethodName, "no such method")
 		}
-		pt.Smethod(bindaddr.MethodName, ln.Addr())
-		log("listening on %s", ln.Addr().String())
-		listeners = append(listeners, ln)
 	}
 	pt.SmethodsDone()
 

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