[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] VersionCell.pack function



commit cf78cc48f811a3f0af1a7904ff7d78d5b20ad1ec
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Mon Jan 8 02:27:51 2018 -0800

    VersionCell.pack function
    
    Think I'll model these similar to stem responses, with a pack/unpack method for
    each cell type.
---
 stem/client.py | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/stem/client.py b/stem/client.py
index 2a598747..a0288f52 100644
--- a/stem/client.py
+++ b/stem/client.py
@@ -133,23 +133,33 @@ class Cell(collections.namedtuple('Cell', ['name', 'value', 'fixed_size', 'for_c
     return cell
 
 
-class Relay(object):
+class VersionCell(Cell):
   """
-  Connection with a `Tor relay's ORPort
-  <https://gitweb.torproject.org/torspec.git/tree/tor-spec.txt>`_.
+  Link version negotiation cell.
   """
 
+  @staticmethod
+  def pack(versions):
+    """
+    Provides the payload for a series of link versions.
 
-def serialize_versions(versions):
-  """
-  Provides the payload for a series of link versions.
+    :param list versions: link versions to serialize
 
-  :param list versions: link versions to serialize
+    :returns: **bytes** with a payload for these versions
+    """
 
-  :returns: **bytes** with a payload for these versions
-  """
+    # Used for link version negotiation so we don't have that yet. This is fine
+    # since VERSION cells avoid most version dependent attributes.
 
-  return b''.join([struct.pack(Pack.SHORT, v) for v in versions])
+    payload = b''.join([struct.pack(Pack.SHORT, v) for v in versions])
+    return Cell.pack('VERSIONS', 3, payload)
+
+
+class Relay(object):
+  """
+  Connection with a `Tor relay's ORPort
+  <https://gitweb.torproject.org/torspec.git/tree/tor-spec.txt>`_.
+  """
 
 
 Pack = enum.Enum(



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits