[Twisted-Python] getPeer() inside conch

Glyph Lefkowitz glyph at twistedmatrix.com
Tue Sep 29 22:48:54 EDT 2009


On Tue, Sep 29, 2009 at 7:16 PM, Benjamin Rutt <rutt.4 at osu.edu> wrote:

> The code:
>
>     print 'hello, peer %s' % (self.terminal.transport.getPeer())
>
> Fails with:
>
>     AttributeError: SSHSessionProcessProtocol instance has no attribute
> 'getPeer'
>

Oops.  Looks like my reading of the code was wrong.

One possible patch to twisted 8.2.0's conch/ssh/session.py's
> SSHSessionProcessProtocol class to add a getPeer() method would be:
>


> +        client = self.session.conn.transport.transport.client
> +        return address.IPv4Address('TCP', client[0], client[1])
> Could someone comment on this?  (I'm fairly certain ssh runs over TCP, but
> less certain that the mouthful self.session.conn.transport.transport.client
> isn't invading layers of abstraction in an unfriendly way).  Thanks.
>

So, nominally, all those things are public (none of them starts with an
underscore) but I'd have to sift through the code to understand exactly how
kosher they are (whether those attributes are a part of the interfaces in
question).

However, (A) 'TCP' isn't quite the right answer here, because actually
there's some SSH in the way, and (B) I am pretty sure there is a getPeer
closer than that.  In particular,

SSHSessionProcessProtocol.session is a twisted.conch.session.SSHSession
SSHSession subclasses twisted.conch.ssh.channel.SSHChannel
SSHChannel implements getPeer already.

So you *should* be able to do self.session.getPeer() and get something
useful.  I hope.

That said, the getPeer implementation in question should really be returning
an IAddress, not a tuple, so you can subclass or delegate to IPv4Address and
still access 'host' on the return value.

Independent of the grossness, if you can contribute some test coverage for
this, we could make the implementation less gross later :).  This is
especially important since hopefully many of these conch APIs will change in
the near future.  (z3p, are you planning on coming to the sprint this
week...?)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20090929/5c0bdf29/attachment.htm 


More information about the Twisted-Python mailing list