Merge pull request #797 from oberstet/rel_0-18-1

Rel 0 18 1
This commit is contained in:
Tobias Oberstein
2017-03-28 20:01:36 +02:00
committed by GitHub
15 changed files with 326 additions and 238 deletions

View File

@@ -39,7 +39,7 @@ Features
- implements `WebSocket compression <http://tools.ietf.org/html/draft-ietf-hybi-permessage-compression>`__
- implements `WAMP <http://wamp-proto.org/>`__, the Web Application Messaging Protocol
- high-performance, fully asynchronous implementation
- best-in-class standards conformance (100% strict passes with `Autobahn Testsuite <http://crossbar.io/autobahn#testsuite>`__: `Client <http://autobahn.ws/testsuite/reports/clients/index.html>__` `Server <http://autobahn.ws/testsuite/reports/servers/index.html>`__)
- best-in-class standards conformance (100% strict passes with `Autobahn Testsuite <http://crossbar.io/autobahn#testsuite>`__: `Client <http://autobahn.ws/testsuite/reports/clients/index.html>`__ `Server <http://autobahn.ws/testsuite/reports/servers/index.html>`__)
- message-, frame- and streaming-APIs for WebSocket
- supports TLS (secure WebSocket) and proxies
- Open-source (`MIT license <https://github.com/crossbario/autobahn-python/blob/master/LICENSE>`__)

View File

@@ -24,4 +24,4 @@
#
###############################################################################
__version__ = u'0.18.0'
__version__ = u'0.18.1'

View File

@@ -29,12 +29,6 @@ import signal
import six
from autobahn.util import public
from autobahn.wamp import protocol
from autobahn.wamp.types import ComponentConfig
from autobahn.websocket.util import parse_url
from autobahn.asyncio.websocket import WampWebSocketClientFactory
try:
import asyncio
except ImportError:
@@ -43,7 +37,20 @@ except ImportError:
import trollius as asyncio
import txaio
txaio.use_asyncio()
txaio.use_asyncio() # noqa
from autobahn.util import public
from autobahn.wamp import protocol
from autobahn.wamp.types import ComponentConfig
from autobahn.websocket.util import parse_url as parse_ws_url
from autobahn.rawsocket.util import parse_url as parse_rs_url
from autobahn.asyncio.websocket import WampWebSocketClientFactory
from autobahn.asyncio.rawsocket import WampRawSocketClientFactory
from autobahn.websocket.compress import PerMessageDeflateOffer, \
PerMessageDeflateResponse, PerMessageDeflateResponseAccept
__all__ = (
'ApplicationSession',
@@ -92,7 +99,14 @@ class ApplicationRunner(object):
log = txaio.make_logger()
def __init__(self, url, realm, extra=None, serializers=None, ssl=None):
def __init__(self,
url,
realm=None,
extra=None,
serializers=None,
ssl=None,
proxy=None,
headers=None):
"""
:param url: The WebSocket URL of the WAMP router to connect to (e.g. `ws://somehost.com:8090/somepath`)
@@ -113,15 +127,32 @@ class ApplicationRunner(object):
method, to which this value is passed as the ``ssl``
keyword parameter.
:type ssl: :class:`ssl.SSLContext` or bool
:param proxy: Explicit proxy server to use; a dict with ``host`` and ``port`` keys
:type proxy: dict or None
:param headers: Additional headers to send (only applies to WAMP-over-WebSocket).
:type headers: dict
"""
assert(type(url) == six.text_type)
assert(realm is None or type(realm) == six.text_type)
assert(extra is None or type(extra) == dict)
assert(headers is None or type(headers) == dict)
assert(proxy is None or type(proxy) == dict)
self.url = url
self.realm = realm
self.extra = extra or dict()
self.serializers = serializers
self.ssl = ssl
self.proxy = proxy
self.headers = headers
@public
def stop(self):
"""
Stop reconnecting, if auto-reconnecting was enabled.
"""
raise NotImplementedError()
@public
def run(self, make, start_loop=True):
@@ -152,8 +183,49 @@ class ApplicationRunner(object):
else:
create = make
isSecure, host, port, resource, path, params = parse_url(self.url)
if self.url.startswith(u'rs'):
# try to parse RawSocket URL ..
isSecure, host, port = parse_rs_url(self.url)
# use the first configured serializer if any (which means, auto-choose "best")
serializer = self.serializers[0] if self.serializers else None
# create a WAMP-over-RawSocket transport client factory
transport_factory = WampRawSocketClientFactory(create, serializer=serializer)
else:
# try to parse WebSocket URL ..
isSecure, host, port, resource, path, params = parse_ws_url(self.url)
# create a WAMP-over-WebSocket transport client factory
transport_factory = WampWebSocketClientFactory(create, url=self.url, serializers=self.serializers, proxy=self.proxy, headers=self.headers)
# client WebSocket settings - similar to:
# - http://crossbar.io/docs/WebSocket-Compression/#production-settings
# - http://crossbar.io/docs/WebSocket-Options/#production-settings
# The permessage-deflate extensions offered to the server ..
offers = [PerMessageDeflateOffer()]
# Function to accept permessage_delate responses from the server ..
def accept(response):
if isinstance(response, PerMessageDeflateResponse):
return PerMessageDeflateResponseAccept(response)
# set WebSocket options for all client connections
transport_factory.setProtocolOptions(maxFramePayloadSize=1048576,
maxMessagePayloadSize=1048576,
autoFragmentSize=65536,
failByDrop=False,
openHandshakeTimeout=2.5,
closeHandshakeTimeout=1.,
tcpNoDelay=True,
autoPingInterval=10.,
autoPingTimeout=5.,
autoPingSize=4,
perMessageCompressionOffers=offers,
perMessageCompressionAccept=accept)
# SSL context for client connection
if self.ssl is None:
ssl = isSecure
else:
@@ -164,22 +236,17 @@ class ApplicationRunner(object):
self.__class__.__name__)
ssl = self.ssl
# 2) create a WAMP-over-WebSocket transport client factory
transport_factory = WampWebSocketClientFactory(create, url=self.url, serializers=self.serializers)
# 3) start the client
# start the client connection
loop = asyncio.get_event_loop()
txaio.use_asyncio()
txaio.config.loop = loop
coro = loop.create_connection(transport_factory, host, port, ssl=ssl)
(transport, protocol) = loop.run_until_complete(coro)
# start a asyncio loop
if not start_loop:
return protocol
else:
# start logging
txaio.start_logging(level='info')

View File

@@ -107,7 +107,14 @@ class ApplicationRunner(object):
log = txaio.make_logger()
def __init__(self, url, realm, extra=None, serializers=None, ssl=None, proxy=None, headers=None):
def __init__(self,
url,
realm=None,
extra=None,
serializers=None,
ssl=None,
proxy=None,
headers=None):
"""
:param url: The WebSocket URL of the WAMP router to connect to (e.g. `ws://somehost.com:8090/somepath`)
@@ -134,10 +141,14 @@ class ApplicationRunner(object):
:param proxy: Explicit proxy server to use; a dict with ``host`` and ``port`` keys
:type proxy: dict or None
:param headers: Additional headers to send (only applies to WAMP-over-WebSocket).
:type headers: dict
"""
assert(type(url) == six.text_type)
assert(realm is None or type(realm) == six.text_type)
assert(extra is None or type(extra) == dict)
assert(headers is None or type(headers) == dict)
assert(proxy is None or type(proxy) == dict)
self.url = url
self.realm = realm
@@ -152,7 +163,11 @@ class ApplicationRunner(object):
# total number of successful connections
self._connect_successes = 0
@public
def stop(self):
"""
Stop reconnecting, if auto-reconnecting was enabled.
"""
self.log.debug('{klass}.stop()', klass=self.__class__.__name__)
if self._client_service:
return self._client_service.stopService()
@@ -209,8 +224,11 @@ class ApplicationRunner(object):
# try to parse RawSocket URL ..
isSecure, host, port = parse_rs_url(self.url)
# use the first configured serializer if any (which means, auto-choose "best")
serializer = self.serializers[0] if self.serializers else None
# create a WAMP-over-RawSocket transport client factory
transport_factory = WampRawSocketClientFactory(create)
transport_factory = WampRawSocketClientFactory(create, serializer=serializer)
else:
# try to parse WebSocket URL ..

View File

@@ -39,7 +39,7 @@ from autobahn.wamp import role
from autobahn.wamp import exception
from autobahn.wamp.exception import ApplicationError, ProtocolError, SessionNotReady, SerializationError
from autobahn.wamp.interfaces import ISession # noqa
from autobahn.wamp.types import SessionDetails
from autobahn.wamp.types import SessionDetails, CloseDetails
from autobahn.wamp.cryptobox import EncryptedPayload
from autobahn.wamp.request import \
Publication, \
@@ -1104,17 +1104,38 @@ class ApplicationSession(BaseSession):
Implements :func:`autobahn.wamp.interfaces.ISession.onJoin`
"""
def _errback_outstanding_requests(self, exc):
"""
Errback any still outstanding requests with exc.
"""
for requests in [self._publish_reqs,
self._subscribe_reqs,
self._unsubscribe_reqs,
self._call_reqs,
self._register_reqs,
self._unregister_reqs]:
for request in requests.values():
self.log.info('cleaning up outstanding {request_type} request {request_id}, firing errback on user handler {request_on_reply}',
request_on_reply=request.on_reply,
request_id=request.request_id,
request_type=request.__class__.__name__)
txaio.reject(request.on_reply, exc)
requests.clear()
@public
def onLeave(self, details):
"""
Implements :func:`autobahn.wamp.interfaces.ISession.onLeave`
"""
if details.reason.startswith('wamp.error.'):
self.log.error('{reason}: {wamp_message}', reason=details.reason, wamp_message=details.message)
if details.reason != CloseDetails.REASON_DEFAULT:
self.log.warn('session closed with reason {reason} [{message}]', reason=details.reason, message=details.message)
# fire ApplicationError on any currently outstanding requests
exc = ApplicationError(details.reason, details.message)
self._errback_outstanding_requests(exc)
if self._transport:
self.disconnect()
# do we ever call onLeave with a valid transport?
@public
def leave(self, reason=None, message=None):
@@ -1141,7 +1162,11 @@ class ApplicationSession(BaseSession):
"""
Implements :func:`autobahn.wamp.interfaces.ISession.onDisconnect`
"""
pass
# fire TransportLost on any _still_ outstanding requests
# (these should have been already cleaned up in onLeave() - when
# this actually has fired)
exc = exception.TransportLost()
self._errback_outstanding_requests(exc)
@public
def publish(self, topic, *args, **kwargs):

View File

@@ -182,7 +182,7 @@ class Deny(HelloReturn):
'message',
)
def __init__(self, reason, message=None):
def __init__(self, reason=u'wamp.error.not_authorized', message=None):
"""
:param reason: The reason of denying the authentication (an URI, e.g. ``u'wamp.error.not_authorized'``)

View File

@@ -5,6 +5,19 @@
Changelog
=========
0.18.1
------
`Published 2017-03-28 <https://pypi.python.org/pypi/autobahn/0.18.1>`__
* fix: errback all user handlers for all WAMP requests still outstanding when session/transport is closed/lost
* fix: allow WebSocketServerProtocol.onConnect to return a Future/Deferred
* new: allow configuration of RawSocket serializer
* new: test all examples on both WebSocket and RawSocket
* fix: revert to default arg for Deny reason
* new: WAMP-RawSocket and WebSocket default settings for asyncio
* new: experimental component based API and new WAMP Session class
0.18.0
------

View File

@@ -221,6 +221,18 @@ There are two environment variables the tests use: ``USE_TWISTED=1`` or ``USE_AS
See ``tox.ini`` for details on how to run in the different environments.
Release Testing
---------------
Before pushing a new release, three levels of tests need to pass:
1. the unit tests (see above)
2. the [WebSocket level tests](wstest/README.md)
3. the [WAMP level tests](examples/README.md) (*)
> (*): these will launch a Crossbar.io router for testing
Sitemap
-------

