<div class="gmail_quote">On Tue, Sep 29, 2009 at 7:16 PM, Benjamin Rutt <span dir="ltr"><<a href="mailto:rutt.4@osu.edu">rutt.4@osu.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>The code:</div><div><br></div><div> print 'hello, peer %s' % (self.terminal.transport.getPeer())</div><div><br></div><div>Fails with:</div><div><br></div><div> AttributeError: SSHSessionProcessProtocol instance has no attribute 'getPeer'</div>
</blockquote><div><br>Oops. Looks like my reading of the code was wrong.<br><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div>
</div><div>One possible patch to twisted 8.2.0's conch/ssh/session.py's SSHSessionProcessProtocol class to add a getPeer() method would be:</div></blockquote><div> <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>+ client = self.session.conn.transport.transport.client </div>
<div>+ return address.IPv4Address('TCP', client[0], client[1]) </div><div>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.</div>
</blockquote><div><br>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).<br>
<br>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,<br><br>SSHSessionProcessProtocol.session is a twisted.conch.session.SSHSession<br>
SSHSession subclasses twisted.conch.ssh.channel.SSHChannel<br>SSHChannel implements getPeer already.<br><br>So you <i>should</i> be able to do self.session.getPeer() and get something useful. I hope.<br><br>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.<br>
<br>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...?)<br>
<br></div></div>