1
0
Fork 0

Use new Request struct for the Server api

logger
ap4y 2016-01-11 21:24:54 +13:00
parent ae345732fa
commit eb24bec29f
2 changed files with 19 additions and 4 deletions

View File

@ -132,14 +132,29 @@ func (s *Server) ServeConn(conn net.Conn) error {
}
// Authenticate the connection
if err := s.authenticate(conn, bufConn); err != nil {
authContext, err := s.authenticate(conn, bufConn)
if err != nil {
err = fmt.Errorf("Failed to authenticate: %v", err)
s.config.Logger.Printf("[ERR] socks: %v", err)
return err
}
request, err := NewRequest(bufConn)
if err != nil {
if err == unrecognizedAddrType {
if err := sendReply(conn, addrTypeNotSupported, nil); err != nil {
return fmt.Errorf("Failed to send reply: %v", err)
}
}
return fmt.Errorf("Failed to read destination address: %v", err)
}
request.AuthContext = authContext
if client, ok := conn.RemoteAddr().(*net.TCPAddr); ok {
request.RemoteAddr = &AddrSpec{IP: client.IP, Port: client.Port}
}
// Process the client request
if err := s.handleRequest(conn, bufConn); err != nil {
if err := s.handleRequest(request, conn); err != nil {
err = fmt.Errorf("Failed to handle request: %v", err)
s.config.Logger.Printf("[ERR] socks: %v", err)
return err

View File

@ -67,7 +67,7 @@ func TestSOCKS5_Connect(t *testing.T) {
// Connect, auth and connec to local
req := bytes.NewBuffer(nil)
req.Write([]byte{5})
req.Write([]byte{2, noAuth, userPassAuth})
req.Write([]byte{2, NoAuth, UserPassAuth})
req.Write([]byte{1, 3, 'f', 'o', 'o', 3, 'b', 'a', 'r'})
req.Write([]byte{5, 1, 0, 1, 127, 0, 0, 1})
@ -83,7 +83,7 @@ func TestSOCKS5_Connect(t *testing.T) {
// Verify response
expected := []byte{
socks5Version, userPassAuth,
socks5Version, UserPassAuth,
1, authSuccess,
5,
0,