[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [flashproxy/master] Send the TRANSPORT extended OR port command.
commit 88e36fcd4393c775001af69c4fec351b8efec43a
Author: David Fifield <david@xxxxxxxxxxxxxxx>
Date: Mon Apr 29 22:54:59 2013 -0700
Send the TRANSPORT extended OR port command.
This is based on the spec from the bug7751_take2 branch from
https://trac.torproject.org/projects/tor/ticket/7751.
---
websocket-transport/pt.go | 33 ++++++++++++++++++++----------
websocket-transport/websocket-server.go | 4 +-
2 files changed, 24 insertions(+), 13 deletions(-)
diff --git a/websocket-transport/pt.go b/websocket-transport/pt.go
index 61ec456..0ff1644 100644
--- a/websocket-transport/pt.go
+++ b/websocket-transport/pt.go
@@ -466,10 +466,11 @@ func extOrPortAuthenticate(s *net.TCPConn, info *PtServerInfo) error {
// See section 3.1 of 196-transport-control-ports.txt.
const (
- extOrCmdDone = 0x0000
- extOrCmdUserAddr = 0x0001
- extOrCmdOkay = 0x1000
- extOrCmdDeny = 0x1001
+ extOrCmdDone = 0x0000
+ extOrCmdUserAddr = 0x0001
+ extOrCmdTransport = 0x0002
+ extOrCmdOkay = 0x1000
+ extOrCmdDeny = 0x1001
)
func extOrPortWriteCommand(s *net.TCPConn, cmd uint16, body []byte) error {
@@ -497,12 +498,18 @@ func extOrPortWriteCommand(s *net.TCPConn, cmd uint16, body []byte) error {
return nil
}
-// Send a USERADDR command on s. See section 3.1 of
+// Send a USERADDR command on s. See section 3.1.2.1 of
// 196-transport-control-ports.txt.
func extOrPortSendUserAddr(s *net.TCPConn, conn net.Conn) error {
return extOrPortWriteCommand(s, extOrCmdUserAddr, []byte(conn.RemoteAddr().String()))
}
+// Send a TRANSPORT command on s. See section 3.1.2.2 of
+// 196-transport-control-ports.txt.
+func extOrPortSendTransport(s *net.TCPConn, methodName string) error {
+ return extOrPortWriteCommand(s, extOrCmdTransport, []byte(methodName))
+}
+
// Send a DONE command on s. See section 3.1 of 196-transport-control-ports.txt.
func extOrPortSendDone(s *net.TCPConn) error {
return extOrPortWriteCommand(s, extOrCmdDone, []byte{})
@@ -534,16 +541,20 @@ func extOrPortRecvCommand(s *net.TCPConn) (cmd uint16, body []byte, err error) {
return cmd, body, err
}
-// Send a USERADDR command followed by a DONE command. Wait for an OKAY or DENY
-// response command from the server. Returns nil if and only if OKAY is
-// received.
-func extOrPortDoUserAddr(s *net.TCPConn, conn net.Conn) error {
+// Send USERADDR and TRANSPORT commands followed by a DONE command. Wait for an
+// OKAY or DENY response command from the server. Returns nil if and only if
+// OKAY is received.
+func extOrPortSetup(s *net.TCPConn, conn net.Conn, methodName string) error {
var err error
err = extOrPortSendUserAddr(s, conn)
if err != nil {
return err
}
+ err = extOrPortSendTransport(s, methodName)
+ if err != nil {
+ return err
+ }
err = extOrPortSendDone(s)
if err != nil {
return err
@@ -565,7 +576,7 @@ func extOrPortDoUserAddr(s *net.TCPConn, conn net.Conn) error {
// open *net.TCPConn. If connecting to the extended OR port, extended OR port
// authentication à la 217-ext-orport-auth.txt is done before returning; an
// error is returned if authentication fails.
-func PtConnectOr(info *PtServerInfo, conn net.Conn) (*net.TCPConn, error) {
+func PtConnectOr(info *PtServerInfo, conn net.Conn, methodName string) (*net.TCPConn, error) {
if info.ExtendedOrAddr == nil {
return net.DialTCP("tcp", nil, info.OrAddr)
}
@@ -580,7 +591,7 @@ func PtConnectOr(info *PtServerInfo, conn net.Conn) (*net.TCPConn, error) {
s.Close()
return nil, err
}
- err = extOrPortDoUserAddr(s, conn)
+ err = extOrPortSetup(s, conn, methodName)
if err != nil {
s.Close()
return nil, err
diff --git a/websocket-transport/websocket-server.go b/websocket-transport/websocket-server.go
index 1abff87..27fc7e2 100644
--- a/websocket-transport/websocket-server.go
+++ b/websocket-transport/websocket-server.go
@@ -19,6 +19,7 @@ import (
"time"
)
+const ptMethodName = "websocket"
const requestTimeout = 10 * time.Second
var logFile = os.Stderr
@@ -168,7 +169,7 @@ func websocketHandler(ws *Websocket) {
handlerChan <- -1
}()
- s, err := PtConnectOr(&ptInfo, ws.Conn)
+ s, err := PtConnectOr(&ptInfo, ws.Conn, ptMethodName)
if err != nil {
Log("Failed to connect to ORPort: " + err.Error())
return
@@ -200,7 +201,6 @@ func startListener(addr *net.TCPAddr) (*net.TCPListener, error) {
}
func main() {
- const ptMethodName = "websocket"
var defaultPort int
var logFilename string
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits