Commit Graph

1012 Commits

Author SHA1 Message Date
Brian Warner
b826e8c73c hack args till they work, add ALLOW_CLOSE
the diagram is a lot simpler if the only way to shut things down is to
terminate the whole process
2017-04-06 12:21:00 -07:00
Brian Warner
d136028fa8 try adding args 2017-04-06 12:21:00 -07:00
Brian Warner
73f3d86107 state machine should be complete, I think 2017-04-06 12:21:00 -07:00
Brian Warner
94b1ed8739 starting to draw new state machines 2017-04-06 12:21:00 -07:00
Brian Warner
65db4729cd rendezvous_websocket.py: add idempotency docs 2017-03-03 05:55:39 -08:00
Brian Warner
8d5770d8cc tor_manager: allow port to be a 'long' 2017-03-03 05:49:36 -08:00
Brian Warner
b7ff5f05d5 transit: allow port to be a 'long' 2017-03-03 05:49:30 -08:00
Brian Warner
cf9053637c test_util: free-space can be a 'long' 2017-03-03 05:49:25 -08:00
Brian Warner
71f34e4f5b test/run_trial.py: protect run() with __name__
Without this, any import (e.g. when running "automat-visualize") caused the
tests to be run as a side-effect.
2017-02-22 18:03:33 -08:00
Brian Warner
6889ba088c remove server/runner.py, no longer used 2017-02-22 17:52:14 -08:00
Shannon Mulloy
ffefb5ebdc improve coverage with input mock 2017-02-05 15:42:49 -08:00
Shannon Mulloy
33526b2180 rx: _remove_existing after accept 2017-02-05 13:29:20 -08:00
Shannon Mulloy
56a0a1f584 rx: allow overwrite with --output-file= #73 2017-02-04 19:27:09 -08:00
Brian Warner
20619bcce7 send: set allowZip64=True, to handle large (>2GB) directories
refs #138
2017-02-02 11:40:24 -08:00
Brian Warner
ed674e5ffe transit: increase connection timeout from 15s to 60s
I haven't seen any timeouts yet, but I'm thinking ahead to .onion connections
that might take longer than 15 seconds to establish.
2017-01-16 17:56:16 -05:00
Brian Warner
862820679c don't hang when asked to send a zero-length file
closes #98
2017-01-16 17:29:40 -05:00
Brian Warner
f2704c6ce0 cli: oops, fix ssh args
wish there were some tests for this
2017-01-16 11:34:32 -05:00
Brian Warner
df62e16462 cli: handle tor args in 'ssh' subcommands 2017-01-16 11:29:20 -05:00
Brian Warner
47007273ec rewrite Tor support (py2 only)
The new TorManager adds --launch-tor and --tor-control-port= arguments
(requiring the user to explicitly request a new Tor process, if that's what
they want). The default (when --tor is enabled) looks for a control port in
the usual places (/var/run/tor/control, localhost:9051, localhost:9151), then
falls back to hoping there's a SOCKS port in the usual
place (localhost:9050). (closes #64)

The ssh utilities should now accept the same tor arguments as ordinary
send/receive commands. There are now full tests for TorManager, and basic
tests for how send/receive use it. (closes #97)

Note that Tor is only supported on python2.7 for now, since txsocksx (and
therefore txtorcon) doesn't work on py3. You need to do "pip install
magic-wormhole[tor]" to get Tor support, and that will get you an inscrutable
error on py3 (referencing vcversioner, "install_requires must be a string or
list of strings", and "int object not iterable").

To run tests, you must install with the [dev] extra (to get "mock" and other
libraries). Our setup.py only includes "txtorcon" in the [dev] extra when on
py2, not on py3. Unit tests tolerate the lack of txtorcon (they mock out
everything txtorcon would provide), so they should provide the same coverage
on both py2 and py3.
2017-01-15 22:39:03 -05:00
Brian Warner
203216c0ff cli: move TorArgs out to separate decorator 2017-01-15 22:21:29 -05:00
Brian Warner
aa772858f5 cli: print useful error when --tor is requested but unavailable 2017-01-15 17:35:46 -05:00
Brian Warner
33370bb1b3 transit: mention tor when describing connections that use it 2017-01-15 17:03:40 -05:00
Brian Warner
bcac0c74f3 codes: don't assume 'readline' has a __doc__
This fixes cygwin, which (for some reason) doesn't include docstrings in the
readline module.

closes #111
2017-01-14 17:56:49 -05:00
Brian Warner
b3763f9e78 show "you can use tabs" reminder if code was input without completion
refs #15
2017-01-12 16:14:42 -08:00
Brian Warner
62b069dea6 Wormhole: control stderr 2017-01-12 16:14:42 -08:00
Brian Warner
2e3a0d4a1d change URL of public relay to new DNS names
These point to the same host (same IP address) as before, but the new names
are tied to the project's official domain (magic-wormhole.io), rather than my
personal one, so they can be managed independently.
2017-01-02 23:42:44 -05:00
Brian Warner
92f8c60b31 upgrade to versioneer-0.18 2017-01-01 14:10:57 -05:00
Brian Warner
7d995ca1d5 transit server: respect --blur-usage= by not logging connections 2017-01-01 13:00:35 -05:00
Brian Warner
b2fd899ac9 prioritize relay connections
closes #103
2016-12-31 00:33:00 -05:00
Brian Warner
8b864c3eae parse/transmit/record hint priorities
Use --transit-helper=tcp:HOST:PORT:priority=1.3 to override the default 0.0 .
Larger (positive) priority numbers will be attempted first.
2016-12-31 00:32:42 -05:00
Brian Warner
bc17047983 test_transit: refactor, simplify 2016-12-31 00:31:23 -05:00
Brian Warner
1abe733a81 more coverage: parse_hint_argv 2016-12-31 00:25:15 -05:00
Brian Warner
fe6ff466d8 more coverage: parse_tcp_v1_hint 2016-12-31 00:21:34 -05:00
Brian Warner
511a73c491 improve coverage: Transit._endpoint_from_hint_obj 2016-12-31 00:09:58 -05:00
Brian Warner
7f54d810eb remove unused+uncovered code 2016-12-31 00:08:26 -05:00
Brian Warner
e500f4a100 rx: tolerate duplicate peer messages
closes #121
2016-12-26 15:27:14 -05:00
Brian Warner
8b5d884636 add (failing/hanging) test of receiving duplicate messages
it's a pity this causes a hang, rather than a cleaner exception
2016-12-26 15:21:45 -05:00
Brian Warner
7ddf0d3c2d server: forbid reclaiming previously-closed nameplates
at least by the same side. This forces the contour of claims (by any given
side) to be strictly unclaimed -> claimed -> released. The "claim"
action (unclaimed -> claimed) is idempotent and can be repeated arbitrarily,
as long as they happen on separate websocket connections. Likewise for the
"release" action (unclaimed -> released). But once a side releases a
nameplate, it should never roll so far back that it tries to claim it again,
especially because the first claim causes a mailbox to be allocated, and if
we manage to allocate two different mailboxes for a single nameplate, then
we've thrown idempotency out the window.
2016-12-25 20:09:55 -05:00
Brian Warner
3a4a3f544f server: make close() idempotent
refs #118
2016-12-25 20:09:52 -05:00
Brian Warner
2c8d00e436 rendezvous_websocket.py: make release() idempotent
and make it possible to call release() even though you haven't called claim()
on that particular socket (releasing a claim that was made on some previous
websocket).

This should enable reconnecting clients, as well as intermittently-connected
"offline" clients.

refs #118
2016-12-25 20:09:48 -05:00
Brian Warner
b44fcf77da test_server: improve debug message 2016-12-25 20:00:05 -05:00
Brian Warner
a746ca726a test_server: factor out common utils 2016-12-25 19:13:00 -05:00
Brian Warner
3ad29379b5 server: fix comment 2016-12-25 14:36:50 -05:00
Brian Warner
9f72b72b76 split Transit out of test_server.py 2016-12-24 17:44:40 -05:00
Brian Warner
72dfb6eb1c write progress/status messages to stderr, not stdout
This should leave stdout clean for use in `foo | wormhole send --text=-` and
`wormhole rx CODE >foo`, although the forms that want interactive code entry
probably won't work that way.

closes #99
2016-12-24 00:03:32 -05:00
Brian Warner
fde98b7c7e more coverage 2016-12-23 22:22:39 -05:00
Brian Warner
db968900d9 test_server: improve coverage 2016-12-23 22:22:39 -05:00
Brian Warner
b8313b4595 dedup relays, include our own relay when connecting
* Previously, we only connected to the relay supplied by our partner, which
  meant that if our relay differed from theirs, we'd never connect
* But we must de-duplicate the relays because when our relay *is* the same as
  theirs, we'd have two copies, which means two connections. Now that we
  deliver sided handshakes, we can tolerate that (previously, our two
  connections would be matched with each other), but it's still wasteful.

This also fixes our handling of relay hints to accept multiple specific
endpoints in each RelayHint. The idea here is that we might know multiple
addresses for a single relay (maybe one IPv4, one IPv6, a Tor .onion, and an
I2P address). Any one connection is good enough, and the connections we can
try depend upon what local interfaces we discover. So a clever implementation
could refrain from making some of those connections when it knows the sibling
hints are just as good. However we might still have multiple relays entirely,
for which it is *not* sufficient to connect to just one.

The change is to create and process RelayV1Hint objects properly, and to set
the connection loop to try every endpoint inside each RelayV1Hint. This is
not "clever" (we could nominally make fewer connection attempts), but it's
plenty good for now.

refs #115

fix relay hints
2016-12-23 22:22:39 -05:00
Brian Warner
80ae9236df make RelayV1Hint objects hashable/comparable 2016-12-23 22:22:39 -05:00
Brian Warner
e1546bf03f Transit: send new (sided) handshakes 2016-12-23 22:22:39 -05:00
Brian Warner
5fcea701bb transit server: accept both new (sided) and old (unsided) handshakes 2016-12-22 23:54:36 -05:00
Brian Warner
c7e4d57405 improve relay test 2016-12-22 23:53:29 -05:00
Brian Warner
f2e011bc9c Add --appid to override the APPID, for subprocess-based wrappers.
Tools which use `wormhole send` under the hood should use a distinct
--appid= (setting the same URL-shaped value on both sides, starting with a
domain name related to the tool and/or its author), so wormhole codes used by
those tools won't compete for short channelids with other tools, or the
default text/file/directory-sending tool.

Closes #113
2016-12-22 15:44:13 -05:00
Brian Warner
57c0894774 cmd_send: flush args.stdout, in case it's different 2016-12-17 17:32:12 -08:00
Joey Hess
8bec79289a send: flush stdout after displaying code
Fixes https://github.com/warner/magic-wormhole/issues/108

Apparently python defaults to buffering stdout when not outputting to
the terminal. It would be better IMHO if every line of stdout were
autoflushed, but based on
http://stackoverflow.com/questions/107705/disable-output-buffering
there's not a really good way to accomplish that in python.
2016-12-17 17:20:45 -04:00
Brian Warner
30af04d245 test_scripts: rename mode to be "slow-text" 2016-12-16 01:33:45 -08:00
Brian Warner
face9423dd internals: ensure _API_establish_key is not called twice 2016-12-16 01:33:17 -08:00
laharah
2d1f474c60 rebased and fixed merge error 2016-12-16 01:06:21 -08:00
laharah
6bdaaf368c Moved slow connection notification to stderr
added test for slow connection notifications
2016-12-16 01:06:21 -08:00
laharah
01318d1130 added notification to cmd_receive plus reactor cleanup
Added a try finally block around verify to ensure notification
deferreds are being cleaned out of the reactor
2016-12-16 01:03:01 -08:00
laharah
a2ab1863cf added the new key waiter to be cleaned up on error in wormhole
Also, set new print statment to print to args.stdout
2016-12-16 01:03:01 -08:00
laharah
f786031f40 basic key established hook added to CLI send 2016-12-16 01:03:01 -08:00
laharah
680b01b3fc added api hooks to get notification about key excange
added more coverage to establish key API hook
2016-12-16 01:03:01 -08:00
laharah
33fa6f6ede tests for new establish_key wormhole hook
defered should behave similarly to the `verify` hook
2016-12-16 01:03:01 -08:00
Brian Warner
5c751eb3ed fix tests on windows 2016-12-15 19:52:26 -08:00
Brian Warner
f3e1aab3a1 reject transfers when there isn't enough disk space available
closes #91

Also tweaks an error message: don't say "refusing to clobber pre-existing
file FOO" when we don't check that it's actually a file. Just say "..
pre-existing 'FOO'".
2016-12-15 19:52:26 -08:00
Brian Warner
b57928431a add utility to estimate free disk space 2016-12-15 19:52:26 -08:00
Brian Warner
2596c58e4a ipaddrs: import function from latest Tahoe
I'm hoping this will help with Cygwin (#13), by removing/bypassing the
assert(os.path.isabs) check.
2016-12-10 13:06:27 -08:00
Brian Warner
58f20d79a7 update to versioneer-0.17
This should fix the pyflakes error when running tox on an unpacked sdist.
2016-12-10 10:36:59 -08:00
Brian Warner
f0bfcd7ca4 fix some py2/py3-isms picked up by mypy
These happened to work, but it's probably best to get the types right.
2016-12-08 23:47:53 -08:00
Brian Warner
582cebfb5f rx: don't reveal file-already-exists, just reject transfer
closes #74
2016-12-08 16:59:54 -08:00
Brian Warner
ab972785aa CLI: don't emit traceback for TransferErrors
But do print the message contained therein

refs #74
2016-12-08 16:59:52 -08:00
Brian Warner
58c7639635 CLI: exit with rc=1 upon errors 2016-12-08 16:59:02 -08:00
Antoine Beaupré
e9cd5b5d60 fix capitalization output to match humanize 2016-11-17 11:36:00 -05:00
Antoine Beaupré
342bebbd0e use humanize library instead of custom implementation 2016-11-11 22:01:21 -05:00
Antoine Beaupré
047af4b27d use human-readable sizes more broadly
there was a function to "abbreviate" sizes, but it was somewhat
unclear and incomplete. reuse the sizeof_fmt_* set of functions from
the borg backup project (MIT licensed) to implement a more complete
and flexible display that will scale up to the Yottabyte and
beyond. it also supports non-IEC units (like "kibibyte", AKA 1024
bytes) if you fancy that stuff.

this is a workaround for #91: it allows users to better see the size
of the file that will be transfered.

*some* places are still kept in bytes, most notably when receive fails
to receive all bytes ("got %d bytes, wanted %d") because we may want
more clarity there.

text transfers also use the "bytes" suffix (instead of "B") because it
will commonly not reach beyond the KiB range.

note that the test suite only covers decimal (non-IEC) prefix, but it
is assumed to be sufficient to be considered correct.
2016-11-09 15:14:01 -05:00
Brian Warner
0004315431 transit: tolerate non-ascii bad handshake
I think somebody was port-scanning the server (or pointed some
non-wormhole client at it), and caused some exceptions in the logs.
These are still bad handshakes, but should be logged normally instead of
throwing exceptions.
2016-08-22 23:13:04 -07:00
Tom Lowenthal
9dd1d738e1 Fix small CLI typo
The output for verified copies asks the user to run `wormhole --verify receive`, but the correct argument order is `wormhole receive --verify`.
2016-08-15 17:39:52 -07:00
Brian Warner
f449466f4f update tests 2016-08-15 17:36:55 -07:00
Brian Warner
899e539cb1 cmd_ssh: ~ is not always /home
On OS-X, in particular, ~foo expands to /Users/foo . We delegate
everything to os.path.expanduser(), which should know the local
convention.
2016-08-15 17:35:38 -07:00
Brian Warner
75d362f60a add some basic tests, doesn't cover everything 2016-08-15 17:35:34 -07:00
Brian Warner
d057b91371 xfer_util: work on py2+py3
wormhole.send takes bytes, but the utility functions take strings. So
encode the JSON blob before sending, and decode it on the way back out.
2016-08-15 17:35:34 -07:00
meejah
fe29b3130b 'wormhole ssh' cleanups
- move to 'wormhole ssh' group with accept/invite subcommands
- change names of methods
- check for permissions
- use --user option (instead of --auth-file)
- move implementation to cmd_ssh.py
- if multiple public-keys, ask user
2016-08-15 00:30:39 -06:00
meejah
069b76485b Add 'wormhole ssh-add' and 'wormhole ssh-send' commands 2016-08-14 19:59:20 -06:00
meejah
026c8fd093 Print proper tracebacks when inlineCallbacks + yield involved 2016-08-14 16:50:29 -06:00
meejah
afa123abae make tests work on pypy 2016-08-04 15:57:01 -04:00
David Reid
6aa8a47f9a Use StreamServerEndpointService (available since Twisted 10.2) 2016-08-04 00:23:02 -07:00
Brian Warner
dc6416a257 fix stats-writing bug on py3
refs #67
2016-08-01 16:31:05 -07:00
Daniel Kahn Gillmor
2fafdf34ee help bad spelers
Some of us can never remember the old ditty:

   i before e, except after c
   or when sounding like "a"
   as in neighbor or weigh.

Perhaps magic wormhole can coddle us in our misorthography :)
2016-07-31 18:55:42 -04:00
Brian Warner
0ba59136a0 upgrade to versioneer-0.16 2016-07-27 19:08:12 -07:00
Brian Warner
5542545165 CLI: move most top-level args down into the subcommand
So instead of "wormhole --verify send", use "wormhole send --verify".

The full set of arguments that were moved down:

* --code-length=
* --verify
* --hide-progress
* --no-listen
* --tor

The following remain as top-level arguments (which should appear after
"wormhole" and before the subcommand):

* --relay-url=
* --transit-helper=
* --dump-timing=
* --version
2016-07-27 17:56:03 -07:00
Brian Warner
e6b38ecacc cli: start factoring out args into common sets 2016-07-23 17:54:29 -07:00
Brian Warner
37b8ccbe4f cli: mostly use kwargs/setattr 2016-07-22 19:13:59 -07:00
Brian Warner
1a82846578 cli.Config: remove common attributes
The values set by the base Config constructor could mask Click parsers
that weren't supplying defaults properly, or which were using different
defaults.
2016-07-14 22:37:35 -06:00
Brian Warner
52ef00b46b CLI: refactor to make testing easier
When tests need a Config object, they now call a function which invokes
Click with a mocked-out go() function, and grabs the Config object
before actually doing anything with it.
2016-07-14 22:34:10 -06:00
Brian Warner
cdb5c19010 websockets: turn on autoPingInterval to expire stale connections
With this, both clients and servers will send a PING at least once every
minute, and will drop connections that haven't seen any traffic for 10
minutes.

This should help keep NAT table entries alive, and will drop connections
that are no longer viable because their NAT entries have expired.

closes #60
2016-07-03 21:51:56 -07:00
Brian Warner
4978be6b90 args: fix --no-listen, --tor
Also add tests to check that argv is being parsed properly, and to check
the defaults.

fixes #59
2016-06-27 14:40:51 -07:00
Brian Warner
0f8b98dec5 DB: log schema upgrades 2016-06-26 18:04:00 -07:00
Brian Warner
de8efdb9f9 cmd_send: wait for ack from close()
Without this, the sender drops the connection before the "close" message
has made it to the server, which leaves the mailbox hanging until it
expires. It still lives in a 'd.addBoth()' slot, so it gets closed even
if some error occurrs, but we wait for it's Deferred to fire in both
success and failure cases.
2016-06-26 17:55:28 -07:00
Brian Warner
1d3b22a0b4 server: hard-code --stats-file=stats.json
We already hard-code 'relay.sqlite', so I don't see a lot of value in
making making the stats file configurable too. That said, if it makes
life easier for packagers (e.g. start-stop-daemon or systemd wanting
these files to go into /var/run/something/ , and if it isn't sufficient
to just use /var/run/something/ as the CWD), I'd accept a patch to
add it back.
2016-06-26 17:55:28 -07:00
Brian Warner
930ed2c089 server: log get_stats time
The DB queries this uses aren't particularly efficient, and when the
time it takes to run starts to become a problem, we should do an
optimization pass.
2016-06-26 17:49:36 -07:00
Brian Warner
45d46643ca transit: rename stats keys 2016-06-26 17:49:36 -07:00
Brian Warner
f950161642 rendezvous: rename stats keys for consistency 2016-06-26 17:49:36 -07:00
Brian Warner
638adc71ec server: add transit to stats.json 2016-06-26 17:49:35 -07:00
Brian Warner
cd934fdfde server: rename stats.json keys 2016-06-26 17:49:35 -07:00
Brian Warner
44bc99e987 get_stats: update comments 2016-06-26 11:25:25 -07:00
Brian Warner
f192db5412 track+report mailbox.for_nameplate in usage
This counts the number of "standalone" mailboxes we create, which
happens when a client does open() without first using a nameplate. The
current client doesn't do this, but future clients might.
2016-06-26 11:19:53 -07:00
Brian Warner
db8511c700 schema: add mailbox_usage.for_nameplate too 2016-06-26 11:18:48 -07:00
Brian Warner
bae020d5a7 DB: add mailboxes.for_nameplate
Also add a few indexes to make get_stats() less expensive
2016-06-26 11:01:52 -07:00
Brian Warner
8eb1396f31 server: delete stats file at reboot
This makes it easier to discover an exception in the stats-gathering
timer, since you get a missing stats.json instead of a stale one.
2016-06-26 11:01:52 -07:00
Brian Warner
7b1d4cbcee more stats: count since last reboot 2016-06-26 11:01:52 -07:00
Brian Warner
9e29898207 Rendezvous: add many stats 2016-06-26 11:01:48 -07:00
Brian Warner
62f9a4d702 move stats-file up to RelayServer
This moves responsibility for the periodic prune-everything Timer up to
RelayServer too. That way we can be sure the stats are dumped
immediately after prune, and we can incorporate stats from Transit as
well.
2016-06-25 11:43:13 -07:00
Brian Warner
7f389dc76e server: add --stats-file= scaffolding
no actual stats yet
2016-06-25 11:05:28 -07:00
Brian Warner
cfcd74db4b remove listener on close too
This was failing to clean up after WrongPassword disconnects.
2016-06-24 18:57:49 -07:00
Brian Warner
6a2cbf9014 server: remove listeners on disconnect
This wasn't happening before, so channels were staying alive until
reboot.
2016-06-24 18:48:28 -07:00
Brian Warner
ffb1a9b9c9 change pruning algorithm
The new approach runs every 10 minutes and keeps a
nameplate/mailbox/messages "channel" alive if the mailbox has been
updated within 11 minutes, or if there has been an attached listener
within that time.

Also remove the "nameplates.updated" column. Now we only track "updated"
timestamps on the "mailboxes" table, and a new mailbox will preserve any
attached nameplate.
2016-06-24 17:35:23 -07:00
Brian Warner
6176500cf4 factor out Mailbox._touch 2016-06-24 16:35:30 -07:00
Brian Warner
0158df9b63 stop using is_active(), or pruning inactive apps
Unless/until people start writing new applications (with different
app-ids), this code is unlikely to get used very much, and the code is
simpler without it.
2016-06-24 16:31:00 -07:00
Brian Warner
08443ee288 rename Rendezvous.prune() to prune_all_apps
so grep can distinguish it from Mailbox.prune()
2016-06-24 16:30:55 -07:00
Brian Warner
b8521e81b1 add comment about new pruning plan 2016-06-24 16:26:42 -07:00
Brian Warner
3c0f832bdc test that mailbox timestamp is updated correctly 2016-06-24 16:25:44 -07:00
Brian Warner
550b9e3c94 db: add v2->v3 upgrader 2016-06-24 16:19:39 -07:00
Brian Warner
404925d314 server: mailbox row should always exist
This makes the nameplate's "mailbox_id" into a foreign-key.
2016-06-24 16:02:37 -07:00
Brian Warner
41f229de87 use 'mailbox_sides' instead of cols in 'mailboxes' 2016-06-24 00:01:51 -07:00
Brian Warner
6c725e4a86 db: use 'nameplate_sides' instead of cols in 'nameplates' 2016-06-23 18:27:26 -07:00
Brian Warner
355ece3e47 db: turn on foreign keys 2016-06-23 18:27:26 -07:00
Brian Warner
74a1902fcd schema: add v3, rename nameplates.id to .name 2016-06-23 18:27:26 -07:00
Brian Warner
6d00576ee4 server-stop: ignore missing twistd.pid
I changed my mind, it's actually easier if 'wormhole-server stop' (and
'restart') does *not* throw an error when there wasn't already a server
running in that directory. Specifically that lets me use 'restart' as an
idempotent "make sure a server is running" command.
2016-06-23 18:25:58 -07:00
Brian Warner
fa29789769 test_scripts: re-enable tests on py3
These weren't running because Click complained about an ASCII locale
when running under py3, which triggered an error check that was there to
detect broken virtualenvs, skipping those tests.

The fix appears to be to force the en_US.UTF-8 locale when running the
wormhole program in a subprocess.
2016-06-22 19:28:17 -07:00
Brian Warner
177aac2d84 test upgrader, badly
This adds a test for database upgrades, which I developed on a branch
that added a new DB schema (v3) and an upgrader to match, but then I
changed my mind about the schema and removed that part. The test will be
useful some time in the future when I change the schema in a small
enough way that I bother to write an upgrader for the change. For now,
the test is disabled.

In addition, the upgrader test is kind of lame. I'd really prefer to
assert that the upgraded schema is identical to the schema of a
brand-new (latest-version) database, but ALTER TABLE doesn't quite work
that way (comments are omitted, and the order of the columns is slightly
different).

This also adds database.dump_db() for the tests.
2016-06-22 19:05:52 -07:00
Brian Warner
7250deb94c add schema upgrades 2016-06-22 19:05:48 -07:00
Brian Warner
b613ac1b3b cli.py: add comment 2016-06-22 13:15:07 -07:00
Brian Warner
60b40c2de2 server/cli.py: remove timing instrumentation
I don't anticipate ever caring how long it takes to import code on the
server side. Only the client's performance is interesting to me.
2016-06-22 13:12:45 -07:00
Brian Warner
d8c2c1249e server/cli.py: fix port numbers
There was some vestigal server-cli code (leftover in the client-side
wormhole.cli.cli_args) that used port 3000/3001, and it accidentally got
used for the new Click-based parser, rather than the actual server-cli
code (in wormhole.server.cli_args) that uses port 4000/4001. This
changes the port numbers to match (everything uses 4000/4001 these days,
to avoid confusing interactions with the old 0.7.6 server that might
still be listening on the old ports).
2016-06-22 13:12:34 -07:00
Brian Warner
940aec7570 cli.py: improve parallelism between send+receive 2016-06-22 13:11:43 -07:00
Brian Warner
b1f994e939 transit.py: improve error 2016-06-22 13:10:46 -07:00
meejah
7fab6b3dff Change UsageError -> InternalError, use click.UsageError for human-visible errors 2016-06-22 02:14:34 -06:00
meejah
6b29d62d78 typo 2016-06-22 01:29:13 -06:00
meejah
03594a2d0e consistent return usage 2016-06-22 01:28:53 -06:00
meejah
ad6200c474 resolve XXX comments 2016-06-22 01:27:29 -06:00
meejah
c4cd4db30e Correct exit code when no twistd.pid file 2016-06-22 01:25:47 -06:00
meejah
e16b53817e Refactor to use Click 2016-06-22 01:11:07 -06:00
Brian Warner
d89fbd69dd sketching out a click-based CLI parser 2016-06-22 01:02:09 -06:00
meejah
07b4067727 unit-test for relay request, and fix Data() handling 2016-06-20 16:32:07 -07:00
laharah
2a056059c0 fix for wormhole-server count-* functions
broken when we switched to dictfactory on db
2016-06-04 16:50:56 -07:00
laharah
150caedf73 u"" cleanup on test_scripts.py 2016-06-04 14:09:19 -07:00
laharah
bb970dafc0 u"" cleanup on test_server.py 2016-06-04 14:09:19 -07:00
laharah
2dd76f57c0 u"" cleanup on test_transit.py 2016-06-04 14:09:19 -07:00
laharah
aff13e9121 u"" cleanup on test_util.py 2016-06-04 14:09:19 -07:00
laharah
8fa40d3cd5 u"" cleanup on test_wormhole.py 2016-06-04 14:09:19 -07:00
laharah
255fb12f88 `u"" cleanup on cmd_usage.py 2016-06-04 14:09:19 -07:00
laharah
57d117e4f0 u"" cleanup on rendezvous_websocket.py 2016-06-04 14:09:19 -07:00
laharah
8537d90527 u"" cleanup on rendezvous.py 2016-06-04 14:09:19 -07:00
laharah
2c38795476 u"" cleanup on transit_server.py 2016-06-04 14:09:19 -07:00
laharah
64f7348d05 u"" cleanup on util.py and codes.py 2016-06-04 14:09:19 -07:00
laharah
2c25b4d97d u"" cleanup on wormhole.py 2016-06-04 14:09:19 -07:00
laharah
6a73d50fdd added unicode_literals import to all apropriate modules
bug in twisted serverFromString prevents test.common and transit
from using unicode properly should revisit if twisted gets patched
2016-06-04 12:42:59 -07:00
laharah
33758abd18 added a dict_factory as a new row_factory for the database 2016-06-04 12:28:09 -07:00
Brian Warner
7c15cf7353 code input: don't eat "b" under GNU readline
GNU libreadline, and the libedit-based library shipped on stock OS-X
python, require different key-binding syntaxes to enable tab completion.
The previous commit to fix this (0977ef0) added both binding commands
Unfortunately when GNU libreadline is given the libedit-style
command (i.e. "bind ^I rl_complete"), it binds the letter "b" to a
non-existent command "ind", or something, and as a result the letter "b"
doesn't work anymore.

This patch uses the readline docstring to sense which flavor is
installed, and only runs the one binding command that's appropriate.

refs #37
2016-06-04 00:52:27 -07:00
Brian Warner
996c739b2a oops, fix tests
In some tests, we artificially call _event_connected() without first
initiating a connection.
2016-06-03 23:30:31 -07:00
Brian Warner
a1ce0d8df0 record websocket establishment in timing data 2016-06-03 22:55:52 -07:00
Brian Warner
e13b95660b test_transit: tolerate a localhost-only system
e.g. Appveyor . Refs #16.
2016-06-03 21:46:56 -07:00
Brian Warner
682fe0ae2c transit: allow 127.0.0.1 if that's all we've got
The appveyor tests were failing because their VMs only have 127.0.0.1,
and stripping it out resulted in an empty hint list, which meant Transit
couldn't work at all.
2016-06-03 18:22:53 -07:00
higs4281
55f2fcc3a7 remove commented line 2016-06-03 18:18:34 -07:00
higs4281
eaed2f0a12 Prevent transmit from suggesting 127.0.0.1
The test runs the listener locally, which can turn up 127.0.0.1.
The added code in transmit stops the hint.
2016-06-03 18:18:34 -07:00
Brian Warner
26445c3fc4 test_scripts: fix on windows 2016-06-03 16:43:22 -07:00
Brian Warner
a8c2fb14b1 expire channels faster: 2 hours, not 3 days
With increased usage, I'm seeing a buildup of stale channels. Since the
channels aren't properly ephemeral yet (where they get closed as soon as
the last subscriber disconnects), clients which terminate without
calling close() tend to leave the channel lying around. We don't have
"persistent wormholes" yet, so channels should be much more ephemeral
than they currently are.
2016-06-03 16:23:28 -07:00
Brian Warner
48cc85e88c add file-mode checks to directory test
This new test failed before fixing _extract_file, and now it passes.
2016-06-03 16:05:51 -07:00
Brian Warner
71512809a9 extract _extract_file, add test 2016-06-03 15:38:49 -07:00
Kurt Neufeld
e6f5b9cea4 verify that extracted files are inside abs_destname
also fixed bug where TwistedReceiver.abs_destname was not in fact
absolute.
2016-06-03 14:32:52 -07:00
Kurt Neufeld
b04e434ad4 restore file permissions when extracting zipfile 2016-06-03 12:36:11 -07:00
Kurt Neufeld
608af12b1d verified that ZIP_DEFLATED compresses the files
The docs are a bit misleading but that's how I interpret them.
2016-06-03 11:53:45 -07:00
Brian Warner
0977ef02c4 do tab-completion on OS-X stock python too (libedit)
Apple's stock python doesn't use GNU libreadline, instead it uses BSD
libedit with a readline compatibility interface. The syntax to enable
tab completion is different for libedit. By including both bindings,
autocomplete should work on both flavors.

Closes #37. Thanks to @wsanchez for the catch and the fix.
2016-06-02 20:55:02 -07:00
meejah
5b23669cf3 use ipaddress not ipaddr 2016-06-02 16:20:12 -07:00
Chris Wolfe
0ad8df3750 flush the correct error 2016-06-02 15:21:31 -07:00
Chris Wolfe
65713d8652 make the error message for the cli a bit more specific 2016-06-02 15:21:31 -07:00
Chris Wolfe
bc7dea8bab add simpler exception message, assert that it is being used 2016-06-02 15:21:31 -07:00
Chris Wolfe
5be436b81d raise a specific error when spaces are detected, pass along the docstring to the user 2016-06-02 15:21:31 -07:00
Chris Wolfe
d4d3320277 add failing test, error 2016-06-02 15:21:31 -07:00
Brian Warner
00277c22cf allow MOTD to be displayed multiple times
(one displayed message per received welcome["motd"])

There's not much value in prohibiting the server from sending multiple
MOTD messages, and it would prevent us from using it to display a "your
client is using an old API, please upgrade" message after having already
sent a regular "please donate" MOTD message. (We could send a second
welcome message with ["error"] to kill the client, but ["motd"] is the
most convenient way to deliver a non-fatal warning).
2016-05-28 19:19:22 -07:00
Brian Warner
ea6619bc46 change hostname of public relay
This is an alias for the same host, so it's not really an incompatible
change. The new hostname is my personal domain, and seems a bit more
suitable for this service.
2016-05-28 19:13:44 -07:00
Brian Warner
52e5cbd690 INCOMPATIBILITY: send "current_cli_version", not "current_version"
The reasoning is that this string is only ever likely to refer to the
version of the primary/initial client (the CLI application, written in
Python, that you get with "pip install magic-wormhole"). When there are
other implementations, with unrelated versions, they should obviously
not pay attention to a warning about the other implementation being out
of date.
2016-05-28 19:11:27 -07:00
Brian Warner
0b53094927 INCOMPATIBILITY: send pake message as dict, not raw bytes
This gives us room in the future to put other keys there, like one which
says we want to use Noise for the phase-message encryption instead of
our current HKDF scheme.
2016-05-28 18:30:36 -07:00
Brian Warner
6a108f93e6 switch most everything to use new utility functions 2016-05-28 18:19:45 -07:00
Brian Warner
3850c164f7 move utility functions to util.py, add new ones 2016-05-28 18:13:32 -07:00
Brian Warner
0d30101d7c SCHEMA CHANGE: add 'request_id' to nameplates table
This will be useful for the upcoming "persistent wormhole" mode. A
client might send an allocation request, crash/terminate before
receiving a response, then restart, then re-send the request. If the
server sees a request with the same request_id a previous request, it
can return the same nameplate.

We'll need code changes on both sides to support this (nothing sends or
checks request_id yet), but this lands the schema change early to reduce
future disruption.
2016-05-28 11:46:14 -07:00
Brian Warner
cca2f3cf13 internal rename msg_id, for consistency 2016-05-28 11:19:53 -07:00
Brian Warner
00efdfa4e2 comment out unfinished function
at this point, it's just an idea
2016-05-27 18:47:14 -07:00
Brian Warner
5fe7d320ab oops, pass blur_usage to apps properly, add tests 2016-05-27 18:44:41 -07:00
Brian Warner
eebc9ebd54 rewrite pruning, add full tests
Apparently it was broken: the first time the LoopingCall fired, it would
throw an exception, and never try again. Now it should be fixed.
2016-05-27 18:42:17 -07:00
Brian Warner
0b3863fb52 remove dead code 2016-05-27 18:41:34 -07:00
Brian Warner
5dddeddffd fix "wormhole-server restart" default ports to match plain "start"
now that was confusing.
2016-05-27 18:40:37 -07:00
Brian Warner
1c963170c3 wormhole-server: add count-channels, count-events 2016-05-26 17:45:41 -07:00
Brian Warner
56fec496e2 send transit abilities to far end too, for the future
This will allow a future peer to figure out what transit modes we can
and cannot do, and thus avoid spinning up expensive modes that we won't
be able to use (e.g. WebRTC).
2016-05-26 16:26:00 -07:00
Brian Warner
db31ffe075 minor shuffles 2016-05-26 15:49:45 -07:00
Brian Warner
7acb68d2ee allow WelcomeError to interrupt input_code() 2016-05-26 15:38:19 -07:00
Brian Warner
905ec05696 fix welcome-error signalling
The handler was calling _signal_error() incorrectly.
2016-05-26 15:37:24 -07:00
Brian Warner
80c88387ef improve formatting of error messages 2016-05-26 15:36:44 -07:00
Brian Warner
19702e01ac make send pay attention to receiver errors correctly
Errors like "Refusing to overwrite existing file" would leave the sender
hanging, because it was looking for the "error" key in the wrong place.
2016-05-25 22:44:18 -07:00
Brian Warner
de627ccbef fix --dump-timing= on py3, wants a text-mode file 2016-05-25 22:06:26 -07:00
Brian Warner
708bcf36d4 INCOMPATIBILITY: send+expect hash of data after xfer
This enhances the ACK that wormhole-receive returns when it finishes
receiving all the data to be a dictionary. The dict includes the SHA256
hash of everything it received, and the sender checks this for a match
before declaring the transfer to be a success. This guards against data
being shuffled somehow during transit.
2016-05-25 19:36:56 -07:00
Brian Warner
d8f6126916 transit.writeToFile: add hasher= argument 2016-05-25 19:35:50 -07:00
Brian Warner
01ec5fb2a6 rename test_transit_twisted.py, drop the twisted 2016-05-25 19:21:54 -07:00
Brian Warner
75877effef finish renaming "confirm" to "version" 2016-05-25 19:13:56 -07:00
Brian Warner
dcdddc9d60 INCOMPATIBILITY: rename "confirm" phase to "version"
This better reflects the purpose of the message. Key confirmation is a
side-effect.

This patch only changes the "phase:" name and the key-derivation string.
A subsequent patch will modify the function and variable names to match.
2016-05-25 19:13:56 -07:00
Brian Warner
424474cd7e remove unused _derive_confirmation_key() 2016-05-25 19:13:56 -07:00
Brian Warner
7f43561a50 INCOMPATIBILITY: change "confirm" message to include version dict
This gives the two Wormholes a way to signal capabilities to each other,
before the applications start sending their own messages.
2016-05-25 18:27:37 -07:00
Brian Warner
e1c488247f remove redundant test 2016-05-25 18:27:24 -07:00
Brian Warner
5553729a87 w.verify() now stalls until confirmation message is checked
If it succeeds, you get back the verifier string, which can be compared
against the other side. If it fails, the wormhole code didn't match.
2016-05-25 18:05:02 -07:00
Brian Warner
8b56892a76 drop peer messages if we're closing
This should remove a few Unhandled Errors when the code was wrong.
2016-05-25 16:29:56 -07:00
Brian Warner
a251e58967 oops, fix tests to use /v1 too 2016-05-25 00:34:13 -07:00
Brian Warner
1fabf18f0e INCOMPATIBILITY: move relay url to /v1
This should make it cleaner to add a /v2 in the future.
2016-05-25 00:29:23 -07:00
Brian Warner
f2050c5fd4 internal renaming: hint objects vs hint structs 2016-05-25 00:23:12 -07:00
Brian Warner
7aa55e6b65 INCOMPATIBILITY: deliver hints as JSON, not strings
The file-send protocol now sends a "hints-v1" key in the "transit"
message, which contains a list of JSON data structures that describe the
connection hints (a mixture of direct, tor, and relay hints, for now).
Previously the direct/tor and relay hints were sent in different keys,
and all were sent as strings like "tcp:hostname:1234" which had to be
parsed by the recipient.

The new structures include a version string, to make it easier to add
new types in the future. Transit logs+ignores hints it cannot
understand.
2016-05-25 00:11:17 -07:00
Brian Warner
afdbbe84c3 cmd_send: allow multiple things in a single message 2016-05-24 19:30:55 -07:00
Brian Warner
8e7c6f16cb cmd_receive: tolerate unrecognized messages
at the expense of not failing quickly when the sender doesn't send an
offer
2016-05-24 19:30:21 -07:00
Brian Warner
1b5f3e125e cmd_receive: add underscore prefix to all internal methods 2016-05-24 19:14:56 -07:00
Brian Warner
812fd0b4da INCOMPATIBILITY: send "transit" message before offer/answer
In the future, both sides should expect to receive "transit" messages at
any time, and they will add to the list of hints that they should try.
For now, each side only sends a single transit message, before they send
the offer (sender) or answer (receiver).
2016-05-24 18:59:04 -07:00
Brian Warner
1a9e565fc3 cmd_send: turn into a self-contained class
This will make it easier to maintain state.
2016-05-24 17:44:41 -07:00
Brian Warner
ac1db705fe INCOMPATIBLE CHANGE: put offer/answer in their own keys
This moves us slowly towards a file-transfer protocol that exchanges
multiple messages, with a single offer (sender->receiver) and
answer (receiver->sender), and one or more connection hint messages (in
either direction) that appear gradually over time as connection
providers come online.

At present the protocol still expects the whole hint list to be present
in the offer/answer message.
2016-05-24 17:32:30 -07:00
Brian Warner
96f25ec7a2 rename phase1 to offer/answer
rearrange cmd_send a bit to do less before the Wormhole is built
2016-05-24 16:41:13 -07:00
Brian Warner
0414051df2 remove wormhole/twisted/ 2016-05-24 16:26:17 -07:00
Brian Warner
c06bc83d3f remove unused twisted/eventual.py 2016-05-24 16:25:37 -07:00
Brian Warner
c218b939c0 move wormhole.twisted.tor_manager up to wormhole/ 2016-05-24 16:25:12 -07:00
Brian Warner
7140565b99 move wormhole.twisted.ipaddrs up to wormhole/ 2016-05-24 16:23:52 -07:00
Brian Warner
0e1a4dd513 move wormhole.twisted.transit up to wormhole.transit 2016-05-24 16:22:37 -07:00
Brian Warner
4b3d53ba4e log+ignore unrecognized phase messages
This should enable forwards-compatibility with clients which send extra
data, like a pre-PAKE "auxdata" message that hints we should spin up a
tor client (because they can connect to it) while we're waiting for the
user to type in the wormhole code.
2016-05-24 16:15:43 -07:00
Brian Warner
783cd984f6 add 'coverage' environment for tox 2016-05-24 16:03:39 -07:00
Brian Warner
90e6d23c17 change server default port to match new public relay 2016-05-24 14:12:10 -07:00
Brian Warner
30ab940034 INCOMPATIBLE: change derivation of phase keys to include side
Previously the encryption key used for "phase messages" (anything sent
from one side to the other, protected by the shared PAKE-generated
session key) was derived just from the session key and the phase name.
The two sides would use the same key for their first message (but with
random, thus different, nonces).

This uses the sending side's string (a random 5-byte/10-character hex
string) in the derivation process too, so the two sides use different
keys. This gives us an easy way to reject reflected messages. We already
ignore messages that claim to use a "side" which matches our own (to
ignore server echoes of our own outbound messages). With this change, an
attacker (or the server) can't swap in the payload of an outbound
message, change the "side" to make it look like a peer message, and then
let us decrypt it correctly.

It also changes the derivation function to combine the phase and side
values safely. This didn't matter much when we only had one
externally-provided string, but with two, there's an opportunity for
format confusion if they were combined with a simple delimiter. Now we
hash both values before concatenating them.

This breaks interoperability with clients from before this change. They
will always get WrongPasswordErrors.
2016-05-24 13:47:15 -07:00
Brian Warner
97c5d08b6a internally, _derive_key now takes bytes
The w.derive_key(purpose) API still requires unicode.
2016-05-24 13:31:03 -07:00
Brian Warner
7c8e5fb062 factor out key-derivation, prepare for change 2016-05-24 13:26:08 -07:00
Brian Warner
77661bf94e use new relay URL, for new protocol 2016-05-24 13:10:45 -07:00
Brian Warner
c5b174dd6a Merge branch 'master' into new-proto 2016-05-24 13:08:21 -07:00
Brian Warner
fb2ffe1963 add --signal-error to restart too 2016-05-24 12:59:02 -07:00
Brian Warner
a2b88dbf61 server: add --signal-error CLI argument 2016-05-24 12:46:42 -07:00
Brian Warner
1ef6218b5b remove old twisted/transcribe.py, now just wormhole.py 2016-05-24 00:01:22 -07:00
Brian Warner
3a062eaa26 bring scripts and tests up to date
* use wormhole instead of transcribe.py
* send() no longer waits
* get_verifier -> verify
* derive_key demands a length
2016-05-24 00:00:44 -07:00
Brian Warner
e2aa43d0a9 transit: expose desired key length 2016-05-24 00:00:21 -07:00
Brian Warner
2c64805ea1 fix input_code 2016-05-24 00:00:04 -07:00
Brian Warner
9bd5afe7df make close() always wait 2016-05-23 23:59:49 -07:00
Brian Warner
e11a6f8243 new connection management, test_wormhole passes 2016-05-23 22:53:26 -07:00
Brian Warner
7bcefa78e6 remove test_twisted, now in test_wormhole 2016-05-23 22:53:26 -07:00
Brian Warner
528092dd97 improve error signalling 2016-05-23 00:14:39 -07:00
Brian Warner
c88d6937c2 close(wait=True): wait for connection to be dropped 2016-05-22 18:45:50 -07:00
Brian Warner
c10fd98167 many tests working
* add "released" ack-response for "release" command, to sync w.close()
* move websocket URL to root
* relayurl= should now be a "ws://" URL
* many tests pass (except for test_twisted, which will be removed, and
  test_scripts)
* still moving integration tests from test_twisted to
  test_wormhole.Wormholes
2016-05-22 18:40:44 -07:00
Brian Warner
3da52b0a3e add 'mock', building out test_wormhole 2016-05-22 11:31:00 -07:00
Brian Warner
0ee56e12b0 change 'list' protocol, make room for nameplate attributes 2016-05-22 11:01:44 -07:00
Brian Warner
53bbcc33f6 new file, state-machine based 2016-05-20 18:49:20 -07:00
Brian Warner
181ef04a91 break out more message components, use SidedMessage 2016-05-20 16:39:59 -07:00
Brian Warner
05aa5ca76e WIP Wormhole 2016-05-20 13:51:05 -07:00
Brian Warner
3b86571de3 fix py3 2016-05-20 12:12:07 -07:00
Brian Warner
390cd08b53 better command/response names: allocate+allocated, claim+claimed 2016-05-20 11:35:30 -07:00
Brian Warner
6c5b517ad1 hush 2016-05-20 11:10:17 -07:00
Brian Warner
ce06d379d9 remove old tests 2016-05-20 11:09:45 -07:00
Brian Warner
0a14901e94 full coverage of websocket 2016-05-20 11:08:10 -07:00
Brian Warner
399efb374c don't close websocket when mailbox is deleted
This made sense for ServerSentEvent channels (which has no purpose once
the channel was gone), but not so much for websockets. And it prevented
testing duplicate-close.
2016-05-20 11:07:21 -07:00
Brian Warner
f044ef0efa tests almost good 2016-05-19 23:50:22 -07:00
Brian Warner
335ed00cb7 build out tests 2016-05-19 19:55:11 -07:00
Brian Warner
e39a8291e3 checkpointing: server roughed out 2016-05-19 18:09:17 -07:00
Brian Warner
0e72422ffa WIP 2016-05-19 14:18:49 -07:00
Brian Warner
5994eb11d4 WIP new proto 2016-05-18 00:16:46 -07:00
Brian Warner
2ea5d96290 Channels don't need "welcome" anymore 2016-05-17 17:35:44 -07:00
Brian Warner
a74b1b1e3a WIP: new server protocol 2016-05-16 22:04:25 -07:00
Brian Warner
5dd91c7311 test too-many-allocate, allocate+claim 2016-05-13 00:46:12 -07:00
Brian Warner
c4c0cf71eb add test 2016-05-13 00:43:59 -07:00
Brian Warner
1198977e06 SCHEMA CHANGE: channelids are now strs, not ints
This will enable the use of large randomly-generated hex or base32
channelids, for post-startup or resumed-connection channels.
2016-05-13 00:37:53 -07:00
Brian Warner
c14e982ae7 rendezvous: allow multiple channels per connection 2016-05-12 18:01:56 -07:00
Brian Warner
31491bb939 update docs 2016-05-12 17:48:26 -07:00
Brian Warner
85dc0fd41b change server API: "release" instead of "deallocate" 2016-05-12 17:46:15 -07:00
Brian Warner
2c2cf29564 update comment: sent -> server_tx 2016-05-12 17:12:04 -07:00
Brian Warner
bdc9066c23 rendezvous: change add_listener signature
Pass in a handle and a pair of functions, rather than an object with two
well-known methods. This should make it easier to subscribe to multiple
channels in the future.
2016-05-12 17:03:57 -07:00
Brian Warner
a34fb2a98b remove plain-HTTP (non-WebSocket) rendezvous server 2016-05-12 16:56:19 -07:00
Brian Warner
104ef44d53 provide wormhole() as a function, rather than a class constructor
You must always provide a reactor= argument. In the future, omitting the
reactor= argument is how you ask for a blocking Wormhole.
2016-05-12 16:45:54 -07:00
Brian Warner
d87aba40e4 rename _confirm message to just "confirm" 2016-05-12 16:45:54 -07:00
Brian Warner
d0ef53fc4d remove phase= from the Wormhole API
Phase are now implicit and numbered.
2016-05-12 16:45:54 -07:00
Brian Warner
501af4b4ec rename send_data/get_data to just send/get 2016-05-12 16:45:54 -07:00
Brian Warner
49785008bb remove blocking implementation: it will return
It will return as a crochet-based wrapper around the Twisted
implementation.
2016-05-12 16:45:54 -07:00
Brian Warner
5501a6bf1c simplify timing, add msgid 2016-05-06 18:53:28 -07:00
Brian Warner
5530c33185 rdv_ws: send acks for each message
but only if the client is modern enough to include "id" in the message,
which lets us avoid sending acks to an 0.7.5 client (which would cause
them to abort, they don't like unrecognized server messages).

The acks let the client learn the server_rx time of messages that
terminate on the server, like "allocate" and "claim".
2016-05-06 18:51:28 -07:00
Brian Warner
644c7c6840 DB schema change: add/store/return msgid
This enables dump-timing to correlate sender logs with receiver logs.
2016-05-06 18:29:58 -07:00
Brian Warner
8a80242532 rdv_ws: deliver "server_tx", not "sent"
Update twisted/transcribe.py to accept it, update tests.
2016-05-06 18:29:58 -07:00
Brian Warner
d2dfc325d8 deliver stored server_rx to clients
This enables the "dump-timing" tools to display more information.
2016-05-06 18:29:58 -07:00
Brian Warner
959ab4baca rdv_ws: get server_rx at a better place 2016-05-06 18:29:58 -07:00
Brian Warner
d9ba55621b Channel.add_message(server_rx=): add new arg 2016-05-06 18:29:58 -07:00
Brian Warner
fe2dfc1a35 DB schema change: rename 'when' to 'server_rx' 2016-05-06 18:29:58 -07:00
Brian Warner
cd9f6e4377 ignore unknown rendezvous messages
I should have added this earlier, so 0.7.5 would be tolerant of new
server messages.
2016-05-06 18:29:19 -07:00
Brian Warner
a671982ab0 rdv: add comment 2016-05-05 19:13:05 -07:00
Brian Warner
58e95cff0d rdv_ws: avoid magic method-name concatenation 2016-05-05 19:11:21 -07:00
Brian Warner
a086effd52 cmd_send: time import of tor_manager too 2016-05-05 19:10:01 -07:00
Brian Warner
cfbd418898 rendezvous: minor refactoring 2016-05-05 18:21:06 -07:00
Brian Warner
8e664fdfcd timing.py: record finish(when) correctly 2016-04-30 15:48:43 -07:00
Brian Warner
24e52c0320 rewrite timing instrumentation: use context managers 2016-04-29 14:27:29 -07:00
Brian Warner
b70c2f8868 Make get_verifier() wait for _confirm to arrive
This improves the error behavior when --verify is used but there's a
WrongPasswordError: the mismatch is detected before the verifiers are
displayed or confirmation is requested.

It requires that the far end sends a "_confirm" message, which was
introduced in release 0.6.0. Use with older versions (if it doesn't
break for other reasons) will cause a hang.

This patch also deletes test_twisted.Basic.test_verifier_mismatch, since
both sides now detect this on their own. It changes
test_wrong_password() too, since we might now notice the error during
send_data (previously we'd only see it in get_data).
2016-04-25 19:01:55 -07:00
Brian Warner
c017de5e4b cosmetic cleanups to error messages 2016-04-25 18:24:39 -07:00
Brian Warner
2a6767ee6f cmd_receive: internal error-handling cleanups 2016-04-25 18:24:18 -07:00
Brian Warner
a181a3fb35 WrongPasswordError: display docstring in str() 2016-04-25 18:16:08 -07:00
Brian Warner
2f6caa04d3 test_scripts.Cleanup: new test
This asserts that we deallocate the rendezvous channel, even when we
terminate early due to errors.
2016-04-25 17:53:00 -07:00
Brian Warner
7e8bfe314d Call w.close() exactly once, in both success and error cases.
One downside is that we keep the wormhole channel allocated longer (we
have to finish the file transfer before we can deallocate it, which
could take a while for large files). Maybe we can fix this in the
future.
2016-04-25 17:53:00 -07:00
Brian Warner
34116c7b1f CLI: document and return correct errors
Also clean up test_scripts.PregeneratedCode:

* fetch results from both sides at the same time
* only check rc when using a subprocess, since the direct call doesn't
  use rc=0 anymore
* no need to cancel the other side's Deferred when one errors
* provide more information if stderr was non-empty
2016-04-25 17:52:59 -07:00
Brian Warner
e4a19748db CLI: don't catch+wrap WrongPasswordError
Also remove .explain, now that we no longer wrap it in TransferError
2016-04-25 17:52:59 -07:00
Brian Warner
b96b052c96 start on cleanups: error catching in CLI dispatch 2016-04-25 17:52:59 -07:00
Brian Warner
a4c1ba9e4e transcribe: stop automatically doing close() on error
And provide a close() that can live at the end of a Deferred chain, so
callers can do d.addBoth(w.close).

I like auto-close-on-error in general, but I'm removing it so I can
clean up the error-handling pathways. It will probably come back later.
The constraint is that it must be possible to wait on the return
Deferred that close() gives you (to synchronize tests, or keep the CLI
program running long enough to deallocate the channel) even if something
else (and error handler) called close() earlier. This will require
either a OneShotObserverList, or keeping a "deallocated" Deferred around
in case more callers want to wait on it later.
2016-04-25 17:50:52 -07:00
Brian Warner
8d0bcf9f82 transcribe._sleep: make it usable from deallocate()
If we're closing because of an error, we need to sleep through the old
error, to be able to wait for the "deallocated" message. This might want
to be different: maybe clear the error first, or store the errors in a
list and sleep until a second error happens.
2016-04-25 17:34:57 -07:00
Brian Warner
4eaf88d7d2 cmd: remove _twisted suffix from function names
No longer necessary now that all commands are twisted-based.
2016-04-24 22:49:18 -07:00
Brian Warner
b0da2a9ac7 cmd_send: fold helper routines back into main function
These were split out to make the blocking- and twisted- based
implementations share some code, but now that we're down to just
Twisted, it's clearer to merge them back in.
2016-04-24 22:46:21 -07:00
Brian Warner
35639dafed cmd_send: rearrange functions, no code changes 2016-04-24 22:40:25 -07:00
Brian Warner
754cabbdd8 Fail better when input-code is interrupted
Hitting Control-C (which sends SIGINT) while we're waiting in the
readline-based input_code() function didn't shut down the process
properly: the reactor would wait for the readline thread to exit, which
wouldn't happen until it finished getting a code, which requires the
user to hit Return. I haven't found a good way to force the thread to
exit, or to synthetically inject a newline into stdin. So my compromise
is to tell the user that they need to hit Return to finish interrupting
the command.

See the _warn_readline() function for a list of other potential
approaches.
2016-04-24 22:20:27 -07:00
Brian Warner
e8d3689a3a runner: display TransferErrors better
These are known failures (like file-not-found, transfer rejected, etc).
Display the error message, but not a traceback.
2016-04-24 12:10:51 -07:00
Brian Warner
86edf96412 switch to tqdm for nicer CLI progress bars 2016-04-24 12:04:05 -07:00
Brian Warner
16c6c0977e progress: make it easier to change display width 2016-04-23 22:43:42 -07:00
Brian Warner
1e7c714453 CLI: don't hide errors so much 2016-04-20 22:36:43 -07:00
Brian Warner
1b16127cad fix --tor
* twisted/transcribe: call correct tor_manager method
* tor_manager: remove now-unused web agent endpoint factory
2016-04-20 22:34:58 -07:00
Brian Warner
b2c3f49038 unsplit txwormhole step 2: edit files 2016-04-20 19:18:41 -07:00
Brian Warner
0ae8463331 unsplit txwormhole step 1: move files 2016-04-20 19:15:33 -07:00
Brian Warner
7c45f3d472 unsplit wormhole_server step 2: edit files 2016-04-20 19:15:33 -07:00
Brian Warner
ec13404fca unsplit wormhole_server step 1: move files 2016-04-20 19:15:33 -07:00
Brian Warner
85b6264826 unsplit cli step 2: edit files 2016-04-20 19:15:33 -07:00
Brian Warner
a3c836bcd3 unsplit cli step 1: move files 2016-04-20 18:54:36 -07:00
Brian Warner
7a5a99a1a8 unsplit tests step 3: modify files 2016-04-20 18:54:10 -07:00
Brian Warner
fc33ea41ff unsplit tests step 2: delete test_load 2016-04-20 18:51:03 -07:00
Brian Warner
c890a850aa unsplit tests step 1: move files 2016-04-20 18:44:33 -07:00
Brian Warner
3b215c106a use "hkdf" from PyPI instead of wormhole.hkdf 2016-04-18 16:49:29 -07:00
Brian Warner
95706c752c move tests step 1: rename files 2016-04-18 16:45:03 -07:00
Brian Warner
17613ce8c1 move hkdf out of util/, remove now-empty directory 2016-04-18 16:45:03 -07:00
Brian Warner
36e63e2347 split wormhole_cli step 2: fix imports, setup.py 2016-04-18 16:43:18 -07:00
Brian Warner
2e7bb1a8f1 split wormhole_cli step 1: move files 2016-04-18 16:43:18 -07:00
Brian Warner
1688da74d9 split txwormhole step 2: fix imports 2016-04-18 16:41:56 -07:00
Brian Warner
323175ddfe split txwormhole step 1: move files 2016-04-18 16:41:52 -07:00
Brian Warner
0b162af09e move ipaddrs.py from wormhole.util to wormhole.twisted 2016-04-18 16:24:13 -07:00
Brian Warner
87266f1292 split wormhole_server step 3: fix tests 2016-04-18 16:18:51 -07:00
Brian Warner
190ce2c027 split wormhole_server step 2: new files, fix imports
remove server commands from old src/wormhole/scripts/runner.py
2016-04-18 16:18:47 -07:00
Brian Warner
bde4696a8b split wormhole_server step 1: move files 2016-04-18 16:18:45 -07:00
Brian Warner
1a455c05f5 remove wormhole.twisted.util port-allocation functions 2016-04-18 16:16:27 -07:00
Brian Warner
e20026488a remove unused observer.py 2016-04-18 16:16:27 -07:00
Brian Warner
a8446d2bc5 merge transit_common into twisted.transit 2016-04-18 16:16:27 -07:00
Brian Warner
db137c26e5 remove blocking.transit 2016-04-18 15:52:29 -07:00
Brian Warner
4e937c2100 rename cmd_send_twisted to cmd_send, same for cmd_receive 2016-04-18 15:52:29 -07:00
Brian Warner
a1033b06a3 merge send_common into cmd_send_twisted 2016-04-18 15:52:29 -07:00
Brian Warner
9b53bb96c6 merge cmd_receive_blocking into cmd_receive_twisted 2016-04-18 15:52:29 -07:00
Brian Warner
8c67a98259 merge test_transit.py into test_server.py 2016-04-18 15:52:29 -07:00
Brian Warner
68b22bec97 remove --twisted, stop using blocking-flavor scripts 2016-04-18 15:52:18 -07:00
Brian Warner
94a3be91b2 add tab-completion to twisted-style input_code() 2016-04-15 17:27:32 -07:00
Brian Warner
589226f076 tor: add comments, let it pick its own control port 2016-03-28 02:26:11 -07:00
Brian Warner
618706681a record time spent importing code 2016-03-28 02:25:40 -07:00
Brian Warner
9630ab9aae find-tor: record more detailed timings 2016-03-28 02:25:32 -07:00
Brian Warner
12c4c51fd8 record tor-launch time in DebugTiming 2016-03-28 02:25:01 -07:00
Brian Warner
01ed9902de add --tor support 2016-03-28 02:25:01 -07:00
Brian Warner
ed6e5ff169 get a TorManager working 2016-03-28 02:25:01 -07:00
Brian Warner
049fac01db tolerate trailing slash on "wormhole send dirname/"
Previously, the trailing slash would cause the receiving side to get an
empty-named directory.
2016-03-24 08:46:29 -07:00
Brian Warner
c5415495c0 dump-timing: store server-sent time too
Adjust dump-timing to ignore the extra data, for now. Also do some
general instrumentation cleanup.
2016-03-03 18:03:27 -08:00
Brian Warner
aaf4e70a33 remove obsolete TODO 2016-03-03 17:56:15 -08:00
Brian Warner
626732b730 relay_server: include 'sent' timestamp with each message
This will be used by client-side timeline instrumentation, to guide
performance improvements.
2016-03-03 17:52:59 -08:00
Brian Warner
e342236b7d relay_server: internal rearrangement
Construct the response in the render_* method, rather than
add_messages(), to prepare for adding server timestamps. Use
json_response() everywhere.
2016-03-03 16:57:44 -08:00
Brian Warner
9d7b9dd8d2 add --no-listen, for debugging 2016-03-03 14:52:14 -08:00
Brian Warner
418fe9419e twisted: use persistent connections, slight speedup
This uses a single TCP connection to the relay server for all
requests (although it probably uses a second one for the downstream
EventSource feed). This should squeeze out some of the round-trip times.
2016-03-03 13:39:09 -08:00
Brian Warner
4f5e037d39 cmd-twisted: report exceptions better
The previous scheme would swallow the real traceback, making debugging
difficult.
2016-03-03 12:33:26 -08:00
Brian Warner
08a5e6043a twisted.transit: tolerate the lack of a listener
In Tor mode, there is no local listener. Eventually we'll add an Onion
Service listener, but it's not guaranteed that we can run one.
2016-03-03 12:32:26 -08:00
Brian Warner
8d92b40139 twisted.transcribe: use same Agent for ReconnectingEventSource
This will be especially important when we add Tor support.
2016-03-03 12:29:57 -08:00
Brian Warner
be2c66a5f5 transit: ignore errors on sockets we were about to close anyways 2016-03-02 14:28:04 -08:00
Brian Warner
26f512fba4 add --twisted to use the twisted CLI flavor 2016-03-02 01:07:37 -08:00
Brian Warner
6d3d0c1cb3 unify synchronous calling of twisted CLI commands 2016-03-02 00:51:21 -08:00
Brian Warner
4d405c8cef cmd_send_twisted: fix display message ordering
By creating the ProgressingFileSender too early, it printed a progress
message before the "Sending" line.
2016-03-02 00:50:22 -08:00
Brian Warner
df2384bea2 twisted.transit: move FileConsumer into RecordPipe
This adds an expected= argument to Connection.connectConsumer(), which
then returns a Deferred that fires when enough bytes have been written
to the consumer. It also adds Connection.writeToFile(), a helper method
that writes bytes to a filehandle.
2016-03-02 00:48:43 -08:00
Brian Warner
7234e25897 twisted.transit: handle multiple records in one chunk
I made the classic dataReceived() mistake, and exited the function after
delivering the first record. Keep at it until there are no complete
records left.
2016-03-02 00:48:43 -08:00
Brian Warner
8d82726c51 add DebugTiming object, --dump-timing= option
This writes timeline data to a .json file, which can be examined later
to find likely candidates for optimization.
2016-03-01 18:23:06 -08:00
Brian Warner
84def8a54b add some inlineCallbacks for simplicity
This control flow was getting too hairy.
2016-03-01 18:22:03 -08:00
Brian Warner
fd143caded tests.ServerBase: print message when threadpool is not idle
The previous commits improve test failures by dropping relay connections
at shutdown, and flunking a test quickly when one client fails but the
other one hangs.

If that doesn't work (say, some client has a time.sleep(), or other
stall that isn't affected by the relay shutdown), we'll be left with an
active thread holding that hanging client.

This patch adds a check to wormhole.test.common.ServerBase.tearDown that
looks for active threads, waits a second (after stopService), then
checks the threadpool again. If the threadpool is empty, everything is
fine. If not, it prints a message (to stdout) to inform the impatient
user why the test is probably hanging.
2016-03-01 17:07:48 -08:00
Brian Warner
b1dae14e6d test_scripts: handle hangs in one client
When test_scripts ran two clients at the same time, an error in one
could leave the other hanging (in a thread). One Deferred would errback,
the other would hang. Tests wait on one Deferred at a time, so if we're
unlucky and were waiting on the hanging Deferred (instead of the
erroring one), we'll wait forever, or at least until the default test
timeout of 180 seconds.

This adds an errback to notice when either client has errored, and
cancels the other Deferred, so it doesn't matter which one we wait upon
first.
2016-03-01 17:07:43 -08:00
Brian Warner
3fc3a563bf relay_server: disconnect clients upon shutdown 2016-03-01 17:07:37 -08:00
Brian Warner
0771aae7c7 server: Relay wasn't pruning channels
I forgot to hook it up to the service parent, so the timer was never
started.
2016-02-29 08:59:53 -08:00
Brian Warner
c225d57f8c cmd_receive_twisted.py: twisted-based implementation 2016-02-29 07:31:34 -08:00
Brian Warner
01064325a2 cmd_receive: refactor (slight message changes)
This prepares the way for a twisted-based implementation.
2016-02-29 07:30:40 -08:00
Brian Warner
6654efb429 move describe() from Transit to RecordPipe 2016-02-28 01:42:46 -08:00
Brian Warner
1903c58248 ipaddrs: return 127.0.0.1 if everything else fails
This helps the windows tests where ipaddrs currently fails entirely.
2016-02-27 17:37:12 -08:00
Brian Warner
ca06e95bbd test_blocking: avoid using real hints 2016-02-27 17:29:04 -08:00
Brian Warner
8067acbf82 cmd_receive: close the file before renaming
I'm always forgetting this one. It's more obvious on windows.
2016-02-27 17:20:43 -08:00
Brian Warner
ed1eb06ae8 blocking/transit: use descriptive error message 2016-02-27 14:48:12 -08:00
Brian Warner
1ff0792b32 test_scripts: prep for windows compatibility
newlines, os.mkfifo errors, JSON type differences
2016-02-27 14:46:38 -08:00
Brian Warner
14dcfeed73 tolerate lack of readline at runtime
'readline' is part of the python stdlib, so declaring a dependency on it
doesn't help. It doesn't exist on windows, and the pypi 'readline'
module doesn't work on windows. So instead, just attempt to import
readline, and if that fails, fall back to a non-completion flavor.
2016-02-27 14:16:58 -08:00
Brian Warner
b7319f90c8 windows "route.exe" is not absolute, and that's ok 2016-02-27 14:15:36 -08:00
Brian Warner
dbba482c62 cmd_receive_blocking.py: refactor 2016-02-17 21:35:53 -08:00
Brian Warner
e6fba34570 start on twisted receive: move old files into new homes 2016-02-17 19:25:19 -08:00
Brian Warner
7f056ca075 send-twisted: set transit key before sending phase1
This ensures that we'll be ready for them. Previously there was a race
between us revealing the direct hints to the peer, and us setting the
transit key (thus allowing us to check inbound handshake requests). The
Transit instance didn't handle the race, causing errors to be thrown
when the other side connected quickly.
2016-02-17 19:02:36 -08:00
Brian Warner
aa27bfd32c add twisted form of sender
Currently this is only invokable from tests.
2016-02-17 19:02:36 -08:00
Brian Warner
7ceffd783a add more assertions around transit_key 2016-02-17 19:02:35 -08:00
Brian Warner
3ffceff9d5 send-blocking: set transit key before sending phase1
This ensures that we'll be ready for them. Previously there was a race
between us revealing the direct hints to the peer, and us setting the
transit key (thus allowing us to check inbound handshake requests). The
Transit instance handles this race (with an interlock on the transit
key), but it's still nicer to do it cleanly.

This exposed a new race in Transit, where the inbound connection would
complete before transit.connect() had been called. The previous commit
adds an interlock to wait for that too. Until this change, the transit
key lock was covering that one up.
2016-02-17 19:02:35 -08:00
Brian Warner
142f3fc154 send-blocking: don't create Transit unless we need it 2016-02-17 19:02:35 -08:00
Brian Warner
dba42aff01 blocking transit: tolerate inbound connections before connect() starts 2016-02-17 19:02:35 -08:00
Brian Warner
369854b4cc test build_phase1_data 2016-02-17 18:07:35 -08:00
Brian Warner
79decea9ea rearrange scripts: make room for twisted 2016-02-17 16:26:03 -08:00
Brian Warner
d36d1cb063 runner.py: new approach to dispatching 2016-02-17 16:03:30 -08:00
Brian Warner
3b447df0f4 move argparser out to a separate module 2016-02-17 15:55:11 -08:00
Brian Warner
5d572137f4 improve test error message 2016-02-17 14:00:03 -08:00
Brian Warner
fd7d1b97d4 test scripts in a thread, not a subprocess, mostly 2016-02-17 14:00:01 -08:00
Brian Warner
903129f4a2 add --hide-progress, mostly for tests 2016-02-17 13:58:41 -08:00
Brian Warner
c5b2800a3e runner: strictly use cwd/stdout/stderr from 'args'
This will make it easier to test the scripts in a controlled fashion.
2016-02-17 13:53:20 -08:00
Brian Warner
e2f3bebe38 allow --relay-helper="" to disable relay
test_scripts now uses this to avoid accidentally using a relay
2016-02-17 13:53:18 -08:00
Brian Warner
d14d35f3cd cmd_send_blocking: close the transit when we're done 2016-02-17 13:52:26 -08:00