Twisted - extending portforward (simple example)

Lee Harr missive at frontiernet.net
Sat Jun 28 11:14:35 EDT 2003


In article <mailman.1056770626.1534.python-list at python.org>, Andrew Bennetts:
> On Fri, Jun 27, 2003 at 03:42:20AM -0700, Paul Moore wrote:
>> I hit a problem yesterday with my mail connection. In a desparate
>> attempt to understand what was going on, I wanted to log the
>> connection traffic. After a bit of searching, I found a post on c.l.p
>> from Andrew Bennetts explaining how to run a port forwarder in 2 lines
>> using Twisted.
>> 
>>     $ mktap portforward -p 8000 -h remote -d 20
>>     $ twistd -f portforward.tap
>> 
>> This looked brilliant - all I needed to do was add logging. A quick
>> look (I was *very* short of time, so I couldn't spend long) showed me
>> no obvious way of adding a hook (at least, not one which wouldn't turn
>> the above 2-liner into something more complex, that I didn't have time
>> to work out...) So I gave in, and just added a print statement in the
>> twisted code.
>> 
>> This gave me the results I wanted, but left me wondering (and not
>> getting far in finding out!) how I *should* have done this.
>> 
>> Ideally, I was expecting to be able to write a small .py file,
>> importing and minimally overriding portforward.py, and then be able to
>> do the mktap/twistd thing. But I couldn't see how.
> 
> The easiest way is probably to do this:
> 
> --- loggingpf.py ---

> 
> Unfortunately, it's not very simple, as you can see -- although you only
> need to override two methods (ProxyClient.dataReceived and
> ProxyServer.dataReceived), you need to make four subclasses to tie it all
> together.
> 


I was thinking about this too, and I was wondering if it might be good to
add a "verbosity" switch to either mktap or twistd, along the lines of
what netcat or ssh does.  (ie, include 2 or 3 -v switches for additional
verbosity).  It seems like it would definitely be helpful in certain 
situations.





More information about the Python-list mailing list