Improve code handling SOCKS connection in tor daemon
After a discussion at the weekly little-t tor meeting on #tor-dev, it appears that the code handling SOCKS4/5 connections is a mess:
```
15:41 < nickm> sad to say, the SOCKS code is a mess right now. It'll probably need significant testing and refactoring before we can think about extending it
```
Considering proposal [229](https://gitweb.torproject.org/torspec.git/blob/HEAD:/proposals/229-further-socks5-extensions.txt|) to extend SOCKS5 for Tor use cases, we should work on improving this code base before anything else.
1) Tests, tests and moar tests
2) Refactor
3) Extend
Related issues: legacy/trac#11134, legacy/trac#9221
issue