<div class="gmail_quote">On Tue, Sep 29, 2009 at 7:16 PM, Benjamin Rutt <span dir="ltr">&lt;<a href="mailto:rutt.4@osu.edu">rutt.4@osu.edu</a>&gt;</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 &#39;hello, peer %s&#39; % (self.terminal.transport.getPeer())</div><div><br></div><div>Fails with:</div><div><br></div><div>    AttributeError: SSHSessionProcessProtocol instance has no attribute &#39;getPeer&#39;</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&#39;s conch/ssh/session.py&#39;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(&#39;TCP&#39;, client[0], client[1]) </div><div>Could someone comment on this?  (I&#39;m fairly certain ssh runs over TCP, but less certain that the mouthful self.session.conn.transport.transport.client isn&#39;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&#39;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) &#39;TCP&#39; isn&#39;t quite the right answer here, because actually there&#39;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 &#39;host&#39; 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>