Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lightnion requires python 3.6 or later #5

Open
plcp opened this issue Nov 8, 2018 · 1 comment
Open

Lightnion requires python 3.6 or later #5

plcp opened this issue Nov 8, 2018 · 1 comment

Comments

@plcp
Copy link
Collaborator

plcp commented Nov 8, 2018

We need dict to keep insertion order due to implementation details in lightnion/cell.

For example using python 3.5 we are randomly unable to validate versions cells during negotiation, failing with traces like:

Traceback (most recent call last):
  File "examples/link.py", line 13, in <module>
    link = lnn.link.initiate(sys_argv.addr, sys_argv.port)
  File "/vagrant/lightnion/link.py", line 203, in initiate
    version = negotiate_version(peer, versions, as_initiator=True)
  File "/vagrant/lightnion/link.py", line 132, in negotiate_version
    lnn.cell.versions.send(peer, lnn.cell.versions.pack(versions))
  File "/vagrant/lightnion/cell/versions.py", line 35, in pack
    length=len(versions))
  File "/vagrant/lightnion/cell/view.py", line 559, in set
    self.finalize(truncate=True)
  File "/vagrant/lightnion/cell/view.py", line 566, in finalize
    self._view, self.raw))
RuntimeError: Invalid payload for <lightnion.cell.view.fields object at 0x7f46a55b84e0> view: b'\x00\x04\x07\x00'

…or…

Traceback (most recent call last):
  File "examples/link.py", line 13, in <module>
    link = lnn.link.initiate(sys_argv.addr, sys_argv.port)
  File "/vagrant/lightnion/link.py", line 203, in initiate
    version = negotiate_version(peer, versions, as_initiator=True)
  File "/vagrant/lightnion/link.py", line 132, in negotiate_version
    lnn.cell.versions.send(peer, lnn.cell.versions.pack(versions))
  File "/vagrant/lightnion/cell/versions.py", line 35, in pack
    length=len(versions))
  File "/vagrant/lightnion/cell/view.py", line 559, in set
    self.finalize(truncate=True)
  File "/vagrant/lightnion/cell/view.py", line 566, in finalize
    self._view, self.raw))
RuntimeError: Invalid payload for <lightnion.cell.view.fields object at 0x7f7ece53f518> view: b'\x00\x04\x07'

…or…

Traceback (most recent call last):
  File "examples/link.py", line 13, in <module>
    link = lnn.link.initiate(sys_argv.addr, sys_argv.port)
  File "/vagrant/lightnion/link.py", line 203, in initiate
    version = negotiate_version(peer, versions, as_initiator=True)
  File "/vagrant/lightnion/link.py", line 132, in negotiate_version
    lnn.cell.versions.send(peer, lnn.cell.versions.pack(versions))
  File "/vagrant/lightnion/cell/versions.py", line 35, in pack
    length=len(versions))
  File "/vagrant/lightnion/cell/view.py", line 558, in set
    self.write(*kargs, **kwargs)
  File "/vagrant/lightnion/cell/view.py", line 555, in write
    self.raw = self._view.write(self.raw, value, **kwargs)
  File "/vagrant/lightnion/cell/view.py", line 626, in raw
    offset = self._parent.offset(self._field)
  File "/vagrant/lightnion/cell/view.py", line 547, in offset
    return self._view.offset(self.raw, field)
  File "/vagrant/lightnion/cell/view.py", line 303, in offset
    return super().offset(payload, field=field)
  File "/vagrant/lightnion/cell/view.py", line 191, in offset
    width = view.width(payload)
  File "/vagrant/lightnion/cell/view.py", line 406, in width
    offset = self.offset(payload, self.quantity - 1)
  File "/vagrant/lightnion/cell/view.py", line 391, in quantity
    return self.length.cache()
  File "/vagrant/lightnion/cell/common.py", line 5, in cache
    return super().cache() // 2
  File "/vagrant/lightnion/cell/view.py", line 703, in cache
    + 'Have you called .value() of parent view yet?')
RuntimeError: Bounded value unknown at runtime: Have you called .value() of parent view yet?

…or even sending invalid versions cells to the OR and then silently hanging:

send b'\x00\x04\x00\x00\x07\x00\x04\x00\x05'
^CTraceback (most recent call last):
  File "examples/link.py", line 13, in <module>
    link = lnn.link.initiate(sys_argv.addr, sys_argv.port)
  File "/vagrant/lightnion/link.py", line 203, in initiate
    version = negotiate_version(peer, versions, as_initiator=True)
  File "/vagrant/lightnion/link.py", line 134, in negotiate_version
    vercell = lnn.cell.versions.recv(peer)
  File "/vagrant/lightnion/cell/versions.py", line 41, in recv
    answer = peer.recv(_cell.header_legacy_view.width())
  File "/usr/lib/python3.5/ssl.py", line 922, in recv
    return self.read(buflen)
  File "/usr/lib/python3.5/ssl.py", line 799, in read
    return self._sslobj.read(len, buffer)
  File "/usr/lib/python3.5/ssl.py", line 585, in read
    v = self._sslobj.read(len)
KeyboardInterrupt

Having ordered dictionaries in python is only guaranteed since python 3.7 and thus makes us rely on a pretty recent guarantee of the python language.

We still have a lot of python 3.4 and python 3.5 out there where lightnion breaks badly, either making the python 3.6+ requirement explicit or supporting python3.4+ can be a good thing.

@plcp
Copy link
Collaborator Author

plcp commented Nov 27, 2018

Started a rewrite of cell/view.py with proper semantics, testing, coverage and support for python3.4 and later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant