meejah / txtorcon

Twisted-based asynchronous Tor control protocol implementation. Includes unit-tests, examples, state-tracking code and configuration abstraction.
http://fjblvrw2jrxnhtg67qpbzi45r7ofojaoo3orzykesly2j3c2m3htapid.onion/
MIT License
250 stars 72 forks source link

Parse desc/name and desc/id responses into Stem's RelayDescriptor class #121

Closed sambuddhabasu closed 9 years ago

sambuddhabasu commented 9 years ago

Implemented _get_descriptor() method The parameters for the method are, nickname, fingerprint. These are the relay's nickname/fingerprint for which we want the descriptor information. Returns the descriptor information. If use_stem is set to True, a stem.descriptor.server_descriptor.RelayDescriptor object is returned with the descriptor information.

sambuddhabasu commented 9 years ago

@meejah Let me know if the method looks fine. If everything looks good then, I will go ahead and add tests for the method.

meejah commented 9 years ago

To work with the rest of the magic accessors of TorInfo, you'll need to arrange for this method to be called when accessing desc.name.<descriptor name> or desc.id.<descriptor fingerprint> -- once TorInfo is setup it hides all members except via the dotted-names things.

So -- you should be able to access descriptors with TorInfo right now on master without any changes...you'll just want to intercept those accesses in case use_stem is True in the underlying protocol and return Stem objects instead.

sambuddhabasu commented 9 years ago

@meejah I do not understand the MagicContainer class completely and hence I am having trouble converting the _get_descriptor() method into something like, desc.name.<descriptor name> as you mentioned in the above comment. Can you shed more light on the conversion to dotted object please?

meejah commented 9 years ago

Well, the above dotted-stuff should work right now I believe; basically the magic-container is translating those into "GETINFO desc/name/" if the info/names ended with a * or simply into "GETINFO foo/bar" (from foo.bar) if the meta-information about that key did not end with a *.

So essentially during setup you'll have to figure out if usestem is set, and if so intercept the setup of certain keys and replace with a suitable other method (so you'd be intercepting "desc/name/" and "desc/id/_" or so).

sambuddhabasu commented 9 years ago

@meejah I have added a new commit, https://github.com/meejah/txtorcon/commit/de88b1614ec842e3704924c4254d99aa47bf40b8 In this commit, I have added a new _get_descriptor method which is called when the use_stem flag is set to True and the desc.name() or desc.id() is called. Let me know if this is what is required, then, I will add appropriate comments for the method, tests for the method and squash all the commits into one.

sambuddhabasu commented 9 years ago

@meejah Added test for the _parse_stem_descriptor method. If the code looks good, I will squash all the commits into one. Thanks

meejah commented 9 years ago

yes, looks great!

...and yes please squash (and just change the commit-comment to a description of the whole change instead of leaving the individual commit-comments).

sambuddhabasu commented 9 years ago

@meejah Made the required changes. This PR can be merged now. Thanks

meejah commented 9 years ago

looks great, thanks for the patch :)