Serve process new connection created after calling `Accept()` in the standard library
(c io.ReadWriter)
| 29 | |
| 30 | // Serve process new connection created after calling `Accept()` in the standard library |
| 31 | func (h *StandardConnectionHandler) Serve(c io.ReadWriter) error { |
| 32 | bufConn := bufio.NewReader(c) |
| 33 | |
| 34 | // read the version byte |
| 35 | version := []byte{0} |
| 36 | if _, err := bufConn.Read(version); err != nil { |
| 37 | return err |
| 38 | } |
| 39 | |
| 40 | // ensure compatibility |
| 41 | if version[0] != socks5Version { |
| 42 | return fmt.Errorf("Unsupported SOCKS version: %v", version) |
| 43 | } |
| 44 | |
| 45 | // handle auth |
| 46 | if err := h.authHandler.Handle(bufConn, c); err != nil { |
| 47 | return err |
| 48 | } |
| 49 | |
| 50 | // process command/request |
| 51 | req, err := NewRequest(bufConn) |
| 52 | if err != nil { |
| 53 | return err |
| 54 | } |
| 55 | |
| 56 | return h.requestHandler.Handle(req, c) |
| 57 | } |
nothing calls this directly
no test coverage detected