Second take on linkspec manipulation code needed by onion services
This follows discussion with @gabi-250 on !1173 (closed), and should be significantly improved. The first three commits are unchanged (but rebased); after that points, things diverge as discussed there.
Also, this time there are tests. ;)
Closes #794 (closed).
Edited by Nick Mathewson