Skip to content

Commit f9ed942

Browse files
authored
Merge pull request #86 from saltyrtc/py37-support
Python 3.7 Support & Task Queue Refactoring (again)
2 parents 43c1215 + 2225967 commit f9ed942

18 files changed

+1795
-468
lines changed

.coveragerc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[run]
22
branch = True
3-
source = saltyrtc
3+
source = saltyrtc.server
44

55
[report]
66
exclude_lines =

.travis-install-libsodium.sh

-14
This file was deleted.

.travis.yml

+53-31
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,95 @@
11
# Use container system
22
sudo: false
33

4-
# Cache pip & libsodium
4+
# Install APT dependencies
5+
addons:
6+
apt:
7+
sources:
8+
- sourceline: "ppa:chris-lea/libsodium"
9+
packages:
10+
- libsodium-dev
11+
12+
# Cache pip
513
cache:
614
directories:
7-
- $HOME/libsodium
815
- $HOME/.cache/pip
916

1017
# Clean up pip log
1118
before_cache:
12-
- rm -f $HOME/.cache/pip/log/debug.log
19+
- rm -f $HOME/.cache/pip/log/debug.log
1320

1421
# Build matrix
1522
language: python
1623
matrix:
1724
include:
1825
- python: "3.4"
1926
env:
20-
- EVENT_LOOP=asyncio
21-
- TIMEOUT=2.0
27+
- EVENT_LOOP=asyncio
28+
- TIMEOUT=2.0
29+
- IGNORE=tests/test_cli.py
2230
- python: "3.5"
2331
env:
24-
- EVENT_LOOP=asyncio
25-
- TIMEOUT=2.0
32+
- EVENT_LOOP=asyncio
33+
- TIMEOUT=2.0
2634
- python: "3.5"
2735
env:
28-
- EVENT_LOOP=uvloop
29-
- TIMEOUT=2.0
36+
- EVENT_LOOP=uvloop
37+
- TIMEOUT=2.0
3038
before_script: "pip install .[uvloop]"
3139
- python: "3.6"
3240
env:
33-
- EVENT_LOOP=asyncio
34-
- TIMEOUT=2.0
41+
- EVENT_LOOP=asyncio
42+
- TIMEOUT=2.0
3543
- python: "3.6"
3644
env:
37-
- EVENT_LOOP=uvloop
38-
- TIMEOUT=2.0
45+
- EVENT_LOOP=uvloop
46+
- TIMEOUT=2.0
3947
before_script: "pip install .[uvloop]"
48+
# TODO: Enable once 3.7 support has been added
49+
# - python: "3.7"
50+
# env:
51+
# - EVENT_LOOP=asyncio
52+
# - TIMEOUT=2.0
53+
# - python: "3.7"
54+
# env:
55+
# - EVENT_LOOP=uvloop
56+
# - TIMEOUT=2.0
57+
# before_script: "pip install .[uvloop]"
4058
- python: "pypy3" # 2017-08-05: It's pypy3-5.8.0-beta
4159
env:
42-
- EVENT_LOOP=asyncio
43-
- TIMEOUT=16.0
60+
- EVENT_LOOP=asyncio
61+
- TIMEOUT=16.0
4462
# TODO: Re-enable once pypy3 is able to compile uvloop
4563
# - python: "pypy3" # 2017-08-05: It's pypy3-5.8.0-beta
4664
# env:
47-
# - EVENT_LOOP=uvloop
48-
# - TIMEOUT=16.0
65+
# - EVENT_LOOP=uvloop
66+
# - TIMEOUT=16.0
4967
# before_script: "pip install .[uvloop]"
5068

5169
# Install dependencies
52-
before_install:
53-
- ./.travis-install-libsodium.sh
54-
- export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${HOME}/libsodium/lib
5570
install:
56-
- pip install -U setuptools pip
57-
- "pip install .[dev]"
58-
- pip install codecov
71+
- pip install -U setuptools pip
72+
- "pip install .[dev]"
73+
- pip install codecov
5974

6075
# Run flake8, isort, check docs & tests
76+
# TODO: Re-enable isort once #85 has been resolved
6177
script:
62-
- >
63-
if [[ "$TRAVIS_PYTHON_VERSION" != "pypy3" ]]; then
64-
flake8 . || travis_terminate 1;
65-
isort -rc -c . || (isort -rc -df . && return 1) || travis_terminate 1;
66-
fi
67-
- python setup.py checkdocs
68-
- py.test --cov-config .coveragerc --cov=saltyrtc.server --loop=$EVENT_LOOP --timeout=$TIMEOUT
78+
- >
79+
if [[ "$TRAVIS_PYTHON_VERSION" != "pypy3" ]]; then
80+
flake8 . || travis_terminate 1;
81+
#isort -rc -c . || (isort -rc -df . && return 1) || travis_terminate 1;
82+
fi
83+
- python setup.py checkdocs
84+
- >
85+
py.test \
86+
--ignore=$IGNORE \
87+
--cov-config=.coveragerc \
88+
--cov=saltyrtc.server \
89+
--loop=$EVENT_LOOP \
90+
--timeout=$TIMEOUT
6991
7092
# After success
7193
after_success:
72-
- codecov
94+
- codecov
7395

saltyrtc/server/bin.py

+4
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,7 @@ def main():
272272
finally:
273273
if obj['logging_handler'] is not None:
274274
obj['logging_handler'].pop_application()
275+
276+
277+
if __name__ == '__main__':
278+
main()

saltyrtc/server/common.py

+33
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
'OverflowSentinel',
2222
'SubProtocol',
2323
'CloseCode',
24+
'ClientState',
2425
'AddressType',
2526
'MessageType',
2627
'available_slot_range',
@@ -82,12 +83,44 @@ class CloseCode(enum.IntEnum):
8283
initiator_could_not_decrypt = 3005
8384
no_shared_tasks = 3006
8485
invalid_key = 3007
86+
timeout = 3008
8587

8688
@property
8789
def is_valid_drop_reason(self):
8890
return self.value in _drop_reasons
8991

9092

93+
@enum.unique
94+
class ClientState(enum.IntEnum):
95+
"""
96+
The state of a :class:`PathClient`.
97+
98+
.. important:: States MUST follow the exact order as enumerated
99+
below. A client cannot go back a state or skip
100+
a state in between. For example, a *dropped* client
101+
MUST have been formerly *authenticated*.
102+
"""
103+
# The client is connected but is not allowed to communicate
104+
# with another client.
105+
restricted = 1
106+
107+
# The client has been authenticated and may communicate with
108+
# other clients (of different type).
109+
authenticated = 2
110+
111+
# The client has been dropped by another client.
112+
dropped = 3
113+
114+
@property
115+
def next(self):
116+
"""
117+
Return the subsequent state.
118+
119+
Raises :exc:`ValueError` in case there is no subsequent state.
120+
"""
121+
return ClientState(self + 1)
122+
123+
91124
@enum.unique
92125
class AddressType(enum.IntEnum):
93126
server = 0x00

saltyrtc/server/message.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
NONCE_FORMATTER,
1515
NONCE_LENGTH,
1616
AddressType,
17+
ClientState,
1718
CloseCode,
1819
MessageType,
1920
OverflowSentinel,
@@ -192,8 +193,8 @@ def pack(self, client):
192193

193194
# Encrypt payload if required
194195
if self.encrypted:
195-
if not client.authenticated:
196-
raise MessageFlowError('Cannot encrypt payload, no box available')
196+
if client.state != ClientState.authenticated:
197+
raise MessageFlowError('Cannot encrypt payload, not authenticated')
197198
payload = self._encrypt_payload(client, nonce, payload)
198199

199200
# Append payload and return as bytes
@@ -224,7 +225,7 @@ def unpack(cls, client, data):
224225
expect_type = None
225226
if destination_type == AddressType.server:
226227
data = data[NONCE_LENGTH:]
227-
if not client.authenticated and client.type is None:
228+
if client.state == ClientState.restricted and client.type is None:
228229
payload = None
229230

230231
# Try client-auth (encrypted)

0 commit comments

Comments
 (0)