[Twisted-Python] Reporting total traffic that goes through an SSL socket

Glyph Lefkowitz glyph at twistedmatrix.com
Wed Mar 25 14:20:30 MDT 2015


> On Mar 25, 2015, at 1:35 AM, Burak Arslan <burak.arslan at arskom.com.tr> wrote:
> 
> Hello All,
> 
> I'm using twisted for implementing a custom protocol via SSL.
> 
> I've been wondering though, is there an easy way of counting the number
> of bytes that go in and out of the socket, including SSL overhead?

Well, "easy" is relative :).

Internally in Twisted, TLS is implemented as a wrapper protocol that sits on a low-level transport, and acts as a transport for your protocol, and a protocol for the TCP (or other stream-based) transport.  Older APIs like connectSSL, listenSSL, and .startTLS on a protocol somewhat obscure this, and there's no nice way to expose it.

However, there is a ticket in progress: https://twistedmatrix.com/trac/ticket/5642 <https://twistedmatrix.com/trac/ticket/5642> which has some code that demonstrates how to make the TLS stuff "purely" a wrapper all the way from the endpoint to your application code.

What you need to do is write your own wrapper protocol and interpose it below the TLS transport (act as the transport for the TLS protocol, and the protocol for the TCP transport).

If it is not obvious how to do this from the documentation for twisted.protocols.policies.ProtocolWrapper and the code in the aforementioned ticket, I (or someone else) can elaborate.

-g
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20150325/2070885d/attachment-0005.html>


More information about the Twisted-Python mailing list