> On Aug 31, 2015, at 11:48 PM, Zuhaib Siddique <zuh...@hipchat.com> wrote:
> 
> Hey all,

Hi Zuhaib!  Thanks for writing.

> I am looking at using HAProxy in front of Twisted for TCP connection and need 
> to pass the source IP along.  We are currently looking at hacking tcp.py to 
> add support for this: 
> http://www.haproxy.org/download/1.5/doc/proxy-protocol.txt but wondering if 
> this is something someone is already working on for twisted or maybe I dont 
> need to hack tcp.py.

I am not aware of an implementation of this protocol, but it looks very 
interesting!  The usual argument I hear for load-balancing HTTP rather than TCP 
is that you lose information about the network protocol you're speaking that 
would be preserved by the "Forwarded" or "X-Forwarded-For" header.  But if 
Twisted supported this protocol then it could live behind haproxy with no loss 
of information, regardless of protocol!  And if it had a server-side version of 
this it could load-balance other similarly equipped software.  Exciting 
possibilities all around.

Hacking tcp.py is definitely the wrong way to go about implementing it, though.

The right way to go about this would be to implement a transceiver: something 
that implements a protocol for its transport, and implements a transport for 
another protocol.  The best example of this within Twisted right now is 
twisted.protocols.tls, the OpenSSL integration that superseded our much 
grosser, less flexible hacking of tcp.py.

So for this proxy protocol, you'd have a protocol that waited until it received 
the full PROXY protocol header (whether text-based or binary) and implement 
ITCPTransport to have values in getHost() and getPeer() that correspond to the 
values received from the PROXY message.

Does that make sense?

If I have an idle moment I might try my hand at an implementation myself, but I 
am not always super reliable ;-).

> Thanks
> Zuhaib

-glyph

_______________________________________________
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

Reply via email to