[Twisted-Python] Conch - Why does one piece of code "fail" while another works
I have two pieces of code (see: https://gist.github.com/dstufft/9dc9978dc0af77e82f0c) one "works" (in that it fails verifying the host key like i'd expect) and one doesn't ("it never tries to verify the host key and just exists immediately). I don't understand *why* though, why does the connectionReady dance make it work? ----------------- Donald Stufft PGP: 0x6E3CBCE93372DCFA // 7C6B 7C5D 5E2B 6356 A926 F04F 6E3C BCE9 3372 DCFA
On 01:21 am, donald@stufft.io wrote:
I have two pieces of code (see: https://gist.github.com/dstufft/9dc9978dc0af77e82f0c) one "works" (in that it fails verifying the host key like i'd expect) and one doesn't ("it never tries to verify the host key and just exists immediately).
I don't understand *why* though, why does the connectionReady dance make it work?
Where's the second piece of code? Jean-Paul
On Oct 2, 2013, at 9:20 AM, exarkun@twistedmatrix.com wrote:
On 01:21 am, donald@stufft.io wrote:
I have two pieces of code (see: https://gist.github.com/dstufft/9dc9978dc0af77e82f0c) one "works" (in that it fails verifying the host key like i'd expect) and one doesn't ("it never tries to verify the host key and just exists immediately).
I don't understand *why* though, why does the connectionReady dance make it work?
Where's the second piece of code?
Jean-Paul
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
Both are in the gist, works.py and fails.py ----------------- Donald Stufft PGP: 0x6E3CBCE93372DCFA // 7C6B 7C5D 5E2B 6356 A926 F04F 6E3C BCE9 3372 DCFA
On 01:31 pm, donald@stufft.io wrote:
On Oct 2, 2013, at 9:20 AM, exarkun@twistedmatrix.com wrote:
On 01:21 am, donald@stufft.io wrote:
I have two pieces of code (see: https://gist.github.com/dstufft/9dc9978dc0af77e82f0c) one "works" (in that it fails verifying the host key like i'd expect) and one doesn't ("it never tries to verify the host key and just exists immediately).
I don't understand *why* though, why does the connectionReady dance make it work?
Where's the second piece of code?
Jean-Paul
Both are in the gist, works.py and fails.py
Oops, sorry. The second one disappeared when I clicked the "raw" link I guess. In the first version, you `react` until `connectProtocol`'s Deferred fires. That's immediately upon the TCP connection setup success - before any appreciable SSH happens. In the second version, you `react` indefinitely (because `connectionReady` never fires) giving SSH ample time to handshake. BTW, I'm not sure what you plan to do with this connection, but if you haven't seen `twisted.conch.endpoints` (and <https://tm.tl/6617>) then you probably want to look. Jean-Paul
On Oct 2, 2013, at 10:00 AM, exarkun@twistedmatrix.com wrote:
On 01:31 pm, donald@stufft.io wrote:
On Oct 2, 2013, at 9:20 AM, exarkun@twistedmatrix.com wrote:
On 01:21 am, donald@stufft.io wrote:
I have two pieces of code (see: https://gist.github.com/dstufft/9dc9978dc0af77e82f0c) one "works" (in that it fails verifying the host key like i'd expect) and one doesn't ("it never tries to verify the host key and just exists immediately).
I don't understand *why* though, why does the connectionReady dance make it work?
Where's the second piece of code?
Jean-Paul
Both are in the gist, works.py and fails.py
Oops, sorry. The second one disappeared when I clicked the "raw" link I guess.
In the first version, you `react` until `connectProtocol`'s Deferred fires. That's immediately upon the TCP connection setup success - before any appreciable SSH happens.
In the second version, you `react` indefinitely (because `connectionReady` never fires) giving SSH ample time to handshake.
ah ha, So for a real workload instead of a connectionReady you'd probably addCallback a deferred that waits for the SSH to connect and does the work.
BTW, I'm not sure what you plan to do with this connection, but if you haven't seen `twisted.conch.endpoints` (and <https://tm.tl/6617>) then you probably want to look.
I've seen the endpoints (and even have a version of this working with it). Essentially what i'm trying to do is connect to up to ~200 some SSH hosts and run a bunch of commands on them (and possibly do things like download files). I have this somewhat working with the command endpoint but the snag in that plan is I don't always have direct access to these servers so I need to "gateway" through another SSH host. I tried to get this working with the command endpoint but I ended up very confused about how the entire thing worked (and I was never able to get the gatewaying working). After some frustration in #twisted I decided to start over and try to grok all the code (and the underlying stuff as well) before just copy/pasting stuff from the examples. Which is where I'm at now.
Jean-Paul
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
----------------- Donald Stufft PGP: 0x6E3CBCE93372DCFA // 7C6B 7C5D 5E2B 6356 A926 F04F 6E3C BCE9 3372 DCFA
On 02/10/13 15:00, exarkun@twistedmatrix.com wrote:
BTW, I'm not sure what you plan to do with this connection, but if you haven't seen `twisted.conch.endpoints` (and <https://tm.tl/6617>) then you probably want to look.
ZOMG I had not seen the (existing) Conch endpoints before. Amazing, and many thanks to whoever did this work.
participants (4)
-
Donald Stufft
-
exarkun@twistedmatrix.com
-
Laurens Van Houtven
-
Phil Mayers