[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Support packing Netinfo cells
commit c24e22402e66b62fdb206a46ec541449b3e7cd6b
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Sat Jan 20 15:37:37 2018 -0800
Support packing Netinfo cells
Now that addresses can be packed supporting Netinfo cells is simple.
---
stem/client/cell.py | 4 ++--
test/unit/client/cell.py | 14 +++++++++-----
2 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/stem/client/cell.py b/stem/client/cell.py
index 074d2079..3a596b9c 100644
--- a/stem/client/cell.py
+++ b/stem/client/cell.py
@@ -366,11 +366,11 @@ class NetinfoCell(Cell):
payload = io.BytesIO()
payload.write(Size.LONG.pack(int(datetime_to_unix(timestamp))))
- payload.write(Address.pack(receiver_address))
+ payload.write(receiver_address.pack())
payload.write(Size.CHAR.pack(len(sender_addresses)))
for addr in sender_addresses:
- payload.write(Address.pack(addr))
+ payload.write(addr.pack())
return cls._pack(link_version, payload.getvalue())
diff --git a/test/unit/client/cell.py b/test/unit/client/cell.py
index 7f3318ee..22de54d9 100644
--- a/test/unit/client/cell.py
+++ b/test/unit/client/cell.py
@@ -33,7 +33,9 @@ VERSIONS_CELLS = {
'\x00\x00\x07\x00\x06\x00\x01\x00\x02\x00\x03': [1, 2, 3],
}
-NETINFO_CELL = '\x00\x00\x08ZZ\xb6\x90\x04\x04\x7f\x00\x00\x01\x01\x04\x04aq\x0f\x02' + ZERO * (FIXED_PAYLOAD_LEN - 17)
+NETINFO_CELLS = {
+ '\x00\x00\x08ZZ\xb6\x90\x04\x04\x7f\x00\x00\x01\x01\x04\x04aq\x0f\x02' + ZERO * (FIXED_PAYLOAD_LEN - 17): (datetime.datetime(2018, 1, 14, 1, 46, 56), Address(AddrType.IPv4, '127.0.0.1'), [Address(AddrType.IPv4, '97.113.15.2')]),
+}
VPADDING_CELLS = {
'\x00\x00\x80\x00\x00': '',
@@ -122,11 +124,13 @@ class TestCell(unittest.TestCase):
self.assertEqual(versions, Cell.unpack(cell_bytes, 2)[0].versions)
def test_netinfo_packing(self):
- cell = Cell.unpack(NETINFO_CELL, 2)[0]
+ for cell_bytes, (timestamp, receiver_address, sender_addresses) in NETINFO_CELLS.items():
+ self.assertEqual(cell_bytes, NetinfoCell.pack(2, receiver_address, sender_addresses, timestamp))
- self.assertEqual(datetime.datetime(2018, 1, 14, 1, 46, 56), cell.timestamp)
- self.assertEqual(Address(AddrType.IPv4, '127.0.0.1'), cell.receiver_address)
- self.assertEqual([Address(AddrType.IPv4, '97.113.15.2')], cell.sender_addresses)
+ cell = Cell.unpack(cell_bytes, 2)[0]
+ self.assertEqual(timestamp, cell.timestamp)
+ self.assertEqual(receiver_address, cell.receiver_address)
+ self.assertEqual(sender_addresses, cell.sender_addresses)
def test_vpadding_packing(self):
for cell_bytes, payload in VPADDING_CELLS.items():
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits