Loading README +1 −1 Original line number Diff line number Diff line Loading @@ -21,5 +21,5 @@ Git master as of 15 August, 2013 works. Add configuration like the following to the relay's torrc. You can change the --port option; make sure that port is open in the firewall. ExtORPort 5555 ExtORPort 6669 ServerTransportPlugin websocket exec /usr/local/bin/websocket-server --port 9901 websocket-client/websocket-client.go +21 −16 Original line number Diff line number Diff line // Tor websocket client transport plugin. // // Usage: // Usage in torrc: // UseBridges 1 // Bridge websocket X.X.X.X:YYYY // ClientTransportPlugin websocket exec ./websocket-client package main import ( Loading @@ -15,6 +16,7 @@ import ( "os" "os/signal" "sync" "syscall" "time" ) Loading Loading @@ -145,6 +147,7 @@ func handleConnection(conn *pt.SocksConn) error { } proxy(conn.Conn.(*net.TCPConn), ws) return nil } Loading Loading @@ -223,32 +226,34 @@ func main() { pt.CmethodsDone() var numHandlers int = 0 var sig os.Signal sigChan := make(chan os.Signal, 1) signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM) signalChan := make(chan os.Signal, 1) signal.Notify(signalChan, os.Interrupt) var sigint bool = false for !sigint { // wait for first signal sig = nil for sig == nil { select { case n := <-handlerChan: numHandlers += n case <-signalChan: Log("SIGINT") sigint = true case sig = <-sigChan: } } for _, ln := range listeners { ln.Close() } sigint = false for numHandlers != 0 && !sigint { if sig == syscall.SIGTERM { return } // wait for second signal or no more handlers sig = nil for sig == nil && numHandlers != 0 { select { case n := <-handlerChan: numHandlers += n case <-signalChan: Log("SIGINT") sigint = true case sig = <-sigChan: } } } websocket-server/websocket-server.go +9 −7 Original line number Diff line number Diff line // Tor websocket server transport plugin. // // Usage: // Usage in torrc: // ExtORPort 6669 // ServerTransportPlugin websocket exec ./websocket-server --port 9901 package main import ( Loading Loading @@ -141,7 +141,6 @@ func newWebSocketConn(ws *websocket.WebSocket) webSocketConn { // Copy from WebSocket to socket and vice versa. func proxy(local *net.TCPConn, conn *webSocketConn) { var wg sync.WaitGroup wg.Add(2) go func() { Loading @@ -153,7 +152,6 @@ func proxy(local *net.TCPConn, conn *webSocketConn) { conn.Close() wg.Done() }() go func() { _, err := io.Copy(local, conn) if err != nil { Loading @@ -171,19 +169,21 @@ func webSocketHandler(ws *websocket.WebSocket) { // Undo timeouts on HTTP request handling. ws.Conn.SetDeadline(time.Time{}) conn := newWebSocketConn(ws) defer conn.Close() handlerChan <- 1 defer func() { handlerChan <- -1 }() s, err := pt.DialOr(&ptInfo, ws.Conn.RemoteAddr(), ptMethodName) or, err := pt.DialOr(&ptInfo, ws.Conn.RemoteAddr(), ptMethodName) if err != nil { log("Failed to connect to ORPort: " + err.Error()) return } defer or.Close() proxy(s, &conn) proxy(or, &conn) } func startListener(addr *net.TCPAddr) (*net.TCPListener, error) { Loading Loading @@ -258,6 +258,7 @@ func main() { sigChan := make(chan os.Signal, 1) signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM) // wait for first signal sig = nil for sig == nil { select { Loading @@ -276,6 +277,7 @@ func main() { return } // wait for second signal or no more handlers sig = nil for sig == nil && numHandlers != 0 { select { Loading Loading
README +1 −1 Original line number Diff line number Diff line Loading @@ -21,5 +21,5 @@ Git master as of 15 August, 2013 works. Add configuration like the following to the relay's torrc. You can change the --port option; make sure that port is open in the firewall. ExtORPort 5555 ExtORPort 6669 ServerTransportPlugin websocket exec /usr/local/bin/websocket-server --port 9901
websocket-client/websocket-client.go +21 −16 Original line number Diff line number Diff line // Tor websocket client transport plugin. // // Usage: // Usage in torrc: // UseBridges 1 // Bridge websocket X.X.X.X:YYYY // ClientTransportPlugin websocket exec ./websocket-client package main import ( Loading @@ -15,6 +16,7 @@ import ( "os" "os/signal" "sync" "syscall" "time" ) Loading Loading @@ -145,6 +147,7 @@ func handleConnection(conn *pt.SocksConn) error { } proxy(conn.Conn.(*net.TCPConn), ws) return nil } Loading Loading @@ -223,32 +226,34 @@ func main() { pt.CmethodsDone() var numHandlers int = 0 var sig os.Signal sigChan := make(chan os.Signal, 1) signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM) signalChan := make(chan os.Signal, 1) signal.Notify(signalChan, os.Interrupt) var sigint bool = false for !sigint { // wait for first signal sig = nil for sig == nil { select { case n := <-handlerChan: numHandlers += n case <-signalChan: Log("SIGINT") sigint = true case sig = <-sigChan: } } for _, ln := range listeners { ln.Close() } sigint = false for numHandlers != 0 && !sigint { if sig == syscall.SIGTERM { return } // wait for second signal or no more handlers sig = nil for sig == nil && numHandlers != 0 { select { case n := <-handlerChan: numHandlers += n case <-signalChan: Log("SIGINT") sigint = true case sig = <-sigChan: } } }
websocket-server/websocket-server.go +9 −7 Original line number Diff line number Diff line // Tor websocket server transport plugin. // // Usage: // Usage in torrc: // ExtORPort 6669 // ServerTransportPlugin websocket exec ./websocket-server --port 9901 package main import ( Loading Loading @@ -141,7 +141,6 @@ func newWebSocketConn(ws *websocket.WebSocket) webSocketConn { // Copy from WebSocket to socket and vice versa. func proxy(local *net.TCPConn, conn *webSocketConn) { var wg sync.WaitGroup wg.Add(2) go func() { Loading @@ -153,7 +152,6 @@ func proxy(local *net.TCPConn, conn *webSocketConn) { conn.Close() wg.Done() }() go func() { _, err := io.Copy(local, conn) if err != nil { Loading @@ -171,19 +169,21 @@ func webSocketHandler(ws *websocket.WebSocket) { // Undo timeouts on HTTP request handling. ws.Conn.SetDeadline(time.Time{}) conn := newWebSocketConn(ws) defer conn.Close() handlerChan <- 1 defer func() { handlerChan <- -1 }() s, err := pt.DialOr(&ptInfo, ws.Conn.RemoteAddr(), ptMethodName) or, err := pt.DialOr(&ptInfo, ws.Conn.RemoteAddr(), ptMethodName) if err != nil { log("Failed to connect to ORPort: " + err.Error()) return } defer or.Close() proxy(s, &conn) proxy(or, &conn) } func startListener(addr *net.TCPAddr) (*net.TCPListener, error) { Loading Loading @@ -258,6 +258,7 @@ func main() { sigChan := make(chan os.Signal, 1) signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM) // wait for first signal sig = nil for sig == nil { select { Loading @@ -276,6 +277,7 @@ func main() { return } // wait for second signal or no more handlers sig = nil for sig == nil && numHandlers != 0 { select { Loading