javipalanca / spade

Smart Python Agent Development Environment
MIT License
253 stars 98 forks source link

SPADE 3.0.1 "Fatal error on tls handshake" with DummyAgent #42

Closed L-Piao closed 5 years ago

L-Piao commented 6 years ago

Description

Firstly, thanks for releasing SPADE 3.0.1! Congratulations! I have been playing with the develop version (3.0.0) and was very excited to test the stable version. I did encounter a problem with the basic example DummyAgent.py as follows:

import spade.agent

class DummyAgent(spade.agent.Agent):
    def setup(self):
        print("Hello World! I'm agent {}".format(str(self.jid)))

dummy = DummyAgent("agentA@xmpp.jp", "password")

dummy.start()
dummy.stop()

What I Did

I ran this simple code on Win10/PowerShell, and on Mac/Terminal, but I got almost the same error on different platforms. It was not this case with SPADE 3.0.0.

Windows PowerShell
Copyright (C) 2016 Microsoft Corporation. All rights reserved.

PS My_location\SPADE_behavior> python dummyAgent.py
Fatal error on tls handshake
protocol: <aioxmpp.protocol.XMLStream object at 0x05171230>
transport: <aioopenssl.STARTTLSTransport object at 0x05171570>
Traceback (most recent call last):
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\aioopenssl-0.4.0-py3.6.egg\aioopenssl\__init__.py", line 33
1, in _tls_do_handshake
    self._tls_conn.do_handshake()
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\pyopenssl-18.0.0-py3.6.egg\OpenSSL\SSL.py", line 1907, in d
o_handshake
    self._raise_ssl_error(self._ssl, result)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\pyopenssl-18.0.0-py3.6.egg\OpenSSL\SSL.py", line 1639, in _
raise_ssl_error
    _raise_current_error()
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\pyopenssl-18.0.0-py3.6.egg\OpenSSL\_util.py", line 54, in e
xception_from_error_queue
    raise exception_type(errors)
OpenSSL.SSL.Error: [('SSL routines', 'ssl3_get_record', 'wrong version number')]
Exception in callback None()
handle: <Handle cancelled>
Traceback (most recent call last):
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\aioopenssl-0.4.0-py3.6.egg\aioopenssl\__init__.py", line 33
1, in _tls_do_handshake
    self._tls_conn.do_handshake()
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\pyopenssl-18.0.0-py3.6.egg\OpenSSL\SSL.py", line 1907, in d
o_handshake
    self._raise_ssl_error(self._ssl, result)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\pyopenssl-18.0.0-py3.6.egg\OpenSSL\SSL.py", line 1639, in _
raise_ssl_error
    _raise_current_error()
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\pyopenssl-18.0.0-py3.6.egg\OpenSSL\_util.py", line 54, in e
xception_from_error_queue
    raise exception_type(errors)
OpenSSL.SSL.Error: [('SSL routines', 'ssl3_get_record', 'wrong version number')]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Python36-32\lib\asyncio\events.py", line 145, in _run
    self._callback(*self._args)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\aioopenssl-0.4.0-py3.6.egg\aioopenssl\__init__.py", line 34
6, in _tls_do_handshake
    self._waiter.set_exception(exc)
asyncio.base_futures.InvalidStateError: invalid state
connection failed: _force_close() called
Hello World! I'm agent My_Agent@xmpp.jp
Future exception was never retrieved
future: <Future finished exception=ConnectionError('stream shut down',)>
ConnectionError: stream shut down

And strange is that if I run the same code again, the error simply disappears:

PS My_location\SPADE_behavior> python dummyAgent.py
Hello World! I'm agent My_Agent@xmpp.jp

Has anyone experienced a similar issue? Thanks for any hints!

Best regards, Piao

L-Piao commented 6 years ago

Along with this I have 4 minor questions about SPADE in general:

  1. What’s the difference between agent.stop() and agent.kill()?

The former calls the latter and sleeps every 0.1 second, but generally creates an error like "Could not disconnect from server: ."

  1. Do I have to use different JIDs for all my agents during a simulation?

What if I need hundreds of agents running together: could I run agents locally rather than on xmpp.jp, etc. (instead of AgentA (“A1@xmpp.jp”, ”password”), …, AgentX(“A100@xmpp.jp”, ”password”)?

  1. Is there any GUI for the SPADE agent management system, or are you planning to work on this? Which tools/packages are helpful in building a GUI (like the ones in JADE)?

  2. And most importantly, where could we get the answers for above questions? I haven’t found a detailed manual for the agent classes, behavior, and methods mentioned in SPADE.

Self-answered: Thanks and I've seen the API for SPADE: http://spade.gti-ia.dsic.upv.es/api/html/index.html

Again, thank you soooo much for releasing SPADE 3.0.1!

Best regards, Piao

javipalanca commented 6 years ago

Hi @L-Piao I'll try to answer all your questions.

Regarding your first issue with the connection, it is an SSL issue and I've asked the main developer of aioxmpp to try to understand what is happening. It looks that the server is trying to multiplex STARTTLS-based XMPP and XMPP-over-TLS on the same port, and that is probably why it fails sometimes. At this moment by best advice would be to use another server (you can even install your own server, I recommend prosody.im) or to talk to the xmpp.jp administrators to fix that issue.

  1. .stop() stops the agent and all its behaviours. .kill() is not available for agent, it is for behaviors and it stops such behavior.

  2. If you don't use different JIDs you may have a mess when sending messages (every agent would receive every sent message). However there is a possible trick if you use resources (https://wiki.xmpp.org/web/Jabber_Resources) by appending a /something to the jid (agent@server/agent1, agent@server/agent2, etc), but I should check first if this works.

  3. Yes. There is a web interface. Please refer to the documentation: https://spade-mas.readthedocs.io/en/latest/web.html

  4. That's an old documentation (that I'm going to remove, thanks for remember me that it exists). The new documentation is at http://spade-mas.readthedocs.io. And, for some reason, the API chapter has not been rendered. Need to fix it.

L-Piao commented 6 years ago

Dear Javi @javipalanca ,

Thank you for your prompt response! I will try with your answers and continue exploring SPADE 3. By the way, thanks for creating a nice web interface for SPADE!

Best regards, Piao