Adding support for gateways

This pull request adds support to establish connection through one or more gateways.