[tor-commits] [stem/master] Use minimum valid circuit id by default for CREATE_FAST

atagar at torproject.org atagar at torproject.org
Wed Feb 7 19:44:51 UTC 2018

commit 6a4f46614043e8423c8a45a203acf6ffcf736952
Author: Damian Johnson <atagar at torproject.org>
Date:   Fri Jan 26 12:23:19 2018 -0800

    Use minimum valid circuit id by default for CREATE_FAST
    To work a CREATE_FAST cell must specify a circuit id. Endosome picks one based
    on the link version with a similar comment to the one we're including here.
    Endosome also has an 'is_initiator' flag which I'm omitting right now since I
    suspect that's only relevant if we attempt to implement *being* a relay which
    isn't in the cards right now.
 stem/client/cell.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/stem/client/cell.py b/stem/client/cell.py
index a0737765..4062edcf 100644
--- a/stem/client/cell.py
+++ b/stem/client/cell.py
@@ -394,7 +394,7 @@ class CreateFastCell(CircuitCell):
     self.key_material = key_material
-  def pack(cls, link_version, circ_id, key_material = None):
+  def pack(cls, link_version, circ_id = None, key_material = None):
     Provides a randomized circuit construction payload.
@@ -405,6 +405,12 @@ class CreateFastCell(CircuitCell):
     :returns: **bytes** with our randomized key material
+    if circ_id is None:
+      # When initiating a circuit the v4 link protocol requires us to set the
+      # most significant bit. Otherwise any id will do.
+      circ_id = 0x80000000 if link_version >= 4 else 0x01
     if key_material and len(key_material) != HASH_LEN:
       raise ValueError('Key material should be %i bytes, but was %i' % (HASH_LEN, len(key_material)))

More information about the tor-commits mailing list