Skip to content

Commit

Permalink
Transport details (#1551)
Browse files Browse the repository at this point in the history
* deactivate arm64 ci for now
* expand wamp transport details
* cleanup transport details interface
* add getter impl for transport details
* cleanup; add tests
* cleanups and refactorings
* bump dev version
  • Loading branch information
oberstet committed Apr 26, 2022
1 parent 3da0c26 commit a196a8b
Show file tree
Hide file tree
Showing 44 changed files with 1,513 additions and 745 deletions.
114 changes: 57 additions & 57 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,60 +73,60 @@ jobs:
make publish_pypy_amd64
# runs on ARM64v8 (AWS Graviton) host: buildbox-arm64.crossbario.com
image_arm64:
runs-on: [self-hosted, linux, ARM64]

# docker images are only built and published (to DockerHub) when merging
# to master (not a yet unmerged PR!)
if: github.ref == 'refs/heads/master'

env:
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
AWS_S3_BUCKET_NAME: ${{ secrets.AWS_S3_BUCKET_NAME }}

steps:
- uses: actions/checkout@v2

- name: Set environment
run: |
echo AUTOBAHN_BUILD_DATE=`date -u +"%Y-%m-%d"` >> $GITHUB_ENV
echo AUTOBAHN_BUILD_ID=$(date --utc +%Y%m%d)-$(git rev-parse --short ${GITHUB_SHA}) >> $GITHUB_ENV
echo AUTOBAHN_VCS_REF=`git rev-parse --short ${GITHUB_SHA}` >> $GITHUB_ENV
echo AUTOBAHN_VERSION=$(grep -E '^(__version__)' ./autobahn/_version.py | cut -d ' ' -f3 | sed -e 's|[u"'\'']||g') >> $GITHUB_ENV
- name: Print environment
run: |
echo ""
echo "Build environment configured:"
echo ""
echo " AUTOBAHN_BUILD_DATE = ${AUTOBAHN_BUILD_DATE}"
echo " AUTOBAHN_BUILD_ID = ${AUTOBAHN_BUILD_ID}"
echo " AUTOBAHN_VCS_REF = ${AUTOBAHN_VCS_REF}"
echo " AUTOBAHN_VERSION = ${AUTOBAHN_VERSION}"
echo ""
echo "Wheels (source):"
echo " AWS_DEFAULT_REGION = ${AWS_DEFAULT_REGION}"
echo " AWS_S3_BUCKET_NAME = ${AWS_S3_BUCKET_NAME}"
echo ""
echo "Docker image (publish):"
echo " DOCKERHUB_USER = ${DOCKERHUB_USER}"
echo ""
- name: Build & publish Docker image for cpy-arm64
run: |
cd ./docker && \
make download_wheels && \
make build_cpy_arm64v8 && \
make test_cpy_arm64v8
docker login -u ${{ secrets.DOCKERHUB_USER }} -p ${{ secrets.DOCKERHUB_PASSWORD }} docker.io && \
make publish_cpy_arm64v8
- name: Build & publish Docker image for pypy-arm64
run: |
cd ./docker && \
make download_wheels && \
make build_pypy_arm64v8 && \
make test_pypy_arm64v8
docker login -u ${{ secrets.DOCKERHUB_USER }} -p ${{ secrets.DOCKERHUB_PASSWORD }} docker.io && \
make publish_pypy_arm64v8
# image_arm64:
# runs-on: [self-hosted, linux, ARM64]

# # docker images are only built and published (to DockerHub) when merging
# # to master (not a yet unmerged PR!)
# if: github.ref == 'refs/heads/master'

# env:
# DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
# AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
# AWS_S3_BUCKET_NAME: ${{ secrets.AWS_S3_BUCKET_NAME }}

# steps:
# - uses: actions/checkout@v2

# - name: Set environment
# run: |
# echo AUTOBAHN_BUILD_DATE=`date -u +"%Y-%m-%d"` >> $GITHUB_ENV
# echo AUTOBAHN_BUILD_ID=$(date --utc +%Y%m%d)-$(git rev-parse --short ${GITHUB_SHA}) >> $GITHUB_ENV
# echo AUTOBAHN_VCS_REF=`git rev-parse --short ${GITHUB_SHA}` >> $GITHUB_ENV
# echo AUTOBAHN_VERSION=$(grep -E '^(__version__)' ./autobahn/_version.py | cut -d ' ' -f3 | sed -e 's|[u"'\'']||g') >> $GITHUB_ENV

# - name: Print environment
# run: |
# echo ""
# echo "Build environment configured:"
# echo ""
# echo " AUTOBAHN_BUILD_DATE = ${AUTOBAHN_BUILD_DATE}"
# echo " AUTOBAHN_BUILD_ID = ${AUTOBAHN_BUILD_ID}"
# echo " AUTOBAHN_VCS_REF = ${AUTOBAHN_VCS_REF}"
# echo " AUTOBAHN_VERSION = ${AUTOBAHN_VERSION}"
# echo ""
# echo "Wheels (source):"
# echo " AWS_DEFAULT_REGION = ${AWS_DEFAULT_REGION}"
# echo " AWS_S3_BUCKET_NAME = ${AWS_S3_BUCKET_NAME}"
# echo ""
# echo "Docker image (publish):"
# echo " DOCKERHUB_USER = ${DOCKERHUB_USER}"
# echo ""

# - name: Build & publish Docker image for cpy-arm64
# run: |
# cd ./docker && \
# make download_wheels && \
# make build_cpy_arm64v8 && \
# make test_cpy_arm64v8
# docker login -u ${{ secrets.DOCKERHUB_USER }} -p ${{ secrets.DOCKERHUB_PASSWORD }} docker.io && \
# make publish_cpy_arm64v8

# - name: Build & publish Docker image for pypy-arm64
# run: |
# cd ./docker && \
# make download_wheels && \
# make build_pypy_arm64v8 && \
# make test_pypy_arm64v8
# docker login -u ${{ secrets.DOCKERHUB_USER }} -p ${{ secrets.DOCKERHUB_PASSWORD }} docker.io && \
# make publish_pypy_arm64v8
18 changes: 14 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ test:
# test under Twisted
test_twisted:
USE_TWISTED=1 trial autobahn
#WAMP_ROUTER_URL="ws://127.0.0.1:8080/ws" USE_TWISTED=1 trial autobahn
# WAMP_ROUTER_URL="ws://127.0.0.1:8080/ws" USE_TWISTED=1 trial autobahn

test_application_runner:
USE_TWISTED=1 trial autobahn.twisted.test.test_tx_application_runner
Expand All @@ -185,7 +185,8 @@ test_tx_choosereactor:
USE_TWISTED=1 trial autobahn.twisted.test.test_choosereactor

test_cryptosign:
USE_ASYNCIO=1 trial autobahn.wamp.test.test_wamp_cryptosign
# USE_ASYNCIO=1 trial autobahn.wamp.test.test_wamp_cryptosign
USE_ASYNCIO=1 pytest -s -v -rfA --ignore=./autobahn/twisted autobahn/wamp/test/test_wamp_cryptosign.py
USE_TWISTED=1 trial autobahn.wamp.test.test_wamp_cryptosign

test_wamp_scram:
Expand All @@ -199,6 +200,13 @@ test_xbr_argon2:
test_xbr_config:
USE_TWISTED=1 trial autobahn.xbr.test.test_xbr_config

test_transport_details:
USE_ASYNCIO=1 trial autobahn.wamp.test.test_wamp_transport_details
USE_TWISTED=1 trial autobahn.wamp.test.test_wamp_transport_details

test_tx_protocol:
USE_TWISTED=1 trial autobahn.twisted.test.test_tx_protocol

test_twisted_coverage:
-rm .coverage
USE_TWISTED=1 coverage run --omit=*/test/* --source=autobahn `which trial` autobahn
Expand All @@ -215,8 +223,10 @@ test_coverage:

# test under asyncio
test_asyncio:
USE_ASYNCIO=1 python -m pytest -rsx autobahn
#WAMP_ROUTER_URL="ws://127.0.0.1:8080/ws" USE_ASYNCIO=1 python -m pytest -rsx
USE_ASYNCIO=1 pytest -s -v -rfP --ignore=./autobahn/twisted autobahn
# USE_ASYNCIO=1 pytest -s -v -rA --ignore=./autobahn/twisted ./autobahn/asyncio/test/test_aio_websocket.py
# USE_ASYNCIO=1 pytest -s -v -rA --log-cli-level=info --ignore=./autobahn/twisted ./autobahn/asyncio/test/test_aio_websocket.py


test_cs1:
USE_ASYNCIO=1 python -m pytest -s -v autobahn/wamp/test/test_cryptosign.py
Expand Down
16 changes: 16 additions & 0 deletions autobahn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,19 @@
from autobahn._version import __version__

version = __version__

import os
import txaio

# this is used in the unit tests (trial/pytest), and when already done here, there
# is no risk and headaches with finding out if/where an import implies a framework
if os.environ.get('USE_TWISTED', False) and os.environ.get('USE_ASYNCIO', False):
raise RuntimeError('fatal: _both_ USE_TWISTED and USE_ASYNCIO are set!')

if os.environ.get('USE_TWISTED', False):
txaio.use_twisted()
elif os.environ.get('USE_ASYNCIO', False):
txaio.use_asyncio()
else:
# neither USE_TWISTED nor USE_ASYNCIO selected from env var
pass
2 changes: 1 addition & 1 deletion autobahn/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
#
###############################################################################

__version__ = '22.4.1.dev5'
__version__ = '22.4.1.dev6'

__build__ = '00000000-0000000'
2 changes: 0 additions & 2 deletions autobahn/asyncio/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
from functools import wraps

import txaio
txaio.use_asyncio() # noqa

from autobahn.asyncio.websocket import WampWebSocketClientFactory
from autobahn.asyncio.rawsocket import WampRawSocketClientFactory

Expand Down
55 changes: 22 additions & 33 deletions autobahn/asyncio/rawsocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
import struct
import math
import copy

from autobahn.util import public, _LazyHexFormatter
from autobahn.wamp.exception import ProtocolError, SerializationError, TransportLost
from autobahn.asyncio.util import peer2str, get_serializers, transport_channel_id
from typing import Optional

import txaio
from autobahn.util import public, _LazyHexFormatter, hltype
from autobahn.wamp.exception import ProtocolError, SerializationError, TransportLost
from autobahn.asyncio.util import get_serializers, create_transport_details

__all__ = (
'WampRawSocketServerProtocol',
Expand All @@ -42,8 +42,6 @@
'WampRawSocketClientFactory'
)

txaio.use_asyncio()

FRAME_TYPE_DATA = 0
FRAME_TYPE_PING = 1
FRAME_TYPE_PONG = 2
Expand All @@ -58,12 +56,22 @@ class PrefixProtocol(asyncio.Protocol):
max_length = 16 * 1024 * 1024
max_length_send = max_length
log = txaio.make_logger() # @UndefinedVariable
peer: Optional[str] = None
is_server: Optional[bool] = None

def connection_made(self, transport):
self.transport = transport
peer = transport.get_extra_info('peername')
self.peer = peer2str(peer)
# asyncio networking framework entry point, called by asyncio
# when the connection is established (either a client or a server)
self.log.debug('RawSocker Asyncio: Connection made with peer {peer}', peer=self.peer)

self.transport = transport

# determine preliminary transport details (what is know at this point)
self._transport_details = create_transport_details(self.transport, self.is_server)

# backward compatibility
self.peer = self._transport_details.peer

self._buffer = b''
self._header = None
self._wait_closed = txaio.create_future()
Expand Down Expand Up @@ -150,9 +158,6 @@ def stringReceived(self, data):

class RawSocketProtocol(PrefixProtocol):

peer = None
peer_transport = None

def __init__(self):
max_size = None
if max_size:
Expand All @@ -166,13 +171,6 @@ def __init__(self):
self.max_length = 2**24

def connection_made(self, transport):
# the peer we are connected to
try:
self.peer = peer2str(transport.get_extra_info('peername'))
except:
self.peer = 'process:{}'.format(self.transport.pid)
self.peer_transport = 'rawsocket'

PrefixProtocol.connection_made(self, transport)
self._handshake_done = False

Expand All @@ -183,7 +181,6 @@ def parse_handshake(self):
buf = bytearray(self._buffer[:4])
if buf[0] != MAGIC_BYTE:
raise HandshakeError('Invalid magic byte in handshake')
return
ser = buf[1] & 0x0F
lexp = buf[1] >> 4
self.max_length_send = 2**(lexp + 9)
Expand Down Expand Up @@ -232,6 +229,8 @@ def __init__(self, msg, code=0):

class RawSocketClientProtocol(RawSocketProtocol):

is_server = False

def check_serializer(self, ser_id):
return True

Expand Down Expand Up @@ -259,6 +258,8 @@ def connection_made(self, transport):

class RawSocketServerProtocol(RawSocketProtocol):

is_server = True

def supports_serializer(self, ser_id):
raise NotImplementedError()

Expand Down Expand Up @@ -308,7 +309,7 @@ def send(self, msg):
Implements :func:`autobahn.wamp.interfaces.ITransport.send`
"""
if self.isOpen():
self.log.debug("WampRawSocketProtocol: TX WAMP message: {msg}", msg=msg)
self.log.debug('{func}: TX WAMP message: {msg}', func=hltype(self.send), msg=msg)
try:
payload, _ = self._serializer.serialize(msg)
except Exception as e:
Expand Down Expand Up @@ -393,12 +394,6 @@ def supports_serializer(self, ser_id):
self.abort()
return False

def get_channel_id(self, channel_id_type=None):
"""
Implements :func:`autobahn.wamp.interfaces.ITransport.get_channel_id`
"""
return transport_channel_id(self.transport, is_server=True, channel_id_type=channel_id_type)


@public
class WampRawSocketClientProtocol(WampRawSocketMixinGeneral, WampRawSocketMixinAsyncio, RawSocketClientProtocol):
Expand All @@ -416,12 +411,6 @@ def serializer_id(self):
self._serializer = copy.copy(self.factory._serializer)
return self._serializer.RAWSOCKET_SERIALIZER_ID

def get_channel_id(self, channel_id_type=None):
"""
Implements :func:`autobahn.wamp.interfaces.ITransport.get_channel_id`
"""
return transport_channel_id(self.transport, is_server=False, channel_id_type=channel_id_type)


class WampRawSocketFactory(object):
"""
Expand Down
25 changes: 25 additions & 0 deletions autobahn/asyncio/test/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
###############################################################################
#
# The MIT License (MIT)
#
# Copyright (c) Crossbar.io Technologies GmbH
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
###############################################################################

0 comments on commit a196a8b

Please sign in to comment.