This is a nice standalone piece of code which doesn't really have to appear in the middle of ssh2transport.