Introduce Finite State Machine abstraction into Tor codebase

This would make e.g. our SOCKS code easier to understand and maintain.