[tor-bugs] #22755 [Obfuscation/BridgeDB]: Use stem to create test descriptors

Tor Bug Tracker & Wiki blackhole at torproject.org
Fri Jul 7 04:39:33 UTC 2017


#22755: Use stem to create test descriptors
-------------------------------------------------+-------------------------
 Reporter:  atagar                               |          Owner:  isis
     Type:  enhancement                          |         Status:
                                                 |  needs_revision
 Priority:  Low                                  |      Milestone:
Component:  Obfuscation/BridgeDB                 |        Version:
 Severity:  Minor                                |     Resolution:
 Keywords:  python, stem, bridgedb-parsers,      |  Actual Points:
  bridgedb-ci                                    |
Parent ID:                                       |         Points:
 Reviewer:                                       |        Sponsor:
-------------------------------------------------+-------------------------

Comment (by atagar):

 Great, thanks Isis!

 > Is there a way to make the descriptors less sparse?

 Certainly, no problem. When not provided with any data stem creates a
 minimal valid descriptor. If you'd care to provide extra fields then
 simply specify them. This goes for extrainfo descriptors, extra-info-
 digest, and transport lines too.

 {{{
 desc = RelayDescriptor.create({
   'router': 'caerSidi 71.35.133.197 9001 0 0',
   'published': '2012-02-29 04:03:19',
   'fingerprint': '4F0C 867D F0EF 6816 0568 C826 838F 482C EA7C FE44',
   'or-address': ['71.35.133.197:9001', '[12ab:2e19:3bcf::02:9970]:9001'],
   'onion-key': '\n-----BEGIN RSA PUBLIC KEY-----%s-----END RSA PUBLIC
 KEY-----' % stem.descriptor.CRYPTO_BLOB,
   'signing-key': '\n-----BEGIN RSA PUBLIC KEY-----%s-----END RSA PUBLIC
 KEY-----' % stem.descriptor.CRYPTO_BLOB,
 })
 }}}

 Internally I use the following five helper methods to concoct random
 descriptor data. Would you find it helpful for them to be public?

 https://gitweb.torproject.org/stem.git/tree/stem/descriptor/__init__.py#n1044

 > Something is writing all the server and extrainfo descriptors to disk in
 separate files...

 Yup, just drop the following couple lines...

 {{{
 write_descriptor(server_desc, 'server_descriptor_%i' % i)
 write_descriptor(extrainfo_desc, 'extrainfo_descriptor_%i' % i)
 }}}

 Took a peek over your revisions and looks good, though a couple more quick
 thoughts...

 > -OUTPUT_DIR = os.path.join(os.getcwd(), 'test_descriptors')
 > +OUTPUT_DIR = os.path.join(os.getcwd())

 With this change the os.path.join() no longer does anything. Actually, if
 I was in your shoes I'd simply drop this constant and replace the spots
 that use OUTPUT_DIR with os.getcwd().

 > + descriptor_file.flush()

 You should be able to drop this line. As the last line in the 'with' block
 this is immediately followed by close() which will flush the content.

 If you have any questions or need an example of anything don't heasitate
 to let me know!

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


More information about the tor-bugs mailing list