[Twisted-Python] Switching Protocols and TLS
Hello, I am running a Twisted Web Site object that switches the protocol for specific paths. The goal is to run Twisted Web, and have certain paths mapped to WebSocket. I am aware of http://twistedmatrix.com/trac/ticket/3204 but in the meantime have working code https://github.com/tavendo/AutobahnPython/blob/master/autobahn/autobahn/reso... This works for non-TLS, but not for TLS. This works perfectly: https://github.com/tavendo/AutobahnPython/tree/master/examples/websocket/ech... and this does NOT work: https://github.com/tavendo/AutobahnPython/tree/master/examples/websocket/ech... The latter is able to send stuff down to client, but won't receive anything. Any hint how to track that down would be great! Thanks, Tobias
On 01:19 pm, tobias.oberstein@tavendo.de wrote:
Hello,
I am running a Twisted Web Site object that switches the protocol for specific paths. The goal is to run Twisted Web, and have certain paths mapped to WebSocket.
I am aware of
http://twistedmatrix.com/trac/ticket/3204
but in the meantime have working code
https://github.com/tavendo/AutobahnPython/blob/master/autobahn/autobahn/reso...
This works for non-TLS, but not for TLS.
This works perfectly:
https://github.com/tavendo/AutobahnPython/tree/master/examples/websocket/ech...
and this does NOT work:
https://github.com/tavendo/AutobahnPython/tree/master/examples/websocket/ech...
The latter is able to send stuff down to client, but won't receive anything.
Any hint how to track that down would be great!
The `protocol´ attribute isn't part of the transport interface. Some transports are implemented in a way such that changing that attribute to refer to a different protocol will produce the behavior you're after, but not all. In particular, the transport implemented in twisted.protocols.tls (used to provide the transport whenever you use listenSSL, connectSSL, or startTLS) does not work this way. You should be able to work out which attribute needs to be mangled by looking at twisted/protocols/tls.py. My initial guess would be `wrappedProtocol`, but that's *only* a guess. And of course, whatever you find is not going to be part of any formal transport interface either, so it's not guaranteed to keep working in the future, or to work with any other transport you might end up using - hence the desire to resolve #3204. Jean-Paul
Any hint how to track that down would be great!
The `protocol´ attribute isn't part of the transport interface. Some transports are implemented in a way such that changing that attribute to refer to a different protocol will produce the behavior you're after, but not all. In particular, the transport implemented in twisted.protocols.tls (used to provide the transport whenever you use listenSSL, connectSSL, or startTLS) does not work this way.
You should be able to work out which attribute needs to be mangled by looking at twisted/protocols/tls.py. My initial guess would be `wrappedProtocol`, but that's *only* a guess. And of course, whatever you find is not going to be part of any formal transport interface either, so it's not guaranteed to keep working in the future, or to work with any other transport you might end up using - hence the desire to resolve #3204.
You are great! ;) It is indeed "wrappedProtocol" .. and by mangling this, it now works also for TLS! Yes, I am fully aware that it's a bloody hack .. and I will change code when #3204 lands. Btw: 1) http://twistedmatrix.com/trac/ticket/4173 will need to have such a hack also. 2) Something that still bugs me: who should be responsible for calling start/stopFactory on the factory that produces the protocol that gets switched over to? I mean (in my case): I can't just derive from twisted.web.server.Site overriding start/stopFactory, since there may be multiple Resources added to Site that do switch protocol. Or should I iterate over the whole Resource tree of Site finding the protocol switching Resources and call startFactory on them? Thanks again! Tobias
participants (2)
-
exarkun@twistedmatrix.com
-
Tobias Oberstein