View File

@@ -22,5 +22,10 @@ flake8:
pylint:
pylint -d line-too-long,invalid-name .
examples:
python run-all-examples.py
examples_rawsocket:
AUTOBAHN_DEMO_ROUTER=rs://127.0.0.1:8080 python run-all-examples.py
examples_websocket:
AUTOBAHN_DEMO_ROUTER=ws://127.0.0.1:8080/ws python run-all-examples.py
examples: examples_websocket examples_rawsocket

View File

@@ -1,109 +0,0 @@
{
"version": 2,
"workers": [
{
"type": "router",
"realms": [
{
"name": "crossbardemo",
"roles": [
{
"name": "anonymous",
"permissions": [
{
"uri": "",
"match": "prefix",
"allow": {
"call": true,
"register": true,
"publish": true,
"subscribe": true
},
"disclose": {
"caller": false,
"publisher": false
},
"cache": true
}
]
},
{
"name": "authenticated",
"permissions": [
{
"uri": "",
"match": "prefix",
"allow": {
"call": true,
"register": true,
"publish": true,
"subscribe": true
},
"disclose": {
"caller": false,
"publisher": false
},
"cache": true
}
]
}
]
}
],
"transports": [
{
"type": "mqtt",
"endpoint": {
"type": "tcp",
"port": 1883
},
"options": {
"realm": "crossbardemo",
"role": "anonymous"
}
},
{
"type": "web",
"endpoint": {
"type": "tcp",
"port": 8080
},
"paths": {
"/": {
"type": "static",
"directory": "../..",
"options": {
"enable_directory_listing": true,
"mime_types": {
".md": "text/plain",
".py": "text/plain"
}
}
},
"ws": {
"type": "websocket"
},
"auth_ws": {
"type": "websocket",
"auth": {
"wampcra": {
"type": "static",
"users": {
"username": {
"secret": "p4ssw0rd",
"role": "authenticated"
}
}
},
"anonymous": {
"type": "static",
"role": "anonymous"
}
}
}
}
}
]
}
]
}

View File

@@ -1,97 +0,0 @@
{
"version": 2,
"workers": [
{
"type": "router",
"realms": [
{
"name": "crossbardemo",
"roles": [
{
"name": "anonymous",
"permissions": [
{
"uri": "",
"match": "prefix",
"allow": {
"call": true,
"register": true,
"publish": true,
"subscribe": true
},
"disclose": {
"caller": false,
"publisher": false
},
"cache": true
}
]
}
]
}
],
"transports": [
{
"type": "mqtt",
"endpoint": {
"type": "tcp",
"port": 1883
},
"options": {
"realm": "crossbardemo",
"role": "anonymous"
}
},
{
"type": "web",
"endpoint": {
"type": "tcp",
"port": 8080
},
"paths": {
"/": {
"type": "static",
"directory": "../..",
"options": {
"enable_directory_listing": true,
"mime_types": {
".md": "text/plain",
".py": "text/plain"
}
}
},
"ws": {
"type": "websocket"
},
"auth_ws": {
"type": "websocket",
"auth": {
"wampcra": {
"type": "static",
"users": {
"username": {
"secret": "p4ssw0rd",
"role": "authenticated"
}
}
}
}
}
}
},
{
"type": "websocket",
"endpoint": {
"type": "tcp",
"interface": "localhost",
"port": 8083,
"tls": {
"key": "server.key",
"certificate": "server.crt"
}
}
}
]
}
]
}

View File

@@ -1 +0,0 @@
config-with-tls.json

View File

@@ -0,0 +1,142 @@
{
"version": 2,
"workers": [
{
"type": "router",
"realms": [
{
"name": "crossbardemo",
"roles": [
{
"name": "anonymous",
"permissions": [
{
"uri": "",
"match": "prefix",
"allow": {
"call": true,
"register": true,
"publish": true,
"subscribe": true
},
"disclose": {
"caller": false,
"publisher": false
},
"cache": true
}
]
},
{
"name": "authenticated",
"permissions": [
{
"uri": "",
"match": "prefix",
"allow": {
"call": true,
"register": true,
"publish": true,
"subscribe": true
},
"disclose": {
"caller": false,
"publisher": false
},
"cache": true
}
]
}
]
}
],
"transports": [
{
"type": "mqtt",
"endpoint": {
"type": "tcp",
"port": 1883
},
"options": {
"realm": "crossbardemo",
"role": "anonymous"
}
},
{
"type": "universal",
"endpoint": {
"type": "tcp",
"port": 8080
},
"rawsocket": {
"serializers": [
"cbor", "msgpack", "ubjson", "json"
]
},
"websocket": {
"ws": {
"type": "websocket",
"serializers": [
"cbor", "msgpack", "ubjson", "json"
],
"options": {
"enable_webstatus": true,
"max_frame_size": 1048576,
"max_message_size": 1048576,
"auto_fragment_size": 65536,
"fail_by_drop": true,
"open_handshake_timeout": 2500,
"close_handshake_timeout": 1000,
"auto_ping_interval": 10000,
"auto_ping_timeout": 5000,
"auto_ping_size": 4,
"compression": {
"deflate": {
"request_no_context_takeover": false,
"request_max_window_bits": 13,
"no_context_takeover": false,
"max_window_bits": 13,
"memory_level": 5
}
}
}
},
"auth_ws": {
"type": "websocket",
"auth": {
"wampcra": {
"type": "static",
"users": {
"username": {
"secret": "p4ssw0rd",
"role": "authenticated"
}
}
},
"anonymous": {
"type": "static",
"role": "anonymous"
}
}
}
},
"web": {
"paths": {
"/": {
"type": "static",
"directory": "../..",
"options": {
"enable_directory_listing": true,
"mime_types": {
".md": "text/plain",
".py": "text/plain"
}
}
}
}
}
}
]
}
]
}

View File

@@ -0,0 +1,7 @@
Crossbar.io node private key - KEEP THIS SAFE!
creator: oberstet@thinkpad-t430s
created-at: 2017-03-26T22:01:20.440Z
machine-id: 7a3357418649414dbd536c31c6bd0ee8
public-key-ed25519: a81b5e80ff63ebb5f31af8afbfd7d0af5983befe3cbfca48b62026d43847c885
private-key-ed25519: af032ab972a29a530463ba9a5beed1636af538103d5d4b413a623b6ebd60d202

View File

@@ -0,0 +1,6 @@
Crossbar.io node public key
creator: oberstet@thinkpad-t430s
created-at: 2017-03-26T22:01:20.440Z
machine-id: 7a3357418649414dbd536c31c6bd0ee8
public-key-ed25519: a81b5e80ff63ebb5f31af8afbfd7d0af5983befe3cbfca48b62026d43847c885

View File

@@ -94,7 +94,7 @@ class CrossbarProcessProtocol(ProcessProtocol):
def start_crossbar():
finished = Deferred()
launched = Deferred()
protocol = CrossbarProcessProtocol(finished, launched, Fore.RED)
protocol = CrossbarProcessProtocol(finished, launched, Fore.YELLOW)
exe = 'crossbar'
args = [exe, 'start', '--cbdir', './router/.crossbar']
@@ -194,10 +194,10 @@ def main(reactor):
print_banner("Running example: " + exdir)
print(" starting backend")
back_proto = yield start_example(backend, Fore.BLUE, ' backend: ', exe=py)
back_proto = yield start_example(backend, Fore.GREEN, ' backend: ', exe=py)
yield sleep(1)
print(" starting frontend")
front_proto = yield start_example(frontend, Fore.YELLOW, 'frontend: ', exe=py)
front_proto = yield start_example(frontend, Fore.BLUE, 'frontend: ', exe=py)
yield sleep(3)
for p in [back_proto, front_proto]: