Skip to content

Commit

Permalink
Merge pull request #797 from oberstet/rel_0-18-1
Browse files Browse the repository at this point in the history
Rel 0 18 1
  • Loading branch information
oberstet committed Mar 28, 2017
2 parents 12e0b14 + fd7ec41 commit 6e8cb7b
Show file tree
Hide file tree
Showing 15 changed files with 326 additions and 238 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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>`__)
Expand Down
2 changes: 1 addition & 1 deletion autobahn/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
#
###############################################################################

__version__ = u'0.18.0'
__version__ = u'0.18.1'
99 changes: 83 additions & 16 deletions autobahn/asyncio/wamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@

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:
Expand All @@ -43,7 +37,20 @@
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',
Expand Down Expand Up @@ -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`)
Expand All @@ -113,15 +127,32 @@ def __init__(self, url, realm, extra=None, serializers=None, ssl=None):
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):
Expand Down Expand Up @@ -152,8 +183,49 @@ def create():
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:
Expand All @@ -164,22 +236,17 @@ def create():
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')

Expand Down
22 changes: 20 additions & 2 deletions autobahn/twisted/wamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand All @@ -134,10 +141,14 @@ def __init__(self, url, realm, extra=None, serializers=None, ssl=None, proxy=Non
: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
Expand All @@ -152,7 +163,11 @@ def __init__(self, url, realm, extra=None, serializers=None, ssl=None, proxy=Non
# 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()
Expand Down Expand Up @@ -209,8 +224,11 @@ def create():
# 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 ..
Expand Down
35 changes: 30 additions & 5 deletions autobahn/wamp/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
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, \
Expand Down Expand Up @@ -1104,17 +1104,38 @@ def onJoin(self, details):
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):
Expand All @@ -1141,7 +1162,11 @@ def onDisconnect(self):
"""
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):
Expand Down
2 changes: 1 addition & 1 deletion autobahn/wamp/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'``)
Expand Down
13 changes: 13 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
------

Expand Down
12 changes: 12 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------

Expand Down
9 changes: 7 additions & 2 deletions examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6e8cb7b

Please sign in to comment.