[tor-bugs] #23966 [Core Tor/Tor]: Refactor node_has_curve25519_onion_key() to use node_get_curve25519_onion_key()

Tor Bug Tracker & Wiki blackhole at torproject.org
Tue Dec 12 00:55:39 UTC 2017


#23966: Refactor node_has_curve25519_onion_key() to use
node_get_curve25519_onion_key()
----------------------------+------------------------------------
 Reporter:  teor            |          Owner:  (none)
     Type:  defect          |         Status:  needs_revision
 Priority:  Medium          |      Milestone:  Tor: 0.3.3.x-final
Component:  Core Tor/Tor    |        Version:
 Severity:  Normal          |     Resolution:
 Keywords:  easy, refactor  |  Actual Points:
Parent ID:                  |         Points:  0.2
 Reviewer:                  |        Sponsor:
----------------------------+------------------------------------
Changes (by teor):

 * status:  new => needs_revision


Comment:

 That's not quite what we wanted - we want node_has_curve25519_onion_key()
 to become a very simple function.

 I'll walk you through the process.

 We start with two functions that look like this:
 {{{
 /** Return true iff <b>node</b> has a curve25519 onion key. */
 int
 node_has_curve25519_onion_key(const node_t *node)
 {
   if (!node)
     return 0;

   if (node->ri)
     return routerinfo_has_curve25519_onion_key(node->ri);
   else if (node->md)
     return microdesc_has_curve25519_onion_key(node->md);
   else
     return 0;
 }

 /** Return the curve25519 key of <b>node</b>, or NULL if none. */
 const curve25519_public_key_t *
 node_get_curve25519_onion_key(const node_t *node)
 {
   if (node->ri)
     return node->ri->onion_curve25519_pkey;
   else if (node->md)
     return node->md->onion_curve25519_pkey;
   else
     return NULL;
 }
 }}}

 And we want to end up with node_has_curve25519_onion_key() calling
 node_get_curve25519_onion_key(), and checking if the result is NULL:
 {{{
 /** Return true iff <b>node</b> has a curve25519 onion key. */
 int
 node_has_curve25519_onion_key(const node_t *node)
 {
   if (!node)
     return 0;

   if (node->ri)
     return routerinfo_has_curve25519_onion_key(node->ri);
   else if (node->md)
     return microdesc_has_curve25519_onion_key(node->md);
   else
     return 0;
 }

 /** Return the curve25519 key of <b>node</b>, or NULL if none. */
 const curve25519_public_key_t *
 node_get_curve25519_onion_key(const node_t *node)
 {
   if (!node)
     return 0;

   if (routerinfo_has_curve25519_onion_key(node->ri))
     return node->ri->onion_curve25519_pkey;
   else if (microdesc_has_curve25519_onion_key(node->md))
     return node->md->onion_curve25519_pkey;
   else
     return NULL;
 }
 }}}

 Can you test that the code works (we use the "make check" command) and
 then turn it into a patch?

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


More information about the tor-bugs mailing list