Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebSocket support #23

Merged
Merged
Show file tree
Hide file tree
Changes from 95 commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
555c23d
first-cut of state-machine style code
meejah Jan 19, 2021
0e11f1b
(wip) refactor to use Automat state-machine
meejah Jan 26, 2021
0e64707
count totals in state-machine
meejah Feb 1, 2021
b51237d
start of refactoring usage-recording: pass one test
meejah Feb 12, 2021
734ed80
fix more tests
meejah Feb 12, 2021
7b91377
try to make 'redudant' mood work
meejah Feb 12, 2021
ff578fc
fix more tests (that examine internals)
meejah Feb 12, 2021
4669619
skip usage-counting if we're jilted but other side is happy?
meejah Feb 12, 2021
40919b5
count bytes missing
meejah Feb 12, 2021
5ed5721
unregister completely
meejah Feb 12, 2021
53864f5
use 'backends' for usage-recording
meejah Feb 12, 2021
b7bcdfd
more stats / recording works
meejah Feb 12, 2021
3ae3bb7
cleanup, remove dead code
meejah Feb 12, 2021
9557bbf
we never remove backends
meejah Feb 12, 2021
83de03c
remove old test-code
meejah Feb 12, 2021
03906ff
pass actual database, not config
meejah Feb 13, 2021
215a0f3
restore 2 missing log-lines
meejah Feb 13, 2021
60e70ba
cleanup / dead code
meejah Feb 13, 2021
ca55509
fix global stats-gathering / recording
meejah Feb 13, 2021
7e58767
pyflakes
meejah Feb 13, 2021
942f204
log again
meejah Feb 13, 2021
b03801d
guard
meejah Feb 13, 2021
e0f5f55
does this ever get called?
meejah Feb 13, 2021
c09f15d
re-instate log message
meejah Feb 13, 2021
9cf42c5
not sure we can hit this state at all
meejah Feb 13, 2021
2b2f06d
unused
meejah Feb 13, 2021
34dd361
unused
meejah Feb 13, 2021
b192b5c
dead code, correct input
meejah Feb 13, 2021
c8fbc22
dead code
meejah Feb 20, 2021
c2147ee
change from review: inline _got_handshake
meejah Feb 20, 2021
34d039c
hack in prelim websocket support
meejah Feb 23, 2021
2b78fbe
test WebSocket client
meejah Feb 23, 2021
1a461aa
haxxor
meejah Feb 23, 2021
5df5f86
not just localhost
meejah Feb 23, 2021
21af1f6
Transit is no longer a factory
meejah Mar 5, 2021
5210566
websocket version of tests, with handshake
meejah Mar 5, 2021
002773d
WIP: first passing IOPump test
meejah Apr 1, 2021
dd1cc7d
upgrade all tests; reactor_turn(); remove debug
meejah Apr 1, 2021
99c7111
a passing thing
meejah Apr 2, 2021
f18edc8
refine
meejah Apr 2, 2021
816e997
post-rebase fixups
meejah Apr 3, 2021
a89988a
get rid of placeholder/test code; skip test_short for websockets
meejah Apr 5, 2021
b829cae
obsolete
meejah Apr 6, 2021
317b5a8
test-client cleanup
meejah Apr 6, 2021
0aaf00f
get rid of prints
meejah Apr 7, 2021
40e1417
don't need 'binary' subprotocol stuff
meejah Apr 7, 2021
0bfff52
note
meejah Apr 7, 2021
b095b69
cleanup
meejah Apr 7, 2021
27d7ea8
error-handling
meejah Apr 7, 2021
9b4e957
whitespace
meejah Apr 7, 2021
e7b7b4c
unexpected hangup
meejah Apr 7, 2021
09e46d3
cleanup
meejah Apr 7, 2021
d7ebd02
unused
meejah Apr 7, 2021
941e4fe
clean up imports
meejah Apr 7, 2021
eb3bc6b
cleanup
meejah Apr 7, 2021
4112f71
unused
meejah Apr 7, 2021
b73c76c
run '_Transit' tests on websockets too
meejah Apr 7, 2021
e689bfc
remove debug, doesn't make sense anymore
meejah Apr 11, 2021
ce7458e
test for disconnect / error propagation
meejah Apr 11, 2021
a057da4
disconnect_redundant is redundant
meejah Apr 11, 2021
ef96af2
websocket tests already use the interface
meejah Apr 11, 2021
8132ea8
more docstrings
meejah Apr 12, 2021
5f43e53
cleanup
meejah Apr 12, 2021
8aeea71
cleanup
meejah Apr 12, 2021
5b7ec9e
move usage-tracking stuff to own module
meejah Apr 12, 2021
5a40544
more-explicit about which protocol clients use
meejah Apr 14, 2021
0db8ed3
even more explicit
meejah Apr 14, 2021
3197946
websocket<-->TCP test
meejah Apr 14, 2021
786cd08
pyflakes; unused imports
meejah Apr 14, 2021
7b92c37
leave state-machine tracing code (but commented)
meejah Apr 14, 2021
e7466a3
add CLI options for WebSockets support
meejah Apr 14, 2021
3191456
better comment
meejah Apr 14, 2021
95a72e6
better comment
meejah Apr 14, 2021
6698cf9
irrelevant (there was only a debug message logged)
meejah Apr 14, 2021
d8da1a6
no more debug-log
meejah Apr 14, 2021
bd06fad
websocket defaults test
meejah Apr 14, 2021
425f040
test for websocket option-parsing
meejah Apr 14, 2021
30688f6
test to ensure we make a websocket service when passing --websocket
meejah Apr 14, 2021
b2ec298
add autobahn dep, upgrade twisted
meejah Apr 15, 2021
141709b
correct twisted version
meejah Apr 15, 2021
360c799
unconstrained autobahn version so we can support other pythons
meejah Apr 15, 2021
553158d
drop unsupported pythons for now
meejah Apr 15, 2021
f225fde
pyflakes cleanup for test-websocket-client
meejah Apr 15, 2021
82c175a
add tcp test-client too
meejah Apr 15, 2021
3cda647
document test-clients
meejah Apr 15, 2021
088757a
add words about websockets support
meejah Apr 15, 2021
7a5b748
Merge branch 'master' into websocket-support-on-iosim-tests-master
meejah Apr 15, 2021
1a1947d
irrelevant
meejah Apr 15, 2021
aa58b85
honour log_requests as original code did
meejah Apr 15, 2021
bfd8312
render empty token correctly
meejah Apr 16, 2021
513e5be
combine checks
meejah Apr 19, 2021
ade99eb
docstring, whitespace
meejah Apr 19, 2021
dfd3bdd
test we can pass an explicit websocket URL
meejah Apr 19, 2021
0ce08b6
defensive if's -> assert
meejah Apr 19, 2021
807dfc1
unify new_protocol_ws, make it a bare helper
meejah Apr 19, 2021
845c55d
test --websocket-url option too
meejah May 10, 2021
6bd063a
clarify
meejah May 10, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""
This is a test-client for the transit-relay that uses TCP. It
doesn't send any data, only prints out data that is received. Uses a
fixed token of 64 'a' characters. Always connects on localhost:4001
"""


from twisted.internet import endpoints
from twisted.internet.defer import (
Deferred,
)
from twisted.internet.task import react
from twisted.internet.error import (
ConnectionDone,
)
from twisted.internet.protocol import (
Protocol,
Factory,
)


class RelayEchoClient(Protocol):
"""
Speaks the version1 magic wormhole transit relay protocol (as a client)
"""

def connectionMade(self):
print(">CONNECT")
self.data = b""
self.transport.write(u"please relay {}\n".format(self.factory.token).encode("ascii"))

def dataReceived(self, data):
print(">RECV {} bytes".format(len(data)))
print(data.decode("ascii"))
self.data += data
if data == "ok\n":
self.transport.write("ding\n")

def connectionLost(self, reason):
if isinstance(reason.value, ConnectionDone):
self.factory.done.callback(None)
else:
print(">DISCONNCT: {}".format(reason))
self.factory.done.callback(reason)


@react
def main(reactor):
ep = endpoints.clientFromString(reactor, "tcp:localhost:4001")
f = Factory.forProtocol(RelayEchoClient)
f.token = "a" * 64
f.done = Deferred()
ep.connect(f)
return f.done
9 changes: 9 additions & 0 deletions docs/running.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ The relevant arguments are:
* ``--usage-db=``: maintains a SQLite database with current and historical usage data
* ``--blur-usage=``: round logged timestamps and data sizes

For WebSockets support, two additional arguments:

* ``--websocket``: the endpoint to listen for websocket connections
on, like ``tcp:4002``
* ``--websocket-url``: the URL of the WebSocket connection. This may
be different from the listening endpoint because of port-forwarding
and so forth. By default it will be ``ws://localhost:<port>`` if not
provided

When you use ``twist``, the relay runs in the foreground, so it will
generally exit as soon as the controlling terminal exits. For persistent
environments, you should daemonize the server.
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
],
package_data={"wormhole_transit_relay": ["db-schemas/*.sql"]},
install_requires=[
"twisted >= 17.5.0",
"twisted >= 21.2.0",
"autobahn >= 21.3.1",
],
extras_require={
':sys_platform=="win32"': ["pypiwin32"],
Expand Down
Loading