Azure / azure-uamqp-c

AMQP library for C
Other
58 stars 63 forks source link

How to set proxy settings #250

Closed annatisch closed 6 years ago

annatisch commented 6 years ago

Hello,

I was wondering how one could set up an AMQP client on a network with a proxy. I see there's various 'setoption' settings for proxy data in Azure C Shared Utility - but I can't find anything that relates directly to the tls IO used for the AMQP connection.

I tried to look through the IoTHub client to see how they do, but they just seem to discard the proxy settings: https://github.com/Azure/azure-iot-sdk-c/blob/master/iothub_client/src/iothubtransportamqp.c#L18

Any guidance here would be great :) Thanks!

dcristoloveanu commented 6 years ago

@annatisch

The xio implementations are the key here. Everything in the world of the C SDK turns at some point into data that goes through an xio. The xio interface is basically a bytes in/bytes out interface.

Thus anything from a socket IO to a websocket IO can be implemented as long as one basic rule can be followed. Once the IO is setup, whatever transformation is done by the IO on the bytes in/bytes out is completely encapsulated. This is very similar to Unix file handles. Does not matter what lives behind the handle (from a console to the most complex replicated file system, they all do file IO).

The implementations of xIOs in C shared were done for this reason. Basically once an IO is implemented it can then be used by uAMQP, uMQTT, uHTTP or whoever wants to use them. This basically allows the IoT C SDK for example to have all the transports (AMQP, MQTT, HTTP) by simply porting the lowest level IO (usually socket IO).

There are several IO implementations in C shared:

How to set it up now. To use HTTP proxy IO a chain of XIOs need to be constructed:

Once HTTP proxy is up you can experiment with adding WS on top of the TLS IO, but I would start simple with just adding the HTTP proxy in the mix.

Sample on how to use the HTTP proxy IO is in the WS ANQP transport in the IoT SDK for C. https://github.com/Azure/azure-iot-sdk-c/blob/29dbc30ead1e5b4962e60e837bfa034f9c11b81f/iothub_client/src/iothubtransportamqp_websockets.c#L79

Let me know how it goes and if you hit any snags.

Cheers, /Dan

annatisch commented 6 years ago

aaaah gotcha! This is very interesting - thanks for such an in-depth explanation! (And you've saved me posting a question on websocket implementation that was bound to come up eventually).

I will close for now as the link provided seems pretty comprehensive. If I trip over anything I'll reopen :)