[tor-bugs] #6234 [Stem]: stem.socket.ControlSocket.is_alive() should check if socket is open explicitly

Tor Bug Tracker & Wiki torproject-admin at torproject.org
Sat Jul 14 17:42:20 UTC 2012


#6234: stem.socket.ControlSocket.is_alive() should check if socket is open
explicitly
------------------------+---------------------------------------------------
    Reporter:  gsathya  |       Owner:  atagar        
        Type:  defect   |      Status:  needs_revision
    Priority:  normal   |   Milestone:                
   Component:  Stem     |     Version:                
  Resolution:           |    Keywords:                
      Parent:           |      Points:                
Actualpoints:           |  
------------------------+---------------------------------------------------
Changes (by atagar):

  * status:  needs_review => needs_revision


Comment:

 > self.msg("QUIT")

 We should check the QUIT's reply. You'll want to use Ravi's SingleLine
 response parser...

 {{{
 response = self.msg("QUIT")
 stem.response.convert("SINGLELINE", response)

 if response.is_ok():
   self.close()
 else:
   raise stem.socket.ProtocolError("The QUIT provided a non-ok response:
 %s" % response)
 }}}

 > +    with runner.get_tor_controller(False) as controller:
 > +      controller.quit()
 > +      self.assertEqual(controller._socket.is_alive(), False)
 > +      self.assertRaises(stem.socket.SocketClosed,
 controller.authenticate(test.runner.CONTROL_PASSWORD))

 Lets test with both an authenticated an unauthenticated controller.
 Amusingly this test would also work if you called
 'controller.msg("GOBBDLYGOOK")' followed by a sleep since unauthenticated
 sockets will disconnect us anyway.

 Also, please use get_socket() rather than accessing the _socket member
 directly and go back to using controller.protocolinfo() rather than
 authenticate (does the same thing and it's less verbose).

 Otherwise looks good!

 ========================================

 Slightly weird idea, but instead of adding a quit() method what about
 adding a best-effort msg("QUIT") call to our close() method instead? Both
 quit() and close() do largely the same thing, and users don't really care
 if the QUIT call succeeds or not as long as the socket is closed (we can
 add a flag if that isn't the case).

-- 
Ticket URL: <https://trac.torproject.org/projects/tor/ticket/6234#comment:16>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online


More information about the tor-bugs mailing list