eudemonia-research / spore

Spore is a simple peer-to-peer library for Python.
6 stars 5 forks source link

Spore doesn't check if a port is passed in as int #10

Open XertroV opened 10 years ago

XertroV commented 10 years ago
xertrov@X-LittleLap:~/src/cryptonet$ python3 examples/grachten.py -addnode 127.0.0.1:32555 -port 32556
set_handlers
chain: new head 0, hash: 00db713a2a561c76caaca9974d87b3b0880e748447ff078dd82e03a94b52f29c
added block 0, hash: 00db713a2a561c76caaca9974d87b3b0880e748447ff078dd82e03a94b52f29c
chain: restarting miner
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/spore/__init__.py", line 60, in _try_except
    callback(self, *args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/spore/__init__.py", line 107, in share_info
    info.port = self._address[1]
  File "/usr/local/lib/python3.4/dist-packages/encodium/__init__.py", line 89, in __setattr__
    field.check_type(value)
  File "/usr/local/lib/python3.4/dist-packages/encodium/__init__.py", line 136, in check_type
    raise ValidationError("is of type " + instance_type + ", expected " + expected_type)
encodium.ValidationError: port is of type list, expected int
on_connect_handler
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/spore/__init__.py", line 60, in _try_except
    callback(self, *args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/spore/__init__.py", line 101, in info
    peer.send('peer', Peer.make(ip=socket.inet_aton(address[0]), port=address[1]))
  File "/usr/local/lib/python3.4/dist-packages/encodium/__init__.py", line 196, in make
    return cls().make(*args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/encodium/__init__.py", line 106, in make
    ret = self.type(*args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/encodium/__init__.py", line 52, in __init__
    setattr(inner_self, key, value)
  File "/usr/local/lib/python3.4/dist-packages/encodium/__init__.py", line 89, in __setattr__
    field.check_type(value)
  File "/usr/local/lib/python3.4/dist-packages/encodium/__init__.py", line 136, in check_type
    raise ValidationError("is of type " + instance_type + ", expected " + expected_type)
encodium.ValidationError: port is of type str, expected int
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/spore/__init__.py", line 60, in _try_except
    callback(self, *args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/spore/__init__.py", line 107, in share_info
    info.port = self._address[1]
  File "/usr/local/lib/python3.4/dist-packages/encodium/__init__.py", line 89, in __setattr__
    field.check_type(value)
  File "/usr/local/lib/python3.4/dist-packages/encodium/__init__.py", line 136, in check_type
    raise ValidationError("is of type " + instance_type + ", expected " + expected_type)
encodium.ValidationError: port is of type list, expected int
on_connect_handler
intro_handler
MSG intro : 22b4d0a6159abb3ff25cee4d28640fe1c962bdef2e5bf31b63fa1f6da508b422
introhand 1629685583822781141942776544559185852632203993122318740065436872644545712
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/spore/__init__.py", line 60, in _try_except
    callback(self, *args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/spore/__init__.py", line 101, in info
    peer.send('peer', Peer.make(ip=socket.inet_aton(address[0]), port=address[1]))
  File "/usr/local/lib/python3.4/dist-packages/encodium/__init__.py", line 196, in make
    return cls().make(*args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/encodium/__init__.py", line 106, in make
    ret = self.type(*args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/encodium/__init__.py", line 52, in __init__
    setattr(inner_self, key, value)
  File "/usr/local/lib/python3.4/dist-packages/encodium/__init__.py", line 89, in __setattr__
    field.check_type(value)
  File "/usr/local/lib/python3.4/dist-packages/encodium/__init__.py", line 136, in check_type
    raise ValidationError("is of type " + instance_type + ", expected " + expected_type)
encodium.ValidationError: port is of type str, expected int
intro_handler
MSG intro : 22b4d0a6159abb3ff25cee4d28640fe1c962bdef2e5bf31b63fa1f6da508b422
introhand 1629685583822781141942776544559185852632203993122318740065436872644545712

examples/grachten.py continues as normal from thereafter (mostly)

ktofu commented 10 years ago

I've taken out the catch-all try except stuff. I don't think this is a bug, but we should definitely add a debug mode with type checking at some point (we don't want this all the time, as it is unnecessary overhead).

This page shows how it might be done: http://code.activestate.com/recipes/578528-type-checking-using-python-3x-annotations/

XertroV commented 10 years ago

Yeah that's a good point. If there's an easy way to add a debug=True arg that'd be good for v0,2 (presuming we'll have the alphanet with V0.1 approx) On Jun 19, 2014 9:55 AM, "Kitten Tofu" notifications@github.com wrote:

I've taken out the catch-all try except stuff. I don't think this is a bug, but we should definitely add a debug mode with type checking at some point (we don't want this all the time, as it is unnecessary overhead).

This page shows how it might be done: http://code.activestate.com/recipes/578528-type-checking-using-python-3x-annotations/

— Reply to this email directly or view it on GitHub https://github.com/eudemonia-research/spore/issues/10#issuecomment-46509219 .