[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [goptlib/master] Encapsulate SOCKS request information in a Request struct.
commit 9b3e369ce561f15ac433c5f8d53ef2874489dd1d
Author: David Fifield <david@xxxxxxxxxxxxxxx>
Date: Mon Dec 2 08:40:05 2013 -0800
Encapsulate SOCKS request information in a Request struct.
---
socks/socks.go | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/socks/socks.go b/socks/socks.go
index 060f746..8d2e870 100644
--- a/socks/socks.go
+++ b/socks/socks.go
@@ -20,6 +20,10 @@ const (
socksRequestFailed = 0x5b
)
+type Request struct {
+ Target string
+}
+
// Read a SOCKS4a connect request, and call the given connect callback with the
// requested destination string. If the callback returns an error, sends a SOCKS
// request failed message. Otherwise, sends a SOCKS request granted message for
@@ -40,12 +44,12 @@ const (
// defer remote.Close()
// copyLoop(local, remote)
func AwaitSocks4aConnect(conn *net.TCPConn, connect func(string) (*net.TCPAddr, error)) error {
- dest, err := readSocks4aConnect(conn)
+ req, err := readSocks4aConnect(conn)
if err != nil {
sendSocks4aResponseFailed(conn)
return err
}
- destAddr, err := connect(dest)
+ destAddr, err := connect(req.Target)
if err != nil {
sendSocks4aResponseFailed(conn)
return err
@@ -54,8 +58,8 @@ func AwaitSocks4aConnect(conn *net.TCPConn, connect func(string) (*net.TCPAddr,
return nil
}
-// Read a SOCKS4a connect request. Returns a "host:port" string.
-func readSocks4aConnect(s io.Reader) (target string, err error) {
+// Read a SOCKS4a connect request. Returns a Request.
+func readSocks4aConnect(s io.Reader) (req Request, err error) {
r := bufio.NewReader(s)
var h [8]byte
@@ -97,7 +101,7 @@ func readSocks4aConnect(s io.Reader) (target string, err error) {
return
}
- target = fmt.Sprintf("%s:%d", host, port)
+ req.Target = fmt.Sprintf("%s:%d", host, port)
return
}
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits