[Twisted-Python] Twisted Conch - Flow control

Itamar Turner-Trauring itamar at futurefoundries.com
Wed Nov 7 07:30:49 EST 2012

On Tue, Nov 6, 2012 at 10:49 PM, Matt Freeman <matt at nonuby.com> wrote:

> I asked this question on  Stackoverflow (even offered a bounty) and IRC:
> http://stackoverflow.com/questions/13117502/twisted-conch-flow-control
> --
> I have a Twisted Conch SSH server and the typical scenario is this:
> git via OpenSSH client >>--- WAN1 --->> Twisted conch svr >>--- WAN2 -->>
> Git server
> There will be occassions that the 'git push' is sending data faster over
> WAN1 than I can proxy it over WAN2, so I need to tell the client to slow
> down (well before any TCP packet loss causes adjustments the TCP window
> size) to avoid buffering too much on the Twisted server. Reading the RFC
> for SSH this is accomplished with not acknowledging via adj window this
> will then cause the git push to block on syscall write to the pipe backed
> by openssh.
> Looking at conch/ssh/connection.py:L216 in the method def
> ssh_CHANNEL_DATA(self, packet): I can accomplish this with setting
> localWindowSize to 0, and inflight data will still land as the predicate on
> 230 should still pass (give localWindowLeft). I am wondering if this is the
> correct approach or am I missing something blindly obvious with regards to
> flow control with Twisted SSH Conch? *
> Note: I acknowledge there are methods placeholders for stopWriting and
> startWriting on (channel) that I can override so I have hooks to control
> the other side of the transmission 'git pull', but Im interested in first
> leg. Also IPush/IPull producer dont seem applicable at this level and I
> cant see how I can tie in these higher abstraction without butchering conch?
The general non-SSH specific answer is to use the producer API. Something

    wan2transport.registerProducer(wan1transport, True)

Assuming WAN2 is also over SSH (it wasn't quite clear), SSHChannel ideally
should implement the producer and consumer APIs so you could do:

    wan2channel.registerProducer(wan1channel, True)

But, as you say, it doesn't implement those APIs. Thus it looks like you'd
want to subclass SSHChannel, and have wan2's SSHChannel.stop/startWriting
call pause/resumeProducing on the WAN1 channel's *transport*
(SSHConnection). Unless you have multiple channels in your incoming SSH
connection that you want to pause/resume separately, and it doesn't sound
like you do, this should work.

twisted.conch.scripts.conch.SSHSession has an example of this, more or
less, except that it's pausing reading from stdin rather than another SSH

Itamar Turner-Trauring, Future Foundries LLC
http://futurefoundries.com/ — Twisted consulting, training and support.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20121107/55506829/attachment.htm 

More information about the Twisted-Python mailing